coupon-activity.vue 15 KB

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