coupon-collection.vue 14 KB

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