|
@@ -141,11 +141,11 @@
|
|
|
<view class="price_and_action">
|
|
|
<text class="price">¥{{ good.price * good.number }}</text>
|
|
|
<view class="btn-group">
|
|
|
- <button type="default" v-show="goodCartNum(good.id)" plain class="btn reduce_btn" size="mini" hover-class="none"
|
|
|
- @tap="handleReduceFromCart(item, good)">
|
|
|
+ <button type="default" v-show="goodCartNum(good.props_text)" plain class="btn reduce_btn" size="mini"
|
|
|
+ hover-class="none" @tap="handleReduceFromCart(item, good)">
|
|
|
<view class="iconfont iconsami-select">-</view>
|
|
|
</button>
|
|
|
- <view class="number" v-show="goodCartNum(good.id)">{{ goodCartNum(good.id) }}</view>
|
|
|
+ <view class="number" v-show="goodCartNum(good.props_text)">{{ goodCartNum(good.props_text) }}</view>
|
|
|
<button type="primary" class="btn add_btn bg-color" size="min" hover-class="none" @tap="handleAddToCart(item, good, 1)">
|
|
|
<view class="iconfont iconadd-select">+</view>
|
|
|
</button>
|
|
@@ -163,46 +163,57 @@
|
|
|
<!-- 规格弹窗 -->
|
|
|
<view class="mode" v-if="selectble">
|
|
|
<view class="sel-mode-1">
|
|
|
- <view class="close" @click="Close">
|
|
|
- <text style="padding: 10rpx; 20rpx">x</text>
|
|
|
- </view>
|
|
|
- <view class="sel-2">
|
|
|
- <image class="neximg" :src="specifications.icon" />
|
|
|
- <view class="nexbox1 flex-around-center">
|
|
|
- <text>销量 {{specifications.sales}}</text>
|
|
|
- <text>好评率 {{ specifications.replyChance*100}}%</text>
|
|
|
- <text class="nexbox-txt3">¥ {{specifications.price}}</text>
|
|
|
+ <view class="good-detail-modal">
|
|
|
+ <view class="close" @click="Close">
|
|
|
+ <text style="padding: 10rpx; 20rpx">x</text>
|
|
|
</view>
|
|
|
- </view>
|
|
|
- <!--规格数组 -->
|
|
|
- <view class="sel-3">
|
|
|
- <text>规格</text>
|
|
|
- <view class="sel-4">
|
|
|
- <view class="sel-5" @click="xubox(item.productId)" :style="{background: item.productId == productid ? '#ff9805' : ''}"
|
|
|
- v-for="(item,index) in productValue" :key="index">
|
|
|
- {{item.optionName}}
|
|
|
+ <view class="sel-2">
|
|
|
+ <image class="neximg" :src="specifications.icon" />
|
|
|
+ <view class="nexbox1 flex-around-center">
|
|
|
+ <text>销量 {{specifications.sales}}</text>
|
|
|
+ <text>好评率 {{ specifications.replyChance*100}}%</text>
|
|
|
+ <text class="nexbox-txt3">¥ {{specifications.price}}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
- </view>
|
|
|
- <!-- 数量 -->
|
|
|
- <view class="sel-6">
|
|
|
- <text>数量</text>
|
|
|
- <!-- 加入购物车 -->
|
|
|
- <view class="btn-group">
|
|
|
- <button v-if="!goodCartNum(specifications.id)" type="primary" class="btn property_btn bg-color" size="min"
|
|
|
- hover-class="none" @tap="handleAddToCart(specificationsList, specifications, 1)">
|
|
|
- 加入购物车
|
|
|
- </button>
|
|
|
- <template v-else>
|
|
|
- <button type="default" v-show="goodCartNum(specifications.id)" plain class="btn reduce_btn" size="mini"
|
|
|
- hover-class="none" @tap="handleReduceFromCart(specificationsList, specifications)">
|
|
|
- <view class="iconfont iconsami-select">-</view>
|
|
|
- </button>
|
|
|
- <view class="number" v-show="goodCartNum(specifications.id)">{{ goodCartNum(specifications.id) }}</view>
|
|
|
- <button type="primary" class="btn add_btn bg-color" size="min" hover-class="none" @tap="handleAddToCart(specificationsList, specifications, 1)">
|
|
|
- <view class="iconfont iconadd-select">+</view>
|
|
|
+ <!--规格数组 -->
|
|
|
+ <scroll-view class="detail" scroll-y>
|
|
|
+ <view class="wrapper">
|
|
|
+ <view class="properties">
|
|
|
+ <view class="property" v-for="(item, index) in good.property" :key="index">
|
|
|
+ <view class="title">
|
|
|
+ <text class="name">{{ item.attributeName }}</text>
|
|
|
+ <!-- <view class="desc" v-if="item.desc">({{ item.desc }})</view> -->
|
|
|
+ </view>
|
|
|
+ <view class="values">
|
|
|
+ <view class="value" v-for="(value, key) in item.optionList" :key="key" :class="{'default': value.is_default}"
|
|
|
+ @tap="changePropertyDefault(index, key)">
|
|
|
+ {{ value.optionName }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </scroll-view>
|
|
|
+ <!-- 数量 -->
|
|
|
+ <view class="sel-6">
|
|
|
+ <text>数量</text>
|
|
|
+ <!-- 加入购物车 -->
|
|
|
+ <view class="btn-group">
|
|
|
+ <button v-if="!goodCartNum(specifications.props_text)" type="primary" class="btn property_btn bg-color" size="min"
|
|
|
+ hover-class="none" @tap="handleAddToCart(specificationsList, specifications, 1)">
|
|
|
+ 加入购物车
|
|
|
</button>
|
|
|
- </template>
|
|
|
+ <template v-else>
|
|
|
+ <button type="default" v-show="goodCartNum(specifications.props_text)" plain class="btn reduce_btn" size="mini"
|
|
|
+ hover-class="none" @tap="handleReduceFromCart(specificationsList, specifications)">
|
|
|
+ <view class="iconfont iconsami-select">-</view>
|
|
|
+ </button>
|
|
|
+ <view class="number" v-show="goodCartNum(specifications.props_text)">{{ goodCartNum(specifications.props_text) }}</view>
|
|
|
+ <button type="primary" class="btn add_btn bg-color" size="min" hover-class="none" @tap="handleAddToCart(specificationsList, specifications, 1)">
|
|
|
+ <view class="iconfont iconadd-select">+</view>
|
|
|
+ </button>
|
|
|
+ </template>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -233,6 +244,9 @@
|
|
|
preOrderApi
|
|
|
} from '@/api/order.js';
|
|
|
import navBar from '@/components/navBar';
|
|
|
+ import {
|
|
|
+ getAddressList
|
|
|
+ } from '@/api/user.js';
|
|
|
let app = getApp();
|
|
|
var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'rpx';
|
|
|
export default {
|
|
@@ -266,8 +280,10 @@
|
|
|
specificationsList: [], //点击的这一项菜品信息的大类
|
|
|
selectble: false, //规格弹窗
|
|
|
productValue: [], //规格数组
|
|
|
+ productObj: {}, //规格对象
|
|
|
productid: '', //选中规格的id
|
|
|
lockcatble: false, // 购物车弹窗
|
|
|
+ addressInfo: {}
|
|
|
}
|
|
|
},
|
|
|
onLoad(options) {
|
|
@@ -294,6 +310,8 @@
|
|
|
this.currentCateId = this.goods[0].id
|
|
|
// this.menuScrollIntoView = `cate-${9999}`
|
|
|
})
|
|
|
+ // 获取用户默认地址
|
|
|
+ this.getAddressList()
|
|
|
// this.getIndexConfig();
|
|
|
// #ifdef MP-WEIXIN
|
|
|
// 获取微信胶囊的位置信息 width,height,top,right,left,bottom
|
|
@@ -306,8 +324,10 @@
|
|
|
},
|
|
|
computed: {
|
|
|
goodCartNum() { //计算单个饮品添加到购物车的数量
|
|
|
- return (id) => this.cart.reduce((acc, cur) => {
|
|
|
- if (cur.id === id) {
|
|
|
+ // this.good
|
|
|
+ return (text) => this.cart.reduce((acc, cur) => {
|
|
|
+ !text ? text = this.getGoodSelectedProps(this.good) : ''
|
|
|
+ if (cur.props_text === text) {
|
|
|
return acc += cur.number
|
|
|
}
|
|
|
return acc
|
|
@@ -336,6 +356,16 @@
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 获取地址数据
|
|
|
+ getAddressList() {
|
|
|
+ getAddressList().then(res => {
|
|
|
+ console.log('地址', res)
|
|
|
+ if (res.code = 200) {
|
|
|
+ this.addressInfo = res.data.find(item => item.isDefault === true);
|
|
|
+ console.log('默认地址', this.addressInfo)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
handBack() {
|
|
|
uni.navigateBack({
|
|
|
delta: 1
|
|
@@ -363,19 +393,6 @@
|
|
|
this.currentCateId = tabs[0].id
|
|
|
}
|
|
|
},
|
|
|
- handleFoot($event) {
|
|
|
- const nextItems = this.findNextAll(this.goods, item => item.id === this.currentCateId);
|
|
|
- if (nextItems.id) {
|
|
|
- this.currentCateId = nextItems.id
|
|
|
- }
|
|
|
- },
|
|
|
- findNextAll(arr, condition) {
|
|
|
- const index = arr.findIndex(condition);
|
|
|
- if (index !== -1) {
|
|
|
- return arr[index + 1] || {}; // 返回符合条件之后的记录
|
|
|
- }
|
|
|
- return {}; // 如果没有找到符合条件的记录,返回空对象
|
|
|
- },
|
|
|
calcSize() {
|
|
|
let h = 10
|
|
|
|
|
@@ -394,8 +411,7 @@
|
|
|
this.sizeCalcState = true
|
|
|
},
|
|
|
showGoodDetailModal(item, good) {
|
|
|
- this.good = JSON.parse(JSON.stringify({ ...good,
|
|
|
- number: 1
|
|
|
+ this.good = JSON.parse(JSON.stringify({ ...good
|
|
|
}))
|
|
|
this.category = JSON.parse(JSON.stringify(item))
|
|
|
this.goodDetailModalVisible = true
|
|
@@ -407,44 +423,53 @@
|
|
|
if (this.good.number === 1) return
|
|
|
this.good.number -= 1
|
|
|
},
|
|
|
+ changePropertyDefault(index, key) { //改变默认属性值
|
|
|
+ this.good.property[index].optionList.forEach(value => this.$set(value, 'is_default', 0))
|
|
|
+ this.good.property[index].optionList[key].is_default = 1
|
|
|
+ this.good.number = 1
|
|
|
+ this.good = JSON.parse(JSON.stringify(this.good))
|
|
|
+ },
|
|
|
handleAddToCartInModal() {
|
|
|
const product = Object.assign({}, this.good, {
|
|
|
props_text: this.getGoodSelectedProps(this.good),
|
|
|
props: this.getGoodSelectedProps(this.good, 'id')
|
|
|
})
|
|
|
this.handleAddToCart(this.category, product, this.good.number)
|
|
|
- this.closeGoodDetailModal()
|
|
|
+ // this.closeGoodDetailModal()
|
|
|
},
|
|
|
getGoodSelectedProps(good, type = 'text') { //计算当前饮品所选属性
|
|
|
- if (good.use_property) {
|
|
|
- let props = []
|
|
|
- good.property.forEach(({
|
|
|
- values
|
|
|
- }) => {
|
|
|
- values.forEach(value => {
|
|
|
- if (value.is_default) {
|
|
|
- props.push(type === 'text' ? value.value : value.id)
|
|
|
- }
|
|
|
- })
|
|
|
+ // if (good.use_property) {
|
|
|
+ let props = []
|
|
|
+ good.property.forEach(({
|
|
|
+ optionList
|
|
|
+ }) => {
|
|
|
+ optionList.forEach(value => {
|
|
|
+ if (value.is_default) {
|
|
|
+ props.push(type === 'text' ? value.optionName : value.id)
|
|
|
+ }
|
|
|
})
|
|
|
- return type === 'text' ? props.join(',') : props
|
|
|
- }
|
|
|
- return ''
|
|
|
+ })
|
|
|
+ return type === 'text' ? props.join(',') : props
|
|
|
+ // }
|
|
|
+ // return ''
|
|
|
},
|
|
|
handleReduceFromCart(item, good) {
|
|
|
- const index = this.cart.findIndex(item => item.id === good.id)
|
|
|
+ const goodText = this.getGoodSelectedProps(this.good) // 购物车当前选中的规格
|
|
|
+ const index = this.cart.findIndex(item => item.id === good.id && item.props_text === goodText)
|
|
|
this.cart[index].number -= 1
|
|
|
if (this.cart[index].number <= 0) {
|
|
|
this.cart.splice(index, 1)
|
|
|
}
|
|
|
},
|
|
|
handleAddToCart(cate, good, num) { //添加到购物车
|
|
|
+ const goodText = this.getGoodSelectedProps(this.good) // 购物车当前选中的规格
|
|
|
const index = this.cart.findIndex(item => {
|
|
|
- if (good.use_property) {
|
|
|
- return (item.id === good.id) && (item.props_text === good.props_text)
|
|
|
- } else {
|
|
|
- return item.id === good.id
|
|
|
- }
|
|
|
+ // if (good.use_property) {
|
|
|
+ // !good.props_text ? good.props_text = this.getGoodSelectedProps(good) : ''
|
|
|
+ return (item.id === good.id) && (item.props_text === goodText)
|
|
|
+ // } else {
|
|
|
+ // return item.id === good.id
|
|
|
+ // }
|
|
|
})
|
|
|
if (index > -1) {
|
|
|
this.cart[index].number += num
|
|
@@ -457,9 +482,9 @@
|
|
|
number: num,
|
|
|
icon: good.icon,
|
|
|
use_property: good.use_property,
|
|
|
- props_text: good.props_text,
|
|
|
- props: good.props,
|
|
|
- productid: this.productid,
|
|
|
+ props_text: this.getGoodSelectedProps(this.good),
|
|
|
+ props: this.getGoodSelectedProps(this.good, 'id'),
|
|
|
+ productid: this.productObj[goodText].id,
|
|
|
...good
|
|
|
})
|
|
|
}
|
|
@@ -497,7 +522,8 @@
|
|
|
uni.setStorageSync('cart', JSON.parse(JSON.stringify(this.cart)))
|
|
|
uni.navigateTo({
|
|
|
// url: `/pages/goods/order_confirm/index?cartList=${cartList}`
|
|
|
- url: '/pages/goods/order_confirm/index?orderNo=' + res.data.orderNo
|
|
|
+ url: '/pages/goods/order_confirm/index?is_address=1&orderNo=' + res.data.orderNo +
|
|
|
+ '&addressId=' + this.addressInfo.id
|
|
|
})
|
|
|
}
|
|
|
})
|
|
@@ -508,14 +534,22 @@
|
|
|
Selectpox(item, itemInfo) {
|
|
|
this.specifications = itemInfo //这一项信息
|
|
|
this.specificationsList = item //这一项信息
|
|
|
+ // this.good = Object.assign({}, this.good, itemInfo)
|
|
|
getProductDetail(
|
|
|
itemInfo.id,
|
|
|
0, 0, ''
|
|
|
).then((res) => {
|
|
|
console.log('规格', res)
|
|
|
if (res.code == 200) {
|
|
|
- this.productValue = res.data.productAttr[0].optionList //规格数组
|
|
|
- this.productid = res.data.productValue.默认.id //默认选择的id
|
|
|
+ this.good.property = res.data.productAttr.map(item => {
|
|
|
+ item.optionList.forEach((items, index) => {
|
|
|
+ index === 0 ? items.is_default = true : '' // 规格默认选中
|
|
|
+ })
|
|
|
+ return { ...item }
|
|
|
+ })
|
|
|
+ console.log(this.good)
|
|
|
+ // this.productValue = res.data.productAttr //规格数组
|
|
|
+ this.productObj = res.data.productValue //默认选择的id
|
|
|
this.selectble = true
|
|
|
}
|
|
|
})
|
|
@@ -1096,7 +1130,7 @@
|
|
|
margin-bottom: 16rpx;
|
|
|
|
|
|
&.default {
|
|
|
- background-color: $color-primary;
|
|
|
+ background-color: $bg-color-primary;
|
|
|
color: $text-color-white;
|
|
|
}
|
|
|
}
|