coupon-activity.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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 (this.hasLogin) {
  222. if (this.userIdentity === 1 || this.userIdentity === 3) {
  223. this.$util.msg('您的身份暂不支持领取优惠券', 2000)
  224. return
  225. }
  226. this.MiniWxPayFor(coupon)
  227. } else {
  228. this.$api.navigateTo('/pages/login/login')
  229. }
  230. },
  231. receiveCoupon(coupon) {
  232. // 点击优惠券领取按钮
  233. if (this.hasLogin) {
  234. if (this.userIdentity === 1 || this.userIdentity === 3) {
  235. this.$util.msg('您的身份暂不支持领取优惠券', 2000)
  236. return
  237. }
  238. if (this.isReceiveLoading) {
  239. return
  240. }
  241. this.ProductService.ReceiveCoupon({
  242. userId: this.listQuery.userId,
  243. couponId: coupon.couponId,
  244. source: 2
  245. })
  246. .then(response => {
  247. this.isReceiveLoading = true
  248. this.$util.msg('领取成功', 1500, true, 'success')
  249. setTimeout(() => {
  250. coupon.couponBtnType = 1
  251. this.isReceiveLoading = false
  252. }, 1500)
  253. })
  254. .catch(error => {
  255. this.$util.msg(error.msg, 2000)
  256. this.isReceiveLoading = false
  257. })
  258. } else {
  259. this.$api.navigateTo('/pages/login/login')
  260. }
  261. },
  262. toUseCoupon(coupon) {
  263. // 去使用跳转路径
  264. console.log('coupon', coupon)
  265. switch (coupon.couponType) {
  266. case 0: // 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  267. if (coupon.productType == 1) {
  268. // 1 全商城通用 2 指定商品
  269. this.$api.switchTabTo('/pages/tabBar/home/index')
  270. } else {
  271. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId=' + coupon.couponId)
  272. }
  273. break
  274. case 1: // 品类券:跳转到产品 287 / 仪器页 286
  275. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${coupon.categoryType == 1 ? 287 : 286}`)
  276. break
  277. case 2: // 用户专享券:跳转到商城首页
  278. this.$api.switchTabTo('/pages/tabBar/home/index')
  279. break
  280. case 3: // 店铺券:跳转到店铺首页
  281. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId=' + coupon.shopId)
  282. break
  283. case 4: // 新用户券:跳转到商城首页
  284. this.$api.switchTabTo('/pages/tabBar/home/index')
  285. break
  286. }
  287. },
  288. async MiniWxPayFor(coupon) {
  289. const wechatcode = await authorize.getCode('weixin')
  290. this.PayService.WeChatCouponMiniWxPay({
  291. userId: this.listQuery.userId,
  292. couponId: coupon.couponId,
  293. payWay: 'WEIXIN',
  294. code: wechatcode
  295. })
  296. .then(response => {
  297. // 友盟埋点收集微信支付
  298. if (process.env.NODE_ENV != 'development') {
  299. this.$uma.trackEvent('Um_Event_ConfirmWechatPay', {
  300. Um_Key_PageName: '微信支付',
  301. Um_Key_SourcePage: '线上支付',
  302. Um_Key_PayName: `${this.buttonText}`,
  303. Um_Key_PayOrderID: `${this.orderId}`
  304. })
  305. }
  306. let PayInfo = JSON.parse(response.data.data.payInfo)
  307. this.WxRequestPayment(PayInfo)
  308. })
  309. .catch(error => {
  310. this.$util.msg(error.msg, 2000)
  311. })
  312. },
  313. WxRequestPayment(data) {
  314. let self = this
  315. wx.requestPayment({
  316. timeStamp: data.timeStamp,
  317. nonceStr: data.nonceStr,
  318. package: data.package,
  319. signType: data.signType,
  320. paySign: data.paySign,
  321. success: function(res) {
  322. wx.reLaunch({ url: '/pages/tabBar/user/user' })
  323. },
  324. fail: function(res) {
  325. self.$util.msg('用户取消支付~')
  326. },
  327. complete: function(res) {}
  328. })
  329. },
  330. navigator(url) {
  331. this.$api.navigateTo(url)
  332. }
  333. },
  334. onShareAppMessage(res) {
  335. //分享美博会优惠券活动页
  336. if (res.from === 'button') {
  337. // console.log('来自页面内转发按钮')
  338. }
  339. return {
  340. title: '采美线上美博会盛大开启,众多优惠等着您~',
  341. path: '/pages/user/coupon/coupon-activity?type=share',
  342. imageUrl: 'https://static.caimei365.com/app/img/icon/icon-shareCoupon@2x.png'
  343. }
  344. },
  345. onPullDownRefresh() {
  346. setTimeout(() => {
  347. this.QueryCouponList()
  348. uni.stopPullDownRefresh()
  349. }, 200)
  350. },
  351. onReachBottom() {
  352. if (this.hasNextPage) {
  353. this.loadding = true
  354. this.pullUpOn = true
  355. this.getOnReachBottomData()
  356. }
  357. },
  358. onShow() {
  359. this.initGetStotage()
  360. }
  361. }
  362. </script>
  363. <style lang="scss">
  364. page {
  365. background-color: #fff1eb;
  366. }
  367. .container {
  368. width: 100%;
  369. height: auto;
  370. }
  371. .container-banner {
  372. width: 750rpx;
  373. height: 750rpx;
  374. .image2x {
  375. width: 750rpx;
  376. height: 750rpx;
  377. display: block;
  378. }
  379. }
  380. .container-title {
  381. width: 100%;
  382. height: 130rpx;
  383. line-height: 130rpx;
  384. text-align: center;
  385. font-size: $font-size-36;
  386. color: #f94b4b;
  387. }
  388. .container-list {
  389. box-sizing: border-box;
  390. padding: 0 24rpx;
  391. .empty-container-image {
  392. width: 260rpx;
  393. height: 260rpx;
  394. margin-top: -300rpx;
  395. }
  396. .toIndexPage {
  397. bottom: 390rpx;
  398. }
  399. .coupon-list {
  400. width: 100%;
  401. height: 200rpx;
  402. margin-bottom: 24rpx;
  403. box-sizing: border-box;
  404. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesbs@2x.png);
  405. background-size: cover;
  406. .list-cell-le {
  407. width: 224rpx;
  408. height: 100%;
  409. box-sizing: border-box;
  410. padding: 37rpx 0;
  411. float: left;
  412. .coupon-maxMoney {
  413. width: 100%;
  414. height: 78rpx;
  415. line-height: 78rpx;
  416. font-size: 56rpx;
  417. color: #ffffff;
  418. text-align: center;
  419. .small {
  420. font-size: $font-size-24;
  421. }
  422. }
  423. .coupon-minMoney {
  424. width: 100%;
  425. height: 33rpx;
  426. line-height: 33rpx;
  427. font-size: $font-size-24;
  428. color: #ffffff;
  429. text-align: center;
  430. }
  431. }
  432. .list-cell-ri {
  433. width: 478rpx;
  434. height: 100%;
  435. box-sizing: border-box;
  436. padding: 20rpx 24rpx 0 24rpx;
  437. float: right;
  438. .list-cell-top {
  439. width: 100%;
  440. height: 121rpx;
  441. float: left;
  442. border-bottom: 1px solid #e1e1e1;
  443. .list-cell-type {
  444. width: 286rpx;
  445. height: 100%;
  446. float: left;
  447. .list-cell-tags {
  448. width: 100%;
  449. height: 32rpx;
  450. margin-bottom: 7rpx;
  451. .tags {
  452. display: inline-block;
  453. padding: 0 10rpx;
  454. height: 32rpx;
  455. line-height: 32rpx;
  456. background-color: #ffdcce;
  457. color: #f94b4b;
  458. font-size: $font-size-20;
  459. border-radius: 8rpx;
  460. text-align: center;
  461. float: left;
  462. }
  463. }
  464. .list-cell-texts {
  465. width: 100%;
  466. height: auto;
  467. line-height: 35rpx;
  468. text-overflow: ellipsis;
  469. display: -webkit-box;
  470. word-break: break-all;
  471. -webkit-box-orient: vertical;
  472. -webkit-line-clamp: 2;
  473. overflow: hidden;
  474. font-size: 26rpx;
  475. color: #333333;
  476. }
  477. }
  478. .list-cell-btn {
  479. width: 128rpx;
  480. height: 100%;
  481. float: right;
  482. .icon-used {
  483. width: 100%;
  484. height: 100%;
  485. box-sizing: border-box;
  486. padding-top: 28rpx;
  487. .icon-used-text {
  488. width: 100%;
  489. text-align: center;
  490. line-height: 26rpx;
  491. font-size: $font-size-20;
  492. color: #f94b4b;
  493. }
  494. .icon-used-btn {
  495. height: 48rpx;
  496. border-radius: 28rpx;
  497. line-height: 48rpx;
  498. font-size: $font-size-26;
  499. padding: 0 6rpx;
  500. text-align: center;
  501. box-sizing: border-box;
  502. &.buy {
  503. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  504. color: #ffffff;
  505. }
  506. &.receive {
  507. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  508. color: #ffffff;
  509. }
  510. &.make {
  511. border: solid 1px #f94b4b;
  512. color: #f94b4b;
  513. }
  514. }
  515. }
  516. }
  517. }
  518. .list-cell-time {
  519. width: 100%;
  520. height: 58rpx;
  521. line-height: 58rpx;
  522. text-align: left;
  523. font-size: $font-size-20;
  524. color: #999999;
  525. }
  526. }
  527. }
  528. }
  529. </style>