coupon_list.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="dt-page">
  3. <scroll-view scroll-x="true" class="tab-h">
  4. <view v-for="(item,index) in tabItemList" :key="index" :class="['tab-item', currentTab == index ? 'active' : '']" @tap="swichNav(index)">{{item.tabName}}</view>
  5. </scroll-view>
  6. <view style="height:80rpx;"></view>
  7. <swiper :style="calcHeight" class="tab-content" :current="currentTab" duration="300" @change="swiperSwitchTab">
  8. <swiper-item v-for="(item, index) in tabItemList" :key="index">
  9. <scroll-view @scrolltolower="onScrollToLower" scroll-y="true" class="scoll-h">
  10. <view v-if="emptyType==0" class="container">
  11. <view style="height:30rpx;"></view>
  12. <view class="voucher" v-for="(item, idx) in dataList" :key="idx">
  13. <DtCoupon :dataDetail="item.coupon" :isEnable="isEnable"
  14. @visible="onVisible($event,idx)"
  15. @recieve="onRecieve"
  16. @use="onUse"/>
  17. </view>
  18. </view>
  19. <DtNoMore v-if="isNoMore" />
  20. <DtEmpty :type="emptyType" />
  21. </scroll-view>
  22. </swiper-item>
  23. </swiper>
  24. <view style="height: 90upx;"></view>
  25. <view @tap="tapToCoupon"
  26. style="
  27. position: fixed;
  28. bottom: 0;
  29. left: 0;
  30. right: 0;
  31. background-color: #2f7ff5;
  32. height: 90upx;
  33. line-height: 90upx;
  34. text-align: center;
  35. font-size: 32upx;
  36. color: #fff;">领取更多优惠券</view>
  37. </view>
  38. </template>
  39. <script>
  40. import DtNoMore from "../comps/dt_no_more.vue";
  41. import DtCoupon from '../comps/dt_coupon.vue';
  42. import DtEmpty from '../comps/dt_empty.vue'
  43. export default {
  44. components: {
  45. DtNoMore,
  46. DtCoupon,
  47. DtEmpty
  48. },
  49. data () {
  50. return {
  51. tabItemList: [
  52. {
  53. tabName: "可使用",
  54. useStatue: 3
  55. },
  56. {
  57. tabName: "已使用",
  58. useStatue: 1,
  59. },
  60. {
  61. tabName: "已过期",
  62. useStatue: 2
  63. }
  64. ],
  65. winHeight: "", //窗口高度
  66. currentTab: 0, //预设当前项的值
  67. dataList: [
  68. // {
  69. // is_get:1,
  70. // voucher_type:1,
  71. // status:1,
  72. // },{
  73. // is_get:0,
  74. // voucher_type:2,
  75. // status:1,
  76. // },{
  77. // is_get:1,
  78. // voucher_type:1,
  79. // status:2,
  80. // }
  81. ],
  82. memberId: '',
  83. showNoMore: false,
  84. showNoDataView: false
  85. };
  86. },
  87. computed: {
  88. calcHeight () {
  89. return "height:"+this.winHeight+"px;";
  90. },
  91. isEnable(){
  92. return this.currentTab==0
  93. },
  94. },
  95. methods: {
  96. // 跳转优惠券
  97. tapToCoupon() {
  98. uni.navigateTo({
  99. url: "/pagesM/pages/coupon_center"
  100. })
  101. },
  102. // 滚动切换标签样式
  103. swiperSwitchTab(e) {
  104. console.log(113,e)
  105. let cur=e.detail.current;
  106. this.currentTab=e.detail.current;
  107. this.pageIndex = 0
  108. this.dataList.length = 0
  109. this.queryDataList()
  110. },
  111. // 点击标题切换当前页时改变样式
  112. swichNav(cur) {
  113. if(this.currentTab==cur) {
  114. return false;
  115. } else {
  116. this.showNoMore=false;
  117. this.currentTab=cur;
  118. }
  119. },
  120. //查看详情
  121. onVisible(ev, idx) {
  122. let dataList = this.dataList.slice(0)
  123. dataList[idx].coupon.isShowDetail = !dataList[idx].coupon.isShowDetail
  124. this.$set(this, 'dataList', dataList)
  125. },
  126. // 领取优惠券
  127. onRecieve(item){
  128. console.log('get Voucher',item)
  129. },
  130. onUse(){
  131. uni.switchTab({
  132. url:'/pagesM/pages/home'
  133. })
  134. },
  135. //获取优惠券列表
  136. async queryDataList(){
  137. let useStatue = this.tabItemList[this.currentTab].useStatue
  138. let resp = await this.$api.getMyCoupons({
  139. memberId:this.memberId,
  140. status:useStatue,
  141. pageNo:this.pageIndex,
  142. pageSize:this.pageSize
  143. })
  144. let list = this.getDataList(resp)
  145. if(this.currentTab==0){
  146. list.map((item,idx)=>{
  147. item.coupon.isReceive = true
  148. return item
  149. })
  150. }
  151. this.dataList = this.dataList.concat(list)
  152. },
  153. onLoadPage (options) {
  154. wx.hideShareMenu();
  155. this.memberId = this.$auth.getMemberId()
  156. this.queryDataList();
  157. // 高度自适应
  158. let res=uni.getSystemInfoSync();
  159. let clientHeight=res.windowHeight;
  160. let clientWidth=res.windowWidth;
  161. let upxR=750/clientWidth;
  162. let calc=clientHeight*upxR-80;
  163. let height=uni.upx2px(calc);
  164. this.winHeight=height;
  165. },
  166. onScrollToLower(){
  167. if(!this.isNoMore){
  168. this.queryDataList()
  169. }
  170. }
  171. }
  172. };
  173. </script>
  174. <style lang="scss" scoped>
  175. .dt-page {
  176. min-height: 100vh;
  177. background-color: #f2f2f2;
  178. .tab-h {
  179. height: 80upx;
  180. width: 100%;
  181. box-sizing: border-box;
  182. overflow: hidden;
  183. line-height: 80upx;
  184. background: white;
  185. font-size: 28upx;
  186. white-space: nowrap;
  187. position: fixed;
  188. top: 0;
  189. left: 0;
  190. z-index: 99;
  191. text-align: center;
  192. display: flex;
  193. flex-direction: row;
  194. justify-content: space-around;
  195. .tab-item {
  196. display: inline-block;
  197. color: rgb(51, 51, 51);
  198. width: 30%;
  199. }
  200. .tab-item.active {
  201. color: $base;
  202. position: relative;
  203. width: 30%;
  204. font-weight: 600;
  205. }
  206. .tab-item.active:after {
  207. content: "";
  208. display: block;
  209. height: 4upx;
  210. width: 30%;
  211. background: $base;
  212. position: absolute;
  213. bottom: 0;
  214. left: 34%;
  215. border-radius: 16upx;
  216. }
  217. }
  218. .scoll-h {
  219. height: 100%;
  220. .container {
  221. font-size: 22upx;
  222. color: rgb(153, 153, 153);
  223. padding: 0 30upx;
  224. }
  225. .voucher {
  226. background: white;
  227. display: flex;
  228. flex-direction: column;
  229. border-radius: 10upx;
  230. margin: 0 0 30upx 0;
  231. position: relative;
  232. }
  233. }
  234. }
  235. </style>