seckill.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view class="seckillBox">
  3. <scroll-view scroll-x="true" class="class-box flex b-t" :scroll-left="scrollLeft" :scroll-with-animation="true">
  4. <view @click="tabClass(idx)" class="item" :style="{ width: topNavWidth }" v-for="(item, idx) in indexList"
  5. :key="idx">
  6. <view class="time" :class="{ action: idx == classIndex }">{{ item.time }}</view>
  7. <view class="status" :class="{ action: idx == classIndex }">{{ item.state }}</view>
  8. </view>
  9. </scroll-view>
  10. <swiper class="list-Box" :current="classIndex" @change="swiperChange" duration="500">
  11. <swiper-item class="list-item" v-for="(ls, idx) in indexList">
  12. <view class=" b-b position-relative">
  13. <view class="title-box flex ">
  14. <view class="title-box-left">
  15. <text v-if="ls.status == 1">抢购中先下先得哦!</text>
  16. <text v-if="ls.status == 2">精品好货即将开抢!</text>
  17. <text v-if="ls.status == 0">本场已结束,下次早点来哦!</text>
  18. </view>
  19. <view class="title-box-right flex">
  20. <text class="tip" v-if="ls.status == 1">距离结束</text>
  21. <text class="tip" v-if="ls.status == 2">距离开始</text>
  22. <uni-countdown color="#F9F9F8" background-color="#666666"
  23. v-if="ls.status == 1 || ls.status == 2" :show-day="false" :hour="ls.stopTimeH"
  24. :minute="ls.stopTimeM" :second="ls.stopTimeS"></uni-countdown>
  25. </view>
  26. </view>
  27. </view>
  28. <scroll-view scroll-y="true" class="list" @scrolltolower="getList(classIndex)">
  29. <view class="goodsList-item flex" :key="ind" v-for="(lss, ind) in ls.dataList">
  30. <image :src="lss.image" lazy-load mode="scaleToFill"></image>
  31. <view class="goodsList-content">
  32. <view class="title clamp">
  33. <text>{{ lss.title }}</text>
  34. </view>
  35. <view class="slider flex">
  36. <view class="slider-box">
  37. <view class="slider-action" :style="{ width: lss.percent + '%' }"></view>
  38. </view>
  39. <view class="sales-nub">已抢{{ lss.percent + '%' }}</view>
  40. </view>
  41. <view class="goods-money flex">
  42. <view class="money-box">
  43. <view class="money">
  44. <text class="font-size-sm">¥</text>
  45. {{ lss.price }}
  46. </view>
  47. <view class="otMoney-box">
  48. <text class="otMoney">¥{{ lss.ot_price }}</text>
  49. </view>
  50. </view>
  51. <view @click="navProduct(ls, ind)" class="cart"
  52. :class="{ 'seckill-action': ls.status == 1 }">
  53. {{ ls.status == 1 ? '去抢购' : ls.status == 2 ? '未开始' : '已结束' }}
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <uni-load-more :status="ls.loadingType"></uni-load-more>
  59. </scroll-view>
  60. </swiper-item>
  61. </swiper>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. shareFun
  67. } from '@/utils/wxAuthorized.js'
  68. import {
  69. mapState,
  70. mapMutations
  71. } from 'vuex'
  72. import {
  73. getSeckillList,
  74. getSeckillClass
  75. } from '@/api/product.js';
  76. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  77. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  78. import {
  79. timeComputed
  80. } from '@/utils/rocessor.js';
  81. export default {
  82. components: {
  83. uniCountdown,
  84. uniLoadMore
  85. },
  86. data() {
  87. return {
  88. indexList: [], //分类列表
  89. showTime: '', //显示的时间
  90. showTImeId: '', //显示时间id用于查询数据
  91. // 判断是否所有活动已经结束
  92. stop: false, //活动是否已经结束
  93. show: false, //是否显示活动
  94. status: 0, //获取状态值1为有活动开始中 2为活动未开始 0为活动已经结束
  95. topNavWidth: '25%', //设置导航默认宽度
  96. classIndex: 0, //当前进行中的活动
  97. itemWidht: 0 //顶部分类宽度
  98. };
  99. },
  100. computed: {
  101. // 计算左侧距离
  102. scrollLeft() {
  103. if (this.classIndex > 1) {
  104. return this.itemWidht * (this.classIndex - 1.5);
  105. } else {
  106. return 0;
  107. }
  108. }
  109. },
  110. onLoad: function(e) {
  111. // 载入分类
  112. this.getClass();
  113. },
  114. methods: {
  115. //抢购时间切换时触发效果
  116. swiperChange(e) {
  117. this.classIndex = e.target.current;
  118. this.getList(this.classIndex, 'tabChange');
  119. },
  120. // 获取项目宽度
  121. numClassWidht() {
  122. uni.createSelectorQuery()
  123. .select('.seckillBox')
  124. .fields({
  125. size: true
  126. },
  127. data => {
  128. // 设置项目宽度
  129. this.itemWidht = Math.floor((data.width / 750) * 187.5);
  130. }
  131. )
  132. .exec();
  133. },
  134. // 切换当前选中的秒杀活动
  135. tabClass(ind) {
  136. // 保存当前选中的对象
  137. this.classIndex = ind;
  138. },
  139. // 跳转到商品详情
  140. navProduct(ls, ind) {
  141. if (ls.status == 1) {
  142. let data = ls.dataList[ind];
  143. console.log(data, 'data');
  144. uni.navigateTo({
  145. url: '/pages/product/miaosha?id=' + data.id + '&type=1' + '&isVip=' + 3
  146. });
  147. }
  148. },
  149. // 获取商品
  150. getList(ind, source) {
  151. // 获取数据对象
  152. let date = this.indexList[ind];
  153. console.log(date, source, '23232323');
  154. if (source === 'tabChange' && date.loaded === true) {
  155. //tab切换只有第一次需要加载数据
  156. return;
  157. }
  158. if (date.loadingType === 'noMore') {
  159. //防止重复加载
  160. return;
  161. }
  162. if (date.loadingType === 'loading') {
  163. //防止重复加载
  164. return;
  165. }
  166. // 修改当前对象状态为加载中
  167. date.loadingType = 'loading';
  168. getSeckillList({
  169. page: date.page,
  170. limit: date.limit
  171. },
  172. date.id
  173. )
  174. .then(e => {
  175. console.log(e, '煮熟');
  176. date.dataList.push(...e.data);
  177. // 查询翻页增加
  178. date.page++;
  179. // 判断是否可以继续加载
  180. if (date.limit == e.data.length) {
  181. date.loadingType = 'more';
  182. } else {
  183. date.loadingType = 'noMore';
  184. }
  185. // 设置当前数据已加载完毕
  186. this.$set(date, 'loaded', true);
  187. })
  188. .catch(e => {
  189. console.log(e);
  190. });
  191. },
  192. // 获取秒杀时间段
  193. getClass() {
  194. let obj = this;
  195. getSeckillClass({})
  196. .then(({
  197. data
  198. }) => {
  199. obj.indexList = data.seckillTime.map((e, ind) => {
  200. // 初始化翻页页数
  201. e.page = 1;
  202. // 初始每次加载的数据条数
  203. e.limit = 6;
  204. // 创建储存订单数据
  205. e.dataList = [];
  206. // 初始化加载
  207. e.loadingType = 'more';
  208. let ar = e;
  209. // 判断是否为进行中的活动
  210. if (ar.status === 1) {
  211. // 计算倒计时时间
  212. obj.timeComputed(ar.stop * 1000, ar);
  213. } else {
  214. // 获取距离开始还需要多少时间
  215. let arTime = ar.time.split(':');
  216. let h = arTime[0];
  217. let m = arTime[1];
  218. let time = new Date();
  219. // 设置时间
  220. time.setHours(h, m, 0);
  221. // 计算倒计时时间
  222. obj.timeComputed(time.getTime(), ar);
  223. }
  224. return e;
  225. });
  226. // 获取当前活动中的下标值
  227. obj.classIndex = data.seckillTimeIndex;
  228. // 获取当前显示中对象的数据
  229. obj.$nextTick(() => {
  230. obj.getList(obj.classIndex);
  231. });
  232. if (obj.indexList.length <= 4) {
  233. // 当数量小于等于4的时候自适应宽度
  234. obj.topNavWidth = 100 / obj.indexList.length + '%';
  235. } else {
  236. // 页面渲染完毕后加载scroll-view左侧距离
  237. obj.$nextTick(() => {
  238. obj.numClassWidht();
  239. });
  240. }
  241. })
  242. .catch(e => {
  243. console.log(e);
  244. });
  245. },
  246. // 计算倒计时时间
  247. timeComputed(da, ar) {
  248. let obj = this;
  249. // 计算时间,保存需要多少时间到期
  250. let stopTime = timeComputed(da);
  251. console.log(stopTime);
  252. ar.stopTimeH = stopTime.hours;
  253. ar.stopTimeM = stopTime.minutes;
  254. ar.stopTimeS = stopTime.seconds;
  255. }
  256. }
  257. };
  258. </script>
  259. <style lang="scss">
  260. page,
  261. .seckillBox {
  262. min-height: 100%;
  263. height: 100%;
  264. }
  265. // 头部时间段样式
  266. .class-box {
  267. white-space: nowrap;
  268. height: 60px;
  269. .item {
  270. text-align: center;
  271. display: inline-block;
  272. color: $font-color-base;
  273. padding: 11.5px 5px;
  274. background-color: #ffffff;
  275. line-height: 1;
  276. .time {
  277. font-size: 16px;
  278. padding-bottom: 3px;
  279. &.action {
  280. color: $color-red;
  281. }
  282. }
  283. .status {
  284. font-size: 12px;
  285. margin: 0 auto;
  286. width: 60px;
  287. padding: 3px 0;
  288. &.action {
  289. color: #ffffff;
  290. border-radius: 99px;
  291. background-color: $color-red;
  292. }
  293. }
  294. }
  295. }
  296. // 列表上方标题样式
  297. .title-box {
  298. margin-top: 10px;
  299. padding: 10px;
  300. background-color: #ffffff;
  301. .title-box-left {
  302. font-size: 15px;
  303. color: $font-color-base;
  304. }
  305. .title-box-right {
  306. .tip {
  307. font-size: 15px;
  308. color: #999999;
  309. padding-right: 5px;
  310. }
  311. /deep/ .uni-countdown__number {
  312. border-radius: 3px;
  313. width: 22px;
  314. }
  315. /deep/ .uni-countdown__splitor,
  316. /deep/ .uni-countdown__number {
  317. height: 20px;
  318. line-height: 18px;
  319. }
  320. }
  321. }
  322. // 列表样式
  323. .list-Box {
  324. height: calc(100% - 60px);
  325. .list {
  326. height: calc(100% - 55px);
  327. }
  328. }
  329. // 商品列表
  330. $slider-color: #fe9398; //滑块左侧颜色
  331. .goodsList-item {
  332. background-color: #ffffff;
  333. padding: 30rpx;
  334. border-bottom: 1px solid $border-color-light;
  335. image {
  336. flex-shrink: 0;
  337. border-radius: $border-radius-sm;
  338. height: 180rpx;
  339. width: 180rpx;
  340. }
  341. .slider {
  342. margin-top: 15rpx;
  343. justify-content: flex-start;
  344. .slider-box {
  345. width: 196rpx;
  346. border-radius: 99px;
  347. border: 1px solid $slider-color;
  348. height: 16rpx;
  349. .slider-action {
  350. background-color: $slider-color;
  351. height: 100%;
  352. }
  353. }
  354. .sales-nub {
  355. color: $font-color-light;
  356. font-size: 24rpx;
  357. padding-left: 20rpx;
  358. }
  359. }
  360. .goodsList-content {
  361. margin-left: 20rpx;
  362. flex-grow: 1;
  363. height: 180rpx;
  364. position: relative;
  365. .title {
  366. font-size: $font-base;
  367. color: $font-color-dark;
  368. font-weight: 500;
  369. width: 0;
  370. min-width: 100%;
  371. }
  372. .goods-money {
  373. position: absolute;
  374. left: 0;
  375. bottom: 0;
  376. width: 100%;
  377. .money-box {
  378. .money {
  379. font-size: $font-lg + 10rpx;
  380. color: $color-red;
  381. font-weight: bold;
  382. }
  383. .otMoney-box {
  384. font-size: $font-sm;
  385. .otMoney {
  386. color: $font-color-light;
  387. padding-right: 20rpx;
  388. text-decoration: line-through;
  389. }
  390. .sales {
  391. color: $font-color-light;
  392. }
  393. }
  394. }
  395. .cart {
  396. font-size: $font-base;
  397. border-radius: 99px;
  398. padding: 15rpx 30rpx;
  399. line-height: 1;
  400. color: #ffffff;
  401. background-color: $color-gray;
  402. &.seckill-action {
  403. border: 1px solid $color-red;
  404. background-color: $color-red;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. </style>