coupon-collection.vue 18 KB

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