coupon-activity.vue 16 KB

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