coupon-collection.vue 16 KB

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