seckill.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <view class="sale">
  3. <view class="sale-head">
  4. <image src="@/pages/promotion/static/head-sample.png"></image>
  5. </view>
  6. <scroll-view scroll-x>
  7. <view class="index-navs">
  8. <view class="index-nav-v">
  9. <view class="index-nav" :class="{ 'index-nav-active': nav == index }" @click="clickNavigateTime(index)" v-for="(item, index) in timeLine" :key="index">
  10. {{ item.timeLine }}:00
  11. <view class="index-nav-desc">{{ index === 0 && item.distanceStartTime === 0 ? '抢购中' : '即将开始' }}
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="trailer" v-if="timeLine[nav] && times">
  17. {{ timeLine[nav].distanceStartTime === 0 ? (onlyOne ? '距结束' : '距下一轮') : '距开始' }}
  18. {{ times.hours == '00' ? '0' : times.hours }}小时{{ times.minutes }}分{{ times.seconds }}秒
  19. </view>
  20. </scroll-view>
  21. <view class="sale-items" v-if="goodsList.length > 0">
  22. <view class="sale-item" v-for="(item,index) in goodsList" :key="index">
  23. <view class="sale-item-img">
  24. <image :src="item.goodsImage" mode="aspectFill"></image>
  25. </view>
  26. <view class="sale-item-content">
  27. <view class="sale-item-title">
  28. {{ item.goodsName }}
  29. <view class="sale-item-title-desc"></view>
  30. </view>
  31. <view class="sale-item-price">
  32. <text class="sale-item-price-now">¥{{ item.price | unitPrice}}</text>
  33. <text class="sale-item-price-origin"> ¥{{ item.originalPrice | unitPrice }}</text>
  34. </view>
  35. <view class="sale-item-surplus">
  36. 仅剩{{ item.quantity - item.salesNum }}件
  37. <view class="sale-item-surplus-text" :style="{ width: (item.quantity / (item.quantity - item.salesNum)) * 100 + '%' }">
  38. </view>
  39. </view>
  40. <view class="sale-item-btn" @click="navigateToGoodsDetail(item)">
  41. {{ timeLine[nav].distanceStartTime === 0 ? (item.salesNum === item.quantity ? '已售空' : '购买') : '即将开始' }}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view v-else>
  47. <view class="nodata">
  48. <image style="height: 240rpx;width: 320rpx;" src="/static/nodata.png" alt="" />
  49. <div>暂无商品</div>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { getSeckillTimeLine, getSeckillTimeGoods } from "@/api/promotions.js";
  56. import Foundation from "@/utils/Foundation.js";
  57. export default {
  58. data() {
  59. return {
  60. nav: 0, //默认选择第一个时间
  61. timeLine: "", //获取几个点活动
  62. resTime: 0, //当前时间
  63. time: 0, //距离下一个活动的时间值
  64. times: {}, //时间集合
  65. onlyOne: "", //是否最后一个商品
  66. goodsList: [], //商品集合
  67. params: {
  68. pageNumber: 1,
  69. pageSize: 10,
  70. },
  71. };
  72. },
  73. /**
  74. * 显示时间活动
  75. */
  76. async onShow() {
  77. await this.getTimeLine();
  78. if (!this.timeLine) {
  79. await uni.showToast({
  80. icon: "none",
  81. duration: 2000,
  82. title: "今天没有活动,明天再来吧",
  83. });
  84. }
  85. this._setTimeInterval = setInterval(() => {
  86. if (this.time <= 0) {
  87. clearInterval(this._setTimeInterval);
  88. this.getGoodsList();
  89. this.getTimeLine();
  90. } else {
  91. this.times = Foundation.countTimeDown(this.time);
  92. this.time--;
  93. }
  94. }, 1000);
  95. },
  96. onUnload() {
  97. this._setTimeInterval && clearInterval(this._setTimeInterval);
  98. },
  99. methods: {
  100. /**
  101. * 获取时间线商品
  102. */
  103. async getTimeLine() {
  104. let res = await getSeckillTimeLine();
  105. if (res.data.success && res.data.result.length > 0) {
  106. let timeLine = res.data.result.sort(
  107. (x, y) => Number(x.timeLine) - Number(y.timeLine)
  108. );
  109. this.timeLine = timeLine.slice(0, 5);
  110. this.resTime = parseInt(new Date().getTime() / 1000);
  111. this.onlyOne = res.data.result.length === 1;
  112. this.diffTime = parseInt(new Date().getTime() / 1000) - this.resTime;
  113. this.time =
  114. this.timeLine[this.nav].distanceStartTime ||
  115. (this.timeLine[this.nav + 1] &&
  116. this.timeLine[this.nav + 1].distanceStartTime) ||
  117. Foundation.theNextDayTime() - this.diffTime;
  118. this.times = Foundation.countTimeDown(this.time);
  119. this.getGoodsList();
  120. }
  121. },
  122. /**
  123. * 获取商品集合
  124. */
  125. async getGoodsList() {
  126. this.params.timeLine = this.timeLine[this.nav].timeLine;
  127. let res = await getSeckillTimeGoods(this.params.timeLine);
  128. if (res.data.success && res.data.result.length != 0) {
  129. this.goodsList = res.data.result;
  130. } else {
  131. this.goodsList = [];
  132. }
  133. },
  134. /**
  135. * 跳转到商品详情
  136. */
  137. navigateToGoodsDetail(item) {
  138. if (
  139. item.sold_num === item.quantity ||
  140. this.timeLine[this.nav].distanceStartTime !== 0
  141. ) {
  142. return;
  143. } else {
  144. uni.navigateTo({
  145. url: `/pages/product/goods?id=${item.skuId}&goodsId=${item.goodsId}`,
  146. });
  147. }
  148. },
  149. /**
  150. * 单击导航时间
  151. */
  152. clickNavigateTime(type) {
  153. this.nav = type;
  154. this.diffTime = parseInt(new Date().getTime() / 1000) - this.resTime;
  155. this.time =
  156. this.timeLine[this.nav].distanceStartTime ||
  157. (this.timeLine[this.nav + 1] &&
  158. this.timeLine[this.nav + 1].distanceStartTime) ||
  159. Foundation.theNextDayTime() - this.diffTime;
  160. this.times = Foundation.countTimeDown(this.time);
  161. this.getGoodsList();
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="scss" scoped>
  167. .sale {
  168. width: 100%;
  169. min-height: 100vh;
  170. background-color: #f7f7f7;
  171. }
  172. .nodata {
  173. flex-direction: column;
  174. display: flex;
  175. width: 100%;
  176. justify-content: center;
  177. align-items: center;
  178. margin-top: 40rpx;
  179. > div {
  180. font-size: 24rpx;
  181. margin-top: 20rpx;
  182. color: #666;
  183. }
  184. }
  185. .sale-head {
  186. image {
  187. width: 100%;
  188. height: 280rpx;
  189. }
  190. }
  191. .sale-items {
  192. padding-top: 20rpx;
  193. display: -webkit-box;
  194. display: -webkit-flex;
  195. display: flex;
  196. align-items: center;
  197. flex-direction: column;
  198. }
  199. .sale-item {
  200. width: 710rpx;
  201. height: 226rpx;
  202. padding-left: 20rpx;
  203. margin-bottom: 10rpx;
  204. border-radius: 12rpx;
  205. background-color: #fff;
  206. position: relative;
  207. display: -webkit-box;
  208. display: -webkit-flex;
  209. display: flex;
  210. align-items: center;
  211. }
  212. .sale-item-img {
  213. margin-right: 20rpx;
  214. image {
  215. width: 186rpx;
  216. height: 186rpx;
  217. border-radius: 8rpx;
  218. }
  219. }
  220. .sale-item-content {
  221. line-height: 2em;
  222. }
  223. .sale-item-title {
  224. display: -webkit-box;
  225. -webkit-box-orient: vertical;
  226. -webkit-line-clamp: 2;
  227. overflow: hidden;
  228. line-height: 1.5;
  229. font-size: 28rpx;
  230. color: #333;
  231. }
  232. .sale-item-title-desc {
  233. font-size: 22rpx;
  234. color: #999;
  235. }
  236. .sale-item-price {
  237. font-size: 22rpx;
  238. color: 999;
  239. }
  240. .sale-item-price-now {
  241. font-size: 40rpx;
  242. color: #ff5a10;
  243. margin: 0 10rpx;
  244. }
  245. .sale-item-price-origin {
  246. font-size: 20rpx;
  247. color: #999;
  248. -webkit-text-decoration-line: line-through;
  249. text-decoration-line: line-through;
  250. text-decoration: line-through;
  251. }
  252. .sale-item-surplus {
  253. border: 2rpx solid rgb(34, 178, 140);
  254. border-radius: 12px;
  255. width: 166rpx;
  256. color: rgb(31, 177, 138);
  257. font-size: 20rpx;
  258. position: relative;
  259. text-align: center;
  260. z-index: 2;
  261. height: 32rpx;
  262. line-height: 28rpx;
  263. overflow: hidden;
  264. }
  265. .sale-item-surplus-text {
  266. width: 166rpx;
  267. background: rgb(234, 247, 245);
  268. position: absolute;
  269. top: 0;
  270. left: 0;
  271. z-index: -1;
  272. height: 100%;
  273. }
  274. .sale-item-btn {
  275. position: absolute;
  276. right: 20rpx;
  277. bottom: 20rpx;
  278. padding: 0 20rpx;
  279. height: 60rpx;
  280. background-color: #1abc9c;
  281. border-radius: 10rpx;
  282. font-size: 25rpx;
  283. color: #fff;
  284. display: -webkit-box;
  285. display: -webkit-flex;
  286. display: flex;
  287. justify-content: center;
  288. align-items: center;
  289. }
  290. .trailer {
  291. height: 100rpx;
  292. background: #ffffff;
  293. display: -webkit-box;
  294. display: -webkit-flex;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. font-size: 22rpx;
  299. color: #666666;
  300. box-sizing: border-box;
  301. position: relative;
  302. z-index: 0;
  303. }
  304. .index-navs {
  305. background-color: #f7f7f7;
  306. display: -webkit-box;
  307. display: -webkit-flex;
  308. display: flex;
  309. align-items: center;
  310. justify-content: space-between;
  311. }
  312. .index-nav-v {
  313. display: -webkit-box;
  314. display: -webkit-flex;
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. position: relative;
  319. }
  320. .index-nav {
  321. font-size: 28rpx;
  322. display: -webkit-box;
  323. display: -webkit-flex;
  324. display: flex;
  325. justify-content: center;
  326. align-items: center;
  327. width: 150rpx;
  328. flex-direction: column;
  329. color: #bababa;
  330. height: 115rpx;
  331. line-height: 1em;
  332. position: relative;
  333. &-active {
  334. background-image: url(/static/seckill/active.png);
  335. background-size: 100% 115rpx;
  336. background-repeat: no-repeat;
  337. color: #ffffff;
  338. position: relative;
  339. z-index: 30;
  340. .index-nav-desc {
  341. color: #ffffff;
  342. }
  343. }
  344. }
  345. .index-nav-desc {
  346. margin-top: 8rpx;
  347. font-size: 22rpx;
  348. color: #bababa;
  349. }
  350. </style>