coupon-collection.vue 15 KB

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