coupon-activity.vue 17 KB

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