coupon-activity.vue 16 KB

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