coupon-activity.vue 15 KB

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