Gao xiaosong 5 years ago
parent
commit
4b6636ba6f
  1. 2
      assets/css/style.less
  2. 18
      main.js
  3. 108
      pages/activity/GoodsSeckill/index.vue
  4. 99
      pages/authorization/index.vue
  5. 148
      pages/home/index.vue
  6. 168
      pages/shop/ShoppingCart/index.vue
  7. 35
      store/index.js
  8. 1
      utils/index.js
  9. 2
      utils/request.js

2
assets/css/style.less

@ -2135,7 +2135,7 @@ flex: 0 2.4*100rpx;
.shoppingCart .footer .checkAll {
font-size: 0.28*100rpx;
color: #282828;
margin-left: 0.6*100rpx;
margin-left: 0.1*100rpx;
}
.shoppingCart .footer .money {

18
main.js

@ -76,28 +76,32 @@ Object.defineProperty(Vue.prototype, '$yroute', {
Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
// #ifdef H5
// H5编译的代码
Vue.prototype.$deviceType = 'h5'
store.commit('UPDATE_DEVICETYPE','h5')
// #endif
// #ifdef APP-PLUS
// App平台编译的代码
console.log('App平台编译的代码')
Vue.prototype.$deviceType = 'app'
store.commit('UPDATE_DEVICETYPE','app')
Vue.prototype.$platform = uni.getSystemInfoSync().platform
// #endif
// #ifdef MP-WEIXIN
// 微信小程序编译的代码
console.log('微信小程序编译的代码')
Vue.prototype.$deviceType = 'weixin'
store.commit('UPDATE_DEVICETYPE','weixin')
// #endif
console.log(wx,121212)
console.log(Vue.prototype.$deviceType)
// if(wx){
// Vue.prototype.$deviceType = 'weixin'
// }
// !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用
// 建议通过 store 去获取 $deviceType 可以保证 template 中取到的值有效
// import { mapState, mapMutations, mapActions } from 'vuex';
// computed: {
// ...mapState(['$deviceType'])
// },
app.$mount()

108
pages/activity/GoodsSeckill/index.vue

@ -1,26 +1,14 @@
<template>
<view class="flash-sale" ref="container">
<view class="header" v-if="headerImg">
<image :src="headerImg" />
</view>
<vant-tabs
:active="active"
@change="setTime"
:sticky="sticky"
animated
line-height="2"
:ellipsis="false"
>
<vant-tab
:ellipsis="false"
:title="[title[index]]"
v-for="(item, index) in timeList"
:key="index"
>
<view slot="title" class="timeItem">
<view class="header" v-if="headerImg"><image :src="headerImg" /></view>
<view class="" v-for="(item, index) in timeList" :key="index">
<view class="timeItem">
<view class="time">{{ item.time }}</view>
<view class="state">{{ item.state }}</view>
</view>
</view>
<view class="" v-for="(item, index) in timeList" :key="index">
<view v-if="active == index">
<view class="countDown font-color-red acea-row row-center-wrapper">
<view v-if="item.status === 0" class="activity">活动已结束</view>
<count-down
@ -36,14 +24,8 @@
<view v-if="item.status === 2" class="activity">活动即将开始</view>
</view>
<view class="list">
<view
class="item acea-row row-between-wrapper"
v-for="(itemSeckill, indexSeckill) in seckillList"
:key="indexSeckill"
>
<view class="pictrue">
<image :src="itemSeckill.image" />
</view>
<view class="item acea-row row-between-wrapper" v-for="(itemSeckill, indexSeckill) in seckillList" :key="indexSeckill">
<view class="pictrue"><image :src="itemSeckill.image" /></view>
<view class="text acea-row row-column-around">
<view class="line1" v-text="itemSeckill.title"></view>
<view class="money">
@ -55,44 +37,40 @@
<view class="piece font-color-red" v-text="'仅剩' + itemSeckill.stock + '件'"></view>
</view>
</view>
<view
class="grab bg-color-red"
v-if="item.status === 1 && itemSeckill.stock > 0"
@click="goDetail(itemSeckill.id)"
>马上抢</view>
<view class="grab bg-color-red" v-if="item.status === 1 && itemSeckill.stock > 0" @click="goDetail(itemSeckill.id)">马上抢</view>
<view class="grab" v-if="item.status === 1 && itemSeckill.stock <= 0">已售磬</view>
<view class="grab bg-color-red" v-if="item.status === 2">即将开始</view>
<view class="grab bg-color-red" v-if="item.status === 0">已结束</view>
</view>
</view>
<view
class="noCommodity"
style="background-color: #fff;"
v-if="seckillList.length === 0 && page > 1"
>
<view class="noPictrue">
<image :src="$VUE_APP_RESOURCES_URL+'/images/noGood.png'" class="image" />
<view class="noCommodity" style="background-color: #fff;" v-if="seckillList.length === 0 && page > 1">
<view class="noPictrue"><image :src="$VUE_APP_RESOURCES_URL + '/images/noGood.png'" class="image" /></view>
</view>
</view>
</view>
<!--
<vant-tabs :active="active" @change="setTime" :sticky="sticky" animated line-height="2" :ellipsis="false">
<vant-tab :ellipsis="false" :title="[title[index]]">
</vant-tab>
</vant-tabs>
</vant-tabs> -->
</view>
</template>
<script>
import { getSeckillConfig, getSeckillList } from "@/api/activity";
import CountDown from "@/components/CountDown";
import { getSeckillConfig, getSeckillList } from '@/api/activity';
import CountDown from '@/components/CountDown';
// import { Tab, Tabs } from "vant-weapp";
import Loading from "@/components/Loading";
import Loading from '@/components/Loading';
export default {
name: "GoodsSeckill",
name: 'GoodsSeckill',
components: {
CountDown
},
props: {},
data: function() {
return {
headerImg: "",
headerImg: '',
timeList: [],
sticky: false,
loading: false,
@ -117,38 +95,38 @@ export default {
var that = this;
uni.showLoading();
getSeckillConfig().then(res => {
that.$set(that, "headerImg", res.data.lovely);
that.$set(that, "timeList", res.data.seckillTime);
that.$set(that, "active", res.data.seckillTimeIndex);
that.$set(that, 'headerImg', res.data.lovely);
that.$set(that, 'timeList', res.data.seckillTime);
that.$set(that, 'active', res.data.seckillTimeIndex);
let title = [];
title = res.data.seckillTime.map((item, index) => {
return {
name: "div",
name: 'div',
attrs: {
class: "timeItem"
class: 'timeItem'
},
children: [
{
name: "div",
name: 'div',
attrs: {
class: "time"
class: 'time'
},
children: [
{
type: "text",
type: 'text',
text: item.time
}
]
},
{
name: "div",
name: 'div',
attrs: {
class: "state"
class: 'state'
},
children: [
{
type: "text",
type: 'text',
text: item.state
}
]
@ -156,7 +134,7 @@ export default {
]
};
});
that.$set(that, "title", title);
that.$set(that, 'title', title);
that.datatime = that.timeList[that.active].stop;
that.getSeckillList();
that.$nextTick(function() {
@ -187,7 +165,7 @@ export default {
var that = this;
var time = that.timeList[that.active].stop;
this.$yrouter.push({
path: "/pages/activity/SeckillDetails/index",
path: '/pages/activity/SeckillDetails/index',
query: { id, time }
});
}
@ -196,23 +174,23 @@ export default {
</script>
<style scoped lang="less">
.timeItem {
font-size: 0.22*100rpx;
font-size: 0.22 * 100rpx;
color: #282828;
width: 100%;
text-align: center;
padding: 0.11*100rpx 0;
height: 0.96*100rpx;
padding: 0.11 * 100rpx 0;
height: 0.96 * 100rpx;
background-color: #efc58f;
}
.timeItem .time {
font-size: 0.32*100rpx;
font-size: 0.32 * 100rpx;
font-weight: bold;
height: 0.37*100rpx;
line-height: 0.37*100rpx;
height: 0.37 * 100rpx;
line-height: 0.37 * 100rpx;
}
.timeItem .state {
height: 0.37*100rpx;
line-height: 0.37*100rpx;
height: 0.37 * 100rpx;
line-height: 0.37 * 100rpx;
}
.activity {
color: #333;

99
pages/authorization/index.vue

@ -1,6 +1,7 @@
<template>
<view class="container">
<view v-if="!$store.getters.token&&$deviceType=='weixin'">
<view v-if="!token">
<view v-if="$deviceType == 'weixin'">
<view class="getUserInfo">
<text>您还未允许微信登录授权请点击下方按钮允许微信授权登录</text>
<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button>
@ -8,42 +9,34 @@
<button @click="back">取消微信登录授权</button>
</view>
</view>
<view v-if="!$store.getters.token&&$deviceType!='weixin'&&$deviceType=='app'">
<view v-if="$deviceType == 'app'">
<view class="getUserInfo">
<text>请先登录</text>
<button type="primary" @click="this.toLogin">去登录</button>
</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState,
mapMutations,
mapActions
} from "vuex";
//
// import request from "@//api/request";
import {
wxappAuth,
getUser
} from "@/api/user";
import dayjs from "dayjs";
import cookie from "@/utils/store/cookie";
import {
login
} from "@/utils";
export default {
import { mapState, mapMutations, mapActions } from 'vuex';
//
// import request from "@//api/request";
import { wxappAuth, getUser } from '@/api/user';
import dayjs from 'dayjs';
import cookie from '@/utils/store/cookie';
import { login } from '@/utils';
export default {
data() {
return {};
return {
};
},
computed: {
...mapState(["isAuthorization"])
...mapState(['isAuthorization','$deviceType','token'])
},
onShow() {
this.UPDATE_AUTHORIZATIONPAGE(true);
},
onHide() {
@ -55,25 +48,25 @@
this.changeAuthorization(false);
},
methods: {
...mapActions(["changeAuthorization", "setUserInfo"]),
...mapMutations(["UPDATE_AUTHORIZATIONPAGE", "CHANGE_TABTAR"]),
...mapActions(['changeAuthorization', 'setUserInfo']),
...mapMutations(['UPDATE_AUTHORIZATIONPAGE', 'CHANGE_TABTAR']),
back() {
this.$yrouter.switchTab({
path: "/pages/home/index",
path: '/pages/home/index',
query: {}
});
},
getUserInfo(data) {
if (data.detail.errMsg == "getUserInfo:fail auth deny") {
if (data.detail.errMsg == 'getUserInfo:fail auth deny') {
uni.showToast({
title: "取消授权",
icon: "none",
title: '取消授权',
icon: 'none',
duration: 2000
});
return;
}
uni.showLoading({
title: "登录中"
title: '登录中'
});
login({
success: () => {}
@ -81,22 +74,23 @@
},
toLogin() {
this.$yrouter.push({
path: "/pages/user/Login/index",
path: '/pages/user/Login/index',
query: {}
});
}
},
onUnload() {},
mounted() {}
};
mounted() {
}
};
</script>
<style lang="less">
.sp-cell {
.sp-cell {
height: 20rpx;
}
}
.getUserInfo {
.getUserInfo {
display: flex;
align-items: center;
flex-direction: column;
@ -107,17 +101,17 @@
text-align: center;
margin-bottom: 20px;
}
}
}
.container {
.container {
flex: 1;
display: flex;
flex-direction: column;
justify-content: flex-start;
position: relative;
}
}
.tab-bar {
.tab-bar {
font-size: 0;
display: flex;
align-items: center;
@ -173,7 +167,8 @@
}
}
.tab-bar-pic-active {}
.tab-bar-pic-active {
}
text {
font-size: 10px;
@ -181,23 +176,23 @@
line-height: 10px;
margin-top: 5px;
}
}
}
.tab-bar-bg {
.tab-bar-bg {
padding-top: 46px;
width: 100%;
}
}
.view-item {
.view-item {
display: none;
width: 100%;
}
}
.view-item-active {
.view-item-active {
display: block;
}
}
.getUserInfo {
.getUserInfo {
display: flex;
align-items: center;
flex-direction: column;
@ -206,9 +201,9 @@
p {
margin-bottom: 20px;
}
}
}
._van-dialog {
._van-dialog {
z-index: 99999999999;
}
}
</style>

148
pages/home/index.vue

@ -2,39 +2,26 @@
<view class="index">
<view class="header acea-row row-center-wrapper">
<view @click="goGoodSearch()" class="search acea-row row-middle">
<text class="iconfont icon-xiazai5"></text>搜索商品
<text class="iconfont icon-xiazai5"></text>
搜索商品
</view>
</view>
<view class="slider-banner banner">
<swiper indicatorDots="true" v-if="banner.length > 0">
<block v-for="(item, bannerIndex) in banner" :key="bannerIndex">
<swiper-item>
<view @click="item.url?$yrouter.push('/'+item.url) : ''" class="swiper-item">
<image :src="item.pic" />
</view>
<view @click="item.url ? $yrouter.push('/' + item.url) : ''" class="swiper-item"><image :src="item.pic" /></view>
</swiper-item>
</block>
</swiper>
</view>
<view class="news acea-row row-between-wrapper">
<view class="pictrue" v-if="$VUE_APP_RESOURCES_URL">
<image :src="$VUE_APP_RESOURCES_URL+'/images/news.png'" />
</view>
<view class="pictrue" v-if="$VUE_APP_RESOURCES_URL"><image :src="$VUE_APP_RESOURCES_URL + '/images/news.png'" /></view>
<view class="swiper-no-swiping new-banner">
<swiper
class="swiper-wrapper"
v-if="roll.length > 0"
:indicator-dots="false"
autoplay
circular
vertical
>
<swiper class="swiper-wrapper" v-if="roll.length > 0" :indicator-dots="false" autoplay circular vertical>
<block v-for="(item, rollIndex) in roll" :key="rollIndex">
<swiper-item class="swiper-slide">
<view
@click="item.uniapp_url?$yrouter.push(item.uniapp_url) : ''"
class="swiper-item acea-row row-between-wrapper"
>
<view @click="item.uniapp_url ? $yrouter.push(item.uniapp_url) : ''" class="swiper-item acea-row row-between-wrapper">
<view class="text acea-row row-between-wrapper">
<view class="label" v-if="item.show === '是'">最新</view>
<view class="newsTitle line1">{{ item.info }}</view>
@ -47,24 +34,15 @@
</view>
</view>
<view class="nav acea-row">
<view
@click="goWxappUrl(item)"
class="item"
v-for="(item, menusIndex) in menus"
:key="menusIndex"
>
<view class="pictrue">
<image :src="item.pic" />
</view>
<view @click="goWxappUrl(item)" class="item" v-for="(item, menusIndex) in menus" :key="menusIndex">
<view class="pictrue"><image :src="item.pic" /></view>
<view>{{ item.name }}</view>
</view>
</view>
<view class="wrapper hot" v-if="bastList.length > 0">
<image class="bg" src="../../static/images/index-bg.png" mode="widthFix" ></image>
<image class="bg" src="../../static/images/index-bg.png" mode="widthFix"></image>
<view class="title acea-row row-between-wrapper">
<view class="text">
<view class="name line1">热门榜单</view>
</view>
<view class="text"><view class="name line1">热门榜单</view></view>
<view @click="goHotNewGoods()" class="more">
更多
<text class="iconfont icon-jiantou"></text>
@ -73,15 +51,8 @@
<view class="newProducts">
<scroll-view scroll-y="false" scroll-x="true">
<view class="newProductsScroll">
<view
@click="goGoodsCon(item)"
class="newProductsItem"
v-for="(item, likeInfoIndex) in likeInfo"
:key="likeInfoIndex"
>
<view class="img-box">
<image :src="item.image" />
</view>
<view @click="goGoodsCon(item)" class="newProductsItem" v-for="(item, likeInfoIndex) in likeInfo" :key="likeInfoIndex">
<view class="img-box"><image :src="item.image" /></view>
<view class="pro-info line1">{{ item.storeName }}</view>
<view class="money font-color-red">{{ item.price }}</view>
</view>
@ -91,9 +62,7 @@
</view>
<view class="wrapper" v-if="bastList.length > 0">
<view class="title acea-row row-between-wrapper">
<view class="text">
<view class="name line1">精品推荐</view>
</view>
<view class="text"><view class="name line1">精品推荐</view></view>
<view @click="goHotNewGoods(1)" class="more">
更多
<text class="iconfont icon-jiantou"></text>
@ -118,15 +87,8 @@
<view class="newProducts">
<scroll-view scroll-y="false" scroll-x="true">
<view class="newProductsScroll">
<view
@click="goGoodsCon(item)"
class="newProductsItem"
v-for="(item, firstListIndex) in firstList"
:key="firstListIndex"
>
<view class="img-box">
<image :src="item.image" />
</view>
<view @click="goGoodsCon(item)" class="newProductsItem" v-for="(item, firstListIndex) in firstList" :key="firstListIndex">
<view class="img-box"><image :src="item.image" /></view>
<view class="pro-info line1">{{ item.storeName }}</view>
<view class="money font-color-red">{{ item.price }}</view>
</view>
@ -136,9 +98,7 @@
</view>
<view class="wrapper" v-if="benefit.length > 0">
<view class="title acea-row row-between-wrapper">
<view class="text">
<view class="name line1">促销单品</view>
</view>
<view class="text"><view class="name line1">促销单品</view></view>
<view @click="goGoodsPromotion()" class="more">
更多
<text class="iconfont icon-jiantou"></text>
@ -146,28 +106,23 @@
</view>
</view>
<PromotionGood :benefit="benefit"></PromotionGood>
<Coupon-window
:coupon-list="couponList"
v-if="showCoupon"
@checked="couponClose"
@close="couponClose"
></Coupon-window>
<Coupon-window :coupon-list="couponList" v-if="showCoupon" @checked="couponClose" @close="couponClose"></Coupon-window>
</view>
</template>
<script>
// import { swiper, swiperSlide } from "vue-awesome-swiper";
import GoodList from "@/components/GoodList";
import PromotionGood from "@/components/PromotionGood";
import CouponWindow from "@/components/CouponWindow";
import { getHomeData, getShare } from "@/api/public";
import cookie from "@/utils/store/cookie";
import { isWeixin } from "@/utils/index";
import GoodList from '@/components/GoodList';
import PromotionGood from '@/components/PromotionGood';
import CouponWindow from '@/components/CouponWindow';
import { getHomeData, getShare } from '@/api/public';
import cookie from '@/utils/store/cookie';
import { isWeixin } from '@/utils/index';
const HAS_COUPON_WINDOW = "has_coupon_window";
const HAS_COUPON_WINDOW = 'has_coupon_window';
export default {
name: "Index",
name: 'Index',
components: {
// swiper,
// swiperSlide,
@ -179,7 +134,7 @@ export default {
data: function() {
return {
showCoupon: false,
logoUrl: "",
logoUrl: '',
banner: [],
menus: [],
roll: [],
@ -199,7 +154,7 @@ export default {
couponList: [],
swiperOption: {
pagination: {
el: ".swiper-pagination",
el: '.swiper-pagination',
clickable: true
},
autoplay: {
@ -212,7 +167,7 @@ export default {
observeParents: true
},
swiperRoll: {
direction: "vertical",
direction: 'vertical',
autoplay: {
disableOnInteraction: false,
delay: 2000
@ -225,13 +180,13 @@ export default {
swiperScroll: {
freeMode: true,
freeModeMomentum: false,
slidesPerView: "auto",
slidesPerView: 'auto',
observer: true,
observeParents: true
},
swiperBoutique: {
pagination: {
el: ".swiper-pagination",
el: '.swiper-pagination',
clickable: true
},
autoplay: {
@ -246,7 +201,7 @@ export default {
swiperProducts: {
freeMode: true,
freeModeMomentum: false,
slidesPerView: "auto",
slidesPerView: 'auto',
observer: true,
observeParents: true
}
@ -255,49 +210,50 @@ export default {
onShow: function() {
let that = this;
uni.showLoading({
title:'加载中'
})
title: '加载中'
});
getHomeData().then(res => {
console.log(res);
that.logoUrl = res.data.logoUrl;
that.$set(that, "banner", res.data.banner);
that.$set(that, "menus", res.data.menus);
that.$set(that, "roll", res.data.roll);
that.$set(that, "activity", res.data.activity);
that.$set(that, 'banner', res.data.banner);
that.$set(that, 'menus', res.data.menus);
that.$set(that, 'roll', res.data.roll);
that.$set(that, 'activity', res.data.activity);
var activityOne = res.data.activity.shift();
that.$set(that, "activityOne", activityOne);
that.$set(that, "info", res.data.info);
that.$set(that, "firstList", res.data.firstList);
that.$set(that, "bastList", res.data.bastList);
that.$set(that, "likeInfo", res.data.likeInfo);
that.$set(that, "lovely", res.data.lovely);
that.$set(that, "benefit", res.data.benefit);
that.$set(that, "couponList", res.data.couponList);
uni.hideLoading()
that.$set(that, 'activityOne', activityOne);
that.$set(that, 'info', res.data.info);
that.$set(that, 'firstList', res.data.firstList);
that.$set(that, 'bastList', res.data.bastList);
that.$set(that, 'likeInfo', res.data.likeInfo);
that.$set(that, 'lovely', res.data.lovely);
that.$set(that, 'benefit', res.data.benefit);
that.$set(that, 'couponList', res.data.couponList);
uni.hideLoading();
that.setOpenShare();
});
},
methods: {
goGoodSearch() {
this.$yrouter.push("/pages/shop/GoodSearch/index");
this.$yrouter.push('/pages/shop/GoodSearch/index');
},
goWxappUrl(item) {
this.$yrouter.push(item.uniapp_url);
},
goHotNewGoods(type) {
this.$yrouter.push({
path: "/pages/shop/HotNewGoods/index",
path: '/pages/shop/HotNewGoods/index',
query: { type }
});
},
goGoodsCon(item) {
console.log(item)
console.log(item);
this.$yrouter.push({
path: "/pages/shop/GoodsCon/index",
path: '/pages/shop/GoodsCon/index',
query: { id: item.id }
});
},
goGoodsPromotion() {
this.$yrouter.push("/pages/shop/GoodsPromotion/index");
this.$yrouter.push('/pages/shop/GoodsPromotion/index');
},
setOpenShare: function() {}
}

168
pages/shop/ShoppingCart/index.vue

@ -3,13 +3,16 @@
<view class v-if="userInfo.uid">
<view class="labelNav acea-row row-around row-middle">
<view class="item">
<text class="iconfont icon-xuanzhong"></text>100%正品保证
<text class="iconfont icon-xuanzhong"></text>
100%正品保证
</view>
<view class="item">
<text class="iconfont icon-xuanzhong"></text>所有商品精挑细选
<text class="iconfont icon-xuanzhong"></text>
所有商品精挑细选
</view>
<view class="item">
<text class="iconfont icon-xuanzhong"></text>售后无忧
<text class="iconfont icon-xuanzhong"></text>
售后无忧
</view>
</view>
<view class="nav acea-row row-between-wrapper">
@ -17,25 +20,15 @@
购物数量
<text class="num font-color-red">{{ count }}</text>
</view>
<view
v-if="cartList.valid.length > 0"
class="administrate acea-row row-center-wrapper"
@click="manage"
>{{ footerswitch ? "取消" : "管理" }}</view>
<view v-if="cartList.valid.length > 0" class="administrate acea-row row-center-wrapper" @click="manage">{{ footerswitch ? '取消' : '管理' }}</view>
</view>
<view v-if="validList.length > 0 || cartList.invalid.length > 0">
<view class="list">
<view
class="item acea-row row-between-wrapper"
v-for="(item, cartListValidIndex) in validList"
:key="cartListValidIndex"
>
<view class="item acea-row row-between-wrapper" v-for="(item, cartListValidIndex) in validList" :key="cartListValidIndex">
<view class="select-btn">
<view class="checkbox-wrapper">
<checkbox-group @change="switchSelect(cartListValidIndex)">
<label class="well-check">
<checkbox value :checked="item.checked"></checkbox>
</label>
<label class="well-check"><checkbox value :checked="item.checked"></checkbox></label>
</checkbox-group>
</view>
</view>
@ -46,31 +39,28 @@
</view>
<view class="text">
<view class="line1">{{ item.productInfo.storeName }}</view>
<view
class="infor line1"
v-if="item.productInfo.attrInfo"
>属性{{ item.productInfo.attrInfo.suk }}</view>
<view class="infor line1" v-if="item.productInfo.attrInfo">属性{{ item.productInfo.attrInfo.suk }}</view>
<view class="money">{{ item.truePrice }}</view>
</view>
<view class="carnum acea-row row-center-wrapper">
<view
class="reduce"
:class="validList[cartListValidIndex].cartNum <= 1 ? 'on' : ''"
@click.prevent="reduce(cartListValidIndex)"
>-</view>
<view class="reduce" :class="validList[cartListValidIndex].cartNum <= 1 ? 'on' : ''" @click.prevent="reduce(cartListValidIndex)">-</view>
<view class="num">{{ item.cartNum }}</view>
<view
class="plus"
v-if="validList[cartListValidIndex].attrInfo"
:class="validList[cartListValidIndex].cartNum >=validList[cartListValidIndex].attrInfo.stock? 'on': ''"
:class="validList[cartListValidIndex].cartNum >= validList[cartListValidIndex].attrInfo.stock ? 'on' : ''"
@click.prevent="plus(cartListValidIndex)"
>+</view>
>
+
</view>
<view
class="plus"
v-else
:class="validList[cartListValidIndex].cartNum >= validList[cartListValidIndex].stock? 'on': ''"
:class="validList[cartListValidIndex].cartNum >= validList[cartListValidIndex].stock ? 'on' : ''"
@click.prevent="plus(cartListValidIndex)"
>+</view>
>
+
</view>
</view>
</view>
</view>
@ -78,25 +68,17 @@
<view class="invalidGoods" v-if="cartList.invalid.length > 0">
<view class="goodsNav acea-row row-between-wrapper">
<view @click="goodsOpen">
<text
class="iconfont"
:class="goodsHidden === true ? 'icon-xiangyou' : 'icon-xiangxia'"
></text>失效商品
<text class="iconfont" :class="goodsHidden === true ? 'icon-xiangyou' : 'icon-xiangxia'"></text>
失效商品
</view>
<view class="del" @click="delInvalidGoods">
<text class="iconfont icon-shanchu1"></text>清空
<text class="iconfont icon-shanchu1"></text>
清空
</view>
</view>
<view class="goodsList" :hidden="goodsHidden">
<view
v-for="(item, cartListinvalidIndex) in cartList.invalid"
:key="cartListinvalidIndex"
>
<view
@click="goGoodsCon(item)"
class="item acea-row row-between-wrapper"
v-if="item.productInfo"
>
<view v-for="(item, cartListinvalidIndex) in cartList.invalid" :key="cartListinvalidIndex">
<view @click="goGoodsCon(item)" class="item acea-row row-between-wrapper" v-if="item.productInfo">
<view class="invalid acea-row row-center-wrapper">失效</view>
<view class="pictrue">
<image :src="item.productInfo.attrInfo.image" v-if="item.productInfo.attrInfo" />
@ -104,13 +86,8 @@
</view>
<view class="text acea-row row-column-between">
<view class="line1">{{ item.productInfo.storeName }}</view>
<view
class="infor line1"
v-if="item.productInfo.attrInfo"
>属性{{ item.productInfo.attrInfo.suk }}</view>
<view class="acea-row row-between-wrapper">
<view class="end">该商品已下架</view>
</view>
<view class="infor line1" v-if="item.productInfo.attrInfo">属性{{ item.productInfo.attrInfo.suk }}</view>
<view class="acea-row row-between-wrapper"><view class="end">该商品已下架</view></view>
</view>
</view>
</view>
@ -119,9 +96,7 @@
</view>
<!--购物车暂无商品-->
<view class="noCart" v-if="cartList.valid.length === 0 && cartList.invalid.length === 0">
<view class="pictrue">
<image :src="$VUE_APP_RESOURCES_URL+'/images/noCart.png'" />
</view>
<view class="pictrue"><image :src="$VUE_APP_RESOURCES_URL + '/images/noCart.png'" /></view>
<Recommend></Recommend>
</view>
<view style="height:210rpx"></view>
@ -164,24 +139,19 @@
</view>
</template>
<script>
import Recommend from "@/components/Recommend";
import Authorization from "@/pages/authorization/index";
import { mapGetters } from "vuex";
import Recommend from '@/components/Recommend';
import Authorization from '@/pages/authorization/index';
import { mapGetters } from 'vuex';
import {
getCartList,
postCartDel,
changeCartNum,
getCartCount
} from "@/api/store";
import { postCollectAll } from "@/api/user";
import { mul, add } from "@/utils/bc";
import cookie from "@/utils/store/cookie";
import { getCartList, postCartDel, changeCartNum, getCartCount } from '@/api/store';
import { postCollectAll } from '@/api/user';
import { mul, add } from '@/utils/bc';
import cookie from '@/utils/store/cookie';
const CHECKED_IDS = "cart_checked";
const CHECKED_IDS = 'cart_checked';
export default {
name: "ShoppingCart",
name: 'ShoppingCart',
components: {
Recommend,
Authorization
@ -204,7 +174,7 @@ export default {
loaded: false
};
},
computed: mapGetters(["userInfo"]),
computed: mapGetters(['userInfo', 'token']),
// watch: {
// $yroute(n) {
@ -223,7 +193,7 @@ export default {
// },
watch: {
userInfo(user) {
console.log(user);
console.log(user, '用户信息,8585');
if (user.uid) {
this.carnum();
this.countMoney();
@ -231,6 +201,15 @@ export default {
this.gainCount();
}
},
token(token) {
console.log(token, '用户token,8585');
if (this.userInfo.uid) {
this.carnum();
this.countMoney();
this.getCartList();
this.gainCount();
}
},
cartList(list) {
this.validList = list.valid;
}
@ -246,7 +225,7 @@ export default {
methods: {
goGoodsCon(item) {
this.$yrouter.push({
path: "/pages/shop/GoodsCon/index",
path: '/pages/shop/GoodsCon/index',
query: {
id: item.productId
}
@ -283,18 +262,17 @@ export default {
});
if (id.length === 0) {
uni.showToast({
title: "请选择产品",
icon: "none",
title: '请选择产品',
icon: 'none',
duration: 2000
});
return;
}
postCartDel(id).then(function() {
list.forEach(function(val, i) {
if (val.checked === false || val.checked === undefined)
valid.push(list[i]);
if (val.checked === false || val.checked === undefined) valid.push(list[i]);
});
that.$set(that.cartList, "valid", valid);
that.$set(that.cartList, 'valid', valid);
that.carnum();
that.countMoney();
that.gainCount();
@ -327,7 +305,7 @@ export default {
let that = this,
data = {
id: [],
category: ""
category: ''
},
list = that.cartList.valid;
list.forEach(function(val) {
@ -338,16 +316,16 @@ export default {
});
if (data.id.length === 0) {
uni.showToast({
title: "请选择产品",
icon: "none",
title: '请选择产品',
icon: 'none',
duration: 2000
});
return;
}
postCollectAll(data).then(function() {
uni.showToast({
title: "收藏成功!",
icon: "none",
title: '收藏成功!',
icon: 'none',
duration: 2000
});
});
@ -364,17 +342,17 @@ export default {
});
if (id.length === 0) {
uni.showToast({
title: "请选择产品",
icon: "none",
title: '请选择产品',
icon: 'none',
duration: 2000
});
return;
}
console.log(id);
this.$yrouter.push({
path: "/pages/order/OrderSubmission/index",
path: '/pages/order/OrderSubmission/index',
query: {
id: id.join(",")
id: id.join(',')
}
});
},
@ -393,11 +371,11 @@ export default {
list.cartNum++;
if (list.attrInfo) {
if (list.cartNum >= list.attrInfo.stock) {
that.$set(list, "cart_num", list.attrInfo.stock);
that.$set(list, 'cart_num', list.attrInfo.stock);
}
} else {
if (list.cartNum >= list.stock) {
that.$set(list, "cart_num", list.stock);
that.$set(list, 'cart_num', list.stock);
}
}
that.carnum();
@ -410,15 +388,15 @@ export default {
let list = that.cartList.valid[index];
if (list.cartNum <= 1) {
uni.showToast({
title: "已经是底线啦!",
icon: "none",
title: '已经是底线啦!',
icon: 'none',
duration: 2000
});
return;
}
list.cartNum--;
if (list.cartNum < 1) {
that.$set(list, "cart_num", 1);
that.$set(list, 'cart_num', 1);
}
that.carnum();
that.countMoney();
@ -433,7 +411,7 @@ export default {
.catch(error => {
uni.showToast({
title: error.response.data.msg,
icon: "none",
icon: 'none',
duration: 2000
});
});
@ -458,8 +436,8 @@ export default {
}
}
that.isAllSelect = selectnum.length === len;
that.$set(that, "cartList", that.cartList);
that.$set(that, "isAllSelect", that.isAllSelect);
that.$set(that, 'cartList', that.cartList);
that.$set(that, 'isAllSelect', that.isAllSelect);
cookie.set(CHECKED_IDS, that.checkedIds);
that.carnum();
that.countMoney();
@ -485,8 +463,8 @@ export default {
};
that.cartList = [];
that.cartList = cartList;
this.$set(this, "cartList", this.cartList);
this.$set(this, "isAllSelect", selectAllStatus);
this.$set(this, 'cartList', this.cartList);
this.$set(this, 'isAllSelect', selectAllStatus);
this.checkedIds = checkedIds;
cookie.set(CHECKED_IDS, checkedIds);
that.carnum();
@ -503,7 +481,7 @@ export default {
carnum += parseInt(array[i].cartNum);
}
}
that.$set(that, "cartCount", carnum);
that.$set(that, 'cartCount', carnum);
},
//
countMoney: function() {

35
store/index.js

@ -5,7 +5,9 @@ Vue.use(Vuex);
const debug = process.env.NODE_ENV !== "production";
import store from "@/utils/store/cookie";
import { getUserInfo } from "@/api/user";
import {
getUserInfo
} from "@/api/user";
import dialog from "@/utils/dialog";
const LOGIN_KEY = "login_status";
@ -17,7 +19,8 @@ const vuexStore = new Vuex.Store({
// 是否授权
isAuthorization: false,
token: store.get(LOGIN_KEY) || null,
userInfo: store.get('userInfo')
userInfo: store.get('userInfo'),
$deviceType: null,
},
mutations: {
SHOW_FOOTER(state) {
@ -63,9 +66,15 @@ const vuexStore = new Vuex.Store({
UPDATE_AUTHORIZATION(state, isAuthorization) {
state.isAuthorization = isAuthorization;
},
UPDATE_DEVICETYPE(state, $deviceType) {
state.$deviceType = $deviceType;
},
},
actions: {
USERINFO({ state, commit }, force) {
USERINFO({
state,
commit
}, force) {
if (state.userInfo !== null && !force)
return Promise.resolve(state.userInfo);
else
@ -78,10 +87,16 @@ const vuexStore = new Vuex.Store({
dialog.error("获取信息失败!");
});
},
changeLogin({ state, commit }, data, date) {
changeLogin({
state,
commit
}, data, date) {
commit("LOGIN", data, date);
},
setUserInfo({ state, commit }, user) {
setUserInfo({
state,
commit
}, user) {
commit("UPDATE_USERINFO", user);
if (user) {
store.set('userInfo', user)
@ -89,10 +104,16 @@ const vuexStore = new Vuex.Store({
store.set('userInfo', null)
}
},
changeAuthorizationPage({ state, commit }, index) {
changeAuthorizationPage({
state,
commit
}, index) {
commit("UPDATE_AUTHORIZATIONPAGE", index);
},
changeAuthorization({ state, commit }, index) {
changeAuthorization({
state,
commit
}, index) {
commit("UPDATE_AUTHORIZATION", index);
},
},

1
utils/index.js

@ -117,7 +117,6 @@ export const replaceLogin = (msg) => {
icon: 'none',
duration: 2000
});
console.log(Vue.prototype.$deviceType)
// 这里代表已经失去登录状态以及401强制推出登录了
store.commit('LOGOUT')
console.log(uni, 989)

2
utils/request.js

@ -45,7 +45,7 @@ function baseRequest(options) {
...option
}).then(res => {
console.log(res)
console.log(url,params,data, ...option)
// console.log(url,params,data, ...option)
const data = res.data || {};
if (res.status !== 200)
return Promise.reject({ msg: "请求失败", res, data });

Loading…
Cancel
Save