coupon-details.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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({ userId: userInfo.userId,
  152. couponId: coupon.couponId })
  153. this.MiniWxPayFor(data.data.couponRecordId)
  154. } catch (error) {
  155. this.$util.msg(error.msg, 2000)
  156. }
  157. },
  158. // 购买优惠券支付
  159. async MiniWxPayFor(couponRecordId) {
  160. const wechatcode = await authorize.getCode('weixin')
  161. const userInfo = await this.$api.getStorage()
  162. const params = {
  163. userId: userInfo.userId,
  164. couponId: this.param.couponId,
  165. couponRecordId: couponRecordId,
  166. payType: 'XCX',
  167. code: wechatcode,
  168. source: 1 //支付来源 1 小程序 2 WWW
  169. }
  170. this.weChatMiniCouponWxPay(params, 'Um_Event_shareCouponPay', '分享优惠券', '线上支付优惠券', this.couponId,
  171. this.userId)
  172. },
  173. async handeleReceiveCoupon(coupon) {
  174. // 点击优惠券领取按钮,
  175. if (this.hasLogin) {
  176. if (this.isReceiveLoading) {
  177. return
  178. }
  179. const userInfo = await this.$api.getStorage()
  180. this.param.userId = userInfo.userId
  181. this.getRceiveCoupon(this.param)
  182. } else {
  183. const pages = getCurrentPages()
  184. const page = pages[pages.length - 1]
  185. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  186. this.$api.redirectTo('/pages/login/login')
  187. }
  188. },
  189. // 执行领取优惠券
  190. async getRceiveCoupon(params) {
  191. try {
  192. await this.ProductService.ReceiveCoupon(params)
  193. this.isReceiveLoading = true
  194. this.$util.msg('领取成功', 1500, true, 'success')
  195. setTimeout(() => {
  196. this.isReceiveLoading = false
  197. this.$api.reLaunch('/pages/user/coupon/coupon')
  198. }, 1500)
  199. } catch (error) {
  200. this.$util.msg(error.msg, 2000)
  201. this.isReceiveLoading = false
  202. }
  203. }
  204. },
  205. onShareAppMessage(res) {
  206. //分享优惠券
  207. if (res.from === 'button') {
  208. // 来自页面内转发按钮
  209. }
  210. const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length);
  211. return {
  212. title: COUPON_TEXT_MAP[randomIndex],
  213. path: `pages/user/coupon/coupon-details?couponId=${this.param.couponId}&shareUserId=${this.param.shareUserId}`,
  214. imageUrl: 'https://static.caimei365.com/app/img/icon/icon-shareCoupon@2x.png'
  215. }
  216. },
  217. onHide() {
  218. // 取消绑定分享参数
  219. wx.offCopyUrl()
  220. },
  221. onShow() {
  222. }
  223. }
  224. </script>
  225. <style lang="scss">
  226. page {
  227. background-color: #FFFFFF;
  228. }
  229. .container {
  230. width: 100%;
  231. height: auto;
  232. }
  233. .empty-container-image {
  234. width: 260rpx;
  235. height: 260rpx;
  236. margin-top: -300rpx;
  237. }
  238. .container-list {
  239. box-sizing: border-box;
  240. padding: 24rpx;
  241. .toIndexPage {
  242. bottom: 390rpx;
  243. }
  244. .coupon-list {
  245. width: 100%;
  246. height: 200rpx;
  247. margin-bottom: 24rpx;
  248. box-sizing: border-box;
  249. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  250. background-size: cover;
  251. position: relative;
  252. .list-cell-le {
  253. width: 224rpx;
  254. height: 100%;
  255. box-sizing: border-box;
  256. padding: 37rpx 0;
  257. float: left;
  258. .coupon-maxMoney {
  259. width: 100%;
  260. height: 78rpx;
  261. line-height: 78rpx;
  262. font-size: 56rpx;
  263. color: #ffffff;
  264. text-align: center;
  265. .small {
  266. font-size: $font-size-24;
  267. }
  268. }
  269. .coupon-minMoney {
  270. width: 100%;
  271. height: 33rpx;
  272. line-height: 33rpx;
  273. font-size: $font-size-24;
  274. color: #ffffff;
  275. text-align: center;
  276. }
  277. }
  278. .list-cell-ri {
  279. width: 478rpx;
  280. height: 100%;
  281. box-sizing: border-box;
  282. padding: 20rpx 24rpx 0 24rpx;
  283. float: right;
  284. .list-cell-top {
  285. width: 100%;
  286. height: 121rpx;
  287. float: left;
  288. border-bottom: 1px solid #e1e1e1;
  289. .list-cell-type {
  290. width: 286rpx;
  291. height: 100%;
  292. float: left;
  293. .list-cell-tags {
  294. width: 100%;
  295. height: 32rpx;
  296. margin-bottom: 7rpx;
  297. .tags {
  298. display: inline-block;
  299. padding: 0 10rpx;
  300. height: 32rpx;
  301. line-height: 32rpx;
  302. background-color: #ffdcce;
  303. color: #f94b4b;
  304. font-size: $font-size-20;
  305. border-radius: 8rpx;
  306. text-align: center;
  307. float: left;
  308. }
  309. }
  310. .list-cell-texts {
  311. width: 100%;
  312. height: auto;
  313. line-height: 35rpx;
  314. text-overflow: ellipsis;
  315. display: -webkit-box;
  316. word-break: break-all;
  317. -webkit-box-orient: vertical;
  318. -webkit-line-clamp: 2;
  319. overflow: hidden;
  320. font-size: 26rpx;
  321. color: #333333;
  322. }
  323. }
  324. .list-cell-btn {
  325. width: 128rpx;
  326. height: 100%;
  327. float: right;
  328. .icon-used {
  329. width: 100%;
  330. height: 100%;
  331. box-sizing: border-box;
  332. padding-top: 57rpx;
  333. .icon-used-btn {
  334. width: 128rpx;
  335. height: 48rpx;
  336. border-radius: 28rpx;
  337. line-height: 48rpx;
  338. font-size: $font-size-24;
  339. text-align: center;
  340. &.receive {
  341. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  342. color: #ffffff;
  343. }
  344. &.make {
  345. border: solid 1px #f94b4b;
  346. color: #f94b4b;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. .list-cell-time {
  353. width: 100%;
  354. height: 58rpx;
  355. line-height: 58rpx;
  356. text-align: left;
  357. font-size: $font-size-20;
  358. color: #999999;
  359. }
  360. }
  361. }
  362. }
  363. .container-button {
  364. width: 100%;
  365. height: 90rpx;
  366. margin-top: 190rpx;
  367. .button {
  368. width: 600rpx;
  369. height: 90rpx;
  370. text-align: center;
  371. background: $btn-confirm;
  372. line-height: 90rpx;
  373. font-size: $font-size-30;
  374. color: #ffffff;
  375. margin: 0 auto;
  376. border-radius: 45rpx;
  377. }
  378. }
  379. </style>