coupon-collection.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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 (this.hasLogin) {
  209. if (this.userIdentity === 1 || this.userIdentity === 3) {
  210. this.$util.msg('您的身份暂不支持领取优惠券', 2000)
  211. return
  212. }
  213. this.MiniWxPayFor(coupon)
  214. } else {
  215. this.$api.navigateTo('/pages/login/login')
  216. }
  217. },
  218. receiveCoupon(coupon) {
  219. // 点击优惠券领取按钮
  220. if (this.hasLogin) {
  221. if (this.isReceiveLoading) {
  222. return
  223. }
  224. this.ProductService.ReceiveCoupon({
  225. userId: this.listQuery.userId,
  226. couponId: coupon.couponId,
  227. source: 2
  228. })
  229. .then(response => {
  230. this.isReceiveLoading = true
  231. this.$util.msg('领取成功', 1500, true, 'success')
  232. setTimeout(() => {
  233. coupon.couponBtnType = 1
  234. this.isReceiveLoading = false
  235. }, 1500)
  236. })
  237. .catch(error => {
  238. this.$util.msg(error.msg, 2000)
  239. this.isReceiveLoading = false
  240. })
  241. } else {
  242. this.$api.navigateTo('/pages/login/login')
  243. }
  244. },
  245. toUseCoupon(coupon) {
  246. // 去使用跳转路径
  247. console.log('coupon', coupon)
  248. switch (coupon.couponType) {
  249. case 0: // 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  250. if (coupon.productType == 1) {
  251. // 1 全商城通用 2 指定商品
  252. this.$api.switchTabTo('/pages/tabBar/home/index')
  253. } else {
  254. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId=' + coupon.couponId)
  255. }
  256. break
  257. case 1: // 品类券:跳转到产品 287 / 仪器页 286
  258. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${coupon.categoryType == 1 ? 287 : 286}`)
  259. break
  260. case 2: // 用户专享券:跳转到商城首页
  261. this.$api.switchTabTo('/pages/tabBar/home/index')
  262. break
  263. case 3: // 店铺券:跳转到店铺首页
  264. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId=' + coupon.shopId)
  265. break
  266. case 4: // 新用户券:跳转到商城首页
  267. this.$api.switchTabTo('/pages/tabBar/home/index')
  268. break
  269. }
  270. },
  271. async MiniWxPayFor(coupon) {
  272. const wechatcode = await authorize.getCode('weixin')
  273. this.PayService.WeChatCouponMiniWxPay({
  274. userId: this.listQuery.userId,
  275. couponId: coupon.couponId,
  276. payWay: 'WEIXIN',
  277. code: wechatcode
  278. })
  279. .then(response => {
  280. // 友盟埋点收集微信支付
  281. if (process.env.NODE_ENV != 'development') {
  282. this.$uma.trackEvent('Um_Event_ConfirmWechatPay', {
  283. Um_Key_PageName: '微信支付',
  284. Um_Key_SourcePage: '线上支付',
  285. Um_Key_PayName: `${this.buttonText}`,
  286. Um_Key_PayOrderID: `${this.orderId}`
  287. })
  288. }
  289. let PayInfo = JSON.parse(response.data.data.payInfo)
  290. this.WxRequestPayment(PayInfo)
  291. })
  292. .catch(error => {
  293. this.$util.msg(error.msg, 2000)
  294. })
  295. },
  296. WxRequestPayment(data) {
  297. let self = this
  298. wx.requestPayment({
  299. timeStamp: data.timeStamp,
  300. nonceStr: data.nonceStr,
  301. package: data.package,
  302. signType: data.signType,
  303. paySign: data.paySign,
  304. success: function(res) {
  305. wx.reLaunch({ url: '/pages/tabBar/user/user' })
  306. },
  307. fail: function(res) {
  308. self.$util.msg('用户取消支付~')
  309. },
  310. complete: function(res) {}
  311. })
  312. },
  313. navigator(url) {
  314. this.$api.navigateTo(url)
  315. }
  316. },
  317. onPullDownRefresh() {
  318. setTimeout(() => {
  319. this.QueryCouponList()
  320. uni.stopPullDownRefresh()
  321. }, 200)
  322. },
  323. onReachBottom() {
  324. if (this.hasNextPage) {
  325. this.loadding = true
  326. this.pullUpOn = true
  327. this.getOnReachBottomData()
  328. }
  329. },
  330. onShow() {
  331. this.initGetStotage()
  332. }
  333. }
  334. </script>
  335. <style lang="scss">
  336. page {
  337. background-color: #f7f7f7;
  338. }
  339. .container {
  340. width: 100%;
  341. height: auto;
  342. }
  343. .container-list {
  344. box-sizing: border-box;
  345. padding: 24rpx;
  346. .empty-container-image {
  347. width: 260rpx;
  348. height: 260rpx;
  349. margin-top: -300rpx;
  350. }
  351. .toIndexPage {
  352. bottom: 390rpx;
  353. }
  354. .coupon-list {
  355. width: 100%;
  356. height: 200rpx;
  357. margin-bottom: 24rpx;
  358. box-sizing: border-box;
  359. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  360. background-size: cover;
  361. .list-cell-le {
  362. width: 224rpx;
  363. height: 100%;
  364. box-sizing: border-box;
  365. padding: 37rpx 0;
  366. float: left;
  367. .coupon-maxMoney {
  368. width: 100%;
  369. height: 78rpx;
  370. line-height: 78rpx;
  371. font-size: 56rpx;
  372. color: #ffffff;
  373. text-align: center;
  374. .small {
  375. font-size: $font-size-24;
  376. }
  377. }
  378. .coupon-minMoney {
  379. width: 100%;
  380. height: 33rpx;
  381. line-height: 33rpx;
  382. font-size: $font-size-24;
  383. color: #ffffff;
  384. text-align: center;
  385. }
  386. }
  387. .list-cell-ri {
  388. width: 478rpx;
  389. height: 100%;
  390. box-sizing: border-box;
  391. padding: 20rpx 24rpx 0 24rpx;
  392. float: right;
  393. .list-cell-top {
  394. width: 100%;
  395. height: 121rpx;
  396. float: left;
  397. border-bottom: 1px solid #e1e1e1;
  398. .list-cell-type {
  399. width: 286rpx;
  400. height: 100%;
  401. float: left;
  402. .list-cell-tags {
  403. width: 100%;
  404. height: 32rpx;
  405. margin-bottom: 7rpx;
  406. .tags {
  407. display: inline-block;
  408. padding: 0 10rpx;
  409. height: 32rpx;
  410. line-height: 32rpx;
  411. background-color: #ffdcce;
  412. color: #f94b4b;
  413. font-size: $font-size-20;
  414. border-radius: 8rpx;
  415. text-align: center;
  416. float: left;
  417. }
  418. }
  419. .list-cell-texts {
  420. width: 100%;
  421. height: auto;
  422. line-height: 35rpx;
  423. text-overflow: ellipsis;
  424. display: -webkit-box;
  425. word-break: break-all;
  426. -webkit-box-orient: vertical;
  427. -webkit-line-clamp: 2;
  428. overflow: hidden;
  429. font-size: 26rpx;
  430. color: #333333;
  431. }
  432. }
  433. .list-cell-btn {
  434. width: 128rpx;
  435. height: 100%;
  436. float: right;
  437. .icon-used {
  438. width: 100%;
  439. height: 100%;
  440. box-sizing: border-box;
  441. padding-top: 28rpx;
  442. .icon-used-text {
  443. width: 100%;
  444. text-align: center;
  445. line-height: 26rpx;
  446. font-size: $font-size-20;
  447. color: #f94b4b;
  448. }
  449. .icon-used-btn {
  450. height: 48rpx;
  451. border-radius: 28rpx;
  452. line-height: 48rpx;
  453. font-size: $font-size-26;
  454. text-align: center;
  455. padding: 0 6rpx;
  456. box-sizing: border-box;
  457. &.buy {
  458. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  459. color: #ffffff;
  460. }
  461. &.receive {
  462. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  463. color: #ffffff;
  464. }
  465. &.make {
  466. border: solid 1px #f94b4b;
  467. color: #f94b4b;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. .list-cell-time {
  474. width: 100%;
  475. height: 58rpx;
  476. line-height: 58rpx;
  477. text-align: left;
  478. font-size: $font-size-20;
  479. color: #999999;
  480. }
  481. }
  482. }
  483. }
  484. </style>