增加代客下单搜索联动
This commit is contained in:
@@ -58,7 +58,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
index: {
|
index: {
|
||||||
type: Number,
|
type: [Number,String],
|
||||||
},
|
},
|
||||||
isSeatFee:{
|
isSeatFee:{
|
||||||
//是否为餐位费
|
//是否为餐位费
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="u-flex u-m-t-20 u-flex-wrap">
|
<view class="u-flex u-m-t-20 u-flex-wrap">
|
||||||
<view class="item" @tap="chooseSkd(index,skd)"
|
<view class="item" @tap="chooseSkd(index,skd)"
|
||||||
:class="{active:item.sel===skd.name,disabled:skd.disabled}" v-for="(skd,skdIndex) in item.values"
|
:class="{active:item.sel===skd.name,disabled:skd.disabled}"
|
||||||
:key="skdIndex">
|
v-for="(skd,skdIndex) in item.values" :key="skdIndex">
|
||||||
{{skd.name}}
|
{{skd.name}}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<template #btn>
|
<template #btn>
|
||||||
<view class="u-p-30 border-top ">
|
<view class="u-p-30 border-top ">
|
||||||
<view class="u-flex u-p-b-30 u-row-between">
|
<view class="u-flex u-p-b-30 u-row-between">
|
||||||
<view class="price" >
|
<view class="price">
|
||||||
<template v-if="goods&&goods.isGrounding">
|
<template v-if="goods&&goods.isGrounding">
|
||||||
<text>¥</text>
|
<text>¥</text>
|
||||||
<text>{{to2(goods.salePrice*number) }}</text>
|
<text>{{to2(goods.salePrice*number) }}</text>
|
||||||
@@ -40,7 +40,9 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="u-m-t-10">
|
<view class="u-m-t-10">
|
||||||
<my-button @tap="close" type="cancel" v-if="isAllDisabled||!goods.isGrounding"><view class="color-999">已下架/售罄</view></my-button>
|
<my-button @tap="close" type="cancel" v-if="isDisabled">
|
||||||
|
<view class="color-999">已下架/售罄</view>
|
||||||
|
</my-button>
|
||||||
<my-button @tap="confirm" v-else>添加</my-button>
|
<my-button @tap="confirm" v-else>添加</my-button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -55,10 +57,15 @@
|
|||||||
ref,
|
ref,
|
||||||
watch
|
watch
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
import util from '../util.js';
|
||||||
import infobox from '@/commons/utils/infoBox.js'
|
import infobox from '@/commons/utils/infoBox.js'
|
||||||
import myModel from '@/components/my-components/my-model.vue'
|
import myModel from '@/components/my-components/my-model.vue'
|
||||||
import myButton from '@/components/my-components/my-button.vue'
|
import myButton from '@/components/my-components/my-button.vue'
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
goodsData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {}
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
@@ -82,53 +89,72 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function to2(number){
|
function to2(number) {
|
||||||
return Number(number).toFixed(2)
|
return Number(number).toFixed(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const selSku=computed(()=>{
|
const selSku = computed(() => {
|
||||||
return props.skus.reduce((prve,cur)=>{
|
return props.skus.reduce((prve, cur) => {
|
||||||
prve.push(cur.sel)
|
prve.push(cur.sel)
|
||||||
return prve
|
return prve
|
||||||
},[]).join()
|
}, []).join()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const goods=computed(()=>{
|
const goods = computed(() => {
|
||||||
return props.skuMap[selSku.value]
|
return props.skuMap[selSku.value]
|
||||||
})
|
})
|
||||||
watch(()=>goods.value,(newval)=>{
|
watch(() => goods.value, (newval) => {
|
||||||
console.log(newval);
|
console.log(props.goodsData.isStock);
|
||||||
number.value=newval.suit||1
|
number.value = newval.suit || 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const isCanBuy=computed(()=>{
|
||||||
|
if(!goods.value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
console.log(util.isCanBuy({
|
||||||
|
...goods.value,
|
||||||
|
isStock: props.goodsData.isStock
|
||||||
|
}));
|
||||||
|
return util.isCanBuy({
|
||||||
|
...goods.value,
|
||||||
|
isStock: props.goodsData.isStock
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
//全部规格是否都无法使用
|
//全部规格是否都无法使用
|
||||||
const isAllDisabled=computed(()=>{
|
const isAllDisabled = computed(() => {
|
||||||
console.log(props.skus);
|
console.log(props.skus);
|
||||||
return props.skus.reduce((prve,cur)=>{
|
return props.skus.reduce((prve, cur) => {
|
||||||
return prve&&cur.values.filter(v=>v.disabled).length===cur.values.length
|
return prve && cur.values.filter(v => v.disabled).length === cur.values.length
|
||||||
},true)
|
}, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
const emits = defineEmits(['confirm','updateSku'])
|
const emits = defineEmits(['confirm', 'updateSku'])
|
||||||
let number = ref(1)
|
let number = ref(1)
|
||||||
|
|
||||||
|
|
||||||
function chooseSkd(skusIndex, skd) {
|
function chooseSkd(skusIndex, skd) {
|
||||||
const {name,disabled}=skd
|
const {
|
||||||
if(disabled){
|
name,
|
||||||
|
disabled
|
||||||
|
} = skd
|
||||||
|
if (disabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(props.skus[skusIndex].sel!=name){
|
if (props.skus[skusIndex].sel != name) {
|
||||||
emits('updateSku',skusIndex,name)
|
emits('updateSku', skusIndex, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const defaultIndex=reactive(new Array(props.skus.length).fill(''))
|
const defaultIndex = reactive(new Array(props.skus.length).fill(''))
|
||||||
for(let i in props.defaultIndex){
|
for (let i in props.defaultIndex) {
|
||||||
defaultIndex[i]=props.defaultIndex[i]
|
defaultIndex[i] = props.defaultIndex[i]
|
||||||
}
|
}
|
||||||
const activeArr = defaultIndex
|
const activeArr = defaultIndex
|
||||||
|
|
||||||
@@ -143,37 +169,39 @@
|
|||||||
function close() {
|
function close() {
|
||||||
model.value.close()
|
model.value.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isDisabled=computed(()=>{
|
||||||
|
return isAllDisabled.value || !isCanBuy.value
|
||||||
|
})
|
||||||
|
|
||||||
function reduce() {
|
function reduce() {
|
||||||
if(isDisabled()){
|
if (isDisabled.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const suit=goods.value.suit||1
|
const suit = goods.value.suit || 1
|
||||||
const newval = number.value - 1
|
const newval = number.value - 1
|
||||||
if(newval<suit){
|
if (newval < suit) {
|
||||||
return infobox.showToast(suit+'个起售')
|
return infobox.showToast(suit + '个起售')
|
||||||
}
|
}
|
||||||
number.value = newval <= 1 ? 1 : newval
|
number.value = newval <= 1 ? 1 : newval
|
||||||
}
|
}
|
||||||
|
|
||||||
function add() {
|
function add() {
|
||||||
if(isDisabled()){
|
if (isDisabled.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const newval = number.value + 1
|
const newval = number.value + 1
|
||||||
number.value = newval
|
number.value = newval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isDisabled(){
|
|
||||||
return isAllDisabled.value
|
|
||||||
}
|
|
||||||
|
|
||||||
function confirm() {
|
function confirm() {
|
||||||
close()
|
close()
|
||||||
if(isDisabled()){
|
if (isDisabled.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
emits('confirm',goods.value,number.value)
|
emits('confirm', goods.value, number.value)
|
||||||
}
|
}
|
||||||
defineExpose({
|
defineExpose({
|
||||||
open,
|
open,
|
||||||
@@ -204,7 +232,8 @@
|
|||||||
border-color: $my-main-color;
|
border-color: $my-main-color;
|
||||||
color: $my-main-color;
|
color: $my-main-color;
|
||||||
}
|
}
|
||||||
&.disabled{
|
|
||||||
|
&.disabled {
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
border-color: #eee;
|
border-color: #eee;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,13 +101,14 @@
|
|||||||
<view class="u-flex u-m-t-20 u-flex-wrap u-row-between">
|
<view class="u-flex u-m-t-20 u-flex-wrap u-row-between">
|
||||||
<view class="u-m-b-30" v-for="(goodsItem, goodsIndex) in searchResult" :key="goodsIndex">
|
<view class="u-m-b-30" v-for="(goodsItem, goodsIndex) in searchResult" :key="goodsIndex">
|
||||||
<goods-item :img="{width:'330rpx',height:'330rpx'}"
|
<goods-item :img="{width:'330rpx',height:'330rpx'}"
|
||||||
@chooseGuige="chooseGuige($event,goodsItem.index)"
|
@chooseGuige="chooseGuige(goodsItem.goodsIndex,goodsItem.index)"
|
||||||
@add="goodsUpdate($event,goodsItem.index,true)"
|
@add="searchGoodsUpdate(goodsItem,goodsIndex,true)"
|
||||||
@reduce="goodsUpdate($event,index,false)" :index="goodsItem.goodsIndex"
|
@reduce="searchGoodsUpdate(goodsItem,goodsIndex,false)" :index="goodsItem.goodsIndex"
|
||||||
:data="goodsItem"></goods-item>
|
:data="goodsItem"></goods-item>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<my-img-empty v-if="!searchResult.length" tips="未搜索到相关商品"></my-img-empty>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
@@ -122,6 +123,7 @@
|
|||||||
|
|
||||||
<!-- 选择规格 -->
|
<!-- 选择规格 -->
|
||||||
<guige-model @update-sku="updateSkuSel" @confirm="guigeConfirm" ref="chooseGuigeModel"
|
<guige-model @update-sku="updateSkuSel" @confirm="guigeConfirm" ref="chooseGuigeModel"
|
||||||
|
:goodsData="selGoods"
|
||||||
:title="guigeModelData.title" :sku-map="guigeModelData.chooseGoods.skuMap"
|
:title="guigeModelData.title" :sku-map="guigeModelData.chooseGoods.skuMap"
|
||||||
:skus="guigeModelData.chooseGoods.skus"></guige-model>
|
:skus="guigeModelData.chooseGoods.skus"></guige-model>
|
||||||
<!-- 添加附加费 -->
|
<!-- 添加附加费 -->
|
||||||
@@ -304,7 +306,7 @@
|
|||||||
masterId: data.masterId,
|
masterId: data.masterId,
|
||||||
tableId: data.table.tableId
|
tableId: data.table.tableId
|
||||||
}) {
|
}) {
|
||||||
const res= await Api.getCart(par)
|
const res = await Api.getCart(par)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
//获取取餐码
|
//获取取餐码
|
||||||
@@ -491,6 +493,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
|
if(searchValue.value===''){
|
||||||
|
isSearch.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
isSearch.value = true
|
isSearch.value = true
|
||||||
searchResult.value = returnSearchGoods()
|
searchResult.value = returnSearchGoods()
|
||||||
console.log(searchResult.value);
|
console.log(searchResult.value);
|
||||||
@@ -673,7 +679,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let selGoods=ref({})
|
||||||
function chooseGuige(foodsindex, index) {
|
function chooseGuige(foodsindex, index) {
|
||||||
if (!canAddGoods()) {
|
if (!canAddGoods()) {
|
||||||
return infoBox.showToast('清先选择桌台', 0.5).then(res => {
|
return infoBox.showToast('清先选择桌台', 0.5).then(res => {
|
||||||
@@ -681,6 +689,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
const $goods = data.tabbar[index].foods[foodsindex]
|
const $goods = data.tabbar[index].foods[foodsindex]
|
||||||
|
selGoods.value=$goods
|
||||||
guigeModelData.title = $goods.name
|
guigeModelData.title = $goods.name
|
||||||
const specList = $goods.specList;
|
const specList = $goods.specList;
|
||||||
const tagSnap = JSON.parse($goods.skuResult.tagSnap)
|
const tagSnap = JSON.parse($goods.skuResult.tagSnap)
|
||||||
@@ -744,8 +753,8 @@
|
|||||||
const tabbarIndex = data.tabbar.findIndex(v => v.id == categoryId)
|
const tabbarIndex = data.tabbar.findIndex(v => v.id == categoryId)
|
||||||
const $goods = data.tabbar[tabbarIndex].foods.find(v => v.id == productId)
|
const $goods = data.tabbar[tabbarIndex].foods.find(v => v.id == productId)
|
||||||
const $sku = $goods.specList.find(v => v.id == skuId)
|
const $sku = $goods.specList.find(v => v.id == skuId)
|
||||||
|
|
||||||
if (num === 0||num<$sku.suit) {
|
if (num === 0 || num < $sku.suit) {
|
||||||
//移除
|
//移除
|
||||||
await removeCartGoods({
|
await removeCartGoods({
|
||||||
cartId
|
cartId
|
||||||
@@ -782,7 +791,16 @@
|
|||||||
function canAddGoods() {
|
function canAddGoods() {
|
||||||
return data.table.tableId
|
return data.table.tableId
|
||||||
}
|
}
|
||||||
async function goodsUpdate(foodsindex, index, isAdd) {
|
|
||||||
|
function searchGoodsUpdate(goodsItem,goodsIndex, isAdd) {
|
||||||
|
goodsUpdate(goodsItem.goodsIndex, goodsItem.index, isAdd,goodsIndex)
|
||||||
|
}
|
||||||
|
function setSearchGoods(index,chooseNumber){
|
||||||
|
if(index!==undefined){
|
||||||
|
searchResult.value[index].chooseNumber=chooseNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function goodsUpdate(foodsindex, index, isAdd,searchGoodsIndex) {
|
||||||
if (!canAddGoods()) {
|
if (!canAddGoods()) {
|
||||||
return infoBox.showToast('请先选择桌台', 0.5).then(res => {
|
return infoBox.showToast('请先选择桌台', 0.5).then(res => {
|
||||||
chooseTable()
|
chooseTable()
|
||||||
@@ -796,17 +814,18 @@
|
|||||||
});
|
});
|
||||||
const productId = $goods.id
|
const productId = $goods.id
|
||||||
const skuId = $goods.specList[0].id
|
const skuId = $goods.specList[0].id
|
||||||
const suit=$goods.specList[0].suit||1
|
const suit = $goods.specList[0].suit || 1
|
||||||
if (goodsInCarIndex !== -1) {
|
if (goodsInCarIndex !== -1) {
|
||||||
//更新
|
//更新
|
||||||
const carGoods = cars[goodsInCarIndex]
|
const carGoods = cars[goodsInCarIndex]
|
||||||
const cartId = carGoods.id
|
const cartId = carGoods.id
|
||||||
const step = isAdd ? 1 : -1
|
const step = isAdd ? 1 : -1
|
||||||
const num = carGoods.number * 1 + step
|
const num = carGoods.number * 1 + step
|
||||||
if (num === 0||num<suit) {
|
if (num === 0 || num < suit) {
|
||||||
//移除
|
//移除
|
||||||
cars.splice(goodsInCarIndex, 1)
|
cars.splice(goodsInCarIndex, 1)
|
||||||
$goods.chooseNumber = 0
|
$goods.chooseNumber = 0
|
||||||
|
setSearchGoods(searchGoodsIndex,0)
|
||||||
return await removeCartGoods({
|
return await removeCartGoods({
|
||||||
cartId
|
cartId
|
||||||
})
|
})
|
||||||
@@ -821,6 +840,7 @@
|
|||||||
})
|
})
|
||||||
carGoods.number = number
|
carGoods.number = number
|
||||||
$goods.chooseNumber = number
|
$goods.chooseNumber = number
|
||||||
|
setSearchGoods(searchGoodsIndex,number)
|
||||||
} else {
|
} else {
|
||||||
//增加
|
//增加
|
||||||
const num = suit
|
const num = suit
|
||||||
|
|||||||
Reference in New Issue
Block a user