coupon-collection.vue 14 KB

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