coupon-activity.vue 16 KB

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