| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- <template>
- <view class="seckillBox">
- <scroll-view scroll-x="true" class="class-box flex " :scroll-left="scrollLeft" :scroll-with-animation="true">
- <view @click="tabClass(idx)" class="item" :style="{ width: topNavWidth }" v-for="(item, idx) in indexList" :key="idx" :class="{ action: idx == classIndex }">
- <view class="time" :class="{ action: idx == classIndex }">{{ item.time}}</view>
- <view class="status" :class="{ action: idx == classIndex }">{{ item.state }}</view>
- </view>
- </scroll-view>
- <swiper class="list-Box" :current="classIndex" @change="swiperChange" duration="500">
- <swiper-item class="list-item" v-for="(ls, idx) in indexList" :key="idx">
- <scroll-view scroll-y="true" class="list" @scrolltolower="getList(classIndex)">
- <view class="jg"></view>
- <view class="spgood" :key="ind" v-for="(lss, ind) in ls.dataList">
- <view class="left-wrapper"><image :src="lss.image" mode="scaleToFill"></image></view>
- <view class="right-wrapper">
- <view class="right-title clamp">{{ lss.title }}</view>
- <view class="ex-addr">
- <image src="../../static/img/shop.png" mode="" class="name-img"></image>
- {{checkedStore.name | longstorename}}
- <image src="../../static/img/point.png" mode="" class="point-img"></image>
- {{ des | distance}}
- </view>
- <view class="right-bottom">
- <view class="sp-price">
- <view class="now-price">¥{{ lss.price }}</view>
- </view>
- <view class="sp-btn" @click="navProduct(ls, ind)" :class="{ 'seckill-action': ls.status == 1 }">{{ ls.status == 1 ? '去抢购' : ls.status == 2 ? '未开始' : '已结束' }}</view>
- </view>
- </view>
- </view>
- <uni-load-more :status="ls.loadingType"></uni-load-more>
- </scroll-view>
- </swiper-item>
- </swiper>
- </view>
- </template>
- <script>
- import { mapState, mapMutations } from 'vuex';
- import { getSeckillList, getSeckillClass } from '@/api/product.js';
- import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
- import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
- import { timeComputed } from '@/utils/rocessor.js';
- export default {
- components: {
- uniCountdown,
- uniLoadMore
- },
- data() {
- return {
- indexList: [], //分类列表
- showTime: '', //显示的时间
- showTImeId: '', //显示时间id用于查询数据
- // 判断是否所有活动已经结束
- stop: false, //活动是否已经结束
- show: false, //是否显示活动
- status: 0, //获取状态值1为有活动开始中 2为活动未开始 0为活动已经结束
- topNavWidth: '25%', //设置导航默认宽度
- classIndex: 0, //当前进行中的活动
- itemWidht: 0 //顶部分类宽度
- };
- },
- filters: {
- storename(val) {
- let str = ''
- if(val) {
- str = val
- if(val.length > 5) {
- str = val.slice(0,5)+'...'
- }
-
- }
- return str
- },
- longstorename(val) {
- let str = ''
- if(val) {
- str = val
- if(val.length > 8) {
- str = val.slice(0,8)+'...'
- }
-
- }
- return str
- },
- distance(val) {
- let str = ''
- if(val) {
- if(val*1 > 1000) {
- return str = (val*1/1000).toFixed(1) + 'km'
- }
- }else {
- return str = (val*1).toFixed(0) + 'm'
- }
- return str
-
- }
- },
- computed: {
- ...mapState('user', ['hasLogin', 'userInfo', 'checkedStore','des']),
- // 计算左侧距离
- scrollLeft() {
- if (this.classIndex > 1) {
- return this.itemWidht * (this.classIndex - 1.5);
- } else {
- return 0;
- }
- }
- },
- onLoad: function(e) {
- // 载入分类
- this.getClass();
- console.log(this.checkedStore,'ddddddddddddddddddddddd')
- },
- methods: {
- space(lat1, lng1) {
- let sp = uni.getStorageSync('latlon');
- console.log(sp);
- let arr1 = sp.split(',');
- let lat2 = arr1[0];
- let lng2 = arr1[1];
- console.log(lat1, lng1, lat2, lng2, '位置信息');
- var radLat1 = (lat1 * Math.PI) / 180.0;
- var radLat2 = (lat2 * Math.PI) / 180.0;
- var a = radLat1 - radLat2;
- var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
- 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)));
- s = s * 6378.137;
- s = Math.round(s * 10000) / 10000;
- // return s * 1000;
- if(s>1) {
- return s.toFixed(2) + 'km'
- }else {
- return s * 1000 + 'm'; // 单位米
- }
- },
- //抢购时间切换时触发效果
- swiperChange(e) {
- this.classIndex = e.target.current;
- this.getList(this.classIndex, 'tabChange');
- },
- // 获取项目宽度
- numClassWidht() {
- uni.createSelectorQuery()
- .select('.seckillBox')
- .fields(
- {
- size: true
- },
- data => {
- // 设置项目宽度
- this.itemWidht = Math.floor((data.width / 750) * 187.5);
- }
- )
- .exec();
- },
- // 切换当前选中的秒杀活动
- tabClass(ind) {
- // 保存当前选中的对象
- this.classIndex = ind;
- },
- // 跳转到商品详情
- navProduct(ls, ind) {
- if (ls.status == 1) {
- let data = ls.dataList[ind];
- uni.navigateTo({
- url: '/pages/product/product?id=' + data.id + '&type=1'
- });
- }
- },
- // 获取商品
- getList(ind, source) {
- // 获取数据对象
- let date = this.indexList[ind];
- console.log(date, source);
- if (source === 'tabChange' && date.loaded === true) {
- //tab切换只有第一次需要加载数据
- return;
- }
- if (date.loadingType === 'noMore') {
- //防止重复加载
- return;
- }
- if (date.loadingType === 'loading') {
- //防止重复加载
- return;
- }
- // 修改当前对象状态为加载中
- date.loadingType = 'loading';
- getSeckillList(
- {
- page: date.page,
- limit: date.limit
- },
- date.id
- )
- .then(e => {
- date.dataList.push(...e.data);
- // 查询翻页增加
- date.page++;
- // 判断是否可以继续加载
- if (date.limit == e.data.length) {
- date.loadingType = 'more';
- } else {
- date.loadingType = 'noMore';
- }
- // 设置当前数据已加载完毕
- this.$set(date, 'loaded', true);
- })
- .catch(e => {
- console.log(e);
- });
- },
- // 获取秒杀时间段
- getClass() {
- let obj = this;
- getSeckillClass({})
- .then(({ data }) => {
- obj.indexList = data.seckillTime.map((e, ind) => {
- // 初始化翻页页数
- e.page = 1;
- // 初始每次加载的数据条数
- e.limit = 6;
- // 创建储存订单数据
- e.dataList = [];
- // 初始化加载
- e.loadingType = 'more';
- let ar = e;
- // 判断是否为进行中的活动
- if (ar.status === 1) {
- // 计算倒计时时间
- obj.timeComputed(ar.stop * 1000, ar);
- } else {
- // 获取距离开始还需要多少时间
- let arTime = ar.time.split(':');
- let h = arTime[0];
- let m = arTime[1];
- let time = new Date();
- // 设置时间
- time.setHours(h, m, 0);
- // 计算倒计时时间
- obj.timeComputed(time.getTime(), ar);
- }
- return e;
- });
- // 获取当前活动中的下标值
- obj.classIndex = data.seckillTimeIndex;
- // 获取当前显示中对象的数据
- obj.$nextTick(() => {
- obj.getList(obj.classIndex);
- });
- if (obj.indexList.length <= 4) {
- // 当数量小于等于4的时候自适应宽度
- obj.topNavWidth = 100 / obj.indexList.length + '%';
- } else {
- // 页面渲染完毕后加载scroll-view左侧距离
- obj.$nextTick(() => {
- obj.numClassWidht();
- });
- }
- })
- .catch(e => {
- console.log(e);
- });
- },
- // 计算倒计时时间
- timeComputed(da, ar) {
- let obj = this;
- // 计算时间,保存需要多少时间到期
- let stopTime = timeComputed(da);
- console.log(stopTime);
- ar.stopTimeH = stopTime.hours;
- ar.stopTimeM = stopTime.minutes;
- ar.stopTimeS = stopTime.seconds;
- }
- }
- };
- </script>
- <style lang="scss">
- page,
- .seckillBox {
- min-height: 100%;
- height: 100%;
- }
- // 头部时间段样式
- .class-box {
- white-space: nowrap;
- height: 60px;
- .item {
- text-align: center;
- display: inline-block;
- color: #fff;
- padding: 11.5px 5px;
- background-color: #901b21;
- line-height: 1;
- .time {
- font-size: 16px;
- padding-bottom: 3px;
- &.action {
- color: #901b21;
- }
- }
- .status {
- font-size: 12px;
- margin: 0 auto;
- width: 60px;
- padding: 3px 0;
- &.action {
- color: #901b21;
- border-radius: 99px;
- background-color: #fff;
- }
- }
- }
- .action {
- color: #901b21;
- background-color: #fff;
- }
- }
- // 列表上方标题样式
- .title-box {
- margin-top: 10px;
- padding: 10px;
- background-color: #ffffff;
- .title-box-left {
- font-size: 15px;
- color: $font-color-base;
- }
- .title-box-right {
- .tip {
- font-size: 15px;
- color: #999999;
- padding-right: 5px;
- }
- /deep/ .uni-countdown__number {
- border-radius: 3px;
- width: 22px;
- }
- /deep/ .uni-countdown__splitor,
- /deep/ .uni-countdown__number {
- height: 20px;
- line-height: 18px;
- }
- }
- }
- // 列表样式
- .list-Box {
- height: calc(100vh - 104px);
- // height: calc(100vh- 60px);
- .list {
- height: calc(100vh - 104px);
- // background-color: pink;
- }
- }
- // 商品列表
- $slider-color: #fe9398; //滑块左侧颜色
- .goodsList-item {
- background-color: #ffffff;
- padding: 30rpx;
- border-bottom: 1px solid $border-color-light;
- image {
- flex-shrink: 0;
- border-radius: $border-radius-sm;
- height: 180rpx;
- width: 180rpx;
- }
- .slider {
- margin-top: 15rpx;
- justify-content: flex-start;
- .slider-box {
- width: 196rpx;
- border-radius: 99px;
- border: 1px solid $slider-color;
- height: 16rpx;
- .slider-action {
- background-color: $slider-color;
- height: 100%;
- }
- }
- .sales-nub {
- color: $font-color-light;
- font-size: 24rpx;
- padding-left: 20rpx;
- }
- }
- .goodsList-content {
- margin-left: 20rpx;
- flex-grow: 1;
- height: 180rpx;
- position: relative;
- .title {
- font-size: $font-base;
- color: $font-color-dark;
- font-weight: 500;
- width: 0;
- min-width: 100%;
- }
- .goods-money {
- position: absolute;
- left: 0;
- bottom: 0;
- width: 100%;
- .money-box {
- .money {
- font-size: $font-lg + 10rpx;
- color: $color-red;
- font-weight: bold;
- }
- .otMoney-box {
- font-size: $font-sm;
- .otMoney {
- color: $font-color-light;
- padding-right: 20rpx;
- text-decoration: line-through;
- }
- .sales {
- color: $font-color-light;
- }
- }
- }
- .cart {
- font-size: $font-base;
- border-radius: 99px;
- padding: 15rpx 30rpx;
- line-height: 1;
- color: #ffffff;
- background-color: $color-gray;
- &.seckill-action {
- border: 1px solid $color-red;
- background-color: $color-red;
- }
- }
- }
- }
- }
- .spgood {
- width: 710rpx;
- height: 290rpx;
- background: #FFFFFF;
- box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
- border-radius: 10rpx;
- padding: 15rpx 20rpx 15rpx 14rpx;
- display: flex;
- margin: 0 auto;
- margin-bottom: 20rpx;
- .left-wrapper {
- width: 260rpx;
- height: 260rpx;
- border-radius: 10rpx;
- image {
- width: 260rpx;
- height: 260rpx;
- border-radius: 10rpx;
- }
- }
- .right-wrapper {
- padding-left: 22rpx;
- width: 100%;
- height: 200rpx;
- // background-color: red;
- .right-title {
- padding-top: 12rpx;
- width: 358rpx;
- // height: 29rpx;
- // font-size: 30rpx;
- // font-weight: bold;
- // color: #333333;
-
- font-size: 30rpx;
- font-weight: bold;
- color: #333333;
- line-height: 35rpx;
- }
- .right-addr {
- margin-top: 18rpx;
- display: flex;
- .shop-img {
- width: 26rpx;
- height: 23rpx;
- margin: 0 4rpx 0 0;
- image {
- width: 100%;
- height: 100%;
- }
- }
- .shop-name {
- // height: 22rpx;
- font-size: 22rpx;
- font-weight: 500;
- color: #dcb876;
- }
- .point-img {
- width: 16rpx;
- height: 23rpx;
- margin: 0 4rpx 0 14rpx;
- image {
- width: 100%;
- height: 21rpx;
- }
- }
- .point-disc {
- font-size: 24rpx;
- font-weight: 500;
- padding-top: 3rpx;
- color: #dcb876;
- }
- }
- .ex-addr {
- margin-top: 16rpx;
- // padding-left: 22rpx;
- height: 22rpx;
- font-size: 25rpx;
- font-weight: 500;
- color: #dcb876;
- image {
- height: 22rpx;
- }
- .name-img {
- // vertical-align: ;
- width: 26rpx;
- margin: 0 4rpx -3rpx 0;
- }
- .point-img {
- width: 16rpx;
- margin: 0 4rpx -3rpx 14rpx;
- }
- }
-
- .right-bottom {
- margin-top: 117rpx;
- // justify-items: flex-end;
- display: flex;
- justify-content: space-between;
- .sp-price {
- height: 52rpx;
- display: flex;
- vertical-align: bottom;
- line-height: 52rpx;
- .now-price {
- // font-size: 30rpx;
- // font-weight: bold;
- // color: #901b21;
- padding-top: 19rpx;
- margin-right: 16rpx;
- font-size: 36rpx;
- font-weight: bold;
- color: #901B21;
- line-height: 35rpx;
- // vertical-align: bottom;
- }
- .old-price {
- font-size: 22rpx;
- font-weight: 500;
- text-decoration: line-through;
- color: #aaaaaa;
- }
- }
- .sp-btn {
- width: 136.6rpx;
- height: 60rpx;
- border-radius: 30rpx;
- font-size: 26rpx;
- text-align: center;
- line-height: 60rpx;
- font-weight: 400;
- color: #ffffff;
- // background-color: #dcb876;
- background-color: #999999;
- &.seckill-action {
- background-color: #dcb876;
- // background-color: #999999;
- }
- }
-
- }
- }
- }
- .jg {
- height: 34rpx;
- }
- </style>
|