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

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