seckill.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <view class="seckillBox">
  3. <scroll-view scroll-x="true" class="class-box flex " :scroll-left="scrollLeft" :scroll-with-animation="true">
  4. <view @click="tabClass(idx)" class="item" :style="{ width: topNavWidth }" v-for="(item, idx) in indexList" :key="idx" :class="{ action: idx == classIndex }">
  5. <view class="time" :class="{ action: idx == classIndex }">{{ item.time}}</view>
  6. <view class="status" :class="{ action: idx == classIndex }">{{ item.state }}</view>
  7. </view>
  8. </scroll-view>
  9. <swiper class="list-Box" :current="classIndex" @change="swiperChange" duration="500">
  10. <swiper-item class="list-item" v-for="(ls, idx) in indexList" :key="idx">
  11. <scroll-view scroll-y="true" class="list" @scrolltolower="getList(classIndex)">
  12. <view class="jg"></view>
  13. <view class="spgood" :key="ind" v-for="(lss, ind) in ls.dataList">
  14. <view class="left-wrapper"><image :src="lss.image" mode="scaleToFill"></image></view>
  15. <view class="right-wrapper">
  16. <view class="right-title clamp">{{ lss.title }}</view>
  17. <view class="ex-addr">
  18. <image src="../../static/img/shop.png" mode="" class="name-img"></image>
  19. {{checkedStore.name | longstorename}}
  20. <image src="../../static/img/point.png" mode="" class="point-img"></image>
  21. {{ des | distance}}
  22. </view>
  23. <view class="right-bottom">
  24. <view class="sp-price">
  25. <view class="now-price">¥{{ lss.price }}</view>
  26. </view>
  27. <view class="sp-btn" @click="navProduct(ls, ind)" :class="{ 'seckill-action': ls.status == 1 }">{{ ls.status == 1 ? '去抢购' : ls.status == 2 ? '未开始' : '已结束' }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <uni-load-more :status="ls.loadingType"></uni-load-more>
  32. </scroll-view>
  33. </swiper-item>
  34. </swiper>
  35. </view>
  36. </template>
  37. <script>
  38. import { mapState, mapMutations } from 'vuex';
  39. import { getSeckillList, getSeckillClass } from '@/api/product.js';
  40. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  41. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  42. import { timeComputed } from '@/utils/rocessor.js';
  43. export default {
  44. components: {
  45. uniCountdown,
  46. uniLoadMore
  47. },
  48. data() {
  49. return {
  50. indexList: [], //分类列表
  51. showTime: '', //显示的时间
  52. showTImeId: '', //显示时间id用于查询数据
  53. // 判断是否所有活动已经结束
  54. stop: false, //活动是否已经结束
  55. show: false, //是否显示活动
  56. status: 0, //获取状态值1为有活动开始中 2为活动未开始 0为活动已经结束
  57. topNavWidth: '25%', //设置导航默认宽度
  58. classIndex: 0, //当前进行中的活动
  59. itemWidht: 0 //顶部分类宽度
  60. };
  61. },
  62. filters: {
  63. storename(val) {
  64. let str = ''
  65. if(val) {
  66. str = val
  67. if(val.length > 5) {
  68. str = val.slice(0,5)+'...'
  69. }
  70. }
  71. return str
  72. },
  73. longstorename(val) {
  74. let str = ''
  75. if(val) {
  76. str = val
  77. if(val.length > 8) {
  78. str = val.slice(0,8)+'...'
  79. }
  80. }
  81. return str
  82. },
  83. distance(val) {
  84. let str = ''
  85. if(val) {
  86. if(val*1 > 1000) {
  87. return str = (val*1/1000).toFixed(1) + 'km'
  88. }
  89. }else {
  90. return str = (val*1).toFixed(0) + 'm'
  91. }
  92. return str
  93. }
  94. },
  95. computed: {
  96. ...mapState('user', ['hasLogin', 'userInfo', 'checkedStore','des']),
  97. // 计算左侧距离
  98. scrollLeft() {
  99. if (this.classIndex > 1) {
  100. return this.itemWidht * (this.classIndex - 1.5);
  101. } else {
  102. return 0;
  103. }
  104. }
  105. },
  106. onLoad: function(e) {
  107. // 载入分类
  108. this.getClass();
  109. console.log(this.checkedStore,'ddddddddddddddddddddddd')
  110. },
  111. methods: {
  112. space(lat1, lng1) {
  113. let sp = uni.getStorageSync('latlon');
  114. console.log(sp);
  115. let arr1 = sp.split(',');
  116. let lat2 = arr1[0];
  117. let lng2 = arr1[1];
  118. console.log(lat1, lng1, lat2, lng2, '位置信息');
  119. var radLat1 = (lat1 * Math.PI) / 180.0;
  120. var radLat2 = (lat2 * Math.PI) / 180.0;
  121. var a = radLat1 - radLat2;
  122. var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  123. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  124. s = s * 6378.137;
  125. s = Math.round(s * 10000) / 10000;
  126. // return s * 1000;
  127. if(s>1) {
  128. return s.toFixed(2) + 'km'
  129. }else {
  130. return s * 1000 + 'm'; // 单位米
  131. }
  132. },
  133. //抢购时间切换时触发效果
  134. swiperChange(e) {
  135. this.classIndex = e.target.current;
  136. this.getList(this.classIndex, 'tabChange');
  137. },
  138. // 获取项目宽度
  139. numClassWidht() {
  140. uni.createSelectorQuery()
  141. .select('.seckillBox')
  142. .fields(
  143. {
  144. size: true
  145. },
  146. data => {
  147. // 设置项目宽度
  148. this.itemWidht = Math.floor((data.width / 750) * 187.5);
  149. }
  150. )
  151. .exec();
  152. },
  153. // 切换当前选中的秒杀活动
  154. tabClass(ind) {
  155. // 保存当前选中的对象
  156. this.classIndex = ind;
  157. },
  158. // 跳转到商品详情
  159. navProduct(ls, ind) {
  160. if (ls.status == 1) {
  161. let data = ls.dataList[ind];
  162. uni.navigateTo({
  163. url: '/pages/product/product?id=' + data.id + '&type=1'
  164. });
  165. }
  166. },
  167. // 获取商品
  168. getList(ind, source) {
  169. // 获取数据对象
  170. let date = this.indexList[ind];
  171. console.log(date, source);
  172. if (source === 'tabChange' && date.loaded === true) {
  173. //tab切换只有第一次需要加载数据
  174. return;
  175. }
  176. if (date.loadingType === 'noMore') {
  177. //防止重复加载
  178. return;
  179. }
  180. if (date.loadingType === 'loading') {
  181. //防止重复加载
  182. return;
  183. }
  184. // 修改当前对象状态为加载中
  185. date.loadingType = 'loading';
  186. getSeckillList(
  187. {
  188. page: date.page,
  189. limit: date.limit
  190. },
  191. date.id
  192. )
  193. .then(e => {
  194. date.dataList.push(...e.data);
  195. // 查询翻页增加
  196. date.page++;
  197. // 判断是否可以继续加载
  198. if (date.limit == e.data.length) {
  199. date.loadingType = 'more';
  200. } else {
  201. date.loadingType = 'noMore';
  202. }
  203. // 设置当前数据已加载完毕
  204. this.$set(date, 'loaded', true);
  205. })
  206. .catch(e => {
  207. console.log(e);
  208. });
  209. },
  210. // 获取秒杀时间段
  211. getClass() {
  212. let obj = this;
  213. getSeckillClass({})
  214. .then(({ data }) => {
  215. obj.indexList = data.seckillTime.map((e, ind) => {
  216. // 初始化翻页页数
  217. e.page = 1;
  218. // 初始每次加载的数据条数
  219. e.limit = 6;
  220. // 创建储存订单数据
  221. e.dataList = [];
  222. // 初始化加载
  223. e.loadingType = 'more';
  224. let ar = e;
  225. // 判断是否为进行中的活动
  226. if (ar.status === 1) {
  227. // 计算倒计时时间
  228. obj.timeComputed(ar.stop * 1000, ar);
  229. } else {
  230. // 获取距离开始还需要多少时间
  231. let arTime = ar.time.split(':');
  232. let h = arTime[0];
  233. let m = arTime[1];
  234. let time = new Date();
  235. // 设置时间
  236. time.setHours(h, m, 0);
  237. // 计算倒计时时间
  238. obj.timeComputed(time.getTime(), ar);
  239. }
  240. return e;
  241. });
  242. // 获取当前活动中的下标值
  243. obj.classIndex = data.seckillTimeIndex;
  244. // 获取当前显示中对象的数据
  245. obj.$nextTick(() => {
  246. obj.getList(obj.classIndex);
  247. });
  248. if (obj.indexList.length <= 4) {
  249. // 当数量小于等于4的时候自适应宽度
  250. obj.topNavWidth = 100 / obj.indexList.length + '%';
  251. } else {
  252. // 页面渲染完毕后加载scroll-view左侧距离
  253. obj.$nextTick(() => {
  254. obj.numClassWidht();
  255. });
  256. }
  257. })
  258. .catch(e => {
  259. console.log(e);
  260. });
  261. },
  262. // 计算倒计时时间
  263. timeComputed(da, ar) {
  264. let obj = this;
  265. // 计算时间,保存需要多少时间到期
  266. let stopTime = timeComputed(da);
  267. console.log(stopTime);
  268. ar.stopTimeH = stopTime.hours;
  269. ar.stopTimeM = stopTime.minutes;
  270. ar.stopTimeS = stopTime.seconds;
  271. }
  272. }
  273. };
  274. </script>
  275. <style lang="scss">
  276. page,
  277. .seckillBox {
  278. min-height: 100%;
  279. height: 100%;
  280. }
  281. // 头部时间段样式
  282. .class-box {
  283. white-space: nowrap;
  284. height: 60px;
  285. .item {
  286. text-align: center;
  287. display: inline-block;
  288. color: #fff;
  289. padding: 11.5px 5px;
  290. background-color: #901b21;
  291. line-height: 1;
  292. .time {
  293. font-size: 16px;
  294. padding-bottom: 3px;
  295. &.action {
  296. color: #901b21;
  297. }
  298. }
  299. .status {
  300. font-size: 12px;
  301. margin: 0 auto;
  302. width: 60px;
  303. padding: 3px 0;
  304. &.action {
  305. color: #901b21;
  306. border-radius: 99px;
  307. background-color: #fff;
  308. }
  309. }
  310. }
  311. .action {
  312. color: #901b21;
  313. background-color: #fff;
  314. }
  315. }
  316. // 列表上方标题样式
  317. .title-box {
  318. margin-top: 10px;
  319. padding: 10px;
  320. background-color: #ffffff;
  321. .title-box-left {
  322. font-size: 15px;
  323. color: $font-color-base;
  324. }
  325. .title-box-right {
  326. .tip {
  327. font-size: 15px;
  328. color: #999999;
  329. padding-right: 5px;
  330. }
  331. /deep/ .uni-countdown__number {
  332. border-radius: 3px;
  333. width: 22px;
  334. }
  335. /deep/ .uni-countdown__splitor,
  336. /deep/ .uni-countdown__number {
  337. height: 20px;
  338. line-height: 18px;
  339. }
  340. }
  341. }
  342. // 列表样式
  343. .list-Box {
  344. height: calc(100vh - 104px);
  345. // height: calc(100vh- 60px);
  346. .list {
  347. height: calc(100vh - 104px);
  348. // background-color: pink;
  349. }
  350. }
  351. // 商品列表
  352. $slider-color: #fe9398; //滑块左侧颜色
  353. .goodsList-item {
  354. background-color: #ffffff;
  355. padding: 30rpx;
  356. border-bottom: 1px solid $border-color-light;
  357. image {
  358. flex-shrink: 0;
  359. border-radius: $border-radius-sm;
  360. height: 180rpx;
  361. width: 180rpx;
  362. }
  363. .slider {
  364. margin-top: 15rpx;
  365. justify-content: flex-start;
  366. .slider-box {
  367. width: 196rpx;
  368. border-radius: 99px;
  369. border: 1px solid $slider-color;
  370. height: 16rpx;
  371. .slider-action {
  372. background-color: $slider-color;
  373. height: 100%;
  374. }
  375. }
  376. .sales-nub {
  377. color: $font-color-light;
  378. font-size: 24rpx;
  379. padding-left: 20rpx;
  380. }
  381. }
  382. .goodsList-content {
  383. margin-left: 20rpx;
  384. flex-grow: 1;
  385. height: 180rpx;
  386. position: relative;
  387. .title {
  388. font-size: $font-base;
  389. color: $font-color-dark;
  390. font-weight: 500;
  391. width: 0;
  392. min-width: 100%;
  393. }
  394. .goods-money {
  395. position: absolute;
  396. left: 0;
  397. bottom: 0;
  398. width: 100%;
  399. .money-box {
  400. .money {
  401. font-size: $font-lg + 10rpx;
  402. color: $color-red;
  403. font-weight: bold;
  404. }
  405. .otMoney-box {
  406. font-size: $font-sm;
  407. .otMoney {
  408. color: $font-color-light;
  409. padding-right: 20rpx;
  410. text-decoration: line-through;
  411. }
  412. .sales {
  413. color: $font-color-light;
  414. }
  415. }
  416. }
  417. .cart {
  418. font-size: $font-base;
  419. border-radius: 99px;
  420. padding: 15rpx 30rpx;
  421. line-height: 1;
  422. color: #ffffff;
  423. background-color: $color-gray;
  424. &.seckill-action {
  425. border: 1px solid $color-red;
  426. background-color: $color-red;
  427. }
  428. }
  429. }
  430. }
  431. }
  432. .spgood {
  433. width: 710rpx;
  434. height: 290rpx;
  435. background: #FFFFFF;
  436. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  437. border-radius: 10rpx;
  438. padding: 15rpx 20rpx 15rpx 14rpx;
  439. display: flex;
  440. margin: 0 auto;
  441. margin-bottom: 20rpx;
  442. .left-wrapper {
  443. width: 260rpx;
  444. height: 260rpx;
  445. border-radius: 10rpx;
  446. image {
  447. width: 260rpx;
  448. height: 260rpx;
  449. border-radius: 10rpx;
  450. }
  451. }
  452. .right-wrapper {
  453. padding-left: 22rpx;
  454. width: 100%;
  455. height: 200rpx;
  456. // background-color: red;
  457. .right-title {
  458. padding-top: 12rpx;
  459. width: 358rpx;
  460. // height: 29rpx;
  461. // font-size: 30rpx;
  462. // font-weight: bold;
  463. // color: #333333;
  464. font-size: 30rpx;
  465. font-weight: bold;
  466. color: #333333;
  467. line-height: 35rpx;
  468. }
  469. .right-addr {
  470. margin-top: 18rpx;
  471. display: flex;
  472. .shop-img {
  473. width: 26rpx;
  474. height: 23rpx;
  475. margin: 0 4rpx 0 0;
  476. image {
  477. width: 100%;
  478. height: 100%;
  479. }
  480. }
  481. .shop-name {
  482. // height: 22rpx;
  483. font-size: 22rpx;
  484. font-weight: 500;
  485. color: #dcb876;
  486. }
  487. .point-img {
  488. width: 16rpx;
  489. height: 23rpx;
  490. margin: 0 4rpx 0 14rpx;
  491. image {
  492. width: 100%;
  493. height: 21rpx;
  494. }
  495. }
  496. .point-disc {
  497. font-size: 24rpx;
  498. font-weight: 500;
  499. padding-top: 3rpx;
  500. color: #dcb876;
  501. }
  502. }
  503. .ex-addr {
  504. margin-top: 16rpx;
  505. // padding-left: 22rpx;
  506. height: 22rpx;
  507. font-size: 25rpx;
  508. font-weight: 500;
  509. color: #dcb876;
  510. image {
  511. height: 22rpx;
  512. }
  513. .name-img {
  514. // vertical-align: ;
  515. width: 26rpx;
  516. margin: 0 4rpx -3rpx 0;
  517. }
  518. .point-img {
  519. width: 16rpx;
  520. margin: 0 4rpx -3rpx 14rpx;
  521. }
  522. }
  523. .right-bottom {
  524. margin-top: 117rpx;
  525. // justify-items: flex-end;
  526. display: flex;
  527. justify-content: space-between;
  528. .sp-price {
  529. height: 52rpx;
  530. display: flex;
  531. vertical-align: bottom;
  532. line-height: 52rpx;
  533. .now-price {
  534. // font-size: 30rpx;
  535. // font-weight: bold;
  536. // color: #901b21;
  537. padding-top: 19rpx;
  538. margin-right: 16rpx;
  539. font-size: 36rpx;
  540. font-weight: bold;
  541. color: #901B21;
  542. line-height: 35rpx;
  543. // vertical-align: bottom;
  544. }
  545. .old-price {
  546. font-size: 22rpx;
  547. font-weight: 500;
  548. text-decoration: line-through;
  549. color: #aaaaaa;
  550. }
  551. }
  552. .sp-btn {
  553. width: 136.6rpx;
  554. height: 60rpx;
  555. border-radius: 30rpx;
  556. font-size: 26rpx;
  557. text-align: center;
  558. line-height: 60rpx;
  559. font-weight: 400;
  560. color: #ffffff;
  561. // background-color: #dcb876;
  562. background-color: #999999;
  563. &.seckill-action {
  564. background-color: #dcb876;
  565. // background-color: #999999;
  566. }
  567. }
  568. }
  569. }
  570. }
  571. .jg {
  572. height: 34rpx;
  573. }
  574. </style>