coupon-details.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <view class="container clearfix">
  3. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading="true"
  4. :loadingType="5" />
  5. <view class="container-content tui-skeleton" v-else>
  6. <view class="empty-container" v-if="!coupon">
  7. <image class="empty-container-image" :src="StaticUrl + '/icon/icon-coupon-empty@2x.png'"></image>
  8. <text class="error-text">暂无优惠券~</text>
  9. </view>
  10. <template v-else>
  11. <view class="container-list">
  12. <view class="coupon-list">
  13. <view class="list-cell-le">
  14. <template v-if="coupon.couponTextFlag === 1">
  15. <view class="coupon-maxMoney"> <text class="small">¥</text> {{ coupon.couponAmount }} </view>
  16. <view class="coupon-minMoney"> 满{{ coupon.touchPrice }}可用 </view>
  17. </template>
  18. <template v-else>
  19. <view class="coupon-maxMoney six"> <text class="small">¥</text> {{ coupon.couponText }} </view>
  20. </template>
  21. </view>
  22. <view class="list-cell-ri">
  23. <view class="list-cell-top">
  24. <view class="list-cell-type">
  25. <view class="list-cell-tags">
  26. <template v-if="coupon.moneyCouponFlag == 1">
  27. <text class="tags"
  28. v-if="coupon.moneyCouponType == 1">意向{{ coupon.couponType | TypeFormat }}</text>
  29. <text class="tags" v-else>定向{{ coupon.couponType | TypeFormat }}</text>
  30. </template>
  31. <template v-else>
  32. <text class="tags">{{ coupon.couponType | TypeFormat }}</text>
  33. </template>
  34. </view>
  35. <view class="list-cell-texts">
  36. <text v-if="coupon.couponType == 0">
  37. {{
  38. coupon.productType && coupon.productType == 1
  39. ? '全商城商品通用'
  40. : coupon.couponName
  41. }}
  42. </text>
  43. <text v-if="coupon.couponType == 1">
  44. {{ coupon.categoryType == 1 ? coupon.couponName : coupon.couponName }}
  45. </text>
  46. <text v-if="coupon.couponType == 3">仅限购买店铺【{{ coupon.shopName }}】的商品</text>
  47. <text v-if="coupon.couponType == 4 || coupon.couponType == 2">全商城商品通用</text>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="container-button">
  56. <view v-if="coupon.moneyCouponFlag === 1" class="button" @click="createCouponRecord(coupon)">
  57. ¥{{ coupon.moneyCouponPrice }}购买</view>
  58. <view v-else class="button" @click="handeleReceiveCoupon(coupon)">领取优惠券</view>
  59. </view>
  60. </template>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import { mapState, mapMutations } from 'vuex'
  66. import wxLogin from '@/common/config/wxLogin.js'
  67. import authorize from '@/common/config/authorize.js'
  68. import { COUPON_TEXT_MAP } from '@/utils/coupon.share.js'
  69. import payMixins from '@/mixins/payMixins.js'
  70. export default {
  71. mixins: [payMixins],
  72. data() {
  73. return {
  74. StaticUrl: this.$Static,
  75. isIphoneX: this.$store.state.isIphoneX,
  76. coupon: {},
  77. coupinList: [],
  78. payAmount: 100, //支付金额
  79. skeletonShow: true,
  80. isReceiveLoading: false, //领券操作状态
  81. param: {
  82. shareUserId: 0,
  83. userId: 0,
  84. couponId: 0,
  85. source: 1
  86. }
  87. }
  88. },
  89. onLoad(option) {
  90. wxLogin.wxLoginAuthorize()
  91. this.param.shareUserId = option.shareUserId
  92. this.param.couponId = option.couponId
  93. // #ifdef MP-WEIXIN
  94. // 绑定分享参数
  95. console.log('绑定分享参数', { query: `couponId=${option.couponId}&shareUserId=${option.shareUserId}` })
  96. wx.onCopyUrl(() => {
  97. return { query: `couponId=${option.couponId}&shareUserId=${option.shareUserId}` }
  98. })
  99. // #endif
  100. this.initCouponDetail(this.param.couponId)
  101. },
  102. filters: {
  103. TypeFormat(value) {
  104. switch (value) {
  105. case 0:
  106. return '活动券'
  107. break
  108. case 1:
  109. return '品类券'
  110. break
  111. case 2:
  112. return '用户专享券'
  113. break
  114. case 3:
  115. return '店铺券'
  116. break
  117. case 4:
  118. return '新用户券'
  119. break
  120. }
  121. }
  122. },
  123. computed: {
  124. ...mapState(['hasLogin', 'userInfo', ])
  125. },
  126. methods: {
  127. async initCouponDetail(couponId) {
  128. // 初始化优惠券信息
  129. try {
  130. const res = await this.ProductService.QueryCouponDetail({ couponId: couponId })
  131. this.coupon = res.data
  132. setTimeout(() => {
  133. this.skeletonShow = false
  134. }, 500)
  135. } catch (e) {
  136. console.log('初始化优惠券信息异常~')
  137. }
  138. },
  139. //购买优惠券
  140. createCouponRecord(coupon) {
  141. // 生成购买优惠券记录Id
  142. if (!this.hasLogin) {
  143. const pages = getCurrentPages()
  144. const page = pages[pages.length - 1]
  145. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  146. this.$api.redirectTo('/pages/login/login')
  147. } else {
  148. this.$api.navigateTo(`/pages/user/pay/card-coupon-under?amount=${coupon.moneyCouponPrice}`)
  149. // this.WeChatCouponRecord(coupon)
  150. }
  151. },
  152. // 调用查询购买
  153. async WeChatCouponRecord(coupon) {
  154. try {
  155. const userInfo = await this.$api.getStorage()
  156. const data = await this.PayService.WeChatCouponRecord({
  157. userId: userInfo.userId,
  158. couponId: coupon.couponId
  159. })
  160. this.MiniWxPayFor(data.data.couponRecordId)
  161. } catch (error) {
  162. this.$util.msg(error.msg, 2000)
  163. }
  164. },
  165. // 购买优惠券支付
  166. async MiniWxPayFor(couponRecordId) {
  167. const wechatcode = await authorize.getCode('weixin')
  168. const userInfo = await this.$api.getStorage()
  169. const params = {
  170. userId: userInfo.userId,
  171. couponId: this.param.couponId,
  172. couponRecordId: couponRecordId,
  173. payType: 'XCX',
  174. code: wechatcode,
  175. source: 1 //支付来源 1 小程序 2 WWW
  176. }
  177. this.weChatMiniCouponWxPay(params, 'Um_Event_shareCouponPay', '分享优惠券', '线上支付优惠券', this.couponId,
  178. this.userId)
  179. },
  180. async handeleReceiveCoupon(coupon) {
  181. // 点击优惠券领取按钮,
  182. if (this.hasLogin) {
  183. if (this.isReceiveLoading) {
  184. return
  185. }
  186. const userInfo = await this.$api.getStorage()
  187. this.param.userId = userInfo.userId
  188. this.getRceiveCoupon(this.param)
  189. } else {
  190. const pages = getCurrentPages()
  191. const page = pages[pages.length - 1]
  192. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  193. this.$api.redirectTo('/pages/login/login')
  194. }
  195. },
  196. // 执行领取优惠券
  197. async getRceiveCoupon(params) {
  198. try {
  199. await this.ProductService.ReceiveCoupon(params)
  200. this.isReceiveLoading = true
  201. this.$util.msg('领取成功', 1500, true, 'success')
  202. setTimeout(() => {
  203. this.isReceiveLoading = false
  204. this.$api.reLaunch('/pages/user/coupon/coupon')
  205. }, 1500)
  206. } catch (error) {
  207. this.$util.msg(error.msg, 2000)
  208. this.isReceiveLoading = false
  209. }
  210. }
  211. },
  212. onShareAppMessage(res) {
  213. //分享优惠券
  214. if (res.from === 'button') {
  215. // 来自页面内转发按钮
  216. }
  217. const coupon = this.coupon
  218. const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length)
  219. const shareTitle = coupon.moneyCouponFlag === 1 ?
  220. `${coupon.moneyCouponPrice}抵${coupon.couponAmount},限时优惠券等您抢购~` : COUPON_TEXT_MAP[randomIndex]
  221. return {
  222. title: coupon.shareCouponTopic ? `${coupon.shareCouponTopic}` : shareTitle,
  223. path: `pages/user/coupon/coupon-details?couponId=${coupon.couponId}&shareUserId=${this.param.shareUserId}`,
  224. imageUrl: coupon.shareCouponImage ? `${coupon.shareCouponImage}` : 'https://static.caimei365.com/app/img/icon/icon-shareCoupon@2x.png'
  225. }
  226. },
  227. onHide() {
  228. // 取消绑定分享参数
  229. wx.offCopyUrl()
  230. },
  231. onShow() {
  232. }
  233. }
  234. </script>
  235. <style lang="scss">
  236. page {
  237. background-color: #FFFFFF;
  238. }
  239. .container {
  240. width: 100%;
  241. height: auto;
  242. }
  243. .empty-container-image {
  244. width: 260rpx;
  245. height: 260rpx;
  246. margin-top: -300rpx;
  247. }
  248. .container-list {
  249. box-sizing: border-box;
  250. padding: 24rpx;
  251. .toIndexPage {
  252. bottom: 390rpx;
  253. }
  254. .coupon-list {
  255. width: 100%;
  256. height: 200rpx;
  257. margin-bottom: 24rpx;
  258. box-sizing: border-box;
  259. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  260. background-size: cover;
  261. position: relative;
  262. .list-cell-le {
  263. width: 224rpx;
  264. height: 100%;
  265. box-sizing: border-box;
  266. padding: 37rpx 0;
  267. float: left;
  268. .coupon-maxMoney {
  269. width: 100%;
  270. height: 78rpx;
  271. line-height: 78rpx;
  272. font-size: 56rpx;
  273. color: #ffffff;
  274. text-align: center;
  275. &.six{
  276. margin-top: 20rpx;
  277. }
  278. .small {
  279. font-size: $font-size-24;
  280. }
  281. }
  282. .coupon-minMoney {
  283. width: 100%;
  284. height: 33rpx;
  285. line-height: 33rpx;
  286. font-size: $font-size-24;
  287. color: #ffffff;
  288. text-align: center;
  289. }
  290. }
  291. .list-cell-ri {
  292. width: 478rpx;
  293. height: 100%;
  294. box-sizing: border-box;
  295. padding: 20rpx 24rpx 0 24rpx;
  296. float: right;
  297. .list-cell-top {
  298. width: 100%;
  299. height: 121rpx;
  300. float: left;
  301. border-bottom: 1px solid #e1e1e1;
  302. .list-cell-type {
  303. width: 100%;
  304. height: 100%;
  305. float: left;
  306. .list-cell-tags {
  307. width: 100%;
  308. height: 32rpx;
  309. margin-bottom: 7rpx;
  310. .tags {
  311. display: inline-block;
  312. padding: 0 10rpx;
  313. height: 32rpx;
  314. line-height: 32rpx;
  315. background-color: #ffdcce;
  316. color: #f94b4b;
  317. font-size: $font-size-20;
  318. border-radius: 8rpx;
  319. text-align: center;
  320. float: left;
  321. }
  322. }
  323. .list-cell-texts {
  324. width: 100%;
  325. height: auto;
  326. line-height: 35rpx;
  327. text-overflow: ellipsis;
  328. display: -webkit-box;
  329. word-break: break-all;
  330. -webkit-box-orient: vertical;
  331. -webkit-line-clamp: 2;
  332. overflow: hidden;
  333. font-size: 26rpx;
  334. color: #333333;
  335. }
  336. }
  337. .list-cell-btn {
  338. width: 128rpx;
  339. height: 100%;
  340. float: right;
  341. .icon-used {
  342. width: 100%;
  343. height: 100%;
  344. box-sizing: border-box;
  345. padding-top: 57rpx;
  346. .icon-used-btn {
  347. width: 128rpx;
  348. height: 48rpx;
  349. border-radius: 28rpx;
  350. line-height: 48rpx;
  351. font-size: $font-size-24;
  352. text-align: center;
  353. &.receive {
  354. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  355. color: #ffffff;
  356. }
  357. &.make {
  358. border: solid 1px #f94b4b;
  359. color: #f94b4b;
  360. }
  361. }
  362. }
  363. }
  364. }
  365. .list-cell-time {
  366. width: 100%;
  367. height: 58rpx;
  368. line-height: 58rpx;
  369. text-align: left;
  370. font-size: $font-size-20;
  371. color: #999999;
  372. }
  373. }
  374. }
  375. }
  376. .container-button {
  377. width: 100%;
  378. height: 90rpx;
  379. margin-top: 190rpx;
  380. .button {
  381. width: 600rpx;
  382. height: 90rpx;
  383. text-align: center;
  384. background: $btn-confirm;
  385. line-height: 90rpx;
  386. font-size: $font-size-30;
  387. color: #ffffff;
  388. margin: 0 auto;
  389. border-radius: 45rpx;
  390. }
  391. }
  392. </style>