coupon-collection.vue 15 KB

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