coupon-collection.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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-btn receive" v-if="coupon.couponBtnType == 0" @click="receiveCoupon(coupon)">领取</view>
  39. <view class="icon-used-btn make" v-if="coupon.couponBtnType == 1" @click="toUseCoupon(coupon)">去使用</view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  44. </view>
  45. </view>
  46. <!--加载loadding-->
  47. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  48. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text='nomoreText'></tui-nomore>
  49. <!--加载loadding-->
  50. </template>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { mapState,mapMutations} from 'vuex'
  56. import couponTabs from '@/components/cm-module/coupon/tui-tabs.vue'
  57. export default {
  58. components:{
  59. couponTabs
  60. },
  61. data() {
  62. return {
  63. StaticUrl:this.$Static,
  64. isIphoneX:this.$store.state.isIphoneX,
  65. listQuery:{
  66. userId:0,
  67. pageNum:1,
  68. pageSize:10
  69. },
  70. coupinList:[],
  71. isRequest:false,
  72. showEmpty: false,
  73. nomoreText: '上拉显示更多',
  74. hasNextPage:false,
  75. loadding: false,
  76. pullUpOn: true,
  77. pullFlag: true,
  78. isReceiveLoading:false, //领券操作状态
  79. }
  80. },
  81. onLoad() {
  82. },
  83. filters: {
  84. TypeFormat(value) {
  85. switch (value) {
  86. case 0:
  87. return '活动券'
  88. break
  89. case 1:
  90. return '品类券'
  91. break
  92. case 2:
  93. return '用户专享券'
  94. break
  95. case 3:
  96. return '店铺券'
  97. break
  98. case 4:
  99. return '新用户券'
  100. break
  101. }
  102. }
  103. },
  104. computed: {
  105. ...mapState(['hasLogin','userInfo','identity','isActivity'])
  106. },
  107. methods: {
  108. QueryCouponList() {// 初始化查询优惠券列表
  109. this.coupinList = []
  110. this.listQuery.pageNum = 1
  111. this.ProductService.QueryCouponCollarList(this.listQuery).then(response =>{
  112. let data = response.data
  113. if(data.list&&data.list.length > 0){
  114. this.showEmpty = false
  115. this.hasNextPage = response.data.hasNextPage
  116. this.coupinList =data.list
  117. this.pullFlag = false
  118. setTimeout(()=>{this.pullFlag = true},500)
  119. if(this.hasNextPage){
  120. this.pullUpOn = false
  121. this.nomoreText = '上拉显示更多'
  122. }else{
  123. if(this.coupinList.length < 8){
  124. this.pullUpOn = true
  125. }else{
  126. this.pullUpOn = false
  127. this.loadding = false
  128. this.nomoreText = '已至底部'
  129. }
  130. }
  131. }else{
  132. this.showEmpty = true
  133. }
  134. this.isRequest = true
  135. }).catch(error =>{
  136. this.$util.msg(error.msg,2000)
  137. })
  138. },
  139. getOnReachBottomData(){// 上滑加载分页
  140. this.listQuery.pageNum+=1
  141. this.ProductService.QueryCouponCollarList(this.listQuery)
  142. .then(response =>{
  143. let data = response.data
  144. if(data.list&&data.list.length > 0){
  145. this.hasNextPage = data.hasNextPage
  146. this.coupinList = this.coupinList.concat(data.list)
  147. this.pullFlag = false// 防上拉暴滑
  148. setTimeout(()=>{this.pullFlag = true},500)
  149. if(this.hasNextPage){
  150. this.pullUpOn = false
  151. this.nomoreText = '上拉显示更多'
  152. }else{
  153. this.pullUpOn = false
  154. this.loadding = false
  155. this.nomoreText = '已至底部'
  156. }
  157. }
  158. })
  159. .catch(error =>{
  160. this.$util.msg(error.msg,2000)
  161. })
  162. },
  163. receiveCoupon(coupon){// 点击优惠券领取按钮
  164. if(this.hasLogin){
  165. if(this.isReceiveLoading){return}
  166. this.ProductService.ReceiveCoupon(
  167. {
  168. userId:this.listQuery.userId,
  169. couponId:coupon.couponId,
  170. source:2
  171. })
  172. .then(response =>{
  173. this.isReceiveLoading = true
  174. this.$util.msg('领取成功',1500,true,'success')
  175. setTimeout(()=>{
  176. coupon.couponBtnType = 1
  177. this.isReceiveLoading = false
  178. },1500)
  179. })
  180. .catch(error =>{
  181. this.$util.msg(error.msg,2000)
  182. this.isReceiveLoading = false
  183. })
  184. }else{
  185. this.$api.navigateTo('/pages/login/login')
  186. }
  187. },
  188. toUseCoupon(coupon){// 去使用跳转路径
  189. console.log('coupon',coupon)
  190. switch (coupon.couponType) {
  191. case 0:// 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  192. if(coupon.productType == 1){// 1 全商城通用 2 指定商品
  193. this.$api.switchTabTo('/pages/tabBar/home/index')
  194. }else{
  195. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId='+coupon.couponId)
  196. }
  197. break
  198. case 1:// 品类券:跳转到产品 287 / 仪器页 286
  199. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${ coupon.categoryType == 1 ? 287 : 286 }`)
  200. break
  201. case 2:// 用户专享券:跳转到商城首页
  202. this.$api.switchTabTo('/pages/tabBar/home/index')
  203. break
  204. case 3:// 店铺券:跳转到店铺首页
  205. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId='+coupon.shopId)
  206. break
  207. case 4:// 新用户券:跳转到商城首页
  208. this.$api.switchTabTo('/pages/tabBar/home/index')
  209. break
  210. }
  211. },
  212. navigator(url){
  213. this.$api.navigateTo(url)
  214. },
  215. },
  216. onPullDownRefresh() {
  217. setTimeout(() => {
  218. this.QueryCouponList()
  219. uni.stopPullDownRefresh()
  220. }, 200)
  221. },
  222. onReachBottom() {
  223. if(this.hasNextPage){
  224. this.loadding = true
  225. this.pullUpOn = true
  226. this.getOnReachBottomData()
  227. }
  228. },
  229. onShow(){
  230. this.$api.getComStorage('userInfo').then((resolve) =>{
  231. this.listQuery.userId = resolve.userId ? resolve.userId : 0
  232. this.QueryCouponList()
  233. })
  234. }
  235. }
  236. </script>
  237. <style lang="scss">
  238. page{
  239. background-color: #F7F7F7;
  240. }
  241. .container{
  242. width: 100%;
  243. height: auto;
  244. }
  245. .container-list {
  246. box-sizing: border-box;
  247. padding:24rpx;
  248. .empty-container-image {
  249. width: 260rpx;
  250. height: 260rpx;
  251. margin-top: -300rpx;
  252. }
  253. .toIndexPage {
  254. bottom: 390rpx;
  255. }
  256. .coupon-list{
  257. width: 100%;
  258. height: 200rpx;
  259. margin-bottom: 24rpx;
  260. box-sizing: border-box;
  261. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  262. background-size: cover;
  263. .list-cell-le{
  264. width: 224rpx;
  265. height: 100%;
  266. box-sizing: border-box;
  267. padding: 37rpx 0;
  268. float: left;
  269. .coupon-maxMoney{
  270. width: 100%;
  271. height: 78rpx;
  272. line-height: 78rpx;
  273. font-size: 56rpx;
  274. color: #FFFFFF;
  275. text-align: center;
  276. .small{
  277. font-size: $font-size-24;
  278. }
  279. }
  280. .coupon-minMoney{
  281. width: 100%;
  282. height: 33rpx;
  283. line-height: 33rpx;
  284. font-size: $font-size-24;
  285. color: #FFFFFF;
  286. text-align: center;
  287. }
  288. }
  289. .list-cell-ri{
  290. width: 478rpx;
  291. height: 100%;
  292. box-sizing: border-box;
  293. padding: 20rpx 24rpx 0 24rpx;
  294. float: right;
  295. .list-cell-top{
  296. width: 100%;
  297. height: 121rpx;
  298. float: left;
  299. border-bottom: 1px solid #e1e1e1;
  300. .list-cell-type{
  301. width: 286rpx;
  302. height: 100%;
  303. float: left;
  304. .list-cell-tags{
  305. width: 100%;
  306. height: 32rpx;
  307. margin-bottom: 7rpx;
  308. .tags{
  309. display: inline-block;
  310. padding: 0 10rpx;
  311. height: 32rpx;
  312. line-height: 32rpx;
  313. background-color: #ffdcce;
  314. color: #f94b4b;
  315. font-size: $font-size-20;
  316. border-radius: 8rpx;
  317. text-align: center;
  318. float: left;
  319. }
  320. }
  321. .list-cell-texts{
  322. width: 100%;
  323. height: auto;
  324. line-height:35rpx;
  325. text-overflow:ellipsis;
  326. display: -webkit-box;
  327. word-break: break-all;
  328. -webkit-box-orient: vertical;
  329. -webkit-line-clamp: 2;
  330. overflow: hidden;
  331. font-size: 26rpx;
  332. color: #333333;
  333. }
  334. }
  335. .list-cell-btn{
  336. width: 128rpx;
  337. height: 100%;
  338. float: right;
  339. .icon-used{
  340. width: 100%;
  341. height: 100%;
  342. box-sizing: border-box;
  343. padding-top: 57rpx;
  344. .icon-used-btn{
  345. width: 128rpx;
  346. height: 48rpx;
  347. border-radius: 28rpx;
  348. line-height: 48rpx;
  349. font-size: $font-size-26;
  350. text-align: center;
  351. &.receive{
  352. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);;
  353. color: #FFFFFF;
  354. }
  355. &.make{
  356. border: solid 1px #f94b4b;
  357. color: #f94b4b;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. .list-cell-time{
  364. width: 100%;
  365. height: 58rpx;
  366. line-height: 58rpx;
  367. text-align: left;
  368. font-size: $font-size-20;
  369. color: #999999;
  370. }
  371. }
  372. }
  373. }
  374. </style>