seckill.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <!-- <view class="seckill-section m-t" v-if="show">
  3. <view class="s-header">
  4. <view class="f-left-icon"></view>
  5. <view class="tit-box"><text class="tit">限时秒杀</text></view>
  6. <view class="tip-box">
  7. <text class="tip" v-if="status == 1">{{ showTime }}点场结束</text>
  8. <text class="tip" v-if="status == 2">距离下场开始</text>
  9. <text class="tip" v-if="status == 0">当天活动已结束</text>
  10. <uni-countdown v-if="status == 1 || status == 2" :show-day="false" :hour="stopTimeH" :minute="stopTimeM" :second="stopTimeS"></uni-countdown>
  11. </view>
  12. <view class="textNav iconfont iconenter" @click="navTo('/pages/product/seckill')">更多</view>
  13. </view>
  14. <scroll-view class="floor-list" scroll-x>
  15. <view class="scoll-wrapper position-relative" @click="navTo('/pages/product/seckill')">
  16. <view v-for="(item, index) in list" :key="index" class="floor-item">
  17. <image class="list-image" :src="item.image" mode="aspectFill"></image>
  18. <text class="title clamp">{{ item.title }}</text>
  19. <text class="price">¥{{ item.price }}</text>
  20. </view>
  21. <view v-if="list.length == 0" class="floor-item ">
  22. <image class="list-image" mode="aspectFill"></image>
  23. <text class="title clamp"></text>
  24. <text class="price"></text>
  25. </view>
  26. <view v-if="list.length == 0" class="noGoodsBg">
  27. <view>敬请期待</view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view> -->
  32. <view class="sckill-wrapper">
  33. <scroll-view scroll-x="true" class="sckill">
  34. <view class="item-wrapper">
  35. <view class="goods-box" v-for="(item, index) in list" :key="index" @click="navTo('/pages/product/product?id='+ item.product_id + '&type=1')">
  36. <view class="image-wrapper"><image :src="item.image" mode="scaleToFill"></image></view>
  37. <view class="good-title">{{ item.store_name }}</view>
  38. <view class="price">
  39. <view class="now-price">¥{{ item.price | mon }}</view>
  40. <view class="old-price">¥{{ item.ot_price }}</view>
  41. </view>
  42. </view>
  43. <view v-if="list.length == 0" class="noGoodsBg"><view>敬请期待</view></view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </template>
  48. <script>
  49. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  50. import { getSeckillList, getSeckillIndexTime } from '@/api/product.js';
  51. import { timeComputed } from '@/utils/rocessor.js';
  52. export default {
  53. components: {
  54. uniCountdown
  55. },
  56. data() {
  57. return {
  58. list: [],
  59. page: 1,
  60. limit: 10,
  61. showTime: '', //显示的时间
  62. showTImeId: '', //显示时间id用于查询数据
  63. stopTimeH: 0,
  64. stopTimeM: 0,
  65. stopTimeS: 0,
  66. // 判断是否所有活动已经结束
  67. stop: false, //活动是否已经结束
  68. show: false, //是否显示活动
  69. status: 0 //获取状态值1为有活动开始中 2为活动未开始 0为活动已经结束
  70. };
  71. },
  72. filters: {
  73. mon(value) {
  74. return +value;
  75. }
  76. },
  77. created: function(e) {
  78. // 载入分类
  79. this.getClass();
  80. },
  81. methods: {
  82. navTo(url) {
  83. uni.navigateTo({
  84. url
  85. });
  86. },
  87. getList() {
  88. // getSeckillList(
  89. // {
  90. // page: this.page,
  91. // limit: this.limit
  92. // },
  93. // this.showTImeId
  94. // )
  95. // .then(e => {
  96. // this.list = e.data;
  97. // console.log(this.list);
  98. // })
  99. // .catch(e => {
  100. // console.log(e);
  101. // });
  102. getSeckillList().then(({ data }) => {
  103. console.log(data,'------------');
  104. this.list = data.list;
  105. });
  106. },
  107. getClass() {
  108. let obj = this;
  109. // getSeckillIndexTime().then(res=> {
  110. // console.log(res)
  111. // })
  112. getSeckillIndexTime()
  113. .then(({ data }) => {
  114. let arr = data.seckillTime;
  115. console.log(arr)
  116. // 用于判断是否有数据
  117. let showDate = false;
  118. for (var i = 0; i < arr.length; i++) {
  119. let ar = arr[i];
  120. if (ar.pc_status === 1 || ar.pc_status === 2) {
  121. obj.status = ar.pc_status;
  122. // 保存要显示的场次时间
  123. console.log(ar.start_time)
  124. if(ar.start_time < 10) {
  125. obj.showTime = '0'+ar.start_time + ':00'
  126. }else {
  127. obj.showTime = ar.start_time + ':00'
  128. }
  129. // obj.showTime = ar.time;
  130. console.log(obj.showTime)
  131. // 保存要显示活动商品的id
  132. obj.showTImeId = ar.seckill_time_id;
  133. // 保存当前状态值
  134. // 计算倒计时时间
  135. if (ar.status === 1) {
  136. obj.timeComputed(ar.stop * 1000);
  137. } else {
  138. // 获取需要开始
  139. let arTime = ar.time.split(':');
  140. let h = arTime[0];
  141. let m = arTime[1];
  142. console.log(h,m,'h,m')
  143. let time = new Date();
  144. // 设置时间
  145. time.setHours(h, m, 0);
  146. obj.timeComputed(time.getTime());
  147. }
  148. // 获取商品列表
  149. obj.getList();
  150. // 保存当前有活动在举行
  151. showDate = true;
  152. // 任务查询结束跳出循环
  153. break;
  154. }
  155. }
  156. // 判断是否有活动
  157. if (arr.length > 0) {
  158. obj.show = true;
  159. }
  160. // 判断今天活动是否已经全部结束
  161. if (!showDate) {
  162. // 保存活动结束最后一个小时的活动商品
  163. obj.showTImeId = arr[arr.length - 1].seckill_time_id;
  164. // 活动已经结束
  165. obj.status = 0;
  166. // 获取结束时的商品
  167. obj.getList();
  168. console.log(obj.status);
  169. }
  170. // 如果所有场次均已经结束
  171. })
  172. .catch(e => {
  173. console.log(e)
  174. uni.showModal({
  175. title: JSON.stringify(e)
  176. });
  177. });
  178. },
  179. // 计算倒计时时间
  180. timeComputed(da) {
  181. let obj = this;
  182. let stopTime = timeComputed(da);
  183. obj.stopTimeH = stopTime.hours;
  184. obj.stopTimeM = stopTime.minutes;
  185. obj.stopTimeS = stopTime.seconds;
  186. console.log(obj.stopTimeH,obj.stopTimeM,obj.stopTimeS)
  187. }
  188. }
  189. };
  190. </script>
  191. <style lang="scss">
  192. /* 秒杀专区 */
  193. .seckill-section {
  194. padding: 4rpx 30rpx 24rpx;
  195. .s-header {
  196. display: flex;
  197. align-items: center;
  198. height: 92rpx;
  199. line-height: 1;
  200. .tit-box {
  201. flex-shrink: 0;
  202. }
  203. .tit {
  204. @extend %font-title;
  205. }
  206. .f-left-icon {
  207. @extend %f-left-icon;
  208. }
  209. .textNav {
  210. line-height: 1;
  211. padding: 15rpx 0;
  212. flex-shrink: 0;
  213. flex-grow: 1;
  214. min-width: 100rpx;
  215. }
  216. .tip-box {
  217. flex-grow: 1;
  218. display: flex;
  219. justify-content: flex-start;
  220. align-items: center;
  221. }
  222. .tip {
  223. font-size: $font-sm;
  224. color: $font-color-light;
  225. padding-left: 10rpx;
  226. padding-right: 10rpx;
  227. }
  228. .timer {
  229. display: inline-block;
  230. width: 40rpx;
  231. height: 36rpx;
  232. text-align: center;
  233. line-height: 36rpx;
  234. margin-right: 14rpx;
  235. font-size: $font-sm + 2rpx;
  236. color: #fff;
  237. border-radius: 2px;
  238. background: rgba(0, 0, 0, 0.8);
  239. }
  240. .iconenter {
  241. font-size: $font-sm;
  242. color: $font-color-light;
  243. flex: 1;
  244. text-align: right;
  245. }
  246. }
  247. .floor-list {
  248. white-space: nowrap;
  249. background-color: white;
  250. padding: 20rpx;
  251. border-radius: 5rpx;
  252. box-shadow: $box-shadow;
  253. }
  254. .scoll-wrapper {
  255. display: flex;
  256. align-items: flex-start;
  257. .noGoodsBg {
  258. display: flex;
  259. align-items: center;
  260. justify-content: center;
  261. height: 100%;
  262. position: absolute;
  263. top: 0;
  264. left: 0;
  265. width: 100%;
  266. color: $font-color-light;
  267. }
  268. .floor-item {
  269. width: 150rpx;
  270. margin-right: 20rpx;
  271. font-size: $font-sm + 2rpx;
  272. color: $font-color-dark;
  273. line-height: 1.8;
  274. .list-image {
  275. width: 150rpx;
  276. height: 150rpx;
  277. border-radius: 6rpx;
  278. }
  279. .price {
  280. color: $color-red;
  281. }
  282. }
  283. }
  284. }
  285. .sckill-wrapper {
  286. width: 701rpx;
  287. height: 293rpx;
  288. background-image: url(../../static/img/sckillbg.png);
  289. background-size: 100% 100%;
  290. margin: 34rpx auto 37rpx;
  291. padding: 31rpx 21rpx;
  292. .sckill {
  293. width: 659rpx;
  294. height: 231rpx;
  295. .noGoodsBg {
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. height: 100%;
  300. position: absolute;
  301. top: 0;
  302. left: 0;
  303. width: 100%;
  304. color: $font-color-light;
  305. }
  306. .item-wrapper {
  307. display: flex;
  308. .goods-box {
  309. width: 192rpx;
  310. height: 231rpx;
  311. margin: 0 42rpx 0 0;
  312. flex-shrink: 0;
  313. .image-wrapper {
  314. width: 192rpx;
  315. height: 150rpx;
  316. border-radius: 10rpx;
  317. overflow: hidden;
  318. image {
  319. width: 100%;
  320. height: 100%;
  321. opacity: 1;
  322. }
  323. }
  324. .good-title {
  325. padding: 15rpx 0rpx 0rpx 6rpx;
  326. font-size: 26rpx;
  327. font-weight: 500;
  328. color: #333333;
  329. line-height: 26rpx;
  330. opacity: 0.8;
  331. white-space: nowrap;
  332. overflow: hidden;
  333. text-overflow: ellipsis;
  334. }
  335. .price {
  336. display: flex;
  337. height: 39rpx;
  338. justify-content: space-between;
  339. .now-price {
  340. // padding-top:19rpx ;
  341. font-size: 24rpx;
  342. font-weight: bold;
  343. color: #901b21;
  344. line-height: 16rpx;
  345. // padding-left: 10rpx;
  346. align-self: flex-end;
  347. }
  348. .old-price {
  349. // padding-top:27rpx ;
  350. align-self: flex-end;
  351. font-size: 15rpx;
  352. font-weight: 500;
  353. text-decoration: line-through;
  354. color: #9d9d9d;
  355. line-height: 16rpx;
  356. // padding-right: 10rpx;
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. </style>