coupon-collection.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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" @click.stop="handleCouponDetails(coupon)">
  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. : coupon.couponName
  34. }}
  35. </text>
  36. <text v-if="coupon.couponType == 1">
  37. {{ coupon.categoryType == 1 ? coupon.couponName : coupon.couponName }}
  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.stop="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.stop="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.stop="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.stop="receiveCoupon(coupon)"
  74. >领取</view
  75. >
  76. <view
  77. class="icon-used-btn make"
  78. v-if="coupon.couponBtnType == 1"
  79. @click.stop="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. // 跳转优惠券详情
  293. handleCouponDetails(coupon){
  294. this.$api.navigateTo(`/pages/user/coupon/coupon-details?couponId=${coupon.couponId}&shareUserId=${this.listQuery.userId}`)
  295. },
  296. toUseCoupon(coupon) {
  297. // 去使用跳转路径,友盟埋点收集去使用优惠券
  298. if (process.env.NODE_ENV != 'development') {
  299. this.$uma.trackEvent('Um_Event_userCouponCollectionToUseCoupon', {
  300. Um_Key_PageName: '领券中心',
  301. Um_Key_EvenName: '使用优惠券',
  302. Um_Key_CouponId: `${coupon.couponId}`,
  303. })
  304. }
  305. switch (coupon.couponType) {
  306. case 0: // 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  307. if (coupon.productType == 1) {
  308. // 1 全商城通用 2 指定商品
  309. this.$api.switchTabTo('/pages/tabBar/home/index')
  310. } else {
  311. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId=' + coupon.couponId)
  312. }
  313. break
  314. case 1: // 品类券:跳转到产品 287 / 仪器页 286
  315. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${coupon.categoryType == 1 ? 287 : 286}`)
  316. break
  317. case 2: // 用户专享券:跳转到商城首页
  318. this.$api.switchTabTo('/pages/tabBar/home/index')
  319. break
  320. case 3: // 店铺券:跳转到店铺首页
  321. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId=' + coupon.shopId)
  322. break
  323. case 4: // 新用户券:跳转到商城首页
  324. this.$api.switchTabTo('/pages/tabBar/home/index')
  325. break
  326. }
  327. },
  328. toDeductCoupon(coupon) {
  329. // 点击采美豆抵扣优惠券
  330. if (process.env.NODE_ENV != 'development') {
  331. this.$uma.trackEvent('Um_Event_userCouponCollectionBuy', {
  332. Um_Key_PageName: '领券中心',
  333. Um_Key_EvenName: '抵扣优惠券',
  334. Um_Key_CouponId: `${coupon.couponId}`,
  335. })
  336. }
  337. if (this.hasLogin) {
  338. if (this.userIdentity === 1 || this.userIdentity === 3) {
  339. this.$util.msg('您的身份暂不支持领取优惠券', 2000)
  340. return
  341. }
  342. this.WeChatPayCouponBeans(coupon)
  343. } else {
  344. this.$api.navigateTo('/pages/login/login')
  345. }
  346. },
  347. WeChatPayCouponBeans(coupon){
  348. // 采美豆抵扣优惠券
  349. this.PayService.WeChatPayCouponBeans({
  350. source: 1, //领取渠道 1 小程序 2 网站
  351. userId: this.listQuery.userId,
  352. couponId: coupon.couponId
  353. })
  354. .then(response => {
  355. this.$util.msg('抵扣成功', 1500)
  356. setTimeout(() => {
  357. coupon.couponBtnType = 1
  358. }, 1500)
  359. })
  360. .catch(error => {
  361. this.$util.msg(error.msg, 2000)
  362. })
  363. },
  364. toPayCoupon(coupon) {
  365. // 点击购买优惠券,友盟埋点收集购买优惠券
  366. if (process.env.NODE_ENV != 'development') {
  367. this.$uma.trackEvent('Um_Event_userCouponCollectionBuy', {
  368. Um_Key_PageName: '领券中心',
  369. Um_Key_EvenName: '购买优惠券',
  370. Um_Key_CouponId: `${coupon.couponId}`,
  371. })
  372. }
  373. if (this.hasLogin) {
  374. if (this.userIdentity === 1 || this.userIdentity === 3) {
  375. this.$util.msg('您的身份暂不支持领取优惠券', 2000)
  376. return
  377. }
  378. this.$api.navigateTo(`/pages/user/pay/card-coupon-under?amount=${coupon.moneyCouponPrice}`)
  379. // this.createCouponRecord(coupon)
  380. } else {
  381. this.$api.navigateTo('/pages/login/login')
  382. }
  383. },
  384. createCouponRecord(coupon){
  385. // 生成购买优惠券记录Id
  386. this.PayService.WeChatCouponRecord({
  387. userId: this.listQuery.userId,
  388. couponId: coupon.couponId
  389. })
  390. .then(response => {
  391. this.MiniWxPayFor(coupon,response.data.couponRecordId)
  392. })
  393. .catch(error => {
  394. if(error.code == -1){//个人机构不能购买
  395. this.contentModalText ='该优惠券仅限医美机构购买,请升级为医美机构后再次购买。'
  396. this.modal = true
  397. }else if(error.code == -2){//会员机构不是医美机构不能购买
  398. this.$util.msg('该优惠券仅限医美机构购买', 2000)
  399. }
  400. })
  401. },
  402. async MiniWxPayFor(coupon,couponRecordId) {
  403. const wechatcode = await authorize.getCode('weixin')
  404. const params = {
  405. userId: this.listQuery.userId,
  406. couponId: coupon.couponId,
  407. couponRecordId:couponRecordId,
  408. payType:'XCX',
  409. code: wechatcode,
  410. source: 1 //支付来源 1 小程序 2 WWW
  411. }
  412. this.weChatMiniCouponWxPay(params,'Um_Event_userCouponCollectionPay','领券中心','线上支付优惠券',coupon.couponId,this.userId)
  413. },
  414. hideMobel(){
  415. this.modal = false
  416. },
  417. handleClick(e){
  418. //个人机构跳转升级页面
  419. if (e.index == 1) {
  420. this.$api.navigateTo('/pages/login/apply')
  421. }
  422. this.modal = false
  423. },
  424. navigator(url) {
  425. this.$api.navigateTo(url)
  426. }
  427. },
  428. onShareAppMessage(res) {
  429. //分享购买优惠券
  430. const coupon = res.target.dataset.coupon
  431. if (res.from === 'button') {
  432. const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length)
  433. const shareTitle = coupon.moneyCouponFlag === 1 ?
  434. `${coupon.moneyCouponPrice}抵${coupon.couponAmount},限时优惠券等您抢购~` :
  435. COUPON_TEXT_MAP[randomIndex]
  436. return {
  437. title: coupon.shareCouponTopic ? `${coupon.shareCouponTopic}` : shareTitle,
  438. path: `pages/user/coupon/coupon-details?couponId=${coupon.couponId}&shareUserId=${this.listQuery.userId}`,
  439. imageUrl: coupon.shareCouponImage ? `${coupon.shareCouponImage}` : 'https://static.caimei365.com/app/img/icon/icon-shareCoupon@2x.png'
  440. }
  441. }
  442. },
  443. onPullDownRefresh() {
  444. setTimeout(() => {
  445. this.QueryCouponList()
  446. uni.stopPullDownRefresh()
  447. }, 200)
  448. },
  449. onReachBottom() {
  450. if (this.hasNextPage) {
  451. this.loadding = true
  452. this.pullUpOn = true
  453. this.getOnReachBottomData()
  454. }
  455. },
  456. onShow() {
  457. this.initGetStotage()
  458. }
  459. }
  460. </script>
  461. <style lang="scss">
  462. page {
  463. background-color: #f7f7f7;
  464. }
  465. .container {
  466. width: 100%;
  467. height: auto;
  468. }
  469. .container-list {
  470. box-sizing: border-box;
  471. padding: 24rpx;
  472. .empty-container-image {
  473. width: 260rpx;
  474. height: 260rpx;
  475. margin-top: -300rpx;
  476. }
  477. .toIndexPage {
  478. bottom: 390rpx;
  479. }
  480. .coupon-list {
  481. width: 100%;
  482. height: 200rpx;
  483. margin-bottom: 24rpx;
  484. box-sizing: border-box;
  485. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  486. background-size: cover;
  487. .list-cell-le {
  488. width: 224rpx;
  489. height: 100%;
  490. box-sizing: border-box;
  491. padding: 37rpx 0;
  492. float: left;
  493. .coupon-maxMoney {
  494. width: 100%;
  495. height: 78rpx;
  496. line-height: 78rpx;
  497. font-size: 56rpx;
  498. color: #ffffff;
  499. text-align: center;
  500. .small {
  501. font-size: $font-size-24;
  502. }
  503. }
  504. .coupon-minMoney {
  505. width: 100%;
  506. height: 33rpx;
  507. line-height: 33rpx;
  508. font-size: $font-size-24;
  509. color: #ffffff;
  510. text-align: center;
  511. }
  512. }
  513. .list-cell-ri {
  514. width: 478rpx;
  515. height: 100%;
  516. box-sizing: border-box;
  517. padding: 20rpx 24rpx 0 24rpx;
  518. float: right;
  519. position: relative;
  520. .list-cell-share{
  521. width: 60rpx;
  522. height: 60rpx;
  523. line-height: 60rpx;
  524. text-align: center;
  525. position: absolute;
  526. right: 0;
  527. bottom: 0;
  528. box-sizing: border-box;
  529. display: block;
  530. background: transparent;
  531. border-radius: 0;
  532. border: 0;
  533. margin: 0;
  534. .iconfont{
  535. font-size: 40rpx;
  536. color: #07c160;
  537. }
  538. }
  539. .list-cell-top {
  540. width: 100%;
  541. height: 121rpx;
  542. float: left;
  543. border-bottom: 1px solid #e1e1e1;
  544. .list-cell-type {
  545. width: 286rpx;
  546. height: 100%;
  547. float: left;
  548. .list-cell-tags {
  549. width: 100%;
  550. height: 32rpx;
  551. margin-bottom: 7rpx;
  552. .tags {
  553. display: inline-block;
  554. padding: 0 10rpx;
  555. height: 32rpx;
  556. line-height: 32rpx;
  557. background-color: #ffdcce;
  558. color: #f94b4b;
  559. font-size: $font-size-20;
  560. border-radius: 8rpx;
  561. text-align: center;
  562. float: left;
  563. }
  564. }
  565. .list-cell-texts {
  566. width: 100%;
  567. height: auto;
  568. line-height: 35rpx;
  569. text-overflow: ellipsis;
  570. display: -webkit-box;
  571. word-break: break-all;
  572. -webkit-box-orient: vertical;
  573. -webkit-line-clamp: 2;
  574. overflow: hidden;
  575. font-size: 26rpx;
  576. color: #333333;
  577. }
  578. }
  579. .list-cell-btn {
  580. width: 128rpx;
  581. height: 100%;
  582. float: right;
  583. .icon-used {
  584. width: 100%;
  585. height: 100%;
  586. box-sizing: border-box;
  587. padding-top: 28rpx;
  588. .icon-used-text {
  589. width: 100%;
  590. text-align: center;
  591. line-height: 26rpx;
  592. font-size: $font-size-20;
  593. color: #f94b4b;
  594. }
  595. .icon-used-btn {
  596. height: 48rpx;
  597. border-radius: 28rpx;
  598. line-height: 48rpx;
  599. font-size: $font-size-26;
  600. text-align: center;
  601. padding: 0 6rpx;
  602. box-sizing: border-box;
  603. &.buy {
  604. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  605. color: #ffffff;
  606. }
  607. &.receive {
  608. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  609. color: #ffffff;
  610. }
  611. &.make {
  612. border: solid 1px #f94b4b;
  613. color: #f94b4b;
  614. }
  615. }
  616. }
  617. }
  618. }
  619. .list-cell-time {
  620. width: 100%;
  621. height: 58rpx;
  622. line-height: 58rpx;
  623. text-align: left;
  624. font-size: $font-size-20;
  625. color: #999999;
  626. }
  627. }
  628. }
  629. }
  630. </style>