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

319 lines
7.9 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.seckill.start_left_time.length==0">距离结束还剩余
  23. {{ item.seckill.ends_at | timeStamp }}
  24. </view>
  25. </view>
  26. <view class="lf-row-between">
  27. <view class="price">
  28. <text>¥{{ item.seckill_price }}</text>
  29. <text>¥{{ item.goods.market_price }}</text>
  30. </view>
  31. <view class="btn" hover-class="lf-opacity">立即秒杀</view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 空数据的情况 -->
  36. <view class="loading-more">
  37. <text v-if="list.length != 0" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text>
  38. <lf-nocontent src="/static/images/empty.png" v-else></lf-nocontent>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <u-back-top :scrollTop="pageScrollTop"></u-back-top>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. list: [],
  50. page: 1,
  51. isPage: true,
  52. loadingClass: true,
  53. loadingText: '正在加载中',
  54. scrollH: 0,
  55. nav_height: 0,
  56. isRefresher: true,
  57. pageSize: 10,
  58. timer: '',
  59. day: '',
  60. hour: '',
  61. min: '',
  62. second: ''
  63. }
  64. },
  65. computed: {
  66. autoHeight() {
  67. return `calc(${this.scrollH}px - ${this.nav_height}px - 180rpx)`;
  68. }
  69. },
  70. onLoad() {
  71. let info = uni.getSystemInfoSync();
  72. this.scrollH = info.screenHeight;
  73. this.getSeckillList();
  74. // setInterval(() => {
  75. // //定时器调用 直接传入时间戳即可
  76. // this.timer = this.timeStamp('2021-09-29 21:27:00')
  77. // }, 1000)
  78. },
  79. filters: {
  80. timeStamp(times) {
  81. // setInterval(() => {
  82. // }, 1000)
  83. //定时器调用 直接传入时间戳即可
  84. let timestamp = Date.parse(new Date());
  85. timestamp = timestamp/1000;
  86. let timestap1 = Date.parse(new Date(times));
  87. let letime = (timestap1/1000) - timestamp;
  88. let time = parseInt(letime);
  89. if (parseInt(letime) > 60) {
  90. let second = parseInt(letime) % 60;
  91. let min = parseInt(letime / 60);
  92. // 直接返回字符串格式:
  93. // time = min + "分" + second + "秒";
  94. // 返回对象格式:
  95. time = {
  96. min: min,
  97. second: second
  98. };
  99. if (min > 60) {
  100. min = parseInt(letime / 60) % 60;
  101. let hour = parseInt(parseInt(letime / 60) / 60);
  102. // 直接返回字符串格式:
  103. // time = hour + "时" + min + "分" + second + "秒";
  104. // 返回对象格式:
  105. time = {
  106. hour: hour,
  107. min: min,
  108. second: second
  109. }
  110. if (hour >= 24) {
  111. hour = parseInt(parseInt(letime / 60) / 60) % 24;
  112. let day = parseInt(parseInt(parseInt(letime / 60) / 60) / 24);
  113. // 直接返回字符串格式:
  114. // time = day + "天" + hour + "时" + min + "分" + second + "秒";
  115. // 返回对象格式:
  116. time = {
  117. day: day,
  118. hour: hour,
  119. min: min,
  120. second: second
  121. }
  122. }
  123. }
  124. }
  125. // 判断是否小于10,小于10就补零
  126. if (time.day < 10) {
  127. time.day = '0' + time.day
  128. } else if (time.day == undefined) {
  129. time.day = '00'
  130. }
  131. if (time.hour < 10) {
  132. time.hour = '0' + time.hour
  133. } else if (time.hour == undefined) {
  134. time.hour = '00'
  135. }
  136. if (time.min < 10) {
  137. time.min = '0' + time.min
  138. } else if (time.min == undefined) {
  139. time.min = '00'
  140. }
  141. if (time.second < 10) {
  142. time.second = '0' + time.second
  143. }
  144. console.log(time)
  145. // this.day = time.day
  146. // this.hour = time.hour
  147. // this.min = time.min
  148. // this.second = time.second
  149. // 输出结果:
  150. return time.day+'天'+time.hour+'时'+time.min+'分'+time.second+'秒';
  151. },
  152. },
  153. methods: {
  154. // 页面触底,加载下一页
  155. onScrolltolower() {
  156. if (this.isPage) {
  157. this.page = this.page + 1;
  158. this.getSeckillList();
  159. }
  160. },
  161. // 下拉刷新处理
  162. refreshFn(options) {
  163. this.page = 1;
  164. this.isPage = true;
  165. this.loadingClass = true;
  166. this.list = []
  167. this.loadingText = '正在加载中';
  168. this.getSeckillList(options);
  169. },
  170. // scroll-view 下拉刷新
  171. onRefresherrefresh() {
  172. this.isRefresher = true;
  173. this.refreshFn({
  174. type: 'scrollRefresh'
  175. });
  176. },
  177. getSeckillList(options = {}) {
  178. this.$http.get({
  179. api: 'api/seckill/all'
  180. }).then(res => {
  181. console.log("----", res);
  182. let isPage = this.page < res.data.meta.pagination.total_pages ? true : false;
  183. this.isPage = isPage;
  184. if (!isPage) {
  185. this.loadingClass = false;
  186. this.loadingText = '没有更多数据啦~';
  187. }
  188. if (options.type == 'pageRefresh') {
  189. uni.stopPullDownRefresh();
  190. } else if (options.type == 'scrollRefresh') {
  191. this.isRefresher = false;
  192. }
  193. if (this.page == 1) {
  194. this.list = res.data.data;
  195. } else {
  196. this.list.push(...res.data.data);
  197. }
  198. })
  199. }
  200. }
  201. }
  202. </script>
  203. <style>
  204. page {
  205. background-color: #F8F8F8;
  206. }
  207. </style>
  208. <style lang="scss" scoped="scoped">
  209. .content {
  210. padding: 30rpx 32rpx;
  211. width: 750rpx;
  212. height: max-content;
  213. box-sizing: border-box;
  214. .card {
  215. width: 686rpx;
  216. height: 260rpx;
  217. background: #FFFFFF;
  218. border-radius: 20rpx;
  219. box-sizing: border-box;
  220. padding: 30rpx;
  221. display: flex;
  222. &:nth-child(n+2) {
  223. margin-top: 30rpx;
  224. }
  225. .goods-img {
  226. width: 200rpx;
  227. height: 200rpx;
  228. border-radius: 10rpx;
  229. overflow: hidden;
  230. position: relative;
  231. margin-right: 15rpx;
  232. .img {
  233. width: 100%;
  234. height: 100%;
  235. background-color: #EEEEEE;
  236. }
  237. .tips {
  238. position: absolute;
  239. bottom: 0;
  240. left: 0;
  241. width: 100%;
  242. height: 37rpx;
  243. background-color: rgba(0, 0, 0, 0.5);
  244. color: #FFFFFF;
  245. font-size: 22rpx;
  246. display: flex;
  247. justify-content: center;
  248. align-items: center;
  249. }
  250. }
  251. .goods-info {
  252. width: 410rpx;
  253. height: 200rpx;
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: space-between;
  257. .title {
  258. font-size: 28rpx;
  259. color: #222222;
  260. font-weight: bold;
  261. }
  262. .desc {
  263. width: 281rpx;
  264. height: max-content;
  265. border-radius: 3rpx;
  266. background-color: #E9F2F2;
  267. font-size: 24rpx;
  268. color: #15716E;
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. }
  273. .price>text:nth-child(1) {
  274. font-size: 36rpx;
  275. color: #F63434;
  276. font-weight: bold;
  277. }
  278. .price>text:nth-child(2) {
  279. font-size: 24rpx;
  280. color: #777777;
  281. margin-left: 20rpx;
  282. text-decoration: line-through;
  283. }
  284. .btn {
  285. width: 142rpx;
  286. height: 60rpx;
  287. background: rgba(21, 113, 110, 0.05);
  288. border-radius: 36rpx;
  289. border: 2rpx solid #15716E;
  290. font-size: 26rpx;
  291. color: #15716E;
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. }
  296. }
  297. }
  298. }
  299. </style>