coupon-details.vue 16 KB

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