coupon-collection.vue 9.8 KB

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