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

324 lines
9.5 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
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" v-if="item.countTime">
  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" v-if="item.countTime">
  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. console.log("time", time);
  175. }else {
  176. this.$set(item,'ifStart',true)
  177. var date = this.getTime()
  178. let time = new Date(item.seckill.ends_at).getTime() - new Date(date).getTime()
  179. this.$set(item,'countTime',time)
  180. console.log("time", time);
  181. }
  182. })
  183. this.list = list
  184. console.log(this.list)
  185. } else {
  186. let list = res.data.data;
  187. list.forEach((item,index) => {
  188. let now_date = new Date(new Date().toLocaleDateString()).getTime();
  189. let start_date = new Date(new Date(item.seckill.starts_at).toLocaleDateString()).getTime();
  190. console.log(now_date)
  191. console.log(start_date)
  192. console.log(item)
  193. if(now_date < start_date) {
  194. this.$set(item,'ifStart',false)
  195. var date = this.getTime()
  196. let time = new Date(item.seckill.starts_at).getTime() - new Date(date).getTime()
  197. this.$set(item,'countTime',time)
  198. }else {
  199. this.$set(item,'ifStart',true)
  200. var date = this.getTime()
  201. let time = new Date(item.seckill.ends_at).getTime() - new Date(date).getTime()
  202. this.$set(item,'countTime',time)
  203. }
  204. })
  205. this.list.push(...list);
  206. }
  207. })
  208. }
  209. }
  210. }
  211. </script>
  212. <style>
  213. page {
  214. background-color: #F8F8F8;
  215. }
  216. </style>
  217. <style lang="scss" scoped="scoped">
  218. .content {
  219. padding: 30rpx 32rpx;
  220. width: 750rpx;
  221. height: max-content;
  222. box-sizing: border-box;
  223. .card {
  224. width: 686rpx;
  225. height: 260rpx;
  226. background: #FFFFFF;
  227. border-radius: 20rpx;
  228. box-sizing: border-box;
  229. padding: 30rpx;
  230. display: flex;
  231. &:nth-child(n+2) {
  232. margin-top: 30rpx;
  233. }
  234. .goods-img {
  235. width: 200rpx;
  236. height: 200rpx;
  237. border-radius: 10rpx;
  238. overflow: hidden;
  239. position: relative;
  240. margin-right: 15rpx;
  241. .img {
  242. width: 100%;
  243. height: 100%;
  244. background-color: #EEEEEE;
  245. }
  246. .tips {
  247. position: absolute;
  248. bottom: 0;
  249. left: 0;
  250. width: 100%;
  251. height: 37rpx;
  252. background-color: rgba(0, 0, 0, 0.5);
  253. color: #FFFFFF;
  254. font-size: 22rpx;
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. }
  259. }
  260. .goods-info {
  261. width: 410rpx;
  262. height: 200rpx;
  263. display: flex;
  264. flex-direction: column;
  265. justify-content: space-between;
  266. .title {
  267. font-size: 28rpx;
  268. color: #222222;
  269. font-weight: bold;
  270. }
  271. .desc {
  272. // width: 281rpx;
  273. height: max-content;
  274. border-radius: 3rpx;
  275. background-color: #E9F2F2;
  276. font-size: 24rpx;
  277. color: #15716E;
  278. display: flex;
  279. justify-content: center;
  280. align-items: center;
  281. }
  282. .price>text:nth-child(1) {
  283. font-size: 36rpx;
  284. color: #F63434;
  285. font-weight: bold;
  286. }
  287. .price>text:nth-child(2) {
  288. font-size: 24rpx;
  289. color: #777777;
  290. margin-left: 20rpx;
  291. text-decoration: line-through;
  292. }
  293. .btn {
  294. width: 142rpx;
  295. height: 60rpx;
  296. background: rgba(21, 113, 110, 0.05);
  297. border-radius: 36rpx;
  298. border: 2rpx solid #15716E;
  299. font-size: 26rpx;
  300. color: #15716E;
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. }
  305. }
  306. }
  307. }
  308. </style>