Commit 2fcd72df by 张成

update

parents 714fad7f 465520c3
<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">
......@@ -56,11 +65,6 @@
</view>
</view>
</view>
<view style="height:200rpx"></view>
</view>
</u-popup>
</template>
<script>
......@@ -76,6 +80,7 @@
}
},
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;
reduce(item,index){
item.num-=1
if(item.num==0){
this.goods.splice(index,1);
}
item.num=num
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,8 +272,20 @@
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{
......@@ -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;
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-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 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 {
export default {
data() {
return {
}
}
},
methods: {
}
}
</script>
<style>
......
<template>
<view>
详情页
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
......@@ -42,12 +42,20 @@
"root": "menuSubPackage",
"pages": [
{
"path": "pages/demo/demo",
"style": {
// "navigationBarBackgroundColor": "",
// "navigationBarTitleText": "",
"path" : "pages/goodsDetail/goodsDetail",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
,{
"path" : "areaSelect/areaSelect",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
// "navigationStyle":"custom"
}
}
......
......@@ -2,17 +2,26 @@
<view class="menu-box" :style="{height:`${height}px`}">
<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`}">
<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>
</view>
<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">
......@@ -45,7 +54,7 @@
>
<view v-for="(category, index) in classifyData" :key="index" class="box">
<view class="right-title">{{category.name}}</view>
<view class="nav-right-item" v-for="(item, i) in category.goods" :key="item.goodsId" @click="cart(item.name)">
<view class="nav-right-item" v-for="(item, i) in category.goods" :key="item.goodsId" @click="cart(item)">
<image class="thumbnail" :src="item.pics.thumbnail" />
<view class="info">
<view class="goods-name">{{ item.name }}</view>
......@@ -54,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>
......@@ -75,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,
......@@ -99,12 +110,14 @@ 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)
//如果你的分类数据为后台异步获取请 将下方代码放置你的数据回调中
// this.$nextTick(()=>{
// this.getHeightList();
......@@ -113,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")
......@@ -133,7 +146,13 @@ 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() {
......@@ -144,10 +163,69 @@ import Menu from '@/request/menu'
uniGetUserInfo() {
User.uniGetUserInfo();
},
async getMenuList() {
let res = await Menu.getMenuList();
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() {
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(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;
......@@ -155,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;
......@@ -229,10 +318,11 @@ import Menu from '@/request/menu'
this.scrollTop == this.arr[index] ? (this.scrollTop = this.scrollTop + 1) : (this.scrollTop = this.arr[index]); //防止两次相等造成点击不触发滚动时间
},
cart: function (text) {
uni.showToast({
title: text,
icon: "none"
});
uni.navigateTo({url:'/menuSubPackage/pages/goodsDetail/goodsDetail'})
// uni.showToast({
// title: text,
// icon: "none"
// });
}
},
components: { ShopCar }
......@@ -240,7 +330,34 @@ import Menu from '@/request/menu'
</script>
<style lang="scss">
.menu-box{}
.menu-box{
.shop-info{
position: absolute;
left: 32rpx;
color: #FFFFFF;
.shop-box{
min-width:300rpx;
font-size: 28rpx;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
display: flex;
.shop-name{
flex: 1;
}
.arrow-right-select{
width:9rpx;
}
}
.distance{
height: 46rpx;
font-size: 24rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
line-height: 42rpx;
}
}
}
.menu-banner{
height: 376rpx;
position:relative;
......@@ -308,7 +425,7 @@ import Menu from '@/request/menu'
}
}
.login-btn{
width: 114rpx;
// width: 114rpx;
height: 48rpx;
background: #006ECF;
border-radius: 4rpx;
......
<template>
<view>
<!-- 单向联动菜单 -->
<view class="scroll-box" :style="{ 'height': scrollHeight +'px' }">
<!-- 左边栏 -->
<view class="left-tab">
<scroll-view class="tab" scroll-y="true" scroll-with-animation >
<block v-for="(item,index) in tabData" :key="index" >
<!-- 标签动态样式 -->
<view class="tab-item" :class=" [currentTab==index ? 'active' : 'none'] " @click="clickTab"
:data-current="index" :data-title="[item.title]" >
{{item.title}}
</view>
</block>
</scroll-view>
</view>
<!-- 右边页面 -->
<scroll-view class="right-box" scroll-y="true" :scroll-top="scrollTop" @scroll="scroll" >
<view class="page-view">
<view class="class-item">
<view class="item-title">
<text>{{goodsTitle}}</text>
</view>
<view class="item-container">
<view class="thumb-box" v-for="(item, index) in menuData" :key="index">
<view class="left-image">
<image class="item-menu-image" :src="item.imgUrl" mode=""></image>
</view>
<view class="right-text">
<view class="item-menu-name">{{item.name}}</view>
<view class="item-menu-explain">{{item.explain}}</view>
<view class="item-menu-ps">
<view class="item-menu-price">¥{{item.price}}</view>
<!-- Animate动画库使用 https://blog.csdn.net/qq_40976321/article/details/107379659 -->
<view class="item-menu-select" hover-class="animated rotateOut" @click="addCar" :data-item="[item]">加购</view>
</view>
</view>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
<!-- 底部购物车 -->
<view class="car" v-if="isShowCar">
<view class="car-left">
<view class="car-pice">¥{{totalPrice}}</view>
</view>
<view class="car-right">
<view class="car-text">选好了</view>
</view>
</view>
<!-- 凸起图标 -->
<view class="car-img-back" v-if="isShowCar" @click="clickCar">
<image class="car-img" src="../../../static/icon/png/bag.png" mode=""></image>
<!-- 角标 -->
<view class="car-num">
<text class="car-num-text">{{totalNum}}</text>
</view>
</view>
<!-- 购物车列表 -->
<view class="car-list" v-if="isShowList">
<scroll-view scroll-y="true" style="height: 500rpx;">
<view class="car-box" v-for="(item, index) in carData" :key="index">
<view class="car-left-image" style="width: 23%;">
<image class="car-menu-image" :src="item.imgUrl" mode=""></image>
</view>
<view class="car-right-text" style="width: 73%;">
<view class="car-menu-name">{{item.name}}</view>
<view class="car-menu-explain">{{item.explain}}</view>
<view class="car-menu-ps">
<view class="car-menu-price" >¥{{item.price}}</view>
<view class="car-num-select" >
<view @click="clickMinus(index)">
<image style="width: 48rpx;height: 48rpx;" src="../../../static/icon/png/jian.png" ></image>
</view>
<view style="margin: 0rpx 15rpx;font-size: 28rpx;"> {{item.num}} </view>
<view @click="clickAdd(index)">
<image style="width: 48rpx;height: 48rpx;" src="../../../static/icon/png/jia.png" ></image>
</view>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
<!-- 遮罩层 -->
<view class="car-mark" v-if="isShowCarMark" @click="clickCarMark"></view>
</view>
</template>
<script>
export default {
data() {
return {
menuData:[]
}
},
methods:{
//点击左边类别栏事件
clickTab(e) {
let clickIndex = e.target.dataset.current //当前标签的索引
this.currentTab = clickIndex
let tapTitle = e.target.dataset.title //获得点击的标题
this.goodsTitle = tapTitle[0]
//对数组进行筛选,让右边的列表只显示对应类别的数据
this.menuData = this.tempData.filter(item => item.title == this.goodsTitle)
//滚动条返回顶部
this.scrollTop = 0
},
//记录滚动条位置
scroll : function(e) {
this.scrollTop = e.detail.scrollTop
},
//显示、隐藏购物车清单
clickCar(){
this.isShowList = !this.isShowList
this.isShowCarMark = !this.isShowCarMark
},
clickCarMark(){
this.isShowList = !this.isShowList
this.isShowCarMark = !this.isShowCarMark
},
//**********商品加入购物车 ***************
addCar(e){
//获得点击加购的商品数据
let item = e.target.dataset.item[0]
//如果购物车里的商品name = 点击数据商品name 则返回此元素下标
let index = this.carData.findIndex(ev => ev.name === item.name)
//如果购物车不存在相同的商品
if(index === -1) {
item.num = 1 //添加数量属性num ,默认为 1【原数据没有数量字段】
this.carData.push(item) //把商品追加进购物车
} else {
this.carData[index].num++ //存在相同的商品则数量叠加
}
//更新总数与总价
this.allNum()
this.allPrice()
//显示购物车
this.isShowCar = true
},
//增加数量
clickAdd(index){
this.carData[index].num = this.carData[index].num + 1
this.allNum()
this.allPrice()
},
//减少数量,小于1时删除元素
clickMinus(index){
if(this.carData[index].num > 1){
this.carData[index].num = this.carData[index].num - 1
} else {
this.carData.splice(index,1) //从数组删除元素
}
this.allNum()
this.allPrice()
},
// 计算商品总数量
allNum() {
let count = 0;
this.carData.forEach(item=>{
count+=item.num
})
this.totalNum = count
//购物车有商品的时候,滚动栏高度减少,让出位置给购物车
if(this.totalNum === 1 && this.isAddHeight){
this.scrollHeight = this.scrollHeight - 50
this.isAddHeight = false
}
//购物车没有商品的时候,隐藏组件,还原滚动栏高度
if (this.totalNum === 0){
this.scrollHeight = this.scrollHeight + 50
this.isAddHeight = true
this.isShowCar = false
this.clickCar()
}
},
// 计算商品总价格
allPrice() {
let Price = 0;
this.carData.forEach(item=>{
//总价格=数量 X 单价 ,由于数组的单价是字符串类型,所以要先转换成浮点数字类型
Price+=item.num * parseFloat(item.price)
})
//Number类型的数据调用toFixed方法,指定保留几位小数,返回的数据是一个string类型
this.totalPrice = Price.toFixed(2)
},
}
}
</script>
<style lang="scss">
.scroll-box{
display: flex;
flex-direction: row;
/* 需要定义高度,否则不能分栏滚动 */
/* height: calc(78.2vh); */
}
.left-tab{
flex: 1; /*均匀分配元素*/
display: flex;
overflow: hidden;
background: #f6f6f6;
}
.tab{
width: 150rpx;
height: 100%;
}
.tab-item{
height: 100rpx;
background: #f6f6f6;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
font-size: 22rpx;
line-height: 1;
}
.active{ /* 选项卡活动时的样式 */
color:#A7D500;
font-weight: bolder;
background: #ffffff;
}
/* 右边页面样式 */
.right-box {
left: 15%;
width: 80%;
background: #f6f6f6;
}
.page-view {
padding: 10rpx;
}
.class-item {
margin-bottom: 30rpx;
background-color: #fff;
padding: 16rpx;
border-radius: 8rpx;
}
.item-title {
font-size: 26rpx;
color: $u-main-color;
font-weight: bold;
}
.item-container {
display: flex;
flex-direction: column;
}
.thumb-box {
width: 98%;
height: 150rpx;
display: flex;
flex-direction: row;
align-items: center;
/* justify-content: center; */
margin-top: 50rpx;
}
.item-menu-image {
width: 150rpx;
height: 150rpx;
}
.item-menu-name {
font-weight: normal;
font-size: 28rpx;
margin-bottom: 10rpx;
}
.item-menu-explain{
font-size: 20rpx;
margin-bottom: 10rpx;
/* 下方四项配合使用,超出范围的显示... */
width: 400rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.item-menu-ps{
display: flex;
flex-direction: row;
justify-content: space-between; /*两边对齐*/
}
.item-menu-price{
font-size: 26rpx;
font-weight: 600;
}
.item-menu-select{
width: 100rpx;
height: 36rpx;
/* 文字垂直居中 (line-height)和(height)设置一样就可以 */
line-height: 36rpx;
/* 文字水平居中 */
text-align:center;
font-size: 22rpx;
background-color: #A7D500;
border-radius: 50rpx;
}
/* 购物车 */
.car{
display: flex;
flex-direction: row;
align-items: center;
height: 100rpx;
width: 100%;
position: fixed;
bottom: 0rpx;
background-color:#ffffff ;
z-index: 79;
}
.car-img-back{
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 100rpx;
width: 100rpx;
position: fixed;
bottom: 35rpx;
left: 30rpx;
background-color: #A7D500;
border-radius: 50%;
z-index: 79;
}
.car-img{
height: 60rpx;
width: 60rpx;
}
.car-left{
/* 平均分布元素,父元素display: flex; 子元素flex:1; */
flex: 1;
}
.car-pice{
padding-left: 160rpx;
font-size: 34rpx;
font-weight: 700;
}
.car-num{
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 30rpx;
width: 30rpx;
position: fixed;
bottom: 100rpx;
left: 110rpx;
background-color: #ffea49;
border-radius: 50%;
z-index: 79;
}
.car-num-text{
font-size: 20rpx;
}
.car-right{
/* 平均分布元素,父元素display: flex; 子元素flex:1; */
flex: 1;
}
.car-text{
height: 100rpx;
width: 200rpx;
line-height: 100rpx;
margin-left: 200rpx;
text-align: center;
background-color: #A7D500;
}
.car-list{
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 500rpx;
width: 100%;
position: fixed;
bottom: 100rpx;
background-color: #ffffff;
border-radius: 10px 10px 0px 0px;
z-index: 78;
}
.car-container {
display: flex;
flex-direction: column;
width: 100%;
}
.car-box {
width: 100%;
height: 120rpx;
display: flex;
flex-direction: row;
align-items: center;
padding: 20rpx 10rpx;
border-bottom: solid #f4f4f4 1px;
}
.car-menu-image {
width: 100rpx;
height: 100rpx;
margin-left: 35rpx;
}
.car-menu-name {
font-weight: normal;
font-size: 28rpx;
margin-bottom: 10rpx;
}
.car-menu-explain{
font-size: 20rpx;
margin-bottom: 10rpx;
/* 下方四项配合使用,超出范围的显示... */
width: 400rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.car-menu-ps{
display: flex;
flex-direction: row;
justify-content: space-between; /*两边对齐*/
}
.car-menu-price{
font-size: 26rpx;
font-weight: 600;
}
.car-num-select{
display: flex;
flex-direction: row;
width: 160rpx;
height: 36rpx;
}
/* 遮罩层 */
.car-mark{
position: fixed;
left:0;
top:0;
width:100%;
height:100%;
z-index:77;
background-color: rgba(0, 0, 0, 0.4);
transition: all 0.3s ease-in 0s;
}
</style>
\ No newline at end of file
......@@ -30,9 +30,9 @@ uni.$u.http.interceptors.request.use((config) => { // å¯ä½¿ç”¨async await åšå¼
mask: true,
});
let Authorization = uni.getStorageSync(`Authorization`);
if (Authorization) {
config.header.Authorization = Authorization;
}
// if (Authorization) {
// config.header.Authorization = Authorization;
// }
console.log(config,4444)
if (!Authorization) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
// return Promise.reject(config);
......
......@@ -3,12 +3,12 @@ export default {
getMenuList(id) {
return uni.$u.http.get('/weixin/infoByShop', {
params:{
shopId:"4"
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);
// 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 = {
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)
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 {
shopCarInfoAdd.push(preItem);
arrA.splice(index, 1)
}
});
})
} else {
shopCarInfo = arrA
}else{
shopCarInfo = [Obj];
}
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) {
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