|
|
|
|
@@ -113,32 +113,12 @@
|
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
|
import {
|
|
|
|
|
onLoad,
|
|
|
|
|
onReady,
|
|
|
|
|
onShow,
|
|
|
|
|
onPageScroll,
|
|
|
|
|
onPullDownRefresh
|
|
|
|
|
} from '@dcloudio/uni-app';
|
|
|
|
|
import {
|
|
|
|
|
computed,
|
|
|
|
|
reactive,
|
|
|
|
|
ref,
|
|
|
|
|
nextTick,
|
|
|
|
|
watch,
|
|
|
|
|
getCurrentInstance,
|
|
|
|
|
onUnmounted,
|
|
|
|
|
onBeforeUnmount,
|
|
|
|
|
} from 'vue';
|
|
|
|
|
import { onLoad, onReady, onShow } from '@dcloudio/uni-app';
|
|
|
|
|
import { computed, reactive, ref, nextTick, watch, getCurrentInstance, onUnmounted, onBeforeUnmount } from 'vue';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import * as Api from '@/http/yskApi/Instead.js'
|
|
|
|
|
import {
|
|
|
|
|
$table,
|
|
|
|
|
$choseTable,
|
|
|
|
|
$returnTableDetail
|
|
|
|
|
} from '@/http/yskApi/table.js'
|
|
|
|
|
import {
|
|
|
|
|
$tbShopCategory
|
|
|
|
|
@@ -231,10 +211,7 @@
|
|
|
|
|
type: ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const websocket = ref(null);
|
|
|
|
|
onLoad((opt) => {
|
|
|
|
|
// console.log(opt)
|
|
|
|
|
option = opt
|
|
|
|
|
Object.assign(data.table, opt)
|
|
|
|
|
if (opt.useType) {
|
|
|
|
|
@@ -246,12 +223,6 @@
|
|
|
|
|
if (JSON.stringify(opt) == '{}') {
|
|
|
|
|
isCreateOrderToDetail.value = true
|
|
|
|
|
}
|
|
|
|
|
// if (!opt.tableId) {
|
|
|
|
|
// infoBox.showErrorToast('暂不支持不选择桌台下载,请从桌台点餐')
|
|
|
|
|
// return setTimeout(() => {
|
|
|
|
|
// go.back()
|
|
|
|
|
// }, 1500)
|
|
|
|
|
// }
|
|
|
|
|
init()
|
|
|
|
|
})
|
|
|
|
|
watch(() => data.table.id, (newval, oldval) => {
|
|
|
|
|
@@ -272,16 +243,11 @@
|
|
|
|
|
getMenuItemTop()
|
|
|
|
|
})
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
if (websocket.value) {
|
|
|
|
|
// websocket.value.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 组件卸载时清理WebSocket
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
if (websocket.value) {
|
|
|
|
|
websocket.value.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
let $originGoods = []
|
|
|
|
|
let $category = []
|
|
|
|
|
@@ -298,43 +264,26 @@
|
|
|
|
|
await getTableInfo()
|
|
|
|
|
|
|
|
|
|
// 获取分类数据
|
|
|
|
|
const categoryRes = await categoryPage({ page: 1, size: 300 })
|
|
|
|
|
const category = categoryRes.records;
|
|
|
|
|
$category = category
|
|
|
|
|
let categoryRes = await categoryPage({ page: 1, size: 300 })
|
|
|
|
|
$category = categoryRes.records
|
|
|
|
|
// 获取商品数据
|
|
|
|
|
const goodsRes = await getGoods()
|
|
|
|
|
const goods = goodsRes.records.filter((v) => {
|
|
|
|
|
let isShow = true;
|
|
|
|
|
if (v.type !== "sku") {
|
|
|
|
|
if (v.type != "sku") {
|
|
|
|
|
isShow = v.skuList.length >= 1;
|
|
|
|
|
}
|
|
|
|
|
return isShow;
|
|
|
|
|
});
|
|
|
|
|
$originGoods = goods
|
|
|
|
|
$originGoods = goods;
|
|
|
|
|
|
|
|
|
|
if (option.type == 'add') {
|
|
|
|
|
cars.length = 0
|
|
|
|
|
setTabBar(category, goods, [])
|
|
|
|
|
setTabBar($category, goods, [])
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (!data.table.id) {
|
|
|
|
|
//无桌台
|
|
|
|
|
// const cartRes = await getCart()
|
|
|
|
|
// cars.length = 0
|
|
|
|
|
// const cartArr = getNowCart(cartRes.records)
|
|
|
|
|
// for (let i in cartArr) {
|
|
|
|
|
// cars.push(cartArr[i])
|
|
|
|
|
// }
|
|
|
|
|
// setTabBar(category, goods, cars)
|
|
|
|
|
// return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// const cartRes = await getCart()
|
|
|
|
|
// cars.length = 0
|
|
|
|
|
// const cartArr = getNowCart(cartRes.records)
|
|
|
|
|
// for (let i in cartArr) {
|
|
|
|
|
// cars.push(cartArr[i])
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
setTabBar(category, goods, cars)
|
|
|
|
|
setTabBar($category, goods, cars)
|
|
|
|
|
initCart()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -345,7 +294,7 @@
|
|
|
|
|
websocketUtil.onMessage(res => {
|
|
|
|
|
let msg = JSON.parse(res);
|
|
|
|
|
let cartItem;
|
|
|
|
|
|
|
|
|
|
console.log(msg)
|
|
|
|
|
if( msg.msg_id ){
|
|
|
|
|
// console.log('Received data:', msg);
|
|
|
|
|
websocketUtil.send(JSON.stringify({
|
|
|
|
|
@@ -362,28 +311,95 @@
|
|
|
|
|
cars.length = 0
|
|
|
|
|
msg.data.map(item=>{
|
|
|
|
|
cartItem = getNowCart(item,$originGoods)
|
|
|
|
|
cars.push(cartItem)
|
|
|
|
|
cartControls(cartItem,'add')
|
|
|
|
|
})
|
|
|
|
|
break;
|
|
|
|
|
case 'onboc_add':
|
|
|
|
|
console.log("onboc_add")
|
|
|
|
|
case 'add':
|
|
|
|
|
cartItem = getNowCart(msg.data,$originGoods)
|
|
|
|
|
cars.push(cartItem)
|
|
|
|
|
cartControls(cartItem,'add')
|
|
|
|
|
break;
|
|
|
|
|
case 'onboc_edit':
|
|
|
|
|
case 'edit':
|
|
|
|
|
cartItem = getNowCart(msg.data,$originGoods)
|
|
|
|
|
cartControls(cartItem,'edit')
|
|
|
|
|
break;
|
|
|
|
|
case 'onboc_del':
|
|
|
|
|
case 'del':
|
|
|
|
|
cartItem = getNowCart(msg.data,$originGoods)
|
|
|
|
|
cartControls(cartItem,'del')
|
|
|
|
|
break;
|
|
|
|
|
case 'onboc_cleanup':
|
|
|
|
|
case 'cleanup':
|
|
|
|
|
cars.length = 0
|
|
|
|
|
for (let i in data.tabbar) {
|
|
|
|
|
for (let k in data.tabbar[i].foods) {
|
|
|
|
|
data.tabbar[i].foods[k].chooseNumber = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(data.tabbar)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化购物车
|
|
|
|
|
*/
|
|
|
|
|
function initCart () {
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
operate_type:'init',
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
}
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 购物车添加菜品
|
|
|
|
|
*/
|
|
|
|
|
function editCart (par,operate_type) {
|
|
|
|
|
console.log('购物车添加菜品',par)
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
operate_type: operate_type,
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
product_id: '',
|
|
|
|
|
sku_id: '', //
|
|
|
|
|
number: 1, //数量
|
|
|
|
|
is_temporary: 0, //是否是临时菜
|
|
|
|
|
}
|
|
|
|
|
Object.assign(params, par)
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除购物车菜品
|
|
|
|
|
*/
|
|
|
|
|
function delCart (id) {
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
id: id,
|
|
|
|
|
operate_type:'del',
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
}
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清除购物车
|
|
|
|
|
*/
|
|
|
|
|
function cleaCart () {
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
operate_type:'cleanup',
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
}
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取商品列表
|
|
|
|
|
@@ -463,62 +479,6 @@
|
|
|
|
|
data.table = item
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化购物车
|
|
|
|
|
*/
|
|
|
|
|
function initCart () {
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
operate_type:'init',
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
}
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 购物车添加菜品
|
|
|
|
|
*/
|
|
|
|
|
function editCart (par,operate_type) {
|
|
|
|
|
console.log('购物车添加菜品',par)
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
operate_type: operate_type,
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
product_id: '',
|
|
|
|
|
sku_id: '', //
|
|
|
|
|
number: 1, //数量
|
|
|
|
|
is_temporary: 0, //是否是临时菜
|
|
|
|
|
}
|
|
|
|
|
Object.assign(params, par)
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除购物车菜品
|
|
|
|
|
*/
|
|
|
|
|
function delCart (id) {
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
id: id,
|
|
|
|
|
operate_type:'del',
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
}
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清除购物车
|
|
|
|
|
*/
|
|
|
|
|
function cleaCart () {
|
|
|
|
|
let params = {
|
|
|
|
|
...data.socketData,
|
|
|
|
|
operate_type:'cleanup',
|
|
|
|
|
table_code: data.table.tableCode,
|
|
|
|
|
}
|
|
|
|
|
websocketUtil.send(JSON.stringify(params))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 菜品操作
|
|
|
|
|
* @param {Object} foodsindex
|
|
|
|
|
@@ -533,49 +493,41 @@
|
|
|
|
|
chooseTable()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const $goods = data.tabbar[index].foods[foodsindex]
|
|
|
|
|
let $goods = data.tabbar[index].foods[foodsindex]
|
|
|
|
|
if ($goods.type !== 'sku') {
|
|
|
|
|
//单规格
|
|
|
|
|
console.log($goods)
|
|
|
|
|
const goodsInCarIndex = cars.findIndex((carsGoods) => {
|
|
|
|
|
let goodsInCarIndex = cars.findIndex((carsGoods) => {
|
|
|
|
|
return carsGoods.sku_id == $goods.skuList[0].id && carsGoods.product_id == $goods.id;
|
|
|
|
|
});
|
|
|
|
|
const product_id = $goods.id
|
|
|
|
|
const sku_id = $goods.skuList[0].id
|
|
|
|
|
let product_id = $goods.id
|
|
|
|
|
let sku_id = $goods.skuList[0].id
|
|
|
|
|
let suitNum = $goods.skuList[0].suitNum || 1
|
|
|
|
|
if (goodsInCarIndex !== -1) {
|
|
|
|
|
//更新
|
|
|
|
|
const carGoods = cars[goodsInCarIndex]
|
|
|
|
|
const cartId = carGoods.id
|
|
|
|
|
// const step = isAdd ? 1 : -1
|
|
|
|
|
// $sku = !product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == sku_id)
|
|
|
|
|
let num = isAdd ? carGoods.number + 1 : + carGoods.number - 1
|
|
|
|
|
let cartItem = cars[goodsInCarIndex]
|
|
|
|
|
let number = isAdd ? cartItem.number + 1 : + cartItem.number - 1
|
|
|
|
|
if( !isAdd ){
|
|
|
|
|
if (num === 0 || num < suitNum) {
|
|
|
|
|
if (number === 0 || number < suitNum) {
|
|
|
|
|
//移除
|
|
|
|
|
cars.splice(goodsInCarIndex, 1)
|
|
|
|
|
$goods.chooseNumber = 0
|
|
|
|
|
setSearchGoods(searchGoodsIndex, 0)
|
|
|
|
|
delCart(cartId)
|
|
|
|
|
delCart(cartItem.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 不影响之前的代码 称重num单独处理
|
|
|
|
|
// 不影响之前的代码 称重number单独处理
|
|
|
|
|
if ($goods.type == 'weigh' && showCurrentInput) {
|
|
|
|
|
num = carGoods.number * 1 + Number(showCurrentInput)
|
|
|
|
|
number = cartItem.number * 1 + Number(showCurrentInput)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
editCart({
|
|
|
|
|
id: cartId,
|
|
|
|
|
number: num,
|
|
|
|
|
id: cartItem.id,
|
|
|
|
|
number: number,
|
|
|
|
|
product_id: product_id,
|
|
|
|
|
sku_id: sku_id,
|
|
|
|
|
},'edit')
|
|
|
|
|
carGoods.number = num
|
|
|
|
|
$goods.chooseNumber = num
|
|
|
|
|
setSearchGoods(searchGoodsIndex, num)
|
|
|
|
|
setSearchGoods(searchGoodsIndex, number)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(suitNum)
|
|
|
|
|
// 不影响之前的代码 称重suit单独处理
|
|
|
|
|
if ($goods.type == 'weigh' && showCurrentInput) {
|
|
|
|
|
suitNum = showCurrentInput
|
|
|
|
|
@@ -587,10 +539,8 @@
|
|
|
|
|
number: suitNum,
|
|
|
|
|
product_id: product_id,
|
|
|
|
|
sku_id: sku_id,
|
|
|
|
|
discount_sale_amount: $goods.lowPrice
|
|
|
|
|
},'add')
|
|
|
|
|
infoBox.showToast('添加成功')
|
|
|
|
|
$goods.chooseNumber = Number(suitNum)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
@@ -598,6 +548,86 @@
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* socket通知购物车商品数量修改处理
|
|
|
|
|
*/
|
|
|
|
|
function cartControls (cartItem,type) {
|
|
|
|
|
let cartIndex = 0;
|
|
|
|
|
let product_id = cartItem.product_id
|
|
|
|
|
let sku_id = cartItem.sku_id
|
|
|
|
|
let $goods;
|
|
|
|
|
cars.map((item,index)=>{
|
|
|
|
|
if(item.id == cartItem.id) {
|
|
|
|
|
cartIndex = index;
|
|
|
|
|
product_id = item.product_id
|
|
|
|
|
sku_id = item.sku_id
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
data.tabbar.map(tabbarItem=>{
|
|
|
|
|
if(tabbarItem.foods.find(v => v.id == product_id)){
|
|
|
|
|
$goods = !product_id ? undefined : tabbarItem.foods.find(v => v.id == product_id)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let $sku;
|
|
|
|
|
if( $goods.type != 'package'){
|
|
|
|
|
//临时菜没有skuList
|
|
|
|
|
$sku = !product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == sku_id)
|
|
|
|
|
} else {
|
|
|
|
|
$sku = !product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == sku_id)
|
|
|
|
|
}
|
|
|
|
|
if( type == 'del' ) {
|
|
|
|
|
cars.splice(cartIndex, 1)
|
|
|
|
|
$goods.chooseNumber = 0
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if( type == 'add' ){
|
|
|
|
|
cars.push(cartItem)
|
|
|
|
|
$goods.chooseNumber = cartItem.number
|
|
|
|
|
}
|
|
|
|
|
if( type == 'edit' ){
|
|
|
|
|
cars[cartIndex].number = cartItem.number
|
|
|
|
|
if ($goods) {
|
|
|
|
|
$goods.chooseNumber = cartItem.number
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(cars)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 购物车商品数量改变处理
|
|
|
|
|
* @param {Object} e
|
|
|
|
|
*/
|
|
|
|
|
async function carsNumberChange(e) {
|
|
|
|
|
console.log("carsNumberChange===",e)
|
|
|
|
|
let $sku;
|
|
|
|
|
let $goods;
|
|
|
|
|
data.tabbar.map(tabbarItem=>{
|
|
|
|
|
if(tabbarItem.foods.find(v => v.id == e.goods.product_id)){
|
|
|
|
|
$goods = !e.goods.product_id ? undefined : tabbarItem.foods.find(v => v.id == e.goods.product_id)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if( $goods.type != 'package'){
|
|
|
|
|
//临时菜没有skuList
|
|
|
|
|
$sku = !e.goods.product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == e.goods.sku_id)
|
|
|
|
|
} else {
|
|
|
|
|
$sku = !e.goods.product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == e.goods.sku_id)
|
|
|
|
|
}
|
|
|
|
|
if (e.num === 0 || e.num < $sku.suitNum) {
|
|
|
|
|
//移除
|
|
|
|
|
delCart(e.goods.id)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
editCart({
|
|
|
|
|
number: e.num,
|
|
|
|
|
id: e.goods.id,
|
|
|
|
|
product_id: e.goods.product_id,
|
|
|
|
|
sku_id: e.goods.sku_id
|
|
|
|
|
},'edit')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加套餐
|
|
|
|
|
* @param {Object} d
|
|
|
|
|
@@ -610,7 +640,6 @@
|
|
|
|
|
product_id: item.id,
|
|
|
|
|
sku_id: item.skuList[0].id,
|
|
|
|
|
pro_group_info: JSON.stringify(d),
|
|
|
|
|
discount_sale_amount: item.lowPrice
|
|
|
|
|
},'add')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -655,17 +684,16 @@
|
|
|
|
|
/**
|
|
|
|
|
* 多规格选择
|
|
|
|
|
* @param {Object} skuList
|
|
|
|
|
* @param {Object} specSnap
|
|
|
|
|
*/
|
|
|
|
|
function returnSelGoodsSkuList(selectSpecInfo) {
|
|
|
|
|
let specSnap = []
|
|
|
|
|
let specInfo = []
|
|
|
|
|
for (var key in selectSpecInfo) {
|
|
|
|
|
specSnap.push({
|
|
|
|
|
specInfo.push({
|
|
|
|
|
name: key,
|
|
|
|
|
value: selectSpecInfo[key]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
let result = specSnap.map((v, index) => {
|
|
|
|
|
let result = specInfo.map((v, index) => {
|
|
|
|
|
return {
|
|
|
|
|
...v,
|
|
|
|
|
valueArr: v.value,
|
|
|
|
|
@@ -686,40 +714,33 @@
|
|
|
|
|
* @param {Object} sku
|
|
|
|
|
* @param {Object} num
|
|
|
|
|
*/
|
|
|
|
|
async function guigeConfirm(sku, num) {
|
|
|
|
|
const goods = guigeModelData.chooseGoods.item
|
|
|
|
|
const skuId = sku.id
|
|
|
|
|
const productId = goods.id
|
|
|
|
|
const res = findGoodsInCar(goods, skuId)
|
|
|
|
|
async function guigeConfirm(sku, suitNum) {
|
|
|
|
|
console.log(sku)
|
|
|
|
|
let goods = guigeModelData.chooseGoods.item
|
|
|
|
|
let sku_id = sku.id
|
|
|
|
|
let product_id = goods.id
|
|
|
|
|
let res = findGoodsInCar(goods, sku_id)
|
|
|
|
|
if (res) {
|
|
|
|
|
//更新
|
|
|
|
|
const {
|
|
|
|
|
index
|
|
|
|
|
} = res
|
|
|
|
|
const carGoods = cars[index]
|
|
|
|
|
const cartId = carGoods.id
|
|
|
|
|
const newNumber = carGoods.number * 1 + num
|
|
|
|
|
const {
|
|
|
|
|
number
|
|
|
|
|
} = await updateCartGoods({
|
|
|
|
|
num: newNumber,
|
|
|
|
|
cartId,
|
|
|
|
|
productId,
|
|
|
|
|
skuId
|
|
|
|
|
})
|
|
|
|
|
carGoods.number = number
|
|
|
|
|
let { index } = res
|
|
|
|
|
let carGoods = cars[index]
|
|
|
|
|
let cartId = carGoods.id
|
|
|
|
|
let newNumber = carGoods.number * 1 + suitNum
|
|
|
|
|
|
|
|
|
|
editCart({
|
|
|
|
|
id: cartId,
|
|
|
|
|
number: newNumber,
|
|
|
|
|
product_id: product_id,
|
|
|
|
|
sku_id: sku_id,
|
|
|
|
|
},'add')
|
|
|
|
|
} else {
|
|
|
|
|
//添加
|
|
|
|
|
const cartGoods = await addCart({
|
|
|
|
|
num,
|
|
|
|
|
productId,
|
|
|
|
|
skuId
|
|
|
|
|
})
|
|
|
|
|
editCart({
|
|
|
|
|
number: suitNum,
|
|
|
|
|
product_id: product_id,
|
|
|
|
|
sku_id: sku_id,
|
|
|
|
|
},'add')
|
|
|
|
|
infoBox.showToast('添加成功')
|
|
|
|
|
cars.push({
|
|
|
|
|
...cartGoods,
|
|
|
|
|
specSnap: sku.specSnap
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -742,24 +763,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//多规格商品弹窗时,找到默认可以下单的规格商品
|
|
|
|
|
function findGoods(skuList = [], goodsListMap = {}, specList) {
|
|
|
|
|
const skuMapNumber = skuList.reduce((prve, cur) => {
|
|
|
|
|
function findGoods(selectSpecInfo = [], goodsListMap = {}, skuList) {
|
|
|
|
|
let skuMapNumber = selectSpecInfo.reduce((prve, cur) => {
|
|
|
|
|
for (let i in cur.valueArr) {
|
|
|
|
|
prve[cur.valueArr[i]] = i;
|
|
|
|
|
}
|
|
|
|
|
return prve;
|
|
|
|
|
}, {});
|
|
|
|
|
const canBudyGoods = specList
|
|
|
|
|
.filter((v) => util.isCanBuy(v, guigeModelData.chooseGoods.item))
|
|
|
|
|
.sort((a, b) => {
|
|
|
|
|
const aNumber = a.specSnap.split(",").reduce((prve, cur) => {
|
|
|
|
|
return prve + skuMapNumber[cur];
|
|
|
|
|
}, 0);
|
|
|
|
|
const bNumber = b.specSnap.split(",").reduce((prve, cur) => {
|
|
|
|
|
return prve + skuMapNumber[cur];
|
|
|
|
|
}, 0);
|
|
|
|
|
return aNumber - bNumber;
|
|
|
|
|
});
|
|
|
|
|
console.log("selectSpecInfo",selectSpecInfo)
|
|
|
|
|
console.log("skuMapNumber",guigeModelData.chooseGoods.item)
|
|
|
|
|
let canBudyGoods = skuList.filter((v) => util.isCanBuy(v, guigeModelData.chooseGoods.item))
|
|
|
|
|
console.log("canBudyGoods",canBudyGoods)
|
|
|
|
|
return canBudyGoods[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -768,17 +782,16 @@
|
|
|
|
|
* @param {Object} goods
|
|
|
|
|
* @param {Object} selectSpecInfo
|
|
|
|
|
* @param {Object} skuMap
|
|
|
|
|
* @param {Object} specList
|
|
|
|
|
* @param {Object} skuList
|
|
|
|
|
*/
|
|
|
|
|
function setSkugoodsDefaultInit(goods, selectSpecInfo, skuMap, specList) {
|
|
|
|
|
function setSkugoodsDefaultInit(goods, selectSpecInfo, skuMap, skuList) {
|
|
|
|
|
guigeModelData.chooseGoods.item = goods
|
|
|
|
|
guigeModelData.chooseGoods.skus = selectSpecInfo
|
|
|
|
|
guigeModelData.chooseGoods.skuMap = skuMap
|
|
|
|
|
const skuGoods = findGoods(selectSpecInfo, skuMap, specList);
|
|
|
|
|
const skuGoods = findGoods(selectSpecInfo, skuMap, skuList);
|
|
|
|
|
if (skuGoods) {
|
|
|
|
|
// this.skuGoods.data = skuGoods;
|
|
|
|
|
// this.skuGoods.number = skuGoods.suit || 1;
|
|
|
|
|
skuGoods.specSnap.split(",").map((v, index) => {
|
|
|
|
|
|
|
|
|
|
skuGoods.specInfo.split(",").map((v, index) => {
|
|
|
|
|
guigeModelData.chooseGoods.skus[index].sel = v;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@@ -791,7 +804,7 @@
|
|
|
|
|
const skuList = guigeModelData.chooseGoods.skus
|
|
|
|
|
const skuMap = guigeModelData.chooseGoods.skuMap
|
|
|
|
|
guigeModelData.chooseGoods.skus[skusIndex].sel = skdName
|
|
|
|
|
const specSnap = guigeModelData.chooseGoods.skus.reduce((prve, cur) => {
|
|
|
|
|
const specInfo = guigeModelData.chooseGoods.skus.reduce((prve, cur) => {
|
|
|
|
|
prve.push(cur.sel)
|
|
|
|
|
return prve
|
|
|
|
|
}, []).join()
|
|
|
|
|
@@ -809,13 +822,12 @@
|
|
|
|
|
return prve;
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
console.log(selArr);
|
|
|
|
|
let selArrAllGroup = util.generateCombinations(selArr, selArr.length - 1);
|
|
|
|
|
console.log(selArrAllGroup);
|
|
|
|
|
const matchArr = [];
|
|
|
|
|
for (let key in skuMap) {
|
|
|
|
|
const goods = skuMap[key];
|
|
|
|
|
const keyArr = key.split(",");
|
|
|
|
|
let goods = skuMap[key];
|
|
|
|
|
console.log(key)
|
|
|
|
|
let keyArr = key.split(",");
|
|
|
|
|
for (let spe of selArrAllGroup) {
|
|
|
|
|
if (util.arrayContainsAll(keyArr, spe)) {
|
|
|
|
|
matchArr.push(goods);
|
|
|
|
|
@@ -823,6 +835,7 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(matchArr);
|
|
|
|
|
//全部规格都已下架
|
|
|
|
|
if (!matchArr.length) {
|
|
|
|
|
for (let k in skuList) {
|
|
|
|
|
@@ -833,11 +846,11 @@
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const includeSkuMap = matchArr.reduce((prve, cur) => {
|
|
|
|
|
const speArr = cur.specSnap.split(",");
|
|
|
|
|
const speArr = cur.specInfo.split(",");
|
|
|
|
|
for (let i of speArr) {
|
|
|
|
|
if (!prve.hasOwnProperty("i")) {
|
|
|
|
|
prve[i] = matchArr
|
|
|
|
|
.filter((v) => v.specSnap.match(i))
|
|
|
|
|
.filter((v) => v.specInfo.match(i))
|
|
|
|
|
.every((v) => {
|
|
|
|
|
return !util.isCanBuy(v, guigeModelData.chooseGoods.item)
|
|
|
|
|
});
|
|
|
|
|
@@ -854,53 +867,7 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 购物车商品数量改变
|
|
|
|
|
* @param {Object} e
|
|
|
|
|
*/
|
|
|
|
|
async function carsNumberChange(e) {
|
|
|
|
|
const { num, index, goods } = e
|
|
|
|
|
const { product_id, categoryId, sku_id } = goods
|
|
|
|
|
const cartId = goods.id
|
|
|
|
|
//临时菜没有对应商品数据
|
|
|
|
|
let $goods;
|
|
|
|
|
data.tabbar.map(tabbarItem=>{
|
|
|
|
|
if(tabbarItem.foods.find(v => v.id == product_id)){
|
|
|
|
|
$goods = !product_id ? undefined : tabbarItem.foods.find(v => v.id == product_id)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
let $sku;
|
|
|
|
|
if( $goods.type != 'package'){
|
|
|
|
|
//临时菜没有skuList
|
|
|
|
|
$sku = !product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == sku_id)
|
|
|
|
|
} else {
|
|
|
|
|
$sku = !product_id ? { suitNum: 1 } : $goods.skuList.find(v => v.id == sku_id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(num)
|
|
|
|
|
console.log($sku.suitNum)
|
|
|
|
|
if (num === 0 || num < $sku.suitNum) {
|
|
|
|
|
//移除
|
|
|
|
|
delCart(cartId)
|
|
|
|
|
cars.splice(index, 1)
|
|
|
|
|
$goods.chooseNumber = 0
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
editCart({
|
|
|
|
|
number: num,
|
|
|
|
|
id: cartId,
|
|
|
|
|
product_id: product_id,
|
|
|
|
|
sku_id: sku_id
|
|
|
|
|
},'edit')
|
|
|
|
|
cars[index].number = num
|
|
|
|
|
if ($goods) {
|
|
|
|
|
$goods.chooseNumber = num
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1292,12 +1259,8 @@
|
|
|
|
|
|
|
|
|
|
function watchUpdate() {
|
|
|
|
|
uni.$off('update:createOrderIndex')
|
|
|
|
|
uni.$off('get:table')
|
|
|
|
|
uni.$off('add:cashCai')
|
|
|
|
|
uni.$on('update:createOrderIndex', () => {
|
|
|
|
|
// data.table = {
|
|
|
|
|
// tableId: ""
|
|
|
|
|
// }
|
|
|
|
|
cars.length = 0
|
|
|
|
|
console.log('update:createOrderIndex');
|
|
|
|
|
init()
|
|
|
|
|
@@ -1309,20 +1272,7 @@
|
|
|
|
|
$originGoods.push(data)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
uni.$on('get:table', () => {
|
|
|
|
|
console.log('get:table');
|
|
|
|
|
if (data.table.id) {
|
|
|
|
|
$table.get({
|
|
|
|
|
qrcode: data.table.id
|
|
|
|
|
}).then(res => {
|
|
|
|
|
if (res.content[0] && res.content[0].status != 'idle') {
|
|
|
|
|
data.table = {
|
|
|
|
|
tableId: ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|