index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="coupon">
  3. <view class="tab-box">
  4. <view class="tab" :class="[query.status == 1?'active':'']" @click="handleTab(1)">
  5. 待使用
  6. </view>
  7. <view class="tab" :class="[query.status == 2?'active':'']" @click="handleTab(2)">
  8. 已使用
  9. </view>
  10. <view class="tab" :class="[query.status == 3?'active':'']" @click="handleTab(3)">
  11. 已失效
  12. </view>
  13. </view>
  14. <!-- 列表 -->
  15. <zs-list class="store-box" mt="84rpx" @load="loadMore" :status="status">
  16. <view class="discounts-item" :class="[query.status != 1?'disabled':'']" v-for="(item,index) in list" :key="index" >
  17. <view class="type-box">
  18. <view class="price">
  19. {{item | filterPrice}}
  20. </view>
  21. <view class="type">
  22. {{item | filterType}}
  23. </view>
  24. </view>
  25. <view class="info">
  26. <view class="title">
  27. {{item.couponName}}
  28. </view>
  29. <view class="limit">
  30. {{item.useStartTime}}后可用
  31. </view>
  32. <view class="desc">
  33. {{item.usrDetail || '-'}}
  34. </view>
  35. </view>
  36. <view class="btn" v-if="query.status == 1">
  37. 待使用
  38. </view>
  39. <image class="icon" v-else-if="query.status == 2" src="../../static/used-icon.png" mode=""></image>
  40. <image class="icon" v-else-if="query.status == 3" src="../../static/disable-icon.png" mode=""></image>
  41. </view>
  42. </zs-list>
  43. </view>
  44. </template>
  45. <script>
  46. import {couponByUser,claim} from '@/api/coupon.js'
  47. export default {
  48. data() {
  49. return {
  50. active: 0,
  51. open:999,
  52. status:'more',
  53. query:{
  54. currentPage:1,
  55. pageSize:10,
  56. status:1,
  57. },
  58. list:[],
  59. tabList:[]
  60. }
  61. },
  62. filters: {
  63. filterPrice: function(val) {
  64. if(val.couponType == 1){
  65. return `¥${val.couponDiscount}`
  66. }else if(val.couponType == 2){
  67. return `${val.couponDiscount}折`
  68. }else if(val.couponType == 3){
  69. return `¥${val.couponDiscount}`
  70. }
  71. },
  72. filterType: function(val) {
  73. if(val.couponType == 1){
  74. if(val.couponCondition){
  75. return `满${val.couponCondition}立减`
  76. }else{
  77. return '无门槛立减'
  78. }
  79. }else if(val.couponType == 2){
  80. if(val.couponCondition){
  81. return `满${val.couponCondition}`
  82. }else{
  83. return '无门槛立减'
  84. }
  85. }else if(val.couponType == 3){
  86. if(val.couponCondition){
  87. return `满${val.couponCondition}立减`
  88. }else{
  89. return '无门槛立减'
  90. }
  91. }
  92. },
  93. },
  94. methods: {
  95. handleTab(val){
  96. this.query.status = val
  97. this.query.currentPage = 1
  98. this.list = []
  99. this.status = 'more'
  100. this.getCouponList()
  101. },
  102. handleOpen(val,open){
  103. if(val === this[open]){
  104. this[open] = 999
  105. }else{
  106. this[open] = val
  107. }
  108. },
  109. loadMore(){
  110. this.getCouponList()
  111. },
  112. getCouponList(){
  113. this.status = 'loading'
  114. couponByUser(this.query).then(res=>{
  115. if(res.state == 'Success'){
  116. this.list = this.list.concat(res.content.records)
  117. this.list.length>= res.content.total?this.status = 'noMore':this.status = 'more'
  118. this.query.currentPage++
  119. }
  120. })
  121. },
  122. claim(couponId,type){
  123. if(type == 0){
  124. claim({couponId}).then(res=>{
  125. if(res.state == 'Success'){
  126. uni.showToast({
  127. title:'领取成功',
  128. icon:'success'
  129. })
  130. this.query.currentPage = 1
  131. this.list = []
  132. this.status = 'more'
  133. this.getCouponList()
  134. }
  135. })
  136. }
  137. }
  138. },
  139. created() {
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .coupon{
  145. background: #f5f5f5;
  146. height: 100vh;
  147. padding: 20rpx 24rpx;
  148. .tab-box{
  149. display: flex;
  150. align-items: center;
  151. background: #fff;
  152. position: fixed;
  153. width: 100%;
  154. top: 0%;
  155. left: 0%;
  156. z-index: 5;
  157. .tab{
  158. flex: 1;
  159. text-align: center;
  160. font-size: 28rpx;
  161. color: #222222;
  162. line-height: 84rpx;
  163. }
  164. .tab.active{
  165. font-weight: 600;
  166. font-size: 32rpx;
  167. }
  168. }
  169. .discounts-item {
  170. margin-bottom: 20rpx;
  171. display: flex;
  172. align-items: center;
  173. background-color: rgb(239, 239, 239);
  174. background: url('../../static/new-card.png') no-repeat;
  175. background-repeat: no-repeat;
  176. background-size: 100% 144rpx;
  177. border-radius: 16rpx;
  178. height: 144rpx;
  179. padding: 0 24rpx;
  180. box-sizing: border-box;
  181. .type-box{
  182. text-align: center;
  183. .price{
  184. ont-size: 40rpx;
  185. color: #FF4D3A;
  186. }
  187. .type{
  188. font-size: 20rpx;
  189. color: #AAAAAA;
  190. margin-top: 12rpx;
  191. }
  192. }
  193. .info {
  194. flex: 1;
  195. margin-left: 40rpx;
  196. .title {
  197. font-size: 28rpx;
  198. color: #222222;
  199. }
  200. .desc{
  201. font-size: 20rpx;
  202. color: #AAAAAA;
  203. }
  204. .limit{
  205. font-size: 20rpx;
  206. color: #AAAAAA;
  207. margin:10rpx 0;
  208. }
  209. }
  210. .btn {
  211. width: 118rpx;
  212. height: 48rpx;
  213. line-height: 48rpx;
  214. text-align: center;
  215. font-size: 24rpx;
  216. color: #FF4D3A;
  217. box-sizing: border-box;
  218. }
  219. .icon{
  220. width: 100rpx;
  221. height: 100rpx;
  222. }
  223. }
  224. .discounts-item.disabled{
  225. filter: grayscale(1);
  226. }
  227. }
  228. </style>