增加代客下单搜索联动

This commit is contained in:
2024-10-12 16:51:28 +08:00
parent 32ab68bfad
commit 54f824f2de
3 changed files with 105 additions and 56 deletions

View File

@@ -58,7 +58,7 @@
}
},
index: {
type: Number,
type: [Number,String],
},
isSeatFee:{
//是否为餐位费

View File

@@ -8,8 +8,8 @@
</view>
<view class="u-flex u-m-t-20 u-flex-wrap">
<view class="item" @tap="chooseSkd(index,skd)"
:class="{active:item.sel===skd.name,disabled:skd.disabled}" v-for="(skd,skdIndex) in item.values"
:key="skdIndex">
:class="{active:item.sel===skd.name,disabled:skd.disabled}"
v-for="(skd,skdIndex) in item.values" :key="skdIndex">
{{skd.name}}
</view>
</view>
@@ -40,7 +40,9 @@
</view>
</view>
<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>
</view>
</view>
@@ -55,10 +57,15 @@
ref,
watch
} from 'vue';
import util from '../util.js';
import infobox from '@/commons/utils/infoBox.js'
import myModel from '@/components/my-components/my-model.vue'
import myButton from '@/components/my-components/my-button.vue'
const props = defineProps({
goodsData: {
type: Object,
default: () => {}
},
title: {
type: String,
default: ''
@@ -101,10 +108,26 @@
return props.skuMap[selSku.value]
})
watch(() => goods.value, (newval) => {
console.log(newval);
console.log(props.goodsData.isStock);
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(() => {
console.log(props.skus);
@@ -118,7 +141,10 @@
function chooseSkd(skusIndex, skd) {
const {name,disabled}=skd
const {
name,
disabled
} = skd
if (disabled) {
return
}
@@ -144,8 +170,12 @@
model.value.close()
}
const isDisabled=computed(()=>{
return isAllDisabled.value || !isCanBuy.value
})
function reduce() {
if(isDisabled()){
if (isDisabled.value) {
return
}
const suit = goods.value.suit || 1
@@ -157,20 +187,18 @@
}
function add() {
if(isDisabled()){
if (isDisabled.value) {
return
}
const newval = number.value + 1
number.value = newval
}
function isDisabled(){
return isAllDisabled.value
}
function confirm() {
close()
if(isDisabled()){
if (isDisabled.value) {
return
}
emits('confirm', goods.value, number.value)
@@ -204,6 +232,7 @@
border-color: $my-main-color;
color: $my-main-color;
}
&.disabled {
color: #ccc;
border-color: #eee;

View File

@@ -101,13 +101,14 @@
<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">
<goods-item :img="{width:'330rpx',height:'330rpx'}"
@chooseGuige="chooseGuige($event,goodsItem.index)"
@add="goodsUpdate($event,goodsItem.index,true)"
@reduce="goodsUpdate($event,index,false)" :index="goodsItem.goodsIndex"
@chooseGuige="chooseGuige(goodsItem.goodsIndex,goodsItem.index)"
@add="searchGoodsUpdate(goodsItem,goodsIndex,true)"
@reduce="searchGoodsUpdate(goodsItem,goodsIndex,false)" :index="goodsItem.goodsIndex"
:data="goodsItem"></goods-item>
</view>
</view>
<my-img-empty v-if="!searchResult.length" tips="未搜索到相关商品"></my-img-empty>
</view>
</scroll-view>
@@ -122,6 +123,7 @@
<!-- 选择规格 -->
<guige-model @update-sku="updateSkuSel" @confirm="guigeConfirm" ref="chooseGuigeModel"
:goodsData="selGoods"
:title="guigeModelData.title" :sku-map="guigeModelData.chooseGoods.skuMap"
:skus="guigeModelData.chooseGoods.skus"></guige-model>
<!-- 添加附加费 -->
@@ -491,6 +493,10 @@
}
function search() {
if(searchValue.value===''){
isSearch.value = false
return
}
isSearch.value = true
searchResult.value = returnSearchGoods()
console.log(searchResult.value);
@@ -674,6 +680,8 @@
}
}
let selGoods=ref({})
function chooseGuige(foodsindex, index) {
if (!canAddGoods()) {
return infoBox.showToast('清先选择桌台', 0.5).then(res => {
@@ -681,6 +689,7 @@
})
}
const $goods = data.tabbar[index].foods[foodsindex]
selGoods.value=$goods
guigeModelData.title = $goods.name
const specList = $goods.specList;
const tagSnap = JSON.parse($goods.skuResult.tagSnap)
@@ -782,7 +791,16 @@
function canAddGoods() {
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()) {
return infoBox.showToast('请先选择桌台', 0.5).then(res => {
chooseTable()
@@ -807,6 +825,7 @@
//移除
cars.splice(goodsInCarIndex, 1)
$goods.chooseNumber = 0
setSearchGoods(searchGoodsIndex,0)
return await removeCartGoods({
cartId
})
@@ -821,6 +840,7 @@
})
carGoods.number = number
$goods.chooseNumber = number
setSearchGoods(searchGoodsIndex,number)
} else {
//增加
const num = suit