Commit 465520c3 by zhangcheng

调整购物车

parent 7b2e7c08
<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="header">
<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 class="container">
<view>
......@@ -21,22 +22,28 @@
<u-checkbox shape="circle" class="selected" color="#555555" :checked="item.flag"/><text></text>
</label>
</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 class="size">
<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><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 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 class="price-x"></text><text class="price-xx">{{item.price}}</text></text>
</view>
</view>
<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 @click="add(item)" class="add">+</text>
</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">
<!-- <checkbox-group @change="selectgoods()">
<label>
......@@ -44,8 +51,10 @@
</label>
</checkbox-group> -->
<view style="display:flex">
<text class="car-img"></text>
<text style="color:#000000;font-weight: bold;display: flex; align-items: center;">{{totalPrice.toFixed(2)}}</text>
<view class="car-img" @click.stop="openShopCar">
<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 class="end-right">
......@@ -55,12 +64,7 @@
</view>
</view>
</view>
<view style="height:200rpx"></view>
</view>
</u-popup>
</view>
</template>
<script>
......@@ -71,11 +75,12 @@
showShopCar:false,//是否弹出购物车列表
show:true,
allchecked:true,
// checked:true,
goods:[],//购物车商品信息
// checked:true,
goods:[],//购物车商品信息
}
},
created() {
$EventBus.$off('updateCar');
// this.getallNum();
},
mounted() {
......@@ -126,6 +131,13 @@
// uni.setStorageSync('shopCarInfo',shopCarInfo)
// this.goods=uni.getStorageSync('shopCarInfo');
// },
// 切换购物车列表显示隐藏
openShopCar() {
this.$nextTick(()=>{
this.showShopCar = !this.showShopCar;
})
},
clearCar() {
uni.removeStorageSync('shopCarInfo');
$EventBus.$emit('updateCar');
......@@ -167,17 +179,11 @@
}
uni.setStorageSync('shopCarInfo',this.goods);
},
reduce(item){
let num=item.num
if(num>1){
num-=1
}else if(num=1){
uni.showToast({
title:"该宝贝不能减少了哟~"
})
return;
}
item.num=num
reduce(item,index){
item.num-=1
if(item.num==0){
this.goods.splice(index,1);
}
uni.setStorageSync('shopCarInfo',this.goods);
},
add(item){
......@@ -211,23 +217,31 @@
.shop-car {
display: flex;
flex-direction: column;
height: 40vh;
height: 860rpx;
.header{
height: 100rpx;
height: 88rpx;
display: flex;
border-bottom:1rpx solid #ccc;
border-bottom:1rpx solid rgb(235,235,235);
.left{
flex: 1;
display: flex;
align-items: center;
padding-left: 40rpx;
font-size: 28rpx;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
color: #000000;
}
.right{
flex: 1;
display: flex;
align-items: center;
justify-content: right;
justify-content: flex-end;
padding-right: 40rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
}
}
.container{
......@@ -243,7 +257,6 @@
padding: 30rpx 15rpx 30rpx 30rpx;
background-color: #fff;
justify-content: space-between;
border-bottom: 5rpx solid #F1F1F1;
align-items: center;
.detail-left{
display: flex;
......@@ -259,9 +272,21 @@
margin-left: 30rpx;
.goods-price{
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{
text{
......@@ -281,7 +306,7 @@
.subtract{
border:1rpx solid #006ECF;
border-radius: 40rpx;
color:red;
color:#006ECF;
}
}
}
......@@ -310,12 +335,13 @@
}
.end{
width: 100%;
height: 90rpx;
height: 92rpx;
background-color:#fff;
position: fixed;
bottom: 100rpx;
bottom: 50px;
left: 0;
display: flex;
z-index: 10075;
align-items: center;
&-left{
width: 70%;
......@@ -330,7 +356,26 @@
width:40rpx;
height: 48rpx;
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{
......
<template>
<!-- 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>
</template>
......
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
......@@ -50,6 +50,15 @@
}
}
,{
"path" : "areaSelect/areaSelect",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
]
},
{
......
......@@ -3,8 +3,8 @@
<view class="menu-banner">
<image src="../../static/imgs/banner.png"></image>
<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">
<text class="shop-name">北京国贸银泰中心店</text>
<view class="shop-box" :style="{height: `${menuINfo.height}px`,'line-height': `${menuINfo.height}px`}">
<text class="shop-name">{{shopInfo.name}}</text>
<u-icon name="arrow-right" class="arrow-right-select" color="#FFFFFF"></u-icon>
</view>
<view class="distance">距您130m</view>
......@@ -13,14 +13,15 @@
<view class="login-area">
<view class="avatar"><image :src="'../../static/logo.png'"></image></view>
<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="dialog">
<view class="content" v-if="userms">希望你今天,明天,天天都开心~</view>
<view class="content" v-if="!userms">请您尽快登录</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 class="order-banner" v-if="buied">
......@@ -62,7 +63,7 @@
</view>
<view class="dis-box">
<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 class="mon">
<view class="discount">{{item.discount}}</view>
......@@ -83,9 +84,11 @@ import User from '@/request/user'
import ShopCar from '../../components/shopCar/shopCar.vue'
import Utils from '@/utils/utils'
import Menu from '@/request/menu'
import { $EventBus } from '@/utils/EventBus';
export default {
data() {
return {
shopInfo:{name:'请选择'},// 店铺信息
menuINfo:{},
buied: true,
orderBannerh: 0,
......@@ -107,11 +110,12 @@ import Menu from '@/request/menu'
},
computed: {
userms() {
let res = uni.getStorageSync("userInfo").userInfo;
let res = uni.getStorageSync("Authorization");
return res;
}
},
created() {
this.getLocation();
this.menuINfo = uni.getMenuButtonBoundingClientRect();
console.log(this.menuINfo,77766)
//如果你的分类数据为后台异步获取请 将下方代码放置你的数据回调中
......@@ -122,7 +126,7 @@ import Menu from '@/request/menu'
async onShow() {
console.log(1243)
// 获取首页菜单数据
await this.getMenuList();
await this.getMenuList(6);
let _this = this;
uni.createSelectorQuery()
.select(".menu-banner")
......@@ -142,8 +146,14 @@ import Menu from '@/request/menu'
}
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() {
......@@ -153,19 +163,69 @@ import Menu from '@/request/menu'
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() {
uni.authorize({
scope:'scope.userLocation',
success(res) {
console.log(res)
User.getLocation();
}
})
let _this = this;
uni.getSetting({
success: (res) => {
if (!res.authSetting['scope.userLocation']) {
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() {
let res = await Menu.getMenuList();
async getMenuList(id) {
let res = await Menu.getMenuList(id);
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)
this.$store.commit('setMenuAllInfo',res.data.data);
this.classifyData = res.data.data.categorys;
......@@ -173,21 +233,32 @@ import Menu from '@/request/menu'
},
// 加入购物车数据
getallNum(item) {
let itemCopy = JSON.parse(JSON.stringify(item));
console.log(this.classifyData,998877)
console.log(item,333)
let 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:item.skus[0].rules
}
]
Utils.getallNum(reItem);
itemCopy.skus = [itemCopy.skus.find(v=>v.state!=2)];
if(!itemCopy.skus){
uni.showToast({title:'本商品已经售罄',icon:'none'});
return;
}else{
itemCopy.num=1;
itemCopy.flag=true;
console.log(itemCopy,'mmmmmmm')
Utils.getallNum(itemCopy);
}
// let 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() {
let _this = this;
......@@ -354,7 +425,7 @@ import Menu from '@/request/menu'
}
}
.login-btn{
width: 114rpx;
// width: 114rpx;
height: 48rpx;
background: #006ECF;
border-radius: 4rpx;
......
......@@ -3,12 +3,12 @@ export default {
getMenuList(id) {
return uni.$u.http.get('/weixin/infoByShop', {
params:{
shopId:"6"
shopId: id
}
}).then(res => {
return res;
}).catch(err => {
uni.showToast({title:'服务器错误',icon:'none'})
})
},
// 下单获取预支付订单
......
import Store from '@/store'
import { $EventBus } from '../../utils/EventBus';
export default{
getLocation() {
uni.getLocation({
let _this = this;
return uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
console.log(res, 'res')
......@@ -9,12 +11,52 @@ export default{
lat: res.latitude,
lng: res.longitude
}
// getAddress(params).then(res => {
// console.log(res, 'aaa')
// })
Store.commit('saveLocation',params);
// 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) {
uni.login({
provider: 'weixin',
......@@ -27,7 +69,6 @@ export default{
encryptedData: res.encryptedData
}).then((response) => {
if (response.statusCode == 200 && response.data && response.data.code==200) {
console.log(response.data.token,54443)
uni.setStorage({key:'Authorization',data:response.data.token});
Store.commit('setAuthorization', response.data.token);
uni.showToast({
......@@ -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) {
uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息
lang: "zh_CN",
......@@ -51,23 +101,8 @@ export default{
success: res => {
uni.setStorage({key:'userInfo', data:res})
Store.commit("setUserInfo",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')
})
// this.uniLogin(res);
}
})
},
}
}
\ No newline at end of file
......@@ -3,6 +3,9 @@ const getters = {
nickName: state => state.user.userInfo.userInfo.nickName,
Authorization: state => state.user.Authorization,
menuAllInfo: state => state.menu.menuAllInfo,
userPhoneInfo: state => state.user.userPhoneInfo,
location: state => state.user.location,
shopInfo: state => state.user.shopInfo,
}
export default getters
\ No newline at end of file
......@@ -3,6 +3,9 @@ const user = {
state: {
userInfo: null, //授权信息
Authorization: null, //是否授权
location:null,//用户经纬度
userPhoneInfo:null,
shopInfo:null//店铺信息
},
mutations: {
// 设置是否授权
......@@ -10,10 +13,22 @@ const user = {
console.log(data,665)
state.Authorization = data;
},
// 设置用户信息
// 设置用户允许昵称头像授权时的信息
setUserInfo(state, userInfo) {
state.userInfo = userInfo;
},
// 授权手机号时允许后的信息
setUserPhoneInfo(state, userPhoneInfo) {
state.userPhoneInfo = userPhoneInfo;
},
// 保存经纬度
saveLocation(state, location) {
state.location = location;
},
// 当前店铺信息
saveShopInfo(state, shopInfo) {
state.shopInfo = shopInfo;
}
},
actions: {
......
......@@ -2,94 +2,68 @@ import Config from '../static/config/index.js';
import WXBizDataCrypt from "./WXBizDataCrypt.js";
import {$EventBus} from './EventBus'
export default{
getallNum(arrA) {
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 = []
getallNum(Obj){
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');
console.log(shopCarInfo,'oooooo')
if (shopCarInfo){
let currentGoods = shopCarInfo.find(v => v.goodsId == Obj.goodsId && v.skuId == Obj.skuId);
if (currentGoods){
console.log(currentGoods,'pppppp')
currentGoods.num+=1;
}else{
shopCarInfo.push(Obj);
}
console.log(shopCarInfo,7777)
}else{
shopCarInfo = [Obj];
}
uni.setStorageSync('shopCarInfo', shopCarInfo);
$EventBus.$emit('updateCar');
},
// 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) {
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