金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
8.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <lf-nav :spreadOut="true" :showIcon="true" bgColor="white" title="优惠券"></lf-nav>
  4. <view class="special_tab">
  5. <u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="true" :current="current" @change="tabChange"></u-tabs>
  6. </view>
  7. <swiper :style="{height: autoHeight}" :current="current" @change="swiperChange">
  8. <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
  9. <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher"
  10. @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  11. <view class="coupon-wrap">
  12. <view class="coupon-card lf-m-b-30" :class="{'invalid-bg': item.ifpast == true}" v-for="(item, index) in tab.list" :key="index">
  13. <view class="coupon-circle-top">
  14. <view class="coupon-circle1"></view>
  15. </view>
  16. <view class="coupon-circle-bottom">
  17. <view class="coupon-circle1"></view>
  18. </view>
  19. <view class="coupon-radius">
  20. <view class="coupon-left">
  21. <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'cash'">
  22. <text></text>
  23. <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text>
  24. </view>
  25. <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'discount'">
  26. <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text>
  27. <text>%</text>
  28. </view>
  29. <view class="coupon-tag" v-if="item.used_at != ''">
  30. 已使用
  31. </view>
  32. <view class="coupon-tag" v-if="item.ifpast">
  33. 已过期
  34. </view>
  35. <view class="coupon-tag" v-if="!item.ifpast && item.used_at == ''">
  36. 待使用
  37. </view>
  38. </view>
  39. <view class="coupon-right">
  40. <view class="lf-font-32 lf-font-bold lf-color-white">{{item.discount.title}}</view>
  41. <view class="lf-font-24 lf-color-white">有效期{{item.discount.ends_at}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 空数据的情况 -->
  46. <view class="loading-more">
  47. <text v-if="tab.list.length"
  48. :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  49. <lf-nocontent v-else></lf-nocontent>
  50. </view>
  51. </view>
  52. </scroll-view>
  53. </swiper-item>
  54. </swiper>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. let _public = {
  61. page: 1,
  62. isPage: true,
  63. loadingClass: true,
  64. loadingText: '正在加载中'
  65. }
  66. return {
  67. current: 0,
  68. tab_list: [
  69. {
  70. name: '全部',
  71. list: [],
  72. type: 'all',
  73. ..._public
  74. },
  75. {
  76. name: '待使用',
  77. list: [],
  78. type: 'valid',
  79. ..._public
  80. },
  81. {
  82. name: '已使用',
  83. list: [],
  84. type: 'used',
  85. ..._public
  86. },
  87. {
  88. name: '已失效',
  89. list: [],
  90. type: 'invalid',
  91. ..._public
  92. }
  93. ],
  94. scrollH: 0,
  95. nav_height: 0,
  96. isRefresher: true
  97. }
  98. },
  99. computed: {
  100. autoHeight(){
  101. return `calc(${this.scrollH}px - ${this.nav_height}px - 86rpx)`;
  102. }
  103. },
  104. methods: {
  105. compareDate(val) {
  106. var nowTime = new Date(new Date().toLocaleDateString()).getTime();
  107. let oldTime = new Date(new Date(val).toLocaleDateString()).getTime();
  108. if(nowTime>oldTime) {
  109. return true;
  110. }else {
  111. return false;
  112. }
  113. },
  114. // 页面触底,加载下一页
  115. onScrolltolower(){
  116. let tab_item = this.tab_list[this.current];
  117. if(tab_item.isPage){
  118. tab_item.page = tab_item.page + 1;
  119. this.getCouponList();
  120. }
  121. },
  122. // 下拉刷新处理
  123. refreshFn(options){
  124. let tab_item = this.tab_list[this.current];
  125. tab_item.page = 1;
  126. tab_item.isPage = true;
  127. tab_item.loadingClass = true;
  128. tab_item.list = []
  129. tab_item.loadingText = '正在加载中';
  130. this.getCouponList(options);
  131. },
  132. // scroll-view 下拉刷新
  133. onRefresherrefresh(){
  134. this.isRefresher = true;
  135. this.refreshFn({type: 'scrollRefresh'});
  136. },
  137. swiperChange(event){
  138. this.current = event.detail.current;
  139. if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  140. this.getCouponList();
  141. },
  142. getCouponList(options = {}) {
  143. let tab_item = this.tab_list[this.current];
  144. this.$http
  145. .get({
  146. api: 'api/coupon',
  147. data: {
  148. type: tab_item.type,
  149. page: tab_item.page
  150. },
  151. header: {
  152. Authorization: this.$cookieStorage.get('user_token')
  153. },
  154. })
  155. .then(res => {
  156. if (res.statusCode == 200) {
  157. let isPage = res.data.total_pages == 1?true:false;
  158. tab_item.isPage = isPage;
  159. if(!isPage) {
  160. tab_item.loadingClass = false;
  161. tab_item.loadingText = '没有更多数据啦~';
  162. }
  163. if(options.type == 'pageRefresh') {
  164. uni.stopPullDownRefresh();
  165. }else if(options.type == 'scrollRefresh') {
  166. this.isRefresher = false;
  167. }
  168. if(tab_item.page == 1) {
  169. tab_item.list = res.data.data;
  170. }else {
  171. tab_item.list.push(...res.data.data);
  172. }
  173. tab_item.list.forEach((item,index) => {
  174. if(this.compareDate(item.discount.ends_at)) {
  175. this.$set(item,'ifpast',true);
  176. }else {
  177. this.$set(item,'ifpast',false);
  178. }
  179. })
  180. } else {
  181. wx.showModal({
  182. content: '请下拉页面刷新重试',
  183. showCancel: false
  184. });
  185. }
  186. wx.hideLoading();
  187. })
  188. .catch(() => {
  189. wx.hideLoading();
  190. });
  191. },
  192. tabChange(index){
  193. this.current = index;
  194. this.getCouponList();
  195. },
  196. },
  197. onLoad() {
  198. let info = uni.getSystemInfoSync();
  199. this.scrollH = info.screenHeight;
  200. this.getCouponList();
  201. }
  202. }
  203. </script>
  204. <style scoped lang="scss">
  205. .coupon-circle1 {
  206. width: 40rpx;
  207. height: 40rpx;
  208. background-color: white;
  209. border-radius: 50%;
  210. }
  211. .coupon-circle-top {
  212. width: 50rpx;
  213. height: 50rpx;
  214. border-radius: 50%;
  215. // background-color: red;
  216. position: absolute;
  217. border: 1px dashed #ccc;
  218. left: 190rpx;
  219. top: -20rpx;
  220. display: flex;
  221. align-items: center;
  222. text-align: center;
  223. justify-content: center;
  224. }
  225. .coupon-circle-bottom {
  226. width: 50rpx;
  227. height: 50rpx;
  228. border-radius: 50%;
  229. // background-color: red;
  230. position: absolute;
  231. border: 1px dashed #ccc;
  232. left: 190rpx;
  233. bottom: -20rpx;
  234. display: flex;
  235. align-items: center;
  236. text-align: center;
  237. justify-content: center;
  238. }
  239. .coupon-right {
  240. text-align: left;
  241. justify-content: center;
  242. align-items: flex-start;
  243. display: flex;
  244. flex-direction: column;
  245. margin-left: 84rpx;
  246. }
  247. .coupon-left {
  248. margin-left: 20rpx;
  249. display: flex;
  250. flex-direction: column;
  251. justify-content: center;
  252. align-items: center;
  253. }
  254. .coupon-tag {
  255. width: max-content;
  256. margin-top: 10rpx;
  257. padding: 0 24rpx;
  258. height: 43rpx;
  259. border-radius: 22rpx;
  260. border: 2rpx solid #FFFFFF;
  261. font-size: 24rpx;
  262. color: white;
  263. }
  264. .coupon-wrap {
  265. display: flex;
  266. justify-content: center;
  267. margin-top: 30rpx;
  268. flex-direction: column;
  269. align-content: center;
  270. align-items: center;
  271. }
  272. .coupon-card {
  273. overflow: hidden;
  274. position: relative;
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. width: 674rpx;
  279. // display: flex;
  280. height: 171rpx;
  281. // opacity: 0.59;
  282. // border: 1rpx solid #FFFFFF;
  283. background: #15716E;
  284. border-radius: 20rpx;
  285. }
  286. .invalid-bg{
  287. background-color: #999999;
  288. }
  289. .coupon-radius {
  290. width: 664rpx;
  291. display: flex;
  292. height: 161rpx;
  293. border: 1rpx dashed #ccc;
  294. // background: #15716E;
  295. border-radius: 20rpx;
  296. }
  297. /deep/.u-scroll-box {
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  302. }
  303. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  304. background-color: #15716E!important;
  305. width: 80rpx!important;
  306. position: absolute;
  307. height: 10rpx;
  308. left: 0;
  309. border-radius: 8rpx 8rpx 0px 0px!important;
  310. bottom: -12rpx;
  311. }
  312. /deep/ .u-tab-item {
  313. font-size: 28rpx!important;
  314. }
  315. </style>