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

322 lines
9.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
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
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
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <lf-nav title="秒杀专场" :showIcon="true" bgColor="#fff"></lf-nav>
  4. <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true"
  5. :refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  6. <view class="content">
  7. <view class="card" v-for="(item, index) in list" :key="index"
  8. @click="$url('/pages/shop/goodsdetail?id='+ item.goods.id)">
  9. <view class="goods-img">
  10. <image class="img" :src="item.goods.img"></image>
  11. <view class="tips lf-line-1">已有{{item.sell_num}}人购买</view>
  12. </view>
  13. <view class="goods-info">
  14. <view>
  15. <view class="lf-line-2 title lf-m-b-16">{{ item.goods.name }}</view>
  16. <!-- <view class="desc" v-if="item.seckill.end_left_time.length==0">距离开始还剩余
  17. {{item.seckill.start_left_time[0]}}{{item.seckill.start_left_time[1]}}{{item.seckill.start_left_time[2]}}{{item.seckill.start_left_time[3]}}
  18. </view>
  19. <view class="desc" v-if="item.seckill.start_left_time.length==0">距离结束还剩余
  20. {{item.seckill.end_left_time[0]}}{{item.seckill.end_left_time[1]}}{{item.seckill.end_left_time[2]}}{{item.seckill.end_left_time[3]}}
  21. </view> -->
  22. <view class="desc" v-if="item.ifStart">距离结束还剩余
  23. <countdown-timer :time="item.countTime" :autoStart="true" @finish="dateFinish">
  24. <template v-slot="{day,hour,minute, second}">
  25. <view class="lf-flex">
  26. <view class="lf-font-24">{{ day >= 10 ? day : "0" + day }}</view>
  27. <view class="lf-font-24"></view>
  28. <view class="lf-font-24">{{ hour >= 10 ? hour : "0" + hour }}</view>
  29. <view class="lf-font-24"></view>
  30. <view class="lf-font-24">{{ minute >= 10 ? minute : "0" + minute }}</view>
  31. <view class="lf-font-24"></view>
  32. <view class="lf-font-24">{{ second >= 10 ? second : "0" + second }}</view>
  33. <view class="lf-font-24"></view>
  34. </view>
  35. </template>
  36. </countdown-timer>
  37. </view>
  38. <view class="desc" v-else>距离开始还剩余
  39. <countdown-timer :time="item.countTime" :autoStart="true" @finish="dateFinish">
  40. <template v-slot="{day,hour,minute, second}">
  41. <view class="lf-flex">
  42. <view class="lf-font-24">{{ day >= 10 ? day : "0" + day }}</view>
  43. <view class="lf-font-24"></view>
  44. <view class="lf-font-24">{{ hour >= 10 ? hour : "0" + hour }}</view>
  45. <view class="lf-font-24"></view>
  46. <view class="lf-font-24">{{ minute >= 10 ? minute : "0" + minute }}</view>
  47. <view class="lf-font-24"></view>
  48. <view class="lf-font-24">{{ second >= 10 ? second : "0" + second }}</view>
  49. <view class="lf-font-24"></view>
  50. </view>
  51. </template>
  52. </countdown-timer>
  53. </view>
  54. </view>
  55. <view class="lf-row-between">
  56. <view class="price">
  57. <text>¥{{ item.seckill_price }}</text>
  58. <text>¥{{ item.goods.market_price }}</text>
  59. </view>
  60. <view class="btn" hover-class="lf-opacity">立即秒杀</view>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 空数据的情况 -->
  65. <view class="loading-more">
  66. <text v-if="list.length != 0" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  67. <lf-nocontent src="/static/images/empty.png" v-else></lf-nocontent>
  68. </view>
  69. </view>
  70. </scroll-view>
  71. <u-back-top :scrollTop="pageScrollTop"></u-back-top>
  72. </view>
  73. </template>
  74. <script>
  75. import countdownTimer from '@/components/countdown-timer/countdown-timer';
  76. export default {
  77. data() {
  78. return {
  79. list: [],
  80. page: 1,
  81. isPage: true,
  82. loadingClass: true,
  83. loadingText: '正在加载中',
  84. scrollH: 0,
  85. nav_height: 0,
  86. isRefresher: true,
  87. pageSize: 10,
  88. timer: '',
  89. day: '',
  90. hour: '',
  91. min: '',
  92. second: ''
  93. }
  94. },
  95. components: {
  96. countdownTimer
  97. },
  98. computed: {
  99. autoHeight() {
  100. return `calc(${this.scrollH}px - ${this.nav_height}px - 180rpx)`;
  101. }
  102. },
  103. onLoad() {
  104. let info = uni.getSystemInfoSync();
  105. this.scrollH = info.screenHeight;
  106. this.getSeckillList();
  107. },
  108. methods: {
  109. // 页面触底,加载下一页
  110. onScrolltolower() {
  111. if (this.isPage) {
  112. this.page = this.page + 1;
  113. this.getSeckillList();
  114. }
  115. },
  116. // 下拉刷新处理
  117. refreshFn(options) {
  118. this.page = 1;
  119. this.isPage = true;
  120. this.loadingClass = true;
  121. this.list = []
  122. this.loadingText = '正在加载中';
  123. this.getSeckillList(options);
  124. },
  125. // scroll-view 下拉刷新
  126. onRefresherrefresh() {
  127. this.isRefresher = true;
  128. this.refreshFn({
  129. type: 'scrollRefresh'
  130. });
  131. },
  132. getTime(){
  133. var date = new Date(),
  134. year = date.getFullYear(),
  135. month = date.getMonth() + 1,
  136. day = date.getDate(),
  137. hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
  138. minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
  139. second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  140. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  141. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  142. var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  143. return timer;
  144. },
  145. getSeckillList(options = {}) {
  146. this.$http.get({
  147. api: 'api/seckill/all'
  148. }).then(res => {
  149. console.log("----", res);
  150. let isPage = this.page < res.data.meta.pagination.total_pages ? true : false;
  151. this.isPage = isPage;
  152. if (!isPage) {
  153. this.loadingClass = false;
  154. this.loadingText = '没有更多数据啦~';
  155. }
  156. if (options.type == 'pageRefresh') {
  157. uni.stopPullDownRefresh();
  158. } else if (options.type == 'scrollRefresh') {
  159. this.isRefresher = false;
  160. }
  161. if (this.page == 1) {
  162. let list = res.data.data;
  163. list.forEach((item,index) => {
  164. let now_date = new Date(new Date().toLocaleDateString()).getTime();
  165. let start_date = new Date(new Date(item.seckill.starts_at).toLocaleDateString()).getTime();
  166. console.log(now_date)
  167. console.log(start_date)
  168. console.log(item)
  169. if(now_date < start_date) {
  170. this.$set(item,'ifStart',false)
  171. var date = this.getTime()
  172. let time = new Date(item.seckill.starts_at).getTime() - new Date(date).getTime()
  173. this.$set(item,'countTime',time)
  174. }else {
  175. this.$set(item,'ifStart',true)
  176. var date = this.getTime()
  177. let time = new Date(item.seckill.ends_at).getTime() - new Date(date).getTime()
  178. this.$set(item,'countTime',time)
  179. }
  180. })
  181. this.list = list
  182. console.log(this.list)
  183. } else {
  184. let list = res.data.data;
  185. list.forEach((item,index) => {
  186. let now_date = new Date(new Date().toLocaleDateString()).getTime();
  187. let start_date = new Date(new Date(item.seckill.starts_at).toLocaleDateString()).getTime();
  188. console.log(now_date)
  189. console.log(start_date)
  190. console.log(item)
  191. if(now_date < start_date) {
  192. this.$set(item,'ifStart',false)
  193. var date = this.getTime()
  194. let time = new Date(item.seckill.starts_at).getTime() - new Date(date).getTime()
  195. this.$set(item,'countTime',time)
  196. }else {
  197. this.$set(item,'ifStart',true)
  198. var date = this.getTime()
  199. let time = new Date(item.seckill.ends_at).getTime() - new Date(date).getTime()
  200. this.$set(item,'countTime',time)
  201. }
  202. })
  203. this.list.push(...list);
  204. }
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style>
  211. page {
  212. background-color: #F8F8F8;
  213. }
  214. </style>
  215. <style lang="scss" scoped="scoped">
  216. .content {
  217. padding: 30rpx 32rpx;
  218. width: 750rpx;
  219. height: max-content;
  220. box-sizing: border-box;
  221. .card {
  222. width: 686rpx;
  223. height: 260rpx;
  224. background: #FFFFFF;
  225. border-radius: 20rpx;
  226. box-sizing: border-box;
  227. padding: 30rpx;
  228. display: flex;
  229. &:nth-child(n+2) {
  230. margin-top: 30rpx;
  231. }
  232. .goods-img {
  233. width: 200rpx;
  234. height: 200rpx;
  235. border-radius: 10rpx;
  236. overflow: hidden;
  237. position: relative;
  238. margin-right: 15rpx;
  239. .img {
  240. width: 100%;
  241. height: 100%;
  242. background-color: #EEEEEE;
  243. }
  244. .tips {
  245. position: absolute;
  246. bottom: 0;
  247. left: 0;
  248. width: 100%;
  249. height: 37rpx;
  250. background-color: rgba(0, 0, 0, 0.5);
  251. color: #FFFFFF;
  252. font-size: 22rpx;
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. }
  257. }
  258. .goods-info {
  259. width: 410rpx;
  260. height: 200rpx;
  261. display: flex;
  262. flex-direction: column;
  263. justify-content: space-between;
  264. .title {
  265. font-size: 28rpx;
  266. color: #222222;
  267. font-weight: bold;
  268. }
  269. .desc {
  270. // width: 281rpx;
  271. height: max-content;
  272. border-radius: 3rpx;
  273. background-color: #E9F2F2;
  274. font-size: 24rpx;
  275. color: #15716E;
  276. display: flex;
  277. justify-content: center;
  278. align-items: center;
  279. }
  280. .price>text:nth-child(1) {
  281. font-size: 36rpx;
  282. color: #F63434;
  283. font-weight: bold;
  284. }
  285. .price>text:nth-child(2) {
  286. font-size: 24rpx;
  287. color: #777777;
  288. margin-left: 20rpx;
  289. text-decoration: line-through;
  290. }
  291. .btn {
  292. width: 142rpx;
  293. height: 60rpx;
  294. background: rgba(21, 113, 110, 0.05);
  295. border-radius: 36rpx;
  296. border: 2rpx solid #15716E;
  297. font-size: 26rpx;
  298. color: #15716E;
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. }
  303. }
  304. }
  305. }
  306. </style>