coupon-collection.vue 17 KB

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