增加代客下单搜索联动
This commit is contained in:
parent
32ab68bfad
commit
54f824f2de
|
|
@ -58,7 +58,7 @@
|
|||
}
|
||||
},
|
||||
index: {
|
||||
type: Number,
|
||||
type: [Number,String],
|
||||
},
|
||||
isSeatFee:{
|
||||
//是否为餐位费
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
<template #btn>
|
||||
<view class="u-p-30 border-top ">
|
||||
<view class="u-flex u-p-b-30 u-row-between">
|
||||
<view class="price" >
|
||||
<view class="price">
|
||||
<template v-if="goods&&goods.isGrounding">
|
||||
<text>¥</text>
|
||||
<text>{{to2(goods.salePrice*number) }}</text>
|
||||
|
|
@ -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: ''
|
||||
|
|
@ -82,53 +89,72 @@
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
function to2(number){
|
||||
|
||||
function to2(number) {
|
||||
return Number(number).toFixed(2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
const selSku=computed(()=>{
|
||||
return props.skus.reduce((prve,cur)=>{
|
||||
|
||||
|
||||
|
||||
const selSku = computed(() => {
|
||||
return props.skus.reduce((prve, cur) => {
|
||||
prve.push(cur.sel)
|
||||
return prve
|
||||
},[]).join()
|
||||
}, []).join()
|
||||
})
|
||||
|
||||
|
||||
const goods=computed(()=>{
|
||||
|
||||
|
||||
const goods = computed(() => {
|
||||
return props.skuMap[selSku.value]
|
||||
})
|
||||
watch(()=>goods.value,(newval)=>{
|
||||
console.log(newval);
|
||||
number.value=newval.suit||1
|
||||
watch(() => goods.value, (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(()=>{
|
||||
const isAllDisabled = computed(() => {
|
||||
console.log(props.skus);
|
||||
return props.skus.reduce((prve,cur)=>{
|
||||
return prve&&cur.values.filter(v=>v.disabled).length===cur.values.length
|
||||
},true)
|
||||
return props.skus.reduce((prve, cur) => {
|
||||
return prve && cur.values.filter(v => v.disabled).length === cur.values.length
|
||||
}, true)
|
||||
})
|
||||
|
||||
const emits = defineEmits(['confirm','updateSku'])
|
||||
|
||||
const emits = defineEmits(['confirm', 'updateSku'])
|
||||
let number = ref(1)
|
||||
|
||||
|
||||
|
||||
|
||||
function chooseSkd(skusIndex, skd) {
|
||||
const {name,disabled}=skd
|
||||
if(disabled){
|
||||
const {
|
||||
name,
|
||||
disabled
|
||||
} = skd
|
||||
if (disabled) {
|
||||
return
|
||||
}
|
||||
if(props.skus[skusIndex].sel!=name){
|
||||
emits('updateSku',skusIndex,name)
|
||||
if (props.skus[skusIndex].sel != name) {
|
||||
emits('updateSku', skusIndex, name)
|
||||
}
|
||||
}
|
||||
const defaultIndex=reactive(new Array(props.skus.length).fill(''))
|
||||
for(let i in props.defaultIndex){
|
||||
defaultIndex[i]=props.defaultIndex[i]
|
||||
const defaultIndex = reactive(new Array(props.skus.length).fill(''))
|
||||
for (let i in props.defaultIndex) {
|
||||
defaultIndex[i] = props.defaultIndex[i]
|
||||
}
|
||||
const activeArr = defaultIndex
|
||||
|
||||
|
|
@ -143,37 +169,39 @@
|
|||
function close() {
|
||||
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
|
||||
const suit = goods.value.suit || 1
|
||||
const newval = number.value - 1
|
||||
if(newval<suit){
|
||||
return infobox.showToast(suit+'个起售')
|
||||
if (newval < suit) {
|
||||
return infobox.showToast(suit + '个起售')
|
||||
}
|
||||
number.value = newval <= 1 ? 1 : newval
|
||||
}
|
||||
|
||||
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)
|
||||
emits('confirm', goods.value, number.value)
|
||||
}
|
||||
defineExpose({
|
||||
open,
|
||||
|
|
@ -204,7 +232,8 @@
|
|||
border-color: $my-main-color;
|
||||
color: $my-main-color;
|
||||
}
|
||||
&.disabled{
|
||||
|
||||
&.disabled {
|
||||
color: #ccc;
|
||||
border-color: #eee;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
<!-- 添加附加费 -->
|
||||
|
|
@ -304,7 +306,7 @@
|
|||
masterId: data.masterId,
|
||||
tableId: data.table.tableId
|
||||
}) {
|
||||
const res= await Api.getCart(par)
|
||||
const res = await Api.getCart(par)
|
||||
return res
|
||||
}
|
||||
//获取取餐码
|
||||
|
|
@ -491,6 +493,10 @@
|
|||
}
|
||||
|
||||
function search() {
|
||||
if(searchValue.value===''){
|
||||
isSearch.value = false
|
||||
return
|
||||
}
|
||||
isSearch.value = true
|
||||
searchResult.value = returnSearchGoods()
|
||||
console.log(searchResult.value);
|
||||
|
|
@ -673,7 +679,9 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
|
|
@ -744,8 +753,8 @@
|
|||
const tabbarIndex = data.tabbar.findIndex(v => v.id == categoryId)
|
||||
const $goods = data.tabbar[tabbarIndex].foods.find(v => v.id == productId)
|
||||
const $sku = $goods.specList.find(v => v.id == skuId)
|
||||
|
||||
if (num === 0||num<$sku.suit) {
|
||||
|
||||
if (num === 0 || num < $sku.suit) {
|
||||
//移除
|
||||
await removeCartGoods({
|
||||
cartId
|
||||
|
|
@ -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()
|
||||
|
|
@ -796,17 +814,18 @@
|
|||
});
|
||||
const productId = $goods.id
|
||||
const skuId = $goods.specList[0].id
|
||||
const suit=$goods.specList[0].suit||1
|
||||
const suit = $goods.specList[0].suit || 1
|
||||
if (goodsInCarIndex !== -1) {
|
||||
//更新
|
||||
const carGoods = cars[goodsInCarIndex]
|
||||
const cartId = carGoods.id
|
||||
const step = isAdd ? 1 : -1
|
||||
const num = carGoods.number * 1 + step
|
||||
if (num === 0||num<suit) {
|
||||
if (num === 0 || num < suit) {
|
||||
//移除
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue