coupon-collection.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <view class="container clearfix">
  3. <view class="container-list" v-show="isRequest">
  4. <view class="empty-container" v-if="showEmpty">
  5. <image class="empty-container-image" :src="StaticUrl + '/icon/icon-coupon-empty@2x.png'"></image>
  6. <text class="error-text">暂无可领的优惠券~</text>
  7. </view>
  8. <template v-else>
  9. <view v-for="(coupon, index) in coupinList" :key="index" :id="coupon.id" class="coupon-list">
  10. <view class="list-cell-le">
  11. <view class="coupon-maxMoney"> <text class="small">¥</text> {{ coupon.couponAmount }} </view>
  12. <view class="coupon-minMoney"> 满{{ coupon.touchPrice }}可用 </view>
  13. </view>
  14. <view class="list-cell-ri">
  15. <view class="list-cell-top">
  16. <view class="list-cell-type">
  17. <view class="list-cell-tags">
  18. <template v-if="coupon.moneyCouponFlag == 1">
  19. <text class="tags" v-if="coupon.moneyCouponType == 1"
  20. >意向{{ coupon.couponType | TypeFormat }}</text
  21. >
  22. <text class="tags" v-else>定向{{ coupon.couponType | TypeFormat }}</text>
  23. </template>
  24. <template v-else>
  25. <text class="tags">{{ coupon.couponType | TypeFormat }}</text>
  26. </template>
  27. </view>
  28. <view class="list-cell-texts">
  29. <text v-if="coupon.couponType == 0">
  30. {{
  31. coupon.productType && coupon.productType == 1
  32. ? '全商城商品通用'
  33. : '仅可购买指定商品'
  34. }}
  35. </text>
  36. <text v-if="coupon.couponType == 1">
  37. {{ coupon.categoryType == 1 ? '仅限购买产品类商品' : '仅限购买仪器类商品' }}
  38. </text>
  39. <text v-if="coupon.couponType == 3"
  40. >仅限购买店铺【{{ coupon.shopName }}】的商品</text
  41. >
  42. <text v-if="coupon.couponType == 4 || coupon.couponType == 2">全商城商品通用</text>
  43. </view>
  44. </view>
  45. <view class="list-cell-btn">
  46. <view class="icon-used">
  47. <template v-if="coupon.moneyCouponFlag == 1">
  48. <view class="icon-used-text">购买</view>
  49. <view class="icon-used-btn buy" @click="toPayCoupon(coupon)"
  50. >¥{{ coupon.moneyCouponPrice }}</view
  51. >
  52. </template>
  53. <template v-else>
  54. <view
  55. class="icon-used-btn receive"
  56. v-if="coupon.couponBtnType == 0"
  57. @click="receiveCoupon(coupon)"
  58. >领取</view
  59. >
  60. <view
  61. class="icon-used-btn make"
  62. v-if="coupon.couponBtnType == 1"
  63. @click="toUseCoupon(coupon)"
  64. >去使用</view
  65. >
  66. </template>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  71. </view>
  72. </view>
  73. <!--加载loadding-->
  74. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  75. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text="nomoreText"></tui-nomore>
  76. <!--加载loadding-->
  77. </template>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import { mapState, mapMutations } from 'vuex'
  83. import authorize from '@/common/config/authorize.js'
  84. import couponTabs from '@/components/cm-module/coupon/tui-tabs.vue'
  85. export default {
  86. components: {
  87. couponTabs
  88. },
  89. data() {
  90. return {
  91. StaticUrl: this.$Static,
  92. isIphoneX: this.$store.state.isIphoneX,
  93. userIdentity: 0,
  94. listQuery: {
  95. userId: 0,
  96. pageNum: 1,
  97. pageSize: 10
  98. },
  99. coupinList: [],
  100. isRequest: false,
  101. showEmpty: false,
  102. nomoreText: '上拉显示更多',
  103. hasNextPage: false,
  104. loadding: false,
  105. pullUpOn: true,
  106. pullFlag: true,
  107. isReceiveLoading: false //领券操作状态
  108. }
  109. },
  110. onLoad() {},
  111. filters: {
  112. TypeFormat(value) {
  113. switch (value) {
  114. case 0:
  115. return '活动券'
  116. break
  117. case 1:
  118. return '品类券'
  119. break
  120. case 2:
  121. return '用户专享券'
  122. break
  123. case 3:
  124. return '店铺券'
  125. break
  126. case 4:
  127. return '新用户券'
  128. break
  129. }
  130. }
  131. },
  132. computed: {
  133. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity'])
  134. },
  135. methods: {
  136. async initGetStotage() {
  137. // 初始化
  138. const userInfo = await this.$api.getStorage()
  139. this.listQuery.userId = userInfo.userId ? userInfo.userId : 0
  140. this.userIdentity = userInfo.userIdentity ? userInfo.userIdentity : 0
  141. this.QueryCouponList()
  142. },
  143. QueryCouponList() {
  144. // 初始化查询优惠券列表
  145. this.coupinList = []
  146. this.listQuery.pageNum = 1
  147. this.ProductService.QueryCouponCollarList(this.listQuery)
  148. .then(response => {
  149. let data = response.data
  150. if (data.list && data.list.length > 0) {
  151. this.showEmpty = false
  152. this.hasNextPage = response.data.hasNextPage
  153. this.coupinList = data.list
  154. this.pullFlag = false
  155. setTimeout(() => {
  156. this.pullFlag = true
  157. }, 500)
  158. if (this.hasNextPage) {
  159. this.pullUpOn = false
  160. this.nomoreText = '上拉显示更多'
  161. } else {
  162. if (this.coupinList.length < 8) {
  163. this.pullUpOn = true
  164. } else {
  165. this.pullUpOn = false
  166. this.loadding = false
  167. this.nomoreText = '已至底部'
  168. }
  169. }
  170. } else {
  171. this.showEmpty = true
  172. }
  173. this.isRequest = true
  174. })
  175. .catch(error => {
  176. this.$util.msg(error.msg, 2000)
  177. })
  178. },
  179. getOnReachBottomData() {
  180. // 上滑加载分页
  181. this.listQuery.pageNum += 1
  182. this.ProductService.QueryCouponCollarList(this.listQuery)
  183. .then(response => {
  184. let data = response.data
  185. if (data.list && data.list.length > 0) {
  186. this.hasNextPage = data.hasNextPage
  187. this.coupinList = this.coupinList.concat(data.list)
  188. this.pullFlag = false // 防上拉暴滑
  189. setTimeout(() => {
  190. this.pullFlag = true
  191. }, 500)
  192. if (this.hasNextPage) {
  193. this.pullUpOn = false
  194. this.nomoreText = '上拉显示更多'
  195. } else {
  196. this.pullUpOn = false
  197. this.loadding = false
  198. this.nomoreText = '已至底部'
  199. }
  200. }
  201. })
  202. .catch(error => {
  203. this.$util.msg(error.msg, 2000)
  204. })
  205. },
  206. toPayCoupon(coupon) {
  207. // 点击购买优惠券,友盟埋点收集购买优惠券
  208. if (process.env.NODE_ENV != 'development') {
  209. this.$uma.trackEvent('Um_Event_userCouponCollectionBuy', {
  210. Um_Key_PageName: '领券中心',
  211. Um_Key_EvenName: '购买优惠券',
  212. Um_Key_CouponId: `${coupon.couponId}`,
  213. })
  214. }
  215. if (this.hasLogin) {
  216. if (this.userIdentity === 1 || this.userIdentity === 3) {
  217. this.$util.msg('您的身份暂不支持领取优惠券', 2000)
  218. return
  219. }
  220. this.MiniWxPayFor(coupon)
  221. } else {
  222. this.$api.navigateTo('/pages/login/login')
  223. }
  224. },
  225. receiveCoupon(coupon) {
  226. // 点击优惠券领取按钮,友盟埋点收集领取优惠券
  227. if (process.env.NODE_ENV != 'development') {
  228. this.$uma.trackEvent('Um_Event_userCouponCollectionReceive', {
  229. Um_Key_PageName: '领券中心',
  230. Um_Key_EvenName: '领取优惠券',
  231. Um_Key_CouponId: `${coupon.couponId}`,
  232. })
  233. }
  234. if (this.hasLogin) {
  235. if (this.isReceiveLoading) {
  236. return
  237. }
  238. this.ProductService.ReceiveCoupon({
  239. userId: this.listQuery.userId,
  240. couponId: coupon.couponId,
  241. source: 2
  242. })
  243. .then(response => {
  244. this.isReceiveLoading = true
  245. this.$util.msg('领取成功', 1500, true, 'success')
  246. setTimeout(() => {
  247. coupon.couponBtnType = 1
  248. this.isReceiveLoading = false
  249. }, 1500)
  250. })
  251. .catch(error => {
  252. this.$util.msg(error.msg, 2000)
  253. this.isReceiveLoading = false
  254. })
  255. } else {
  256. this.$api.navigateTo('/pages/login/login')
  257. }
  258. },
  259. toUseCoupon(coupon) {
  260. // 去使用跳转路径,友盟埋点收集去使用优惠券
  261. if (process.env.NODE_ENV != 'development') {
  262. this.$uma.trackEvent('Um_Event_userCouponCollectionToUseCoupon', {
  263. Um_Key_PageName: '领券中心',
  264. Um_Key_EvenName: '使用优惠券',
  265. Um_Key_CouponId: `${coupon.couponId}`,
  266. })
  267. }
  268. switch (coupon.couponType) {
  269. case 0: // 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  270. if (coupon.productType == 1) {
  271. // 1 全商城通用 2 指定商品
  272. this.$api.switchTabTo('/pages/tabBar/home/index')
  273. } else {
  274. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId=' + coupon.couponId)
  275. }
  276. break
  277. case 1: // 品类券:跳转到产品 287 / 仪器页 286
  278. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${coupon.categoryType == 1 ? 287 : 286}`)
  279. break
  280. case 2: // 用户专享券:跳转到商城首页
  281. this.$api.switchTabTo('/pages/tabBar/home/index')
  282. break
  283. case 3: // 店铺券:跳转到店铺首页
  284. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId=' + coupon.shopId)
  285. break
  286. case 4: // 新用户券:跳转到商城首页
  287. this.$api.switchTabTo('/pages/tabBar/home/index')
  288. break
  289. }
  290. },
  291. async MiniWxPayFor(coupon) {
  292. const wechatcode = await authorize.getCode('weixin')
  293. this.PayService.WeChatCouponMiniWxPay({
  294. userId: this.listQuery.userId,
  295. couponId: coupon.couponId,
  296. payWay: 'WEIXIN',
  297. code: wechatcode,
  298. source: 1 //支付来源 1 小程序 2 WWW
  299. })
  300. .then(response => {
  301. // 友盟埋点收集微信支付
  302. if (process.env.NODE_ENV != 'development') {
  303. this.$uma.trackEvent('Um_Event_userCouponCollectionPay', {
  304. Um_Key_PageName: '领券中心',
  305. Um_Key_SourcePage: '线上支付优惠券',
  306. Um_Key_CouponId: `${coupon.couponId}`,
  307. Um_Key_userId: `${this.userId}`
  308. })
  309. }
  310. let PayInfo = JSON.parse(response.data.data.payInfo)
  311. this.WxRequestPayment(PayInfo)
  312. })
  313. .catch(error => {
  314. this.$util.msg(error.msg, 2000)
  315. })
  316. },
  317. WxRequestPayment(data) {
  318. let self = this
  319. wx.requestPayment({
  320. timeStamp: data.timeStamp,
  321. nonceStr: data.nonceStr,
  322. package: data.package,
  323. signType: data.signType,
  324. paySign: data.paySign,
  325. success: function(res) {
  326. wx.reLaunch({ url: '/pages/tabBar/user/user' })
  327. },
  328. fail: function(res) {
  329. self.$util.msg('用户取消支付~')
  330. },
  331. complete: function(res) {}
  332. })
  333. },
  334. navigator(url) {
  335. this.$api.navigateTo(url)
  336. }
  337. },
  338. onPullDownRefresh() {
  339. setTimeout(() => {
  340. this.QueryCouponList()
  341. uni.stopPullDownRefresh()
  342. }, 200)
  343. },
  344. onReachBottom() {
  345. if (this.hasNextPage) {
  346. this.loadding = true
  347. this.pullUpOn = true
  348. this.getOnReachBottomData()
  349. }
  350. },
  351. onShow() {
  352. this.initGetStotage()
  353. }
  354. }
  355. </script>
  356. <style lang="scss">
  357. page {
  358. background-color: #f7f7f7;
  359. }
  360. .container {
  361. width: 100%;
  362. height: auto;
  363. }
  364. .container-list {
  365. box-sizing: border-box;
  366. padding: 24rpx;
  367. .empty-container-image {
  368. width: 260rpx;
  369. height: 260rpx;
  370. margin-top: -300rpx;
  371. }
  372. .toIndexPage {
  373. bottom: 390rpx;
  374. }
  375. .coupon-list {
  376. width: 100%;
  377. height: 200rpx;
  378. margin-bottom: 24rpx;
  379. box-sizing: border-box;
  380. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  381. background-size: cover;
  382. .list-cell-le {
  383. width: 224rpx;
  384. height: 100%;
  385. box-sizing: border-box;
  386. padding: 37rpx 0;
  387. float: left;
  388. .coupon-maxMoney {
  389. width: 100%;
  390. height: 78rpx;
  391. line-height: 78rpx;
  392. font-size: 56rpx;
  393. color: #ffffff;
  394. text-align: center;
  395. .small {
  396. font-size: $font-size-24;
  397. }
  398. }
  399. .coupon-minMoney {
  400. width: 100%;
  401. height: 33rpx;
  402. line-height: 33rpx;
  403. font-size: $font-size-24;
  404. color: #ffffff;
  405. text-align: center;
  406. }
  407. }
  408. .list-cell-ri {
  409. width: 478rpx;
  410. height: 100%;
  411. box-sizing: border-box;
  412. padding: 20rpx 24rpx 0 24rpx;
  413. float: right;
  414. .list-cell-top {
  415. width: 100%;
  416. height: 121rpx;
  417. float: left;
  418. border-bottom: 1px solid #e1e1e1;
  419. .list-cell-type {
  420. width: 286rpx;
  421. height: 100%;
  422. float: left;
  423. .list-cell-tags {
  424. width: 100%;
  425. height: 32rpx;
  426. margin-bottom: 7rpx;
  427. .tags {
  428. display: inline-block;
  429. padding: 0 10rpx;
  430. height: 32rpx;
  431. line-height: 32rpx;
  432. background-color: #ffdcce;
  433. color: #f94b4b;
  434. font-size: $font-size-20;
  435. border-radius: 8rpx;
  436. text-align: center;
  437. float: left;
  438. }
  439. }
  440. .list-cell-texts {
  441. width: 100%;
  442. height: auto;
  443. line-height: 35rpx;
  444. text-overflow: ellipsis;
  445. display: -webkit-box;
  446. word-break: break-all;
  447. -webkit-box-orient: vertical;
  448. -webkit-line-clamp: 2;
  449. overflow: hidden;
  450. font-size: 26rpx;
  451. color: #333333;
  452. }
  453. }
  454. .list-cell-btn {
  455. width: 128rpx;
  456. height: 100%;
  457. float: right;
  458. .icon-used {
  459. width: 100%;
  460. height: 100%;
  461. box-sizing: border-box;
  462. padding-top: 28rpx;
  463. .icon-used-text {
  464. width: 100%;
  465. text-align: center;
  466. line-height: 26rpx;
  467. font-size: $font-size-20;
  468. color: #f94b4b;
  469. }
  470. .icon-used-btn {
  471. height: 48rpx;
  472. border-radius: 28rpx;
  473. line-height: 48rpx;
  474. font-size: $font-size-26;
  475. text-align: center;
  476. padding: 0 6rpx;
  477. box-sizing: border-box;
  478. &.buy {
  479. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  480. color: #ffffff;
  481. }
  482. &.receive {
  483. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  484. color: #ffffff;
  485. }
  486. &.make {
  487. border: solid 1px #f94b4b;
  488. color: #f94b4b;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. .list-cell-time {
  495. width: 100%;
  496. height: 58rpx;
  497. line-height: 58rpx;
  498. text-align: left;
  499. font-size: $font-size-20;
  500. color: #999999;
  501. }
  502. }
  503. }
  504. }
  505. </style>