coupon-collection.vue 12 KB

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