金诚优选前端代码
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.

320 lines
8.4 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
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,'lf-bg-haveuse': item.used_at != ''}" 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.starts_at}}~{{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 src="/static/images/empty.png" 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. .lf-bg-haveuse {
  206. background-color: rgba(255, 255, 255, 1)!important;
  207. }
  208. .coupon-circle1 {
  209. width: 40rpx;
  210. height: 40rpx;
  211. background-color: white;
  212. border-radius: 50%;
  213. }
  214. .coupon-circle-top {
  215. width: 50rpx;
  216. height: 50rpx;
  217. border-radius: 50%;
  218. // background-color: red;
  219. position: absolute;
  220. border: 1px dashed #ccc;
  221. left: 190rpx;
  222. top: -20rpx;
  223. display: flex;
  224. align-items: center;
  225. text-align: center;
  226. justify-content: center;
  227. }
  228. .coupon-circle-bottom {
  229. width: 50rpx;
  230. height: 50rpx;
  231. border-radius: 50%;
  232. // background-color: red;
  233. position: absolute;
  234. border: 1px dashed #ccc;
  235. left: 190rpx;
  236. bottom: -20rpx;
  237. display: flex;
  238. align-items: center;
  239. text-align: center;
  240. justify-content: center;
  241. }
  242. .coupon-right {
  243. text-align: left;
  244. justify-content: center;
  245. align-items: flex-start;
  246. display: flex;
  247. flex-direction: column;
  248. margin-left: 84rpx;
  249. }
  250. .coupon-left {
  251. margin-left: 20rpx;
  252. display: flex;
  253. flex-direction: column;
  254. justify-content: center;
  255. align-items: center;
  256. }
  257. .coupon-tag {
  258. width: max-content;
  259. margin-top: 10rpx;
  260. padding: 0 24rpx;
  261. height: 43rpx;
  262. border-radius: 22rpx;
  263. border: 2rpx solid #FFFFFF;
  264. font-size: 24rpx;
  265. color: white;
  266. }
  267. .coupon-wrap {
  268. display: flex;
  269. justify-content: center;
  270. margin-top: 30rpx;
  271. flex-direction: column;
  272. align-content: center;
  273. align-items: center;
  274. }
  275. .coupon-card {
  276. overflow: hidden;
  277. position: relative;
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. width: 674rpx;
  282. // display: flex;
  283. height: 171rpx;
  284. // opacity: 0.59;
  285. // border: 1rpx solid #FFFFFF;
  286. background: #15716E;
  287. border-radius: 20rpx;
  288. }
  289. .invalid-bg{
  290. background-color: #999999;
  291. }
  292. .coupon-radius {
  293. width: 664rpx;
  294. display: flex;
  295. height: 161rpx;
  296. border: 1rpx dashed #ccc;
  297. // background: #15716E;
  298. border-radius: 20rpx;
  299. }
  300. /deep/.u-scroll-box {
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  305. }
  306. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  307. background-color: #15716E!important;
  308. width: 80rpx!important;
  309. position: absolute;
  310. height: 10rpx;
  311. left: 0;
  312. border-radius: 8rpx 8rpx 0px 0px!important;
  313. bottom: -12rpx;
  314. }
  315. /deep/ .u-tab-item {
  316. font-size: 28rpx!important;
  317. }
  318. </style>