myCoupon.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item,index) in navList" :key="index" class="nav-item"
  5. :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  6. </view>
  7. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  8. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  9. <scroll-view scroll-y="true" :style="{'height': height}">
  10. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  11. <view class="kp-item flex" :class="{'sy':tabCurrentIndex != 0}" v-for="item in tabItem.orderList"
  12. :key="item.id" @click="navTo('/user/page/coupon?id='+item.id)">
  13. <image src="https://hy.liuniu946.com/app/img/my-kq-1.png" mode="" class="kp-bg" v-if="item._type == 0">
  14. </image>
  15. <image src="https://hy.liuniu946.com/app/img/my-kq.png" mode="" class="kp-bg" v-if="item._type !=0">
  16. </image>
  17. <view class="kp-left flex">
  18. <view class="left-val">
  19. {{item.coupon_price}}
  20. </view>
  21. </view>
  22. <view class="kp-right flex">
  23. <view class="">
  24. <view class="right-tit clamp2">
  25. {{item.coupon_title}}
  26. </view>
  27. <view class="right-tip" v-if="item.use_min_price!='0.00'">
  28. 使用条件:满{{item.use_min_price}}¥可用
  29. </view>
  30. <view class="right-tip" v-else>
  31. 使用条件:无门槛
  32. </view>
  33. <view class="right-tip" v-if="!item.store">
  34. 购物下单时自动抵扣
  35. </view>
  36. <view class="right-tip" v-else>
  37. 使用商户:{{item.store.name}}
  38. </view>
  39. </view>
  40. <view class="right-time">
  41. 有效期至:{{item._end_time}}
  42. </view>
  43. </view>
  44. </view>
  45. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  46. </scroll-view>
  47. <!-- 空白页 -->
  48. </swiper-item>
  49. </swiper>
  50. </view>
  51. </template>
  52. <script>
  53. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  54. import empty from '@/components/empty';
  55. import {
  56. getCouponsList
  57. } from '@/api/order.js'
  58. export default {
  59. components: {
  60. uniLoadMore,
  61. empty
  62. },
  63. data() {
  64. return {
  65. height: '',
  66. tabCurrentIndex: 0,
  67. navList: [{
  68. state: 0,
  69. text: '全部',
  70. loadingType: 'more',
  71. orderList: [],
  72. page: 1, //当前页数
  73. limit: 10, //每次信息条数
  74. loaded: false
  75. },
  76. {
  77. state: 1,
  78. text: '未使用',
  79. loadingType: 'more',
  80. orderList: [],
  81. page: 1, //当前页数
  82. limit: 10, //每次信息条数
  83. loaded: false
  84. },
  85. {
  86. state: 2,
  87. text: '已使用',
  88. loadingType: 'more',
  89. orderList: [],
  90. page: 1, //当前页数
  91. limit: 10, //每次信息条数
  92. loaded: false
  93. }
  94. ]
  95. }
  96. },
  97. onLoad() {
  98. this.getMyCoupons()
  99. },
  100. onShow() {
  101. },
  102. onReachBottom() {
  103. },
  104. onReady() {
  105. var obj = this;
  106. uni.getSystemInfo({
  107. success: resu => {
  108. const query = uni.createSelectorQuery();
  109. query.select('.swiper-box').boundingClientRect();
  110. query.exec(function(res) {
  111. obj.height = resu.windowHeight - res[0].top + 'px';
  112. });
  113. },
  114. fail: res => {}
  115. });
  116. },
  117. methods: {
  118. navTo(url) {
  119. console.log(url);
  120. let pages = getCurrentPages();
  121. console.log(pages, 'pages');
  122. let prevPage = pages[pages.length - 2]
  123. console.log(prevPage, 'pages2');
  124. // if (!this.hasLogin) {
  125. // // 保存地址
  126. // saveUrl();
  127. // // 登录拦截
  128. // interceptor();
  129. // } else {
  130. uni.navigateTo({
  131. url
  132. });
  133. // }
  134. },
  135. getMyCoupons(type) {
  136. let obj = this
  137. let index = obj.tabCurrentIndex
  138. let navitem = obj.navList[index]
  139. if(type == 'tab' && navitem.loaded) {
  140. return
  141. }
  142. if (navitem.loadingType == 'noMore' || navitem.loadingType == 'loading') {
  143. return
  144. }
  145. navitem.loadingType = 'loading'
  146. getCouponsList({
  147. pages: navitem.page,
  148. limit: navitem.limit
  149. }, navitem.state).then(({data}) => {
  150. let da = data.map(e => {
  151. e.coupon_price = +(e.coupon_price.replace(',', ''));
  152. e.use_min_price = +e.use_min_price.replace(',', '');
  153. return e
  154. });
  155. navitem.orderList = navitem.orderList.concat(da);
  156. console.log(navitem.orderList);
  157. navitem.page++;
  158. if (navitem.limit == data.length) {
  159. // 判断是否还有数据,有改为more,没有改为noMore
  160. navitem.loadingType = 'more';
  161. return;
  162. }else {
  163. navitem.loadingType = 'noMore';
  164. }
  165. uni.hideLoading();
  166. this.$set(navitem, 'loaded', true);
  167. })
  168. },
  169. //顶部tab点击
  170. tabClick(index) {
  171. this.tabCurrentIndex = index;
  172. this.getMyCoupons()
  173. },
  174. //swiper 切换
  175. changeTab(e) {
  176. console.log(e, 'eeeeeeeeeeeeeeeeee')
  177. if (e.target.current > this.navList.length - 1) {
  178. this.tabCurrentIndex = 0
  179. } else {
  180. this.tabCurrentIndex = e.target.current;
  181. }
  182. },
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. page,
  188. .content {
  189. background: $page-color-base;
  190. height: 100%;
  191. }
  192. .navbar {
  193. display: flex;
  194. height: 40px;
  195. padding: 0 5px;
  196. background: #fff;
  197. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  198. position: relative;
  199. z-index: 10;
  200. .nav-item {
  201. flex: 1;
  202. display: flex;
  203. justify-content: center;
  204. align-items: center;
  205. height: 100%;
  206. font-size: 15px;
  207. color: $font-color-dark;
  208. position: relative;
  209. &.current {
  210. color: #FF4C4C;
  211. &:after {
  212. content: '';
  213. position: absolute;
  214. left: 50%;
  215. bottom: 0;
  216. transform: translateX(-50%);
  217. width: 44px;
  218. height: 0;
  219. border-bottom: 2px solid #FF4C4C;
  220. }
  221. }
  222. }
  223. }
  224. .swiper-box {
  225. height: calc(100% - 40px);
  226. .tab-content {
  227. // padding: 25rpx 0px;
  228. font-size: 28rpx;
  229. color: #1b1b1b;
  230. }
  231. }
  232. .kp-item {
  233. width: 690rpx;
  234. height: 240rpx;
  235. margin: 0 auto 20rpx;
  236. position: relative;
  237. .kp-bg {
  238. width: 690rpx;
  239. height: 240rpx;
  240. position: absolute;
  241. top: 0;
  242. left: 0;
  243. }
  244. .kp-left {
  245. width: 221rpx;
  246. height: 240rpx;
  247. justify-content: center;
  248. align-items: center;
  249. position: relative;
  250. flex-shrink: 0;
  251. .left-val {
  252. font-size: 90rpx;
  253. font-weight: 400;
  254. color: #FFFFFF;
  255. text-shadow: 0px 10px 5px rgba(255, 125, 69, 0.3);
  256. &::before {
  257. content: '¥';
  258. font-size: 40rpx;
  259. font-weight: 400;
  260. color: #FFFFFF;
  261. }
  262. }
  263. }
  264. .kp-right {
  265. // width: 648rpx;
  266. flex-grow: 1;
  267. height: 240rpx;
  268. position: relative;
  269. // background: #000;
  270. flex-direction: column;
  271. justify-content: space-between;
  272. padding: 40rpx;
  273. align-items: flex-end;
  274. text-align: right;
  275. .right-tit {
  276. font-size: 40rpx;
  277. font-weight: 400;
  278. color: #FFFFFF;
  279. }
  280. .right-tip {
  281. font-size: 24rpx;
  282. font-weight: 400;
  283. color: #FFFFFF;
  284. }
  285. .right-time {
  286. font-size: 20rpx;
  287. font-weight: bold;
  288. color: #FFFFFF;
  289. }
  290. }
  291. }
  292. .sy {
  293. .kp-left {
  294. .left-val {
  295. text-shadow: 0px 10px 5px rgba(173, 173, 173, 0.3);
  296. }
  297. }
  298. }
  299. </style>