coupon-collection.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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.isMobileDisabled = true;
  174. this.$util.msg('领取成功',1500,true,'success')
  175. setTimeout(()=>{
  176. coupon.couponBtnType = 1;
  177. this.isMobileDisabled = false;
  178. },1500)
  179. })
  180. .catch(error =>{
  181. this.$util.msg(error.msg,2000);
  182. })
  183. }else{
  184. this.$api.navigateTo('/pages/login/login')
  185. }
  186. },
  187. toUseCoupon(coupon){// 去使用跳转路径
  188. console.log('coupon',coupon)
  189. switch (coupon.couponType) {
  190. case 0:// 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  191. if(coupon.productType == 1){// 1 全商城通用 2 指定商品
  192. this.$api.switchTabTo('/pages/tabBar/home/index')
  193. }else{
  194. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId='+coupon.couponId)
  195. }
  196. break;
  197. case 1:// 品类券:跳转到产品 287 / 仪器页 286
  198. let categoryId = 0;
  199. if(coupon.categoryType == 1){
  200. categoryId = 287
  201. }else{
  202. categoryId = 286
  203. }
  204. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${ coupon.categoryType == 1 ? 287 : 286 }`)
  205. break;
  206. case 2:// 用户专享券:跳转到商城首页
  207. this.$api.switchTabTo('/pages/tabBar/home/index')
  208. break;
  209. case 3:// 店铺券:跳转到店铺首页
  210. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId='+coupon.shopId)
  211. break;
  212. case 4:// 新用户券:跳转到商城首页
  213. this.$api.switchTabTo('/pages/tabBar/home/index')
  214. break;
  215. }
  216. },
  217. navigator(url){
  218. this.$api.navigateTo(url)
  219. },
  220. },
  221. onPullDownRefresh() {
  222. setTimeout(() => {
  223. this.QueryCouponList()
  224. uni.stopPullDownRefresh()
  225. }, 200)
  226. },
  227. onReachBottom() {
  228. if(this.hasNextPage){
  229. this.loadding = true
  230. this.pullUpOn = true
  231. this.getOnReachBottomData()
  232. }
  233. },
  234. onShow(){
  235. this.$api.getComStorage('userInfo').then((resolve) =>{
  236. this.listQuery.userId = resolve.userId ? resolve.userId : 0
  237. this.QueryCouponList();
  238. })
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. page{
  244. background-color: #F7F7F7;
  245. }
  246. .container{
  247. width: 100%;
  248. height: auto;
  249. }
  250. .container-list {
  251. box-sizing: border-box;
  252. padding:24rpx;
  253. .empty-container-image {
  254. width: 260rpx;
  255. height: 260rpx;
  256. margin-top: -300rpx;
  257. }
  258. .toIndexPage {
  259. bottom: 390rpx;
  260. }
  261. .coupon-list{
  262. width: 100%;
  263. height: 200rpx;
  264. margin-bottom: 24rpx;
  265. box-sizing: border-box;
  266. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  267. background-size: cover;
  268. .list-cell-le{
  269. width: 224rpx;
  270. height: 100%;
  271. box-sizing: border-box;
  272. padding: 37rpx 0;
  273. float: left;
  274. .coupon-maxMoney{
  275. width: 100%;
  276. height: 78rpx;
  277. line-height: 78rpx;
  278. font-size: 56rpx;
  279. color: #FFFFFF;
  280. text-align: center;
  281. .small{
  282. font-size: $font-size-24;
  283. }
  284. }
  285. .coupon-minMoney{
  286. width: 100%;
  287. height: 33rpx;
  288. line-height: 33rpx;
  289. font-size: $font-size-24;
  290. color: #FFFFFF;
  291. text-align: center;
  292. }
  293. }
  294. .list-cell-ri{
  295. width: 478rpx;
  296. height: 100%;
  297. box-sizing: border-box;
  298. padding: 20rpx 24rpx 0 24rpx;
  299. float: right;
  300. .list-cell-top{
  301. width: 100%;
  302. height: 121rpx;
  303. float: left;
  304. border-bottom: 1px solid #e1e1e1;
  305. .list-cell-type{
  306. width: 286rpx;
  307. height: 100%;
  308. float: left;
  309. .list-cell-tags{
  310. width: 100%;
  311. height: 32rpx;
  312. margin-bottom: 7rpx;
  313. .tags{
  314. display: inline-block;
  315. padding: 0 10rpx;
  316. height: 32rpx;
  317. line-height: 32rpx;
  318. background-color: #ffdcce;
  319. color: #f94b4b;
  320. font-size: $font-size-20;
  321. border-radius: 8rpx;
  322. text-align: center;
  323. float: left;
  324. }
  325. }
  326. .list-cell-texts{
  327. width: 100%;
  328. height: auto;
  329. line-height:35rpx;
  330. text-overflow:ellipsis;
  331. display: -webkit-box;
  332. word-break: break-all;
  333. -webkit-box-orient: vertical;
  334. -webkit-line-clamp: 2;
  335. overflow: hidden;
  336. font-size: 26rpx;
  337. color: #333333;
  338. }
  339. }
  340. .list-cell-btn{
  341. width: 128rpx;
  342. height: 100%;
  343. float: right;
  344. .icon-used{
  345. width: 100%;
  346. height: 100%;
  347. box-sizing: border-box;
  348. padding-top: 57rpx;
  349. .icon-used-btn{
  350. width: 128rpx;
  351. height: 48rpx;
  352. border-radius: 28rpx;
  353. line-height: 48rpx;
  354. font-size: $font-size-26;
  355. text-align: center;
  356. &.receive{
  357. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);;
  358. color: #FFFFFF;
  359. }
  360. &.make{
  361. border: solid 1px #f94b4b;
  362. color: #f94b4b;
  363. }
  364. }
  365. }
  366. }
  367. }
  368. .list-cell-time{
  369. width: 100%;
  370. height: 58rpx;
  371. line-height: 58rpx;
  372. text-align: left;
  373. font-size: $font-size-20;
  374. color: #999999;
  375. }
  376. }
  377. }
  378. }
  379. </style>