Commit 465520c3 by zhangcheng

调整购物车

parent 7b2e7c08
<template> <template>
<u-popup :show="false" mode="bottom" :round="10" :overlay="true" :safeAreaInsetBottom="true" @close="showShopCar=false"> <view>
<u-popup :show="showShopCar && goods.length" mode="bottom" :round="10" :overlay="true" :closeOnClickOverlay="true">
<view class="shop-car"> <view class="shop-car">
<view class="header"> <view class="header">
<text class="left">购物袋</text> <text class="left">购物袋</text>
<text class="right" @click="clearCar"><u-icon name="trash" color="#2979ff" size="28"></u-icon>清空购物车</text> <text class="right" @click="clearCar">清空购物车</text>
</view> </view>
<view class="container"> <view class="container">
<view> <view>
...@@ -21,22 +22,28 @@ ...@@ -21,22 +22,28 @@
<u-checkbox shape="circle" class="selected" color="#555555" :checked="item.flag"/><text></text> <u-checkbox shape="circle" class="selected" color="#555555" :checked="item.flag"/><text></text>
</label> </label>
</u-checkbox-group> </u-checkbox-group>
<image :src="item.thumbnail" style="width: 150rpx;height: 140rpx;"></image> <image :src="item.pics.thumbnailApplet || item.pics.thumbnail" style="width: 150rpx;height: 140rpx;"></image>
</view> </view>
<view class="size"> <view class="size">
<text style="font-size: 28rpx;color: #000000;">{{item.name}}</text> <text style="font-size: 28rpx;color: #000000;">{{item.name}}</text>
<text style="font-size:20rpx;color:#666666"><text v-for="(rl,index) in item.rules" :key="rl.ruleName">{{rl.ruleName}}<text v-if="index!=item.rules.length-1">/</text></text></text> <text style="font-size:20rpx;color:#666666"><text v-for="(rl,index) in item.skus[0].rules" :key="rl.ruleName">{{rl.ruleName}}<text v-if="index!=item.skus.rules.length-1">/</text></text></text>
<text><text class="goods-price">{{item.discount}}</text><text style="color: #666666; font-size:20rpx;text-decoration:line-through; margin-left:10rpx">{{item.price}}</text></text> <text><text class="goods-price">{{item.discount}}</text><text class="price-x"></text><text class="price-xx">{{item.price}}</text></text>
</view> </view>
</view> </view>
<view class="detail-right"> <view class="detail-right">
<text class="subtract" @click="reduce(item)">-</text> <text class="subtract" @click="reduce(item,index)">-</text>
<text class="num">{{item.num}}</text> <text class="num">{{item.num}}</text>
<text @click="add(item)" class="add">+</text> <text @click="add(item)" class="add">+</text>
</view> </view>
</view> </view>
</view> </view>
<view class="end"> </view>
</view>
<view style="height:200rpx"></view>
</view>
</u-popup>
<view class="end" v-if="goods.length">
<view class="end-left"> <view class="end-left">
<!-- <checkbox-group @change="selectgoods()"> <!-- <checkbox-group @change="selectgoods()">
<label> <label>
...@@ -44,8 +51,10 @@ ...@@ -44,8 +51,10 @@
</label> </label>
</checkbox-group> --> </checkbox-group> -->
<view style="display:flex"> <view style="display:flex">
<text class="car-img"></text> <view class="car-img" @click.stop="openShopCar">
<text style="color:#000000;font-weight: bold;display: flex; align-items: center;">{{totalPrice.toFixed(2)}}</text> <text class="badge" v-if="totalNum">{{totalNum}}</text>
</view>
<text style="color:#000000;font-weight: bold;font-size: 28rpx;display: flex; margin-left: 30rpx; align-items: center;">{{totalPrice.toFixed(2)}}</text>
</view> </view>
</view> </view>
<view class="end-right"> <view class="end-right">
...@@ -55,12 +64,7 @@ ...@@ -55,12 +64,7 @@
</view> </view>
</view> </view>
</view>
<view style="height:200rpx"></view>
</view>
</u-popup>
</template> </template>
<script> <script>
...@@ -71,11 +75,12 @@ ...@@ -71,11 +75,12 @@
showShopCar:false,//是否弹出购物车列表 showShopCar:false,//是否弹出购物车列表
show:true, show:true,
allchecked:true, allchecked:true,
// checked:true, // checked:true,
goods:[],//购物车商品信息 goods:[],//购物车商品信息
} }
}, },
created() { created() {
$EventBus.$off('updateCar');
// this.getallNum(); // this.getallNum();
}, },
mounted() { mounted() {
...@@ -126,6 +131,13 @@ ...@@ -126,6 +131,13 @@
// uni.setStorageSync('shopCarInfo',shopCarInfo) // uni.setStorageSync('shopCarInfo',shopCarInfo)
// this.goods=uni.getStorageSync('shopCarInfo'); // this.goods=uni.getStorageSync('shopCarInfo');
// }, // },
// 切换购物车列表显示隐藏
openShopCar() {
this.$nextTick(()=>{
this.showShopCar = !this.showShopCar;
})
},
clearCar() { clearCar() {
uni.removeStorageSync('shopCarInfo'); uni.removeStorageSync('shopCarInfo');
$EventBus.$emit('updateCar'); $EventBus.$emit('updateCar');
...@@ -167,17 +179,11 @@ ...@@ -167,17 +179,11 @@
} }
uni.setStorageSync('shopCarInfo',this.goods); uni.setStorageSync('shopCarInfo',this.goods);
}, },
reduce(item){ reduce(item,index){
let num=item.num item.num-=1
if(num>1){ if(item.num==0){
num-=1 this.goods.splice(index,1);
}else if(num=1){ }
uni.showToast({
title:"该宝贝不能减少了哟~"
})
return;
}
item.num=num
uni.setStorageSync('shopCarInfo',this.goods); uni.setStorageSync('shopCarInfo',this.goods);
}, },
add(item){ add(item){
...@@ -211,23 +217,31 @@ ...@@ -211,23 +217,31 @@
.shop-car { .shop-car {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 40vh; height: 860rpx;
.header{ .header{
height: 100rpx; height: 88rpx;
display: flex; display: flex;
border-bottom:1rpx solid #ccc; border-bottom:1rpx solid rgb(235,235,235);
.left{ .left{
flex: 1; flex: 1;
display: flex; display: flex;
align-items: center; align-items: center;
padding-left: 40rpx; padding-left: 40rpx;
font-size: 28rpx;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
color: #000000;
} }
.right{ .right{
flex: 1; flex: 1;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: right; justify-content: flex-end;
padding-right: 40rpx; padding-right: 40rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
} }
} }
.container{ .container{
...@@ -243,7 +257,6 @@ ...@@ -243,7 +257,6 @@
padding: 30rpx 15rpx 30rpx 30rpx; padding: 30rpx 15rpx 30rpx 30rpx;
background-color: #fff; background-color: #fff;
justify-content: space-between; justify-content: space-between;
border-bottom: 5rpx solid #F1F1F1;
align-items: center; align-items: center;
.detail-left{ .detail-left{
display: flex; display: flex;
...@@ -259,9 +272,21 @@ ...@@ -259,9 +272,21 @@
margin-left: 30rpx; margin-left: 30rpx;
.goods-price{ .goods-price{
font-size: 24rpx; font-size: 24rpx;
color: #F44545; font-family: Arial-BoldMT, Arial;
font-weight: normal;
color: #FF5200;
} }
.price-x{
margin-left:6rpx;
font-size:20rpx;
font-family: ArialMT;
line-height: 22rpx;
color: #666666;
}
.price-xx{
font-size:20rpx;
text-decoration:line-through;
}
} }
.detail-right{ .detail-right{
text{ text{
...@@ -281,7 +306,7 @@ ...@@ -281,7 +306,7 @@
.subtract{ .subtract{
border:1rpx solid #006ECF; border:1rpx solid #006ECF;
border-radius: 40rpx; border-radius: 40rpx;
color:red; color:#006ECF;
} }
} }
} }
...@@ -310,12 +335,13 @@ ...@@ -310,12 +335,13 @@
} }
.end{ .end{
width: 100%; width: 100%;
height: 90rpx; height: 92rpx;
background-color:#fff; background-color:#fff;
position: fixed; position: fixed;
bottom: 100rpx; bottom: 50px;
left: 0; left: 0;
display: flex; display: flex;
z-index: 10075;
align-items: center; align-items: center;
&-left{ &-left{
width: 70%; width: 70%;
...@@ -330,7 +356,26 @@ ...@@ -330,7 +356,26 @@
width:40rpx; width:40rpx;
height: 48rpx; height: 48rpx;
display: inline-block; display: inline-block;
background: #006ECF; border:1px solid #006ECF;
position: relative;
.badge{
position: absolute;
height: 24rpx;
background: #006ECF;
right:-16rpx;
top: -12rpx;
min-width: 24rpx;
font-size: 16rpx;
font-family: Arial-BoldMT, Arial;
font-weight: normal;
color: #FFFFFF;
line-height: 18rpx;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
}
} }
} }
&-right{ &-right{
......
<template> <template>
<!-- Tab --> <!-- Tab -->
<u-tabbar zIndex="10075" v-model="selectedTabbar" :border="false" inactive-color="#000000" active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch"> <u-tabbar zIndex="10075" v-model="selectedTabbar" :border="false" inactive-color="#000000" height="50" active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch">
<u-tabbar-item v-for="(item,index) in list" :key="item.text" :text="item.text" :icon="selectedTabbar==index?item.activeIcon:item.icon"></u-tabbar-item> <u-tabbar-item v-for="(item,index) in list" :key="item.text" :text="item.text" :icon="selectedTabbar==index?item.activeIcon:item.icon"></u-tabbar-item>
</u-tabbar> </u-tabbar>
</template> </template>
......
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
...@@ -50,6 +50,15 @@ ...@@ -50,6 +50,15 @@
} }
} }
,{
"path" : "areaSelect/areaSelect",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
] ]
}, },
{ {
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
<view class="menu-banner"> <view class="menu-banner">
<image src="../../static/imgs/banner.png"></image> <image src="../../static/imgs/banner.png"></image>
<view class="shop-info" :style="{top: `${menuINfo.top}px`}"> <view class="shop-info" :style="{top: `${menuINfo.top}px`}">
<view class="shop-box" :style="{height: `${menuINfo.height}px`,'line-height': `${menuINfo.height}px`}" @click="getLocation"> <view class="shop-box" :style="{height: `${menuINfo.height}px`,'line-height': `${menuINfo.height}px`}">
<text class="shop-name">北京国贸银泰中心店</text> <text class="shop-name">{{shopInfo.name}}</text>
<u-icon name="arrow-right" class="arrow-right-select" color="#FFFFFF"></u-icon> <u-icon name="arrow-right" class="arrow-right-select" color="#FFFFFF"></u-icon>
</view> </view>
<view class="distance">距您130m</view> <view class="distance">距您130m</view>
...@@ -13,14 +13,15 @@ ...@@ -13,14 +13,15 @@
<view class="login-area"> <view class="login-area">
<view class="avatar"><image :src="'../../static/logo.png'"></image></view> <view class="avatar"><image :src="'../../static/logo.png'"></image></view>
<view class="user-info"> <view class="user-info">
<view class="user-name" v-if="userms">HI!{{userms.nickName}}</view> <view class="user-name" v-if="userms">HI!{{'我是谁'}}</view>
<view class="user-name" v-else>未登录</view> <view class="user-name" v-else>未登录</view>
<view class="dialog"> <view class="dialog">
<view class="content" v-if="userms">希望你今天,明天,天天都开心~</view> <view class="content" v-if="userms">希望你今天,明天,天天都开心~</view>
<view class="content" v-if="!userms">请您尽快登录</view> <view class="content" v-if="!userms">请您尽快登录</view>
</view> </view>
</view> </view>
<view class="login-btn" v-if="!userms" @click="uniGetUserInfo">立刻登录</view> <!-- <view class="login-btn" v-if="!userms" @click="uniGetUserInfo">立刻登录</view> -->
<button class="login-btn" v-if="!userms" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立刻登录</button>
</view> </view>
</view> </view>
<view class="order-banner" v-if="buied"> <view class="order-banner" v-if="buied">
...@@ -62,7 +63,7 @@ ...@@ -62,7 +63,7 @@
</view> </view>
<view class="dis-box"> <view class="dis-box">
<view class="dis">{{item.desc}}</view> <view class="dis">{{item.desc}}</view>
<view class="add-btn" @click="getallNum(item)">+</view> <view class="add-btn" @click.stop="getallNum(item)">+</view>
</view> </view>
<view class="mon"> <view class="mon">
<view class="discount">{{item.discount}}</view> <view class="discount">{{item.discount}}</view>
...@@ -83,9 +84,11 @@ import User from '@/request/user' ...@@ -83,9 +84,11 @@ import User from '@/request/user'
import ShopCar from '../../components/shopCar/shopCar.vue' import ShopCar from '../../components/shopCar/shopCar.vue'
import Utils from '@/utils/utils' import Utils from '@/utils/utils'
import Menu from '@/request/menu' import Menu from '@/request/menu'
import { $EventBus } from '@/utils/EventBus';
export default { export default {
data() { data() {
return { return {
shopInfo:{name:'请选择'},// 店铺信息
menuINfo:{}, menuINfo:{},
buied: true, buied: true,
orderBannerh: 0, orderBannerh: 0,
...@@ -107,11 +110,12 @@ import Menu from '@/request/menu' ...@@ -107,11 +110,12 @@ import Menu from '@/request/menu'
}, },
computed: { computed: {
userms() { userms() {
let res = uni.getStorageSync("userInfo").userInfo; let res = uni.getStorageSync("Authorization");
return res; return res;
} }
}, },
created() { created() {
this.getLocation();
this.menuINfo = uni.getMenuButtonBoundingClientRect(); this.menuINfo = uni.getMenuButtonBoundingClientRect();
console.log(this.menuINfo,77766) console.log(this.menuINfo,77766)
//如果你的分类数据为后台异步获取请 将下方代码放置你的数据回调中 //如果你的分类数据为后台异步获取请 将下方代码放置你的数据回调中
...@@ -122,7 +126,7 @@ import Menu from '@/request/menu' ...@@ -122,7 +126,7 @@ import Menu from '@/request/menu'
async onShow() { async onShow() {
console.log(1243) console.log(1243)
// 获取首页菜单数据 // 获取首页菜单数据
await this.getMenuList(); await this.getMenuList(6);
let _this = this; let _this = this;
uni.createSelectorQuery() uni.createSelectorQuery()
.select(".menu-banner") .select(".menu-banner")
...@@ -142,8 +146,14 @@ import Menu from '@/request/menu' ...@@ -142,8 +146,14 @@ import Menu from '@/request/menu'
} }
this.getHeightList(); this.getHeightList();
}, },
onLoad: function () { onLoad: async function () {
$EventBus.$off('getMenuList')
$EventBus.$on('getMenuList',(data)=>{
this.shopInfo=data;
console.log(data,554433)
this.getMenuList(data.id)
})
}, },
onReady() { onReady() {
...@@ -153,19 +163,69 @@ import Menu from '@/request/menu' ...@@ -153,19 +163,69 @@ import Menu from '@/request/menu'
uniGetUserInfo() { uniGetUserInfo() {
User.uniGetUserInfo(); User.uniGetUserInfo();
}, },
getPhoneNumber(e) {
// uni.exitMiniProgram({success: (res) => {}})
if(e.detail.errMsg=='getPhoneNumber:ok'){
User.getPhoneNumber(e);
}else if( e.detail.errMsg=="getPhoneNumber:fail user deny"){
uni.showToast({title:'已拒绝手机号授权',icon:'error'})
}
// console.log(e,333)
},
getLocation() { getLocation() {
uni.authorize({ let _this = this;
scope:'scope.userLocation', uni.getSetting({
success(res) { success: (res) => {
console.log(res) if (!res.authSetting['scope.userLocation']) {
User.getLocation(); uni.authorize({
} scope: 'scope.userLocation',
}) success: (e) => { //1.1 允许授权
console.log(e,11111)
User.getLocation();
},
fail:(err)=> { //1.2 拒绝授权
console.log(err,'拒绝')
uni.showModal({
title:'提示',
content:'您已拒绝授权定位,请重新开启',
confirmText:'去开启',
success() {
uni.openSetting({
success(res) {
console.log(res,8877)
if(res.authSetting['scope.userLocation']==true){
User.getLocation();
}
// 如果不设置,res结果:
// {errMsg: "openSetting:ok", authSetting: {scope.userLocation: false}}
// 如果设置, res结果:
// {errMsg: "openSetting:ok", authSetting: {scope.userLocation: true}}
// console.log('小程序设置界面:', res)
}})
}
})
}
})
} else {
User.getLocation();
}
}
})
}, },
async getMenuList() { async getMenuList(id) {
let res = await Menu.getMenuList(); let res = await Menu.getMenuList(id);
if(res.data.code ==200){ if(res.data.code ==200){
res.data.data = JSON.parse(JSON.stringify(res.data.data)); res.data.data.categorys.forEach(y=>{
y.goods.forEach(v=>{
v.specs=JSON.parse(v.specs);
v.skus.forEach(u=>{u.rules=JSON.parse(u.rules)})
})
})
res.data.data = res.data.data;
console.log(res.data.data,87654567) console.log(res.data.data,87654567)
this.$store.commit('setMenuAllInfo',res.data.data); this.$store.commit('setMenuAllInfo',res.data.data);
this.classifyData = res.data.data.categorys; this.classifyData = res.data.data.categorys;
...@@ -173,21 +233,32 @@ import Menu from '@/request/menu' ...@@ -173,21 +233,32 @@ import Menu from '@/request/menu'
}, },
// 加入购物车数据 // 加入购物车数据
getallNum(item) { getallNum(item) {
let itemCopy = JSON.parse(JSON.stringify(item));
console.log(this.classifyData,998877) console.log(this.classifyData,998877)
console.log(item,333) itemCopy.skus = [itemCopy.skus.find(v=>v.state!=2)];
let reItem =[ if(!itemCopy.skus){
{ uni.showToast({title:'本商品已经售罄',icon:'none'});
goodsId: item.goodsId, return;
name: item.name, }else{
price: item.price,
discount: item.discount, itemCopy.num=1;
flag:true, itemCopy.flag=true;
thumbnail:'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg', console.log(itemCopy,'mmmmmmm')
num:1, Utils.getallNum(itemCopy);
rules:item.skus[0].rules }
} // let reItem =[
] // {
Utils.getallNum(reItem); // goodsId: item.goodsId,
// name: item.name,
// price: item.price,
// discount: item.discount,
// flag:true,
// thumbnail:'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg',
// num:1,
// rules:JSON.parse(item.skus[0].rules)//这里还要查看是否售罄,如果售罄则取下一个临近的sku
// }
// ]
}, },
getHeightList() { getHeightList() {
let _this = this; let _this = this;
...@@ -354,7 +425,7 @@ import Menu from '@/request/menu' ...@@ -354,7 +425,7 @@ import Menu from '@/request/menu'
} }
} }
.login-btn{ .login-btn{
width: 114rpx; // width: 114rpx;
height: 48rpx; height: 48rpx;
background: #006ECF; background: #006ECF;
border-radius: 4rpx; border-radius: 4rpx;
......
...@@ -3,12 +3,12 @@ export default { ...@@ -3,12 +3,12 @@ export default {
getMenuList(id) { getMenuList(id) {
return uni.$u.http.get('/weixin/infoByShop', { return uni.$u.http.get('/weixin/infoByShop', {
params:{ params:{
shopId:"6" shopId: id
} }
}).then(res => { }).then(res => {
return res; return res;
}).catch(err => { }).catch(err => {
uni.showToast({title:'服务器错误',icon:'none'})
}) })
}, },
// 下单获取预支付订单 // 下单获取预支付订单
......
import Store from '@/store' import Store from '@/store'
import { $EventBus } from '../../utils/EventBus';
export default{ export default{
getLocation() { getLocation() {
uni.getLocation({ let _this = this;
return uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度 type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) { success: function (res) {
console.log(res, 'res') console.log(res, 'res')
...@@ -9,12 +11,52 @@ export default{ ...@@ -9,12 +11,52 @@ export default{
lat: res.latitude, lat: res.latitude,
lng: res.longitude lng: res.longitude
} }
// getAddress(params).then(res => { Store.commit('saveLocation',params);
// console.log(res, 'aaa') // return params;
// }) _this.getAddress(params);
},
fail: function (res) {
console.log(res,3333)
uni.showToast({
title: '获取地址失败,将导致部分功能不可用',
icon: 'none'
});
} }
}) })
}, },
// 获取具体位置店铺/weixin/getShop
getAddress(params) {
return uni.$u.http.get('/weixin/getShop',{
params
}).then((res)=>{
if(res.data.code==200){
console.log(res.data.data,12345678)
Store.commit('saveShopInfo', res.data.data);
if (res.data.data.length){
$EventBus.$emit('getMenuList', res.data.data[0])
}
}
return res;
}).catch(err=>{
return err;
});
},
// 通过地址选择店铺xxxx
// getAddress(params) {
// return uni.$u.http.get('/weixin/getShop', {
// params
// }).then((res) => {
// if (res.data.code == 200) {
// console.log(res.data.data, 12345678)
// Store.commit('saveShopInfo', res.data.data);
// }
// return res;
// }).catch(err => {
// return err;
// });
// },
uniLogin(res) { uniLogin(res) {
uni.login({ uni.login({
provider: 'weixin', provider: 'weixin',
...@@ -27,7 +69,6 @@ export default{ ...@@ -27,7 +69,6 @@ export default{
encryptedData: res.encryptedData encryptedData: res.encryptedData
}).then((response) => { }).then((response) => {
if (response.statusCode == 200 && response.data && response.data.code==200) { if (response.statusCode == 200 && response.data && response.data.code==200) {
console.log(response.data.token,54443)
uni.setStorage({key:'Authorization',data:response.data.token}); uni.setStorage({key:'Authorization',data:response.data.token});
Store.commit('setAuthorization', response.data.token); Store.commit('setAuthorization', response.data.token);
uni.showToast({ uni.showToast({
...@@ -43,7 +84,16 @@ export default{ ...@@ -43,7 +84,16 @@ export default{
} }
}) })
}, },
// 手机号授权登录
getPhoneNumber(res) {
console.log(res,12321)
uni.setStorage({
key: 'userPhoneInfo',
data: res
})
Store.commit("setUserPhoneInfo", res);
this.uniLogin(res.detail);
},
async uniGetUserInfo(e) { async uniGetUserInfo(e) {
uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息 uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息
lang: "zh_CN", lang: "zh_CN",
...@@ -51,23 +101,8 @@ export default{ ...@@ -51,23 +101,8 @@ export default{
success: res => { success: res => {
uni.setStorage({key:'userInfo', data:res}) uni.setStorage({key:'userInfo', data:res})
Store.commit("setUserInfo",res) Store.commit("setUserInfo",res)
this.uniLogin(res); // this.uniLogin(res);
}
})
},
getLocation() {
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
console.log(res, 'res')
var params = {
lat: res.latitude,
lng: res.longitude
}
getAddress(params).then(res => {
console.log(res, 'aaa')
})
} }
}) })
}, }
} }
\ No newline at end of file
...@@ -3,6 +3,9 @@ const getters = { ...@@ -3,6 +3,9 @@ const getters = {
nickName: state => state.user.userInfo.userInfo.nickName, nickName: state => state.user.userInfo.userInfo.nickName,
Authorization: state => state.user.Authorization, Authorization: state => state.user.Authorization,
menuAllInfo: state => state.menu.menuAllInfo, menuAllInfo: state => state.menu.menuAllInfo,
userPhoneInfo: state => state.user.userPhoneInfo,
location: state => state.user.location,
shopInfo: state => state.user.shopInfo,
} }
export default getters export default getters
\ No newline at end of file
...@@ -3,6 +3,9 @@ const user = { ...@@ -3,6 +3,9 @@ const user = {
state: { state: {
userInfo: null, //授权信息 userInfo: null, //授权信息
Authorization: null, //是否授权 Authorization: null, //是否授权
location:null,//用户经纬度
userPhoneInfo:null,
shopInfo:null//店铺信息
}, },
mutations: { mutations: {
// 设置是否授权 // 设置是否授权
...@@ -10,10 +13,22 @@ const user = { ...@@ -10,10 +13,22 @@ const user = {
console.log(data,665) console.log(data,665)
state.Authorization = data; state.Authorization = data;
}, },
// 设置用户信息 // 设置用户允许昵称头像授权时的信息
setUserInfo(state, userInfo) { setUserInfo(state, userInfo) {
state.userInfo = userInfo; state.userInfo = userInfo;
}, },
// 授权手机号时允许后的信息
setUserPhoneInfo(state, userPhoneInfo) {
state.userPhoneInfo = userPhoneInfo;
},
// 保存经纬度
saveLocation(state, location) {
state.location = location;
},
// 当前店铺信息
saveShopInfo(state, shopInfo) {
state.shopInfo = shopInfo;
}
}, },
actions: { actions: {
......
...@@ -2,94 +2,68 @@ import Config from '../static/config/index.js'; ...@@ -2,94 +2,68 @@ import Config from '../static/config/index.js';
import WXBizDataCrypt from "./WXBizDataCrypt.js"; import WXBizDataCrypt from "./WXBizDataCrypt.js";
import {$EventBus} from './EventBus' import {$EventBus} from './EventBus'
export default{ export default{
getallNum(arrA) { getallNum(Obj){
let arrA1 = [{
"goodsId": 100,
"name": "冰茶咖啡",
"price": 29.9,
"discount": 19.9,
flag: true,
thumbnail: 'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg',
num: 1,
rules: [{
"specId": 1,
"specName": "温度",
"ruleId": 1,
"ruleName": "常温"
},
{
"specId": 2,
"specName": "糖度",
"ruleId": 3,
"ruleName": "无糖"
}
]
},
{
"goodsId": 101,
"name": "冰茶咖啡",
"price": 29.9,
"discount": 19.9,
flag: true,
thumbnail: 'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg',
num: 3,
rules: [{
"specId": 1,
"specName": "温度",
"ruleId": 1,
"ruleName": "常温"
},
{
"specId": 2,
"specName": "糖度",
"ruleId": 3,
"ruleName": "无糖"
}
]
}
]
// arrA = []
let shopCarInfo = uni.getStorageSync('shopCarInfo'); let shopCarInfo = uni.getStorageSync('shopCarInfo');
let shopCarInfoAdd = [] console.log(shopCarInfo,'oooooo')
console.log(shopCarInfo, 55553333) if (shopCarInfo){
if (shopCarInfo) { let currentGoods = shopCarInfo.find(v => v.goodsId == Obj.goodsId && v.skuId == Obj.skuId);
let ids = shopCarInfo.map(v => v.goodsId); if (currentGoods){
console.log(ids, 444) console.log(currentGoods,'pppppp')
shopCarInfo.forEach((item) => { currentGoods.num+=1;
arrA.forEach((preItem, index) => { }else{
console.log(ids.includes(preItem.goodsId), 1234567) shopCarInfo.push(Obj);
let ind = ids.indexOf(preItem.goodsId); }
if (ind > -1) { console.log(shopCarInfo,7777)
let num = 0;
for (let i = 0; i < item.rules.length; i++) { }else{
let it = item.rules[i]; shopCarInfo = [Obj];
for (let r = 0; r < preItem.rules.length; r++) { }
let ry = preItem.rules[r]; uni.setStorageSync('shopCarInfo', shopCarInfo);
if (ry.specId == it.specId && ry.ruleId == it.ruleId) { $EventBus.$emit('updateCar');
num += 1;
}
}
}
if (num == item.rules.length) {
item.num += 1
} else {
shopCarInfoAdd.push(preItem)
}
} else {
shopCarInfoAdd.push(preItem);
arrA.splice(index, 1)
}
});
})
} else {
shopCarInfo = arrA
}
shopCarInfo = [...shopCarInfo, ...shopCarInfoAdd];
uni.setStorageSync('shopCarInfo', shopCarInfo);
$EventBus.$emit('updateCar');
// this.goods = uni.getStorageSync('shopCarInfo');
}, },
// getallNum(arrA) {
// // arrA = []
// let shopCarInfo = uni.getStorageSync('shopCarInfo');
// let shopCarInfoAdd = []
// console.log(shopCarInfo, 55553333)
// if (shopCarInfo) {
// let ids = shopCarInfo.map(v => v.goodsId);
// console.log(ids, 444)
// shopCarInfo.forEach((item) => {
// arrA.forEach((preItem, index) => {
// console.log(ids.includes(preItem.goodsId), 1234567)
// let ind = ids.indexOf(preItem.goodsId);
// if (ind > -1) {
// let num = 0;
// for (let i = 0; i < item.rules.length; i++) {
// let it = item.rules[i];
// for (let r = 0; r < preItem.rules.length; r++) {
// let ry = preItem.rules[r];
// if (ry.specId == it.specId && ry.ruleId == it.ruleId) {
// num += 1;
// }
// }
// }
// if (num == item.rules.length) {
// item.num += 1
// } else {
// shopCarInfoAdd.push(preItem)
// }
// } else {
// shopCarInfoAdd.push(preItem);
// arrA.splice(index, 1)
// }
// });
// })
// } else {
// shopCarInfo = arrA
// }
// shopCarInfo = [...shopCarInfo, ...shopCarInfoAdd];
// uni.setStorageSync('shopCarInfo', shopCarInfo);
// $EventBus.$emit('updateCar');
// // this.goods = uni.getStorageSync('shopCarInfo');
// },
// 解密手机 // 解密手机
async onGetPhoneNumber(appid,session_key,encryptedData,iv) { async onGetPhoneNumber(appid,session_key,encryptedData,iv) {
let pc = await new WXBizDataCrypt(appid,session_key); let pc = await new WXBizDataCrypt(appid,session_key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment