增加代客下单页面
This commit is contained in:
parent
e08a2eb4b7
commit
f961bf7d92
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
基于 Vue3 + Vite5+ TypeScript5 + Element-Plus + Pinia 等主流技术栈构建
|
||||
|
||||
## 宝塔
|
||||
|
||||
101.37.12.135:19928/mianban
|
||||
chaozg
|
||||
chaozg123
|
||||
|
||||
## API文档
|
||||
|
||||
[超掌柜收银机](https://app.apifox.com/project/5827475)
|
||||
|
|
|
|||
|
|
@ -55,4 +55,306 @@ export interface Responseres {
|
|||
[property: string]: any;
|
||||
}
|
||||
|
||||
export default AuthAPI;
|
||||
export default AuthAPI;
|
||||
|
||||
|
||||
export interface Response {
|
||||
code: number;
|
||||
data: Data;
|
||||
msg: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
pageNumber: string;
|
||||
pageSize: string;
|
||||
records: Record[];
|
||||
totalPage: string;
|
||||
totalRow: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export interface Record {
|
||||
/**
|
||||
* 分类id
|
||||
*/
|
||||
categoryId: string;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
categoryName: string;
|
||||
/**
|
||||
* 封面图url
|
||||
*/
|
||||
coverImg: string;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
createTime: string;
|
||||
/**
|
||||
* 定时上下架周期
|
||||
*/
|
||||
days: string;
|
||||
/**
|
||||
* 起用结束时间
|
||||
*/
|
||||
endTime: string;
|
||||
/**
|
||||
* 团购卷分类,可有多个分类
|
||||
*/
|
||||
groupCategoryId: string;
|
||||
/**
|
||||
* 套餐内容
|
||||
*/
|
||||
groupSnap: GroupSnap[];
|
||||
/**
|
||||
* 套餐类型,0 固定套餐 1可选套餐
|
||||
*/
|
||||
groupType: number;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 封面图urls
|
||||
*/
|
||||
images: string[];
|
||||
/**
|
||||
* 是否允许临时改价
|
||||
*/
|
||||
isAllowTempModifyPrice: number;
|
||||
/**
|
||||
* 是否逻辑删除
|
||||
*/
|
||||
isDel: number;
|
||||
/**
|
||||
* 是否推荐
|
||||
*/
|
||||
isHot: number;
|
||||
/**
|
||||
* 退款是否退回库存
|
||||
*/
|
||||
isRefundStock: number;
|
||||
/**
|
||||
* 是否上架
|
||||
*/
|
||||
isSale: number;
|
||||
/**
|
||||
* 是否售罄
|
||||
*/
|
||||
isSoldStock: number;
|
||||
/**
|
||||
* 是否启用库存
|
||||
*/
|
||||
isStock: number;
|
||||
/**
|
||||
* 会员最低价
|
||||
*/
|
||||
lowMemberPrice: number;
|
||||
/**
|
||||
* 商品最低价
|
||||
*/
|
||||
lowPrice: number;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 打包费
|
||||
*/
|
||||
packFee: number;
|
||||
/**
|
||||
* 套餐详情入参使用
|
||||
*/
|
||||
proGroupVo: string[];
|
||||
selectSpecInfo: { [key: string]: any };
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
shopId: string;
|
||||
/**
|
||||
* 商品介绍
|
||||
*/
|
||||
shortTitle: string;
|
||||
/**
|
||||
* sku集合
|
||||
*/
|
||||
skuList: SkuList[];
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
sort: number;
|
||||
/**
|
||||
* 规格完整名称
|
||||
*/
|
||||
specFullName: string;
|
||||
/**
|
||||
* 规格id
|
||||
*/
|
||||
specId: null;
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
specName: string;
|
||||
/**
|
||||
* 起用开始时间
|
||||
*/
|
||||
startTime: string;
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
stockNumber: number;
|
||||
/**
|
||||
* 商品类型,single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* 单位id
|
||||
*/
|
||||
unitId: string;
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
unitName: string;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
updateTime: string;
|
||||
/**
|
||||
* 库存警戒线
|
||||
*/
|
||||
warnLine: number;
|
||||
/**
|
||||
* 重量
|
||||
*/
|
||||
weight?: number;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export interface GroupSnap {
|
||||
/**
|
||||
* 套餐内商品总数
|
||||
*/
|
||||
count: number;
|
||||
/**
|
||||
* 套餐内商品列表
|
||||
*/
|
||||
goods: Good[];
|
||||
/**
|
||||
* 可选套餐几选几,固定套餐没有值
|
||||
*/
|
||||
number: number;
|
||||
/**
|
||||
* 可选套餐名称
|
||||
*/
|
||||
title: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export interface Good {
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
number: string;
|
||||
/**
|
||||
* 商品单价
|
||||
*/
|
||||
price: number;
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
proId: number;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
proName: string;
|
||||
/**
|
||||
* skuId
|
||||
*/
|
||||
skuId: number;
|
||||
/**
|
||||
* sku名称
|
||||
*/
|
||||
skuName: string;
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
unitName: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export interface SkuList {
|
||||
/**
|
||||
* 条形码
|
||||
*/
|
||||
barCode: string;
|
||||
/**
|
||||
* 成本价
|
||||
*/
|
||||
costPrice: number;
|
||||
/**
|
||||
* 封面图
|
||||
*/
|
||||
coverImg: string;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
createTime: string;
|
||||
/**
|
||||
* sku-id
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 是否已删除
|
||||
*/
|
||||
isDel: number;
|
||||
/**
|
||||
* 是否上架
|
||||
*/
|
||||
isGrounding: number;
|
||||
/**
|
||||
* 是否售罄
|
||||
*/
|
||||
isPauseSale: number;
|
||||
/**
|
||||
* 会员价
|
||||
*/
|
||||
memberPrice: number;
|
||||
/**
|
||||
* 原价
|
||||
*/
|
||||
originPrice: number;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
productId: string;
|
||||
/**
|
||||
* 销量
|
||||
*/
|
||||
realSalesNumber: number;
|
||||
/**
|
||||
* 售价
|
||||
*/
|
||||
salePrice: number;
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
shopId: string;
|
||||
/**
|
||||
* 规格详情
|
||||
*/
|
||||
specInfo: string;
|
||||
/**
|
||||
* 起售数量
|
||||
*/
|
||||
suitNum: number;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
updateTime: string;
|
||||
/**
|
||||
* 重量
|
||||
*/
|
||||
weight: null;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
|
@ -181,27 +181,25 @@ onMounted(() => {
|
|||
// NoticeAPI.getMyNoticePage({ pageNum: 1, pageSize: 5, isRead: 0 }).then((data) => {
|
||||
// notices.value = data.list;
|
||||
// });
|
||||
|
||||
WebSocketManager.subscribeToTopic("/user/queue/message", (message) => {
|
||||
console.log("收到消息:", message);
|
||||
const data = JSON.parse(message);
|
||||
const id = data.id;
|
||||
if (!notices.value.some((notice) => notice.id == id)) {
|
||||
notices.value.unshift({
|
||||
id,
|
||||
title: data.title,
|
||||
type: data.type,
|
||||
publishTime: data.publishTime,
|
||||
});
|
||||
|
||||
ElNotification({
|
||||
title: "您收到一条新的通知消息!",
|
||||
message: data.title,
|
||||
type: "success",
|
||||
position: "bottom-right",
|
||||
});
|
||||
}
|
||||
});
|
||||
// WebSocketManager.subscribeToTopic("/user/queue/message", (message) => {
|
||||
// console.log("收到消息:", message);
|
||||
// const data = JSON.parse(message);
|
||||
// const id = data.id;
|
||||
// if (!notices.value.some((notice) => notice.id == id)) {
|
||||
// notices.value.unshift({
|
||||
// id,
|
||||
// title: data.title,
|
||||
// type: data.type,
|
||||
// publishTime: data.publishTime,
|
||||
// });
|
||||
// ElNotification({
|
||||
// title: "您收到一条新的通知消息!",
|
||||
// message: data.title,
|
||||
// type: "success",
|
||||
// position: "bottom-right",
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
});
|
||||
|
||||
// 阅读通知公告
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ export const constantRoutes: RouteRecordRaw[] = [
|
|||
children: [
|
||||
{
|
||||
path: "index",
|
||||
component: () => import("@/views/tool/index.vue"),
|
||||
component: () => import("@/views/tool/Instead/index.vue"),
|
||||
name: "toolIndex",
|
||||
meta: {
|
||||
title: "代客下单",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,228 @@
|
|||
import { store } from "@/store";
|
||||
import WebSocketManager, { type ApifoxModel, msgType } from "@/utils/websocket";
|
||||
|
||||
export interface CartsState {
|
||||
id: string | number;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export const useCartsStore = defineStore("carts", () => {
|
||||
//当前购物车数据
|
||||
const list = useStorage<any[]>("carts", []);
|
||||
//赠菜
|
||||
const giftList = useStorage<any[]>("giftList", []);
|
||||
let goodsMap: { [key: string]: any } = {};
|
||||
//当前选中cart
|
||||
let selListIndex = ref(-1);
|
||||
//当前选中商品是否是赠菜
|
||||
const isSelGift = ref(false);
|
||||
const defaultCart = {
|
||||
id: '',
|
||||
number: 0,
|
||||
}
|
||||
const selCart = computed(() => {
|
||||
if (isSelGift.value) {
|
||||
return giftList.value[selListIndex.value] || defaultCart
|
||||
}
|
||||
return list.value[selListIndex.value] || defaultCart
|
||||
})
|
||||
//赠菜总价
|
||||
const giftMoney = computed(() => {
|
||||
return giftList.value.reduce((acc: number, cur: any) => {
|
||||
return acc + cur.number * cur.salePrice
|
||||
}, 0)
|
||||
})
|
||||
const yiyouhui = computed(() => {
|
||||
const youhui = giftMoney.value
|
||||
if (youhui > 0) {
|
||||
return '已优惠¥' + youhui.toFixed(2)
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
//支付总价
|
||||
const payMoney = computed(() => {
|
||||
const money = list.value.reduce((acc: number, cur: any) => {
|
||||
return acc + cur.number * cur.salePrice
|
||||
}, 0)
|
||||
return money.toFixed(2)
|
||||
})
|
||||
//总计数量
|
||||
const totalNumber = computed(() => {
|
||||
const cartNumber = list.value.reduce((acc: number, cur: any) => {
|
||||
return acc + cur.number * 1
|
||||
}, 0)
|
||||
const giftNumber = list.value.reduce((acc: number, cur: any) => {
|
||||
return acc + cur.number * 1
|
||||
}, 0)
|
||||
return cartNumber + giftNumber
|
||||
})
|
||||
|
||||
|
||||
const table_code = ref('');
|
||||
function changeNumber(step: number, item: CartsState) {
|
||||
if (item.number * 1 + step <= 0) {
|
||||
del(item);
|
||||
return;
|
||||
}
|
||||
update({ ...item, number: step * 1 });
|
||||
}
|
||||
|
||||
function changeSelCart(cart: CartsState) {
|
||||
console.log(cart)
|
||||
if (!cart.id) {
|
||||
return
|
||||
}
|
||||
if (cart.is_gift) {
|
||||
isSelGift.value = true
|
||||
selListIndex.value = giftList.value.findIndex((item: CartsState) => item.id === cart.id);
|
||||
console.log(selListIndex.value)
|
||||
|
||||
} else {
|
||||
isSelGift.value = false
|
||||
selListIndex.value = list.value.findIndex((item: CartsState) => item.id === cart.id);
|
||||
}
|
||||
}
|
||||
function add(data: any) {
|
||||
sendMessage('add', data);
|
||||
}
|
||||
function del(data: any) {
|
||||
sendMessage('del', data);
|
||||
}
|
||||
|
||||
function update(data: any) {
|
||||
console.log(data);
|
||||
sendMessage('edit', data);
|
||||
}
|
||||
function updateTag(key: string, val: any) {
|
||||
sendMessage('edit', { ...selCart.value, number: 0, [key]: val });
|
||||
}
|
||||
function clear() {
|
||||
sendMessage('cleanup', {});
|
||||
}
|
||||
function getProductDetails(v: { product_id: string, sku_id: string }) {
|
||||
const goods = goodsMap[v.product_id]
|
||||
const skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id);
|
||||
if (skuData) {
|
||||
return {
|
||||
salePrice: skuData ? skuData.salePrice : 0,
|
||||
coverImg: goods.coverImg,
|
||||
name: goods.name
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function init(initParams: ApifoxModel, $goodsMap: any) {
|
||||
// 商品id对应的数据map
|
||||
goodsMap = $goodsMap
|
||||
table_code.value = initParams && initParams.table_code ? initParams.table_code : '';
|
||||
WebSocketManager.subscribeToTopic(initParams, (msg) => {
|
||||
console.log("收到消息:", msg);
|
||||
if (msg.hasOwnProperty('status') && msg.status != 1) {
|
||||
return ElMessage.error(msg.message || '操作失败')
|
||||
}
|
||||
// 初始化
|
||||
if (msg.operate_type === "manage_init") {
|
||||
// 设置单价
|
||||
list.value = msg.data.filter((v: { is_gift: any; }) => !v.is_gift).map((v: Record<string, any>) => {
|
||||
const skuData = getProductDetails({ product_id: v.product_id, sku_id: v.sku_id })
|
||||
return {
|
||||
...skuData,
|
||||
...v,
|
||||
}
|
||||
});
|
||||
giftList.value = msg.data.filter((v: { is_gift: any; }) => v.is_gift).map((v: Record<string, any>) => {
|
||||
const skuData = getProductDetails({ product_id: v.product_id, sku_id: v.sku_id })
|
||||
return {
|
||||
...skuData,
|
||||
...v,
|
||||
}
|
||||
});
|
||||
console.log(giftList.value)
|
||||
}
|
||||
if (msg.operate_type === "manage_add") {
|
||||
const skuData = getProductDetails({ product_id: msg.data[0].product_id, sku_id: msg.data[0].sku_id })
|
||||
list.value.push({ ...skuData, ...msg.data[0] })
|
||||
return ElMessage.success(msg.message || '添加成功')
|
||||
|
||||
}
|
||||
if (msg.operate_type === "manage_edit") {
|
||||
const newCart = msg.data[0]
|
||||
const index = list.value.findIndex((item) => item.id === newCart.id)
|
||||
const giftIndex = giftList.value.findIndex((item) => item.id === newCart.id)
|
||||
const cartItem = list.value[index];
|
||||
const giftItem = giftList.value[giftIndex];
|
||||
if (isSelGift.value) {
|
||||
//操作赠菜
|
||||
if (newCart.is_gift != giftItem.is_gift) {
|
||||
//修改了赠菜状态
|
||||
giftList.value.splice(giftIndex, 1)
|
||||
list.value.push({ ...giftItem, ...newCart })
|
||||
selListIndex.value = -1
|
||||
} else {
|
||||
giftList.value[giftIndex] = { ...giftItem, ...newCart }
|
||||
}
|
||||
return
|
||||
}
|
||||
if (!isSelGift.value) {
|
||||
//操作非赠菜
|
||||
if (newCart.is_gift != cartItem.is_gift) {
|
||||
list.value.splice(index, 1)
|
||||
giftList.value.push({ ...cartItem, ...newCart })
|
||||
selListIndex.value = -1
|
||||
} else {
|
||||
list.value[index] = { ...cartItem, ...newCart }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
if (msg.operate_type === "manage_del") {
|
||||
if (!isSelGift.value) {
|
||||
const index = list.value.findIndex((item) => item.id === msg.data.id)
|
||||
if (index > -1) {
|
||||
list.value.splice(index, 1)
|
||||
if (list.value.length >= 1) {
|
||||
selListIndex.value = index - 1;
|
||||
}
|
||||
return ElMessage.success(msg.message || '删除成功')
|
||||
}
|
||||
} else {
|
||||
const index = giftList.value.findIndex((item) => item.id === msg.data.id)
|
||||
if (index > -1) {
|
||||
giftList.value.splice(index, 1)
|
||||
if (giftList.value.length >= 1) {
|
||||
selListIndex.value = index - 1;
|
||||
}
|
||||
return ElMessage.success(msg.message || '删除成功')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
console.log(list.value)
|
||||
});
|
||||
}
|
||||
function sendMessage(operate_type: msgType, message: any) {
|
||||
console.log({ ...message, operate_type: operate_type, table_code: table_code.value })
|
||||
WebSocketManager.sendMessage({ ...message, operate_type: operate_type, table_code: table_code.value });
|
||||
}
|
||||
return {
|
||||
updateTag,
|
||||
list,
|
||||
add,
|
||||
del,
|
||||
update,
|
||||
init,
|
||||
changeNumber,
|
||||
selCart, totalNumber,
|
||||
changeSelCart, payMoney,
|
||||
clear, yiyouhui, giftList
|
||||
};
|
||||
});
|
||||
|
||||
export function useDictStoreHook() {
|
||||
return useCartsStore(store);
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ export const useUserStore = defineStore("user", () => {
|
|||
return new Promise<void>((resolve, reject) => {
|
||||
AuthAPI.login(loginRequest)
|
||||
.then((data) => {
|
||||
Object.assign(userInfo.value, { ...data.shopInfo });
|
||||
Object.assign(userInfo.value, { ...data.shopInfo, shopId: data.shopInfo.id });
|
||||
promissionList.value = data.promissionList;
|
||||
const token = data.tokenInfo.tokenValue;
|
||||
setToken(token); // Bearer eyJhbGciOiJIUzI1NiJ9.xxx.xxx
|
||||
|
|
|
|||
|
|
@ -1,6 +1,36 @@
|
|||
import qs from "qs";
|
||||
import { useUserStoreHook } from "@/store";
|
||||
|
||||
const user = useUserStoreHook()
|
||||
|
||||
export interface ApifoxModel {
|
||||
account: string;
|
||||
/**
|
||||
* 操作类型
|
||||
*/
|
||||
operate_type: string;
|
||||
shop_id: string;
|
||||
/**
|
||||
* 桌码
|
||||
*/
|
||||
table_code?: string;
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
type: string;
|
||||
[property: string]: any;
|
||||
}
|
||||
export type msgType = 'add' | 'reduce' | 'remove' | 'edit' | 'init' | 'cleanup' | 'del'
|
||||
class WebSocketManager {
|
||||
private client: WebSocket | null = null;
|
||||
private connected: boolean = false;
|
||||
private initParams: ApifoxModel = {
|
||||
type: 'manage',
|
||||
account: `${user.userInfo.shopId}`,
|
||||
operate_type: 'init',
|
||||
table_code: '',
|
||||
shop_id: `${user.userInfo.shopId}`,
|
||||
};
|
||||
private onMessage: (message: any) => void = function () { };
|
||||
private messageHandlers: Map<string, ((message: string) => void)[]> = new Map();
|
||||
private type: string = 'manage';
|
||||
|
|
@ -22,11 +52,13 @@ class WebSocketManager {
|
|||
console.log("客户端已存在并且连接正常");
|
||||
return this.client;
|
||||
}
|
||||
this.client = new WebSocket(endpoint)
|
||||
const url = qs.stringify(this.initParams)
|
||||
console.log(this.initParams)
|
||||
this.client = new WebSocket(endpoint + '?' + url);
|
||||
this.client.onopen = () => {
|
||||
this.connected = true;
|
||||
console.log("WebSocket 连接已建立");
|
||||
this.sendMessage('test')
|
||||
this.sendMessage(this.initParams)
|
||||
};
|
||||
this.client.onclose = () => {
|
||||
this.connected = false;
|
||||
|
|
@ -42,28 +74,45 @@ class WebSocketManager {
|
|||
};
|
||||
this.client.onmessage = (event) => {
|
||||
const message = event.data;
|
||||
this.getMessage(message)
|
||||
const msg = JSON.parse(message)
|
||||
if (msg && msg.msg_id) {
|
||||
this.onMessageHandler({ msg_id: msg.msg_id })
|
||||
}
|
||||
this.onMessage(msg);
|
||||
};
|
||||
}
|
||||
private getMessage(message: any) {
|
||||
console.log("收到消息:", message);
|
||||
|
||||
// 消息回执
|
||||
public onMessageHandler(data: any) {
|
||||
if (this.client) {
|
||||
this.client.send(JSON.stringify({ ...data, type: 'receipt' }));
|
||||
}
|
||||
}
|
||||
|
||||
// 订阅主题
|
||||
public subscribeToTopic(topic: string, onMessage: (message: string) => void) {
|
||||
console.log(`正在订阅主题: ${topic}`);
|
||||
if (!this.client || !this.connected) {
|
||||
this.setupWebSocket();
|
||||
}
|
||||
if (this.connected) {
|
||||
this.onMessage = onMessage;
|
||||
public subscribeToTopic(initParams: ApifoxModel, onMessage: (message: any) => void) {
|
||||
console.log(`正在订阅主题: `);
|
||||
console.log(initParams);
|
||||
|
||||
this.initParams = { ...this.initParams, ...initParams }
|
||||
if (this.client && this.connected) {
|
||||
this.disconnect();
|
||||
}
|
||||
this.setupWebSocket();
|
||||
this.onMessage = onMessage;
|
||||
}
|
||||
public sendMessage(message: any) {
|
||||
if (this.client) {
|
||||
this.client.send(message);
|
||||
const msg = JSON.stringify({
|
||||
...this.initParams,
|
||||
...message,
|
||||
})
|
||||
this.client.send(msg);
|
||||
}
|
||||
}
|
||||
public canSendMessage() {
|
||||
return this.client && this.connected;
|
||||
}
|
||||
// 断开 WebSocket 连接
|
||||
public disconnect() {
|
||||
if (this.client) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import VersionApi, { type addRequest } from "@/api/system/version";
|
||||
import { sourceOptions, typeOptions, isForceOptions } from "./config";
|
||||
import API, { type addRequest } from "@/api/system/miniAppPages";
|
||||
import type { IModalConfig } from "@/components/CURD/types";
|
||||
|
||||
const modalConfig: IModalConfig<addRequest> = {
|
||||
pageName: "sys:user",
|
||||
dialog: {
|
||||
title: "新增版本",
|
||||
title: "新增小程序页面",
|
||||
width: 800,
|
||||
draggable: true,
|
||||
},
|
||||
|
|
@ -13,75 +12,78 @@ const modalConfig: IModalConfig<addRequest> = {
|
|||
labelWidth: 140,
|
||||
},
|
||||
formAction: function (data) {
|
||||
return VersionApi.add({ ...data, url: typeof data.url === "string" ? data.url : data.url[0] });
|
||||
if (data.icon) {
|
||||
data.icon = typeof data.icon === "string" ? data.icon : data.icon[0]
|
||||
}
|
||||
return API.add(data);
|
||||
},
|
||||
beforeSubmit(data) {
|
||||
console.log("提交之前处理", data);
|
||||
},
|
||||
formItems: [
|
||||
|
||||
{
|
||||
label: "渠道",
|
||||
prop: "source",
|
||||
rules: [{ required: true, message: "请选择渠道", trigger: "blur" }],
|
||||
type: "select",
|
||||
type: "UpImage",
|
||||
label: "图标",
|
||||
prop: "icon",
|
||||
rules: [{ required: false, message: "请上传图标", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请选择渠道",
|
||||
placeholder: "请上传图标",
|
||||
},
|
||||
options: sourceOptions,
|
||||
},
|
||||
{
|
||||
label: "类型",
|
||||
prop: "type",
|
||||
rules: [{ required: true, message: "请选择类型", trigger: "blur" }],
|
||||
type: "select",
|
||||
attrs: {
|
||||
placeholder: "请选择类型",
|
||||
},
|
||||
col: {
|
||||
xs: 24,
|
||||
sm: 12,
|
||||
},
|
||||
options: typeOptions,
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
label: "版本号",
|
||||
prop: "version",
|
||||
rules: [{ required: true, message: "请输入版本号", trigger: "blur" }],
|
||||
label: "小程序页面名称",
|
||||
prop: "name",
|
||||
rules: [{ required: true, message: "请输入小程序页面名称", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请输入版本号",
|
||||
placeholder: "请输入小程序页面名称",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "radio",
|
||||
label: "是否强制更新",
|
||||
prop: "isForce",
|
||||
rules: [{ required: true, message: "请输入版本号", trigger: "blur" }],
|
||||
type: "input",
|
||||
label: "小程序页面路径",
|
||||
prop: "path",
|
||||
rules: [{ required: true, message: "请输入小程序页面路径", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请输入版本号",
|
||||
placeholder: "请输入小程序页面路径",
|
||||
},
|
||||
initialValue: 0,
|
||||
options: isForceOptions,
|
||||
},
|
||||
{
|
||||
type: "textarea",
|
||||
label: "更新提示内容",
|
||||
prop: "message",
|
||||
rules: [{ required: true, message: "请输入更新提示内容", trigger: "blur" }],
|
||||
label: "页面描述",
|
||||
prop: "description",
|
||||
rules: [{ required: false, message: "请输入页面描述", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请输入更新提示内容",
|
||||
placeholder: "请输入页面描述",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "custom",
|
||||
label: "版本文件",
|
||||
prop: "url",
|
||||
rules: [{ required: true, message: "请上传版本文件", trigger: "blur" }],
|
||||
type: "input-number",
|
||||
label: "排序",
|
||||
prop: "sort",
|
||||
rules: [{ required: false, message: "请输入排序", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请上传版本文件",
|
||||
placeholder: "请输入排序",
|
||||
},
|
||||
initialValue: [],
|
||||
initialValue: 0,
|
||||
},
|
||||
{
|
||||
type: "radio-button",
|
||||
label: "小程序页面状态",
|
||||
prop: "status",
|
||||
options: [
|
||||
{
|
||||
label: "启用",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: "禁用",
|
||||
value: 0,
|
||||
},
|
||||
],
|
||||
initialValue: 1,
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,17 @@
|
|||
import { property } from "lodash";
|
||||
|
||||
export const sourceOptions: options[] = [
|
||||
{ label: "桌面端", value: "pc" },
|
||||
{ label: "管理端", value: "manager_app" },
|
||||
{ label: "电话机点餐", value: "phone_book " },
|
||||
];
|
||||
export const typeOptions: options[] = [
|
||||
{ label: "windows", value: "0" },
|
||||
{ label: "安卓", value: "1" },
|
||||
{ label: "IOS", value: "2" },
|
||||
];
|
||||
export const isForceOptions: options[] = [
|
||||
{ label: "不强制更新", value: 0 },
|
||||
{ label: "强制更新", value: 1 },
|
||||
export const statusOptions: options[] = [
|
||||
{ label: "全部", value: '' },
|
||||
{ label: "启用", value: 1 },
|
||||
{ label: "禁用", value: 0 },
|
||||
];
|
||||
|
||||
export type optionsType = "source" | "type" | "isForce";
|
||||
|
||||
export type optionsType = "status";
|
||||
|
||||
export function returnOptions(type: optionsType) {
|
||||
if (type === "source") {
|
||||
return sourceOptions;
|
||||
}
|
||||
if (type === "type") {
|
||||
return typeOptions;
|
||||
}
|
||||
if (type === "isForce") {
|
||||
return isForceOptions;
|
||||
if (type === "status") {
|
||||
return statusOptions;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import VersionApi from "@/api/system/version";
|
||||
import type { editRequest } from "@/api/system/version";
|
||||
import API, { type editRequest } from "@/api/system/miniAppPages";
|
||||
import type { IContentConfig } from "@/components/CURD/types";
|
||||
|
||||
const contentConfig: IContentConfig<editRequest> = {
|
||||
|
|
@ -15,61 +14,50 @@ const contentConfig: IContentConfig<editRequest> = {
|
|||
pageSizes: [10, 20, 30, 50],
|
||||
},
|
||||
indexAction: function (params) {
|
||||
return VersionApi.getList();
|
||||
return API.getList(params);
|
||||
},
|
||||
deleteAction: VersionApi.delete,
|
||||
deleteAction: API.delete,
|
||||
// modifyAction: function (data) {
|
||||
// // return VersionApi.edit(data);
|
||||
// // return API.edit(data);
|
||||
// },
|
||||
pk: "id",
|
||||
toolbar: ["add"],
|
||||
defaultToolbar: ["refresh", "filter", "search"],
|
||||
cols: [
|
||||
{ type: "selection", width: 50, align: "center" },
|
||||
{ label: "id", align: "center", prop: "id", width: 100, show: true },
|
||||
{
|
||||
label: "渠道",
|
||||
label: "小程序页面名称",
|
||||
align: "center",
|
||||
prop: "source",
|
||||
width: 120,
|
||||
prop: "name",
|
||||
},
|
||||
{
|
||||
label: "图标",
|
||||
align: "center",
|
||||
prop: "icon",
|
||||
templet: "custom",
|
||||
slotName: "options",
|
||||
slotName: "icon",
|
||||
},
|
||||
{
|
||||
label: "类型",
|
||||
label: "小程序页面路径",
|
||||
align: "center",
|
||||
prop: "type",
|
||||
width: 120,
|
||||
prop: "path",
|
||||
},
|
||||
{
|
||||
label: "页面描述",
|
||||
align: "center",
|
||||
prop: "description",
|
||||
},
|
||||
{
|
||||
label: "排序",
|
||||
align: "center",
|
||||
prop: "sort",
|
||||
},
|
||||
{
|
||||
label: "状态",
|
||||
align: "center",
|
||||
prop: "status",
|
||||
templet: "custom",
|
||||
slotName: "options",
|
||||
},
|
||||
{
|
||||
label: "版本号",
|
||||
align: "center",
|
||||
width: 120,
|
||||
prop: "version",
|
||||
},
|
||||
|
||||
{
|
||||
label: "是否强制升级",
|
||||
align: "center",
|
||||
prop: "isForce",
|
||||
width: 120,
|
||||
templet: "switch",
|
||||
slotName: "isForce",
|
||||
},
|
||||
{
|
||||
label: "更新内容",
|
||||
align: "center",
|
||||
prop: "message",
|
||||
width: 240,
|
||||
},
|
||||
{
|
||||
label: "下载地址",
|
||||
align: "center",
|
||||
prop: "url",
|
||||
templet: "url",
|
||||
slotName: "url",
|
||||
slotName: "status",
|
||||
},
|
||||
{
|
||||
label: "操作",
|
||||
|
|
|
|||
|
|
@ -1,86 +1,91 @@
|
|||
import VersionApi, { type editRequest } from "@/api/system/version";
|
||||
import API, { type editRequest } from "@/api/system/miniAppPages";
|
||||
import type { IModalConfig } from "@/components/CURD/types";
|
||||
import { sourceOptions, typeOptions, isForceOptions } from "./config";
|
||||
|
||||
const modalConfig: IModalConfig<editRequest> = {
|
||||
pageName: "sys:user",
|
||||
dialog: {
|
||||
title: "编辑版本",
|
||||
title: "编辑小程序页面",
|
||||
width: 800,
|
||||
draggable: true,
|
||||
},
|
||||
pk: "id",
|
||||
form: {
|
||||
labelWidth: 140,
|
||||
},
|
||||
formAction: function (data) {
|
||||
return VersionApi.edit({ ...data, url: typeof data.url === "string" ? data.url : data.url[0] });
|
||||
if (data.icon) {
|
||||
data.icon = typeof data.icon === "string" ? data.icon : data.icon[0]
|
||||
}
|
||||
return API.edit(data);
|
||||
},
|
||||
beforeSubmit(data) {
|
||||
console.log("提交之前处理", data);
|
||||
},
|
||||
formItems: [
|
||||
|
||||
{
|
||||
label: "渠道",
|
||||
prop: "source",
|
||||
rules: [{ required: true, message: "请选择渠道", trigger: "blur" }],
|
||||
type: "select",
|
||||
type: "UpImage",
|
||||
label: "图标",
|
||||
prop: "icon",
|
||||
rules: [{ required: false, message: "请上传图标", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请选择渠道",
|
||||
placeholder: "请上传图标",
|
||||
},
|
||||
options: sourceOptions,
|
||||
},
|
||||
{
|
||||
label: "类型",
|
||||
prop: "type",
|
||||
rules: [{ required: true, message: "请选择类型", trigger: "blur" }],
|
||||
type: "select",
|
||||
attrs: {
|
||||
placeholder: "请选择类型",
|
||||
},
|
||||
col: {
|
||||
xs: 24,
|
||||
sm: 12,
|
||||
},
|
||||
options: typeOptions,
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
label: "版本号",
|
||||
prop: "version",
|
||||
rules: [{ required: true, message: "请输入版本号", trigger: "blur" }],
|
||||
label: "小程序页面名称",
|
||||
prop: "name",
|
||||
rules: [{ required: true, message: "请输入小程序页面名称", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请输入版本号",
|
||||
placeholder: "请输入小程序页面名称",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "radio",
|
||||
label: "是否强制更新",
|
||||
prop: "isForce",
|
||||
rules: [{ required: true, message: "请输入版本号", trigger: "blur" }],
|
||||
type: "input",
|
||||
label: "小程序页面路径",
|
||||
prop: "path",
|
||||
rules: [{ required: true, message: "请输入小程序页面路径", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请输入版本号",
|
||||
placeholder: "请输入小程序页面路径",
|
||||
},
|
||||
initialValue: 0,
|
||||
options: isForceOptions,
|
||||
},
|
||||
{
|
||||
type: "textarea",
|
||||
label: "更新提示内容",
|
||||
prop: "message",
|
||||
rules: [{ required: true, message: "请输入更新提示内容", trigger: "blur" }],
|
||||
label: "页面描述",
|
||||
prop: "description",
|
||||
rules: [{ required: false, message: "请输入页面描述", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请输入更新提示内容",
|
||||
placeholder: "请输入页面描述",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "custom",
|
||||
label: "版本文件",
|
||||
prop: "url",
|
||||
rules: [{ required: true, message: "请上传版本文件", trigger: "blur" }],
|
||||
type: "input-number",
|
||||
label: "排序",
|
||||
prop: "sort",
|
||||
rules: [{ required: false, message: "请输入排序", trigger: "blur" }],
|
||||
attrs: {
|
||||
placeholder: "请上传版本文件",
|
||||
placeholder: "请输入排序",
|
||||
},
|
||||
initialValue: [],
|
||||
initialValue: 0,
|
||||
},
|
||||
{
|
||||
type: "radio-button",
|
||||
label: "小程序页面状态",
|
||||
prop: "status",
|
||||
options: [
|
||||
{
|
||||
label: "启用",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: "禁用",
|
||||
value: 0,
|
||||
},
|
||||
],
|
||||
initialValue: 1,
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
// 如果有异步数据会修改配置的,推荐用reactive包裹,而纯静态配置的可以直接导出
|
||||
export default reactive(modalConfig);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,39 @@
|
|||
import type { ISearchConfig } from "@/components/CURD/types";
|
||||
|
||||
import { statusOptions } from './config'
|
||||
const searchConfig: ISearchConfig = {
|
||||
pageName: "sys:user",
|
||||
formItems: [
|
||||
{
|
||||
type: "input",
|
||||
label: "版本号",
|
||||
prop: "keywords",
|
||||
label: "小程序页面路径",
|
||||
prop: "name",
|
||||
attrs: {
|
||||
placeholder: "请输入版本号",
|
||||
placeholder: "请输入小程序页面路径",
|
||||
clearable: true,
|
||||
style: {
|
||||
width: "200px",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
label: "小程序页面路径",
|
||||
prop: "path",
|
||||
attrs: {
|
||||
placeholder: "请输入小程序页面路径",
|
||||
clearable: true,
|
||||
style: {
|
||||
width: "200px",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "radio-button",
|
||||
label: "小程序页面状态",
|
||||
prop: "status",
|
||||
options: statusOptions,
|
||||
initialValue: '',
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@
|
|||
{{ scope.row[scope.prop] == 1 ? "启用" : "禁用" }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template #icon="scope">
|
||||
<el-image
|
||||
style="width: 50px; height: 50px"
|
||||
:src="scope.row[scope.prop]"
|
||||
:preview-src-list="[scope.row[scope.prop]]"
|
||||
/>
|
||||
</template>
|
||||
<template #options="scope">
|
||||
{{ returnOptionsLabel(scope.prop, scope.row[scope.prop]) }}
|
||||
</template>
|
||||
|
|
@ -99,8 +106,8 @@ async function handleEditClick(row: IObject) {
|
|||
editModalRef.value?.setModalVisible();
|
||||
// 根据id获取数据进行填充
|
||||
// const data = await Api.getFormData(row.id);
|
||||
console.log({ ...row, url: [row.url] });
|
||||
editModalRef.value?.setFormData({ ...row, url: [row.url] });
|
||||
console.log({ ...row, icon: row.icon ? [row.icon] : [] });
|
||||
editModalRef.value?.setFormData({ ...row, icon: row.icon ? [row.icon] : [] });
|
||||
}
|
||||
1;
|
||||
// 其他工具栏
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ export default {
|
|||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
::v-deep(.el-dialog__header) {
|
||||
:deep(.el-dialog__header) {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,465 @@
|
|||
<template>
|
||||
<div class="flex order-item u-m-b-14 relative" :class="[isActive]" @click="itemClick">
|
||||
<div class="absolute status-box">
|
||||
<span class="pack" v-if="item.pack_number * 1 > 0">
|
||||
包
|
||||
<span class="number">{{ item.pack_number * 1 }}</span>
|
||||
</span>
|
||||
<span class="da" v-if="item.is_print || item.is_print === null">打</span>
|
||||
<span class="isWaitCall" v-if="item.is_wait_call">等</span>
|
||||
<span class="tui" v-if="item.status === 'return'">退</span>
|
||||
</div>
|
||||
<div class="flex u-col-top">
|
||||
<div class="img">
|
||||
<div class="isSeatFee img u-line-1 u-flex u-col-center u-row-center" v-if="isSeatFee">
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
<div
|
||||
class="isSeatFee img u-line-1 u-flex u-col-center u-row-center"
|
||||
v-else-if="!item.product_id"
|
||||
>
|
||||
<span>临时菜</span>
|
||||
</div>
|
||||
<img v-else :src="item.coverImg" class="" alt="" />
|
||||
</div>
|
||||
<div class="good-info u-p-t-6">
|
||||
<div class="flex lh-16">
|
||||
<div class="name" :class="{ 'free-price': item.status === 'return' }">
|
||||
{{ item.name }}
|
||||
</div>
|
||||
<span class="good_info_discount" v-if="item.is_gift">赠</span>
|
||||
</div>
|
||||
<div v-if="item.typeEnum == 'weight'" class="specSnap">
|
||||
¥{{ currentPrice }}/{{ item.unit }}
|
||||
</div>
|
||||
<div v-if="item.specSnap" class="specSnap">
|
||||
{{ item.specSnap }}
|
||||
</div>
|
||||
<div v-if="item.proGroupInfo" class="specSnapss">
|
||||
<span>{{ item.groupType == 0 ? "固定套餐" : "可选套餐" }}:</span>
|
||||
<span v-for="(a, b) in proGroupInfo" :key="a.proId">
|
||||
{{ b == 0 ? "" : "," }}{{ a.proName }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="" v-if="placeNum == 0">
|
||||
<div class="note" v-if="item.remark">备注:{{ item.remark }}</div>
|
||||
<div class="note flex" v-else>
|
||||
<span>备注:</span>
|
||||
<el-icon @click="editNote" color="#999"><EditPen /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="note" v-if="placeNum != 0 && item.note">备注:{{ item.remark || "" }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="width: 10px"></div>
|
||||
<div class="flex u-p-t-6">
|
||||
<div class="order-number-box u-font-12">
|
||||
<div class="" v-if="isSeatFee">X{{ item.totalNumber }}</div>
|
||||
<div class="" v-else>X{{ item.number }}</div>
|
||||
<div class="absolute" v-if="canChangeNumber">
|
||||
<div class="order-input-number">
|
||||
<el-icon color="#d8d8d8" size="22" @click="changeOrderNumber(-1)"><Remove /></el-icon>
|
||||
|
||||
<div style="width: 60px; margin: 0 4px" class="number-box">
|
||||
<el-input
|
||||
:min="0"
|
||||
type="number"
|
||||
@input="cartGoodsNumberInput"
|
||||
@change="cartGoodsNumberChange"
|
||||
v-model="number"
|
||||
placeholder="0"
|
||||
></el-input>
|
||||
</div>
|
||||
<el-icon color="#22bf64" size="22" @click="changeOrderNumber(1)">
|
||||
<CirclePlusFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="color-333 total-price">
|
||||
<template v-if="item.is_gift || item.status == 'return'">
|
||||
<div>¥0</div>
|
||||
<div class="free-price">
|
||||
<span v-if="isSeatFee">¥{{ item.totalAmount }}</span>
|
||||
<span v-else>¥{{ isShowVipPrice ? vipAllPrice : allPrice }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="item.discountSaleAmount">
|
||||
<div>¥{{ discountNewPrice }}</div>
|
||||
<div class="free-price">
|
||||
<span>¥{{ isShowVipPrice ? vipAllPrice : allPrice }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div v-if="isSeatFee">¥{{ item.totalAmount }}</div>
|
||||
<div v-else>
|
||||
<div v-if="isShowVipPrice && vipAllPrice != allPrice">¥{{ vipAllPrice }}</div>
|
||||
<div
|
||||
:class="{
|
||||
'free-price': isShowVipPrice && vipAllPrice != allPrice,
|
||||
}"
|
||||
>
|
||||
<span>¥{{ allPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
isShowVipPrice: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
//是否是餐位费
|
||||
isSeatFee: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
//是否是历史订单商品
|
||||
isOld: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
//第几次下单 1以及以上为历史订单 0为当前购物车
|
||||
placeNum: {
|
||||
type: [String, Number],
|
||||
default: 0,
|
||||
},
|
||||
selPlaceNum: {
|
||||
type: [String, Number],
|
||||
default: -1,
|
||||
},
|
||||
//是否允许改变数量
|
||||
canChangeNumber: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
item: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {
|
||||
number: 0,
|
||||
};
|
||||
},
|
||||
},
|
||||
selCart: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {
|
||||
id: "",
|
||||
};
|
||||
},
|
||||
},
|
||||
index: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
let number = ref(0);
|
||||
|
||||
const currentPrice = computed(() => {
|
||||
return 0;
|
||||
});
|
||||
const proGroupInfo = computed(() => {
|
||||
return JSON.parse(props.item.proGroupInfo);
|
||||
});
|
||||
const discountNewPrice = computed(() => {
|
||||
return 0;
|
||||
});
|
||||
const vipAllPrice = computed(() => {
|
||||
return 0;
|
||||
});
|
||||
const allPrice = computed(() => {
|
||||
return props.item.number * props.item.salePrice;
|
||||
});
|
||||
|
||||
const isActive = computed(() => {
|
||||
return props.item.id == props.selCart.id ? "active" : "";
|
||||
});
|
||||
watch(
|
||||
() => props.item.number,
|
||||
(newval) => {
|
||||
console.log(newval);
|
||||
number.value = newval;
|
||||
}
|
||||
);
|
||||
|
||||
const emits = defineEmits([
|
||||
"editNote",
|
||||
"cartGoodsNumberChange",
|
||||
"cartGoodsNumberInput",
|
||||
"changeNumber",
|
||||
"itemClick",
|
||||
]);
|
||||
function editNote() {
|
||||
emits("editNote", props.index);
|
||||
}
|
||||
//购物车商品输入框数量改变
|
||||
function cartGoodsNumberChange(newval) {
|
||||
if (newval <= 0) {
|
||||
item.number = 1;
|
||||
}
|
||||
newval = `${newval}`.split(".")[0] * 1;
|
||||
number.value = newval;
|
||||
changeOrderNumber(newval - props.item.number);
|
||||
}
|
||||
//购物车商品输入框数量输入
|
||||
function cartGoodsNumberInput(newval) {
|
||||
if (newval <= 0) {
|
||||
return (number.value = 1);
|
||||
}
|
||||
newval = `${newval}`.split(".")[0] * 1;
|
||||
number.value = newval;
|
||||
}
|
||||
function changeOrderNumber(step) {
|
||||
emits("changeNumber", step, props.item);
|
||||
}
|
||||
function itemClick() {
|
||||
emits("itemClick");
|
||||
}
|
||||
onMounted(() => {
|
||||
number.value = props.item.number;
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
::v-deep .number-box .el-input__inner {
|
||||
border: none;
|
||||
}
|
||||
|
||||
::v-deep .el-button--text {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
::v-deep .number-box .el-input__inner {
|
||||
border: none;
|
||||
padding: 0 4px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.isSeatFee {
|
||||
background: #3f9eff;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.icon-remove {
|
||||
border: 1px solid #d8d8d8;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
box-sizing: border-box;
|
||||
cursor: pointer;
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
display: block;
|
||||
width: 10px;
|
||||
height: 1px;
|
||||
background: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-add {
|
||||
color: rgb(34, 191, 100);
|
||||
font-size: 22px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.flex.order-item {
|
||||
padding: 4px;
|
||||
border-radius: 2px;
|
||||
display: flex;
|
||||
overflow: visible;
|
||||
cursor: pointer;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
background-color: rgba(0, 0, 0, 0);
|
||||
transition: all 0.3s;
|
||||
|
||||
.status-box {
|
||||
width: 18px;
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
|
||||
> span {
|
||||
display: block;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 4px 0 4px 0;
|
||||
font-size: 12px;
|
||||
line-height: 17px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.isWaitCall {
|
||||
background: #d3adf7;
|
||||
}
|
||||
|
||||
.pack {
|
||||
background: #35ac6a;
|
||||
.number {
|
||||
background: #f56c6c;
|
||||
color: #fff;
|
||||
position: absolute;
|
||||
left: -7px;
|
||||
top: -7px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
text-align: center;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.da {
|
||||
background: #35ac6a;
|
||||
}
|
||||
|
||||
.tui {
|
||||
background: #ac4735;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.total-price {
|
||||
width: 94px;
|
||||
font-size: 16px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.good-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
min-width: 70px;
|
||||
|
||||
.specSnap {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.specSnapss {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
margin-top: 3px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
|
||||
.specSnap {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
color: #212121;
|
||||
overflow: hidden;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.img {
|
||||
width: 59px;
|
||||
height: 59px;
|
||||
position: relative;
|
||||
margin-right: 10px;
|
||||
|
||||
img {
|
||||
width: 59px;
|
||||
height: 59px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.note {
|
||||
max-width: 70%;
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
text-align: left;
|
||||
color: #999;
|
||||
margin-top: 5px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.order-number-box {
|
||||
position: relative;
|
||||
|
||||
.absolute {
|
||||
width: 60px;
|
||||
height: 40px;
|
||||
right: -38px;
|
||||
top: -14px;
|
||||
position: absolute;
|
||||
|
||||
.order-input-number {
|
||||
position: absolute;
|
||||
right: -6px;
|
||||
top: 0;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: none;
|
||||
background-color: #fff;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.06);
|
||||
padding: 9px 6px;
|
||||
background-color: #fff;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
&:hover .order-input-number {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.good_info_discount {
|
||||
height: 16px;
|
||||
padding: 0 3px;
|
||||
color: #ff3f3f;
|
||||
background-color: rgba(255, 63, 63, 0.1);
|
||||
border-radius: 2px;
|
||||
margin-left: 6px;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
::v-deep .order-input-number .el-input__inner::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
::v-deep .order-input-number .el-input__inner::-webkit-outer-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
<template>
|
||||
<div class="list">
|
||||
<div class="carts">
|
||||
<!-- 当前购物车 -->
|
||||
<div v-for="(item, index) in carts.list" :key="index">
|
||||
<carts-item
|
||||
:item="item"
|
||||
@changeNumber="changeNumber"
|
||||
:selCart="carts.selCart"
|
||||
@itemClick="itemClick(item)"
|
||||
></carts-item>
|
||||
</div>
|
||||
<!-- 赠菜 -->
|
||||
<div class="cart-title"><span>以下是优惠菜品</span></div>
|
||||
<div v-for="(item, index) in carts.giftList" :key="index">
|
||||
<carts-item
|
||||
:item="item"
|
||||
@changeNumber="changeNumber"
|
||||
:selCart="carts.selCart"
|
||||
@itemClick="itemClick(item)"
|
||||
></carts-item>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="yiyouhui">{{ carts.yiyouhui }}</div>
|
||||
<div class="u-flex u-row-between">
|
||||
<el-link type="primary">打印制作单</el-link>
|
||||
<div>
|
||||
<span class="totalNumber">共{{ carts.totalNumber }}件</span>
|
||||
<span class="totalPrice">¥{{ carts.payMoney }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<el-button type="primary">微信/支付宝</el-button>
|
||||
<el-button type="primary">现金</el-button>
|
||||
<el-button type="primary">更多支付</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import cartsItem from "./item.vue";
|
||||
import { useCartsStore } from "@/store/modules/carts";
|
||||
|
||||
const props = defineProps({
|
||||
goodsList: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
goodsMapisFinish: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const selCartId = ref(null);
|
||||
|
||||
const carts = useCartsStore();
|
||||
const goodsMap = {};
|
||||
watch(
|
||||
() => props.goodsMapisFinish,
|
||||
(newval) => {
|
||||
if (newval) {
|
||||
for (let goods of props.goodsList) {
|
||||
goodsMap[goods.id] = goods;
|
||||
}
|
||||
carts.init({}, goodsMap);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function itemClick(item) {
|
||||
carts.changeSelCart(item);
|
||||
}
|
||||
|
||||
function changeNumber(step, item) {
|
||||
carts.changeNumber(step * 1, item);
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
carts,
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.list {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.totalNumber {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
.totalPrice {
|
||||
font-size: 18px;
|
||||
color: #000;
|
||||
}
|
||||
.bottom {
|
||||
position: relative;
|
||||
padding-top: 14px;
|
||||
border-top: 1px solid #ebebeb;
|
||||
.yiyouhui {
|
||||
text-align: right;
|
||||
color: #c12a2a;
|
||||
font-size: 13px;
|
||||
line-height: 16px;
|
||||
top: 14px;
|
||||
}
|
||||
}
|
||||
:deep(.btn-group) {
|
||||
display: flex;
|
||||
margin-top: 20px;
|
||||
.el-button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
.carts {
|
||||
height: calc(100% - 120px);
|
||||
overflow-y: scroll;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
/* 修改垂直滚动条 */
|
||||
.carts::-webkit-scrollbar {
|
||||
width: 0; /* 修改宽度 */
|
||||
}
|
||||
|
||||
/* 修改滚动条轨道背景色 */
|
||||
.carts::-webkit-scrollbar-track {
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
.cart-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
color: rgba(0, 0, 0, 0.4);
|
||||
&::after {
|
||||
content: "";
|
||||
flex: 1;
|
||||
height: 1px;
|
||||
background-color: #ebebeb;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<template>
|
||||
<div class="controls">
|
||||
<div class="input-number">
|
||||
<div class="reduce">
|
||||
<el-icon @click="carts.changeNumber(-1, carts.selCart)"><Minus /></el-icon>
|
||||
</div>
|
||||
<span class="text">{{ carts.selCart.number || 1 }}</span>
|
||||
<div class="add">
|
||||
<el-icon @click="carts.changeNumber(1, carts.selCart)"><Plus /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<el-button
|
||||
v-for="(item, index) in controls"
|
||||
:key="index"
|
||||
v-bund="item"
|
||||
:disabled="btnDisabled(item)"
|
||||
@click="controlsClick(item)"
|
||||
>
|
||||
{{ returnLabel(item) }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const number = ref(1);
|
||||
import { useCartsStore } from "@/store/modules/carts";
|
||||
const carts = useCartsStore();
|
||||
|
||||
const controls = ref([
|
||||
{ label: "规格", key: "", disabled: false, per: "sku" },
|
||||
{ label: "赠送", key: "is_gift", disabled: false, per: "cart" },
|
||||
{ label: "打包", key: "is_pack", disabled: false, per: "cart" },
|
||||
{ label: "删除", key: "del", disabled: false, per: "cart" },
|
||||
{ label: "存单", key: "", disabled: false, per: "save" },
|
||||
{ label: "取单", key: "", disabled: false },
|
||||
{ label: "单品备注", key: "one-note", disabled: false, per: "one-note" },
|
||||
{ label: "整单备注", key: "all-note", disabled: false, per: "all-note" },
|
||||
{ label: "退菜", key: "", disabled: false, per: "order" },
|
||||
{ label: "免厨打", key: "is_print", disabled: false, per: "cart" },
|
||||
{ label: "单品改价", key: "", disabled: false, per: "cart" },
|
||||
{ label: "等叫", key: "", disabled: false, per: "cart" },
|
||||
{ label: "整单等叫", key: "", disabled: false, per: "all-wating" },
|
||||
]);
|
||||
|
||||
const emits = defineEmits(["noteClick"]);
|
||||
function controlsClick(item) {
|
||||
switch (item.key) {
|
||||
case "is_gift":
|
||||
carts.updateTag("is_gift", carts.selCart.is_gift ? 0 : 1);
|
||||
break;
|
||||
case "is_pack":
|
||||
emits("packClick", carts.selCart.pack_number, carts.selCart.number);
|
||||
break;
|
||||
case "is_print":
|
||||
carts.updateTag("is_print", carts.selCart.is_print ? 0 : 1);
|
||||
break;
|
||||
case "del":
|
||||
carts.del(carts.selCart);
|
||||
break;
|
||||
case "save":
|
||||
carts.saveCart();
|
||||
break;
|
||||
case "one-note":
|
||||
emits("noteClick", true);
|
||||
break;
|
||||
case "all-note":
|
||||
emits("noteClick", false);
|
||||
break;
|
||||
case "order":
|
||||
carts.order();
|
||||
break;
|
||||
case "all-wating":
|
||||
carts.allWating();
|
||||
break;
|
||||
}
|
||||
}
|
||||
const perList = computed(() => {
|
||||
if (!carts.selCart.id) {
|
||||
return ["all-wating", "all-note"];
|
||||
}
|
||||
if (carts.selCart.id) {
|
||||
return ["cart", "save", "one-note", "all-note", "all-wating"];
|
||||
}
|
||||
});
|
||||
|
||||
function btnDisabled(item) {
|
||||
return !perList.value.includes(item.per);
|
||||
}
|
||||
function returnLabel(item) {
|
||||
if (item.key == "is_gift") {
|
||||
return carts.selCart.is_gift ? "取消赠送" : "赠送";
|
||||
}
|
||||
if (item.key == "is_pack") {
|
||||
return carts.selCart.is_pack ? "取消打包" : "打包";
|
||||
}
|
||||
if (item.key == "is_print") {
|
||||
return carts.selCart.is_print ? "免厨打" : "打印";
|
||||
}
|
||||
return item.label;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
$gap: 10px;
|
||||
.controls {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
width: 106px;
|
||||
padding: 14px 10px;
|
||||
background-color: #f7f7fa;
|
||||
}
|
||||
.el-button + .el-button {
|
||||
margin-top: $gap;
|
||||
margin-left: 0;
|
||||
}
|
||||
.input-number {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #fff;
|
||||
border: 1px solid #dcdfe6;
|
||||
margin-bottom: $gap;
|
||||
cursor: pointer;
|
||||
.reduce,
|
||||
.text,
|
||||
.add {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 38px;
|
||||
}
|
||||
.text {
|
||||
height: 48px;
|
||||
font-size: 30px;
|
||||
border-top: 1px solid #dcdfe6;
|
||||
border-bottom: 1px solid #dcdfe6;
|
||||
}
|
||||
.reduce {
|
||||
}
|
||||
.add {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
<template>
|
||||
<!-- 选择规格 -->
|
||||
<el-dialog width="410px" :title="goods.name" v-model="show" @close="close">
|
||||
<div class="tag-group">
|
||||
<div class="tag-item" v-for="(item, key) in goods.selectSpecInfo" :key="key">
|
||||
<div class="tag-name">{{ key }}</div>
|
||||
<div>
|
||||
<span style="margin: 0 10px 10px 0" v-for="(val, valIndex) in item.list" :key="valIndex">
|
||||
<el-button
|
||||
plain
|
||||
:type="val === item.sel ? 'primary' : ''"
|
||||
:disabled="val.disabled"
|
||||
@click="changeSkuSel(key, val)"
|
||||
>
|
||||
{{ val }}
|
||||
</el-button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<template v-if="skuData">
|
||||
<div class="u-flex u-row-between">
|
||||
<div>
|
||||
<div class="price">¥ {{ skuData.salePrice }}</div>
|
||||
<div class="sku-group-text">
|
||||
<span>{{ skuName }}</span>
|
||||
<span>库存:{{ 0 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="u-flex">
|
||||
<el-input-number v-model="number" :min="skuData.suitNum"></el-input-number>
|
||||
</div>
|
||||
</div>
|
||||
<div class="u-flex" style="margin-top: 14px">
|
||||
<el-button v-if="!skuData.isGrounding" disabled style="width: 100%">已下架</el-button>
|
||||
<template v-else>
|
||||
<el-button type="primary" style="width: 100%">确 定</el-button>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else>
|
||||
<el-button type="primary" style="width: 100%" disabled>确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup >
|
||||
let show = ref(false);
|
||||
// const props = defineProps({
|
||||
// goods: {
|
||||
// type: Object,
|
||||
// default: () => ({}),
|
||||
// },
|
||||
// });
|
||||
|
||||
let number = ref(1);
|
||||
|
||||
const defaultGoods = { selectSpecInfo: {}, skuList: [] };
|
||||
let goods = ref({ ...defaultGoods });
|
||||
|
||||
function resetData() {
|
||||
goods.value = { ...defaultGoods };
|
||||
}
|
||||
|
||||
function changeSkuSel(key, val) {
|
||||
console.log(key, val);
|
||||
goods.value.selectSpecInfo[key].sel = val;
|
||||
}
|
||||
|
||||
function open(data) {
|
||||
show.value = true;
|
||||
if (data) {
|
||||
let selectSpecInfo = {};
|
||||
for (let i in data.selectSpecInfo) {
|
||||
if (data.selectSpecInfo[i].length > 0) {
|
||||
selectSpecInfo[i] = {
|
||||
list: data.selectSpecInfo[i],
|
||||
sel: "",
|
||||
disabled: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
goods.value = { ...data, selectSpecInfo };
|
||||
console.log(goods.value);
|
||||
}
|
||||
}
|
||||
function close() {
|
||||
show.value = false;
|
||||
resetData();
|
||||
}
|
||||
const skuName = computed(() => {
|
||||
if (goods.value.selectSpecInfo) {
|
||||
let sku = [];
|
||||
for (let i in goods.value.selectSpecInfo) {
|
||||
sku.push(goods.value.selectSpecInfo[i].sel);
|
||||
}
|
||||
return sku.join(",");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
const skuData = computed(() => {
|
||||
if (goods.value.skuList.length <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
return goods.value.skuList.find((item) => {
|
||||
return item.specInfo === skuName.value;
|
||||
});
|
||||
});
|
||||
|
||||
defineExpose({ open, close });
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.tag-group {
|
||||
margin-top: 10px;
|
||||
|
||||
.tag-item {
|
||||
margin-bottom: 20px;
|
||||
|
||||
.tag-name {
|
||||
margin-bottom: 10px;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
.price {
|
||||
font-size: 18px;
|
||||
text-align: left;
|
||||
color: #ff5152;
|
||||
font-weight: 600;
|
||||
}
|
||||
.sku-group-text {
|
||||
text-align: left;
|
||||
color: #666;
|
||||
font-size: 11px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
::v-deep .number-box .el-input__inner {
|
||||
border: none;
|
||||
padding: 0 4px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<template>
|
||||
<div class="goods-item">
|
||||
<el-image v-if="item.coverImg" class="goods-image" :src="item.coverImg" fit="cover"></el-image>
|
||||
<div class="info">
|
||||
<div class="name u-flex u-flex-wrap">
|
||||
<span class="weight" v-if="item.type == 'weigh'">称重</span>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
<div class="">¥{{ item.lowPrice }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
item: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
index: Number,
|
||||
active: Boolean,
|
||||
select: Function,
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.goods-item {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
.goods-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.info {
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
padding: 8px;
|
||||
font-size: 14px;
|
||||
color: #fff;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
background-color: rgba(46, 46, 46, 0.38);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
<template>
|
||||
<el-dialog :title="title" width="410px" v-model="show" @close="reset">
|
||||
<el-input :rows="6" type="textarea" v-model="note" placeholder="请输入备注"></el-input>
|
||||
<div>
|
||||
<el-tag
|
||||
v-for="(tag, index) in tags"
|
||||
@click="addNote(tag)"
|
||||
size="medium"
|
||||
:key="index"
|
||||
closable
|
||||
@close="delTag(index)"
|
||||
type="primary"
|
||||
>
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button size="medium" @click="close">取消</el-button>
|
||||
<el-button size="medium" type="primary" @click="confirm">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup>
|
||||
let show = ref(false);
|
||||
let tags = ref([]);
|
||||
let note = ref("");
|
||||
let title = ref("整单备注(提交订单时生效)");
|
||||
let isOne = ref(false);
|
||||
watch(
|
||||
() => tags.length,
|
||||
() => {
|
||||
localStorage.setItem("tags", JSON.stringify(tags.value));
|
||||
}
|
||||
);
|
||||
|
||||
function reset() {
|
||||
note.value = "";
|
||||
}
|
||||
function delTag(index) {
|
||||
this.tags.splice(index, 1);
|
||||
}
|
||||
function addNote(tag) {
|
||||
if (!note.value) {
|
||||
return (note.value = tag);
|
||||
}
|
||||
note.value = tag + "," + note.value;
|
||||
}
|
||||
function open(remark, isOneNote) {
|
||||
isOne.value = isOneNote;
|
||||
title.value = isOneNote ? "整单备注(提交订单时生效)" : "单品备注(提交订单时生效)";
|
||||
show.value = true;
|
||||
note.value = remark ? remark : "";
|
||||
const tags = localStorage.getItem("tags");
|
||||
console.log(tags);
|
||||
this.tags = tags ? JSON.parse(tags) : ["免香菜", "不要辣", "不要葱"];
|
||||
}
|
||||
function close() {
|
||||
show.value = false;
|
||||
}
|
||||
const emits = defineEmits(["confirm"]);
|
||||
function confirm() {
|
||||
const originTags = [...tags.value];
|
||||
if (note.value) {
|
||||
if (originTags >= 10) {
|
||||
originTags.shift();
|
||||
}
|
||||
if (note.value.length <= 16) {
|
||||
const newTags = new Set([note.value, ...originTags]);
|
||||
localStorage.setItem("tags", JSON.stringify([...newTags]));
|
||||
}
|
||||
}
|
||||
emits("confirm", note.value, isOne.value);
|
||||
close();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
::v-deep .el-dialog__body {
|
||||
margin-bottom: 14px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
::v-deep .el-tag {
|
||||
margin-top: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
line-height: 35px;
|
||||
height: 35px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
<template>
|
||||
<el-dialog title="修改打包数量" width="410px" v-model="show" @close="reset">
|
||||
<el-input-number
|
||||
:min="0"
|
||||
:max="max"
|
||||
type="number"
|
||||
v-model="number"
|
||||
placeholder="请输入打包数量"
|
||||
></el-input-number>
|
||||
<template #footer>
|
||||
<el-button size="medium" @click="close">取消</el-button>
|
||||
<el-button size="medium" type="primary" @click="confirm">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup>
|
||||
let show = ref(false);
|
||||
let number = ref(0);
|
||||
const max = ref(0);
|
||||
function reset() {
|
||||
max.value = 0;
|
||||
number.value = 0;
|
||||
}
|
||||
|
||||
function open(packNumber, maxNumber) {
|
||||
show.value = true;
|
||||
max.value = maxNumber || 0;
|
||||
number.value = packNumber || 0;
|
||||
}
|
||||
function close() {
|
||||
show.value = false;
|
||||
reset();
|
||||
}
|
||||
const emits = defineEmits(["confirm"]);
|
||||
function confirm() {
|
||||
emits("confirm", number.value);
|
||||
close();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
::v-deep .el-dialog__body {
|
||||
margin-bottom: 14px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
::v-deep .el-tag {
|
||||
margin-top: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
line-height: 35px;
|
||||
height: 35px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,403 @@
|
|||
<template>
|
||||
<div class="box">
|
||||
<div class="content">
|
||||
<div class="top">
|
||||
<div class="left u-flex u-col-center">
|
||||
<span class="title">代客下单</span>
|
||||
<div class="u-m-l-20 flex">
|
||||
<el-button type="primary">选择用户</el-button>
|
||||
<el-button>选择桌号</el-button>
|
||||
<el-button type="warning">扫码验券</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
<el-input placeholder="请输入商品名称" v-model="keywords" clearable>
|
||||
<template #suffix>
|
||||
<el-icon class="el-input__icon"><search /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="diancan">
|
||||
<div class="left">
|
||||
<div class="diners">
|
||||
<el-button-group v-model="diners.sel" style="width: 100%; display: flex">
|
||||
<el-button
|
||||
:class="{ active: index == diners.sel }"
|
||||
v-for="(item, index) in diners.list"
|
||||
:key="index"
|
||||
>
|
||||
{{ item.label }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
</div>
|
||||
|
||||
<div class="u-flex u-font-14 clear u-m-t-10 perpoles">
|
||||
<div
|
||||
class="u-flex u-p-r-14 u-m-r-14"
|
||||
style="border-right: 1px solid #ebebeb; line-height: 1"
|
||||
>
|
||||
<span>就餐人数:-位</span>
|
||||
<el-icon><ArrowRight /></el-icon>
|
||||
</div>
|
||||
<a @click="clearCarts" style="color: #1890ff">清空</a>
|
||||
</div>
|
||||
<cartsList
|
||||
:goodsMapisFinish="goodsMapisFinish"
|
||||
:goodsList="goods.list"
|
||||
ref="refCart"
|
||||
></cartsList>
|
||||
</div>
|
||||
<div class="center">
|
||||
<Controls @noteClick="showNote" @packClick="showPack" />
|
||||
</div>
|
||||
<div class="right">
|
||||
<div class="flex categoty u-col-center">
|
||||
<div
|
||||
class="show_more_btn"
|
||||
:class="{ showAll: category.showAll }"
|
||||
@click="toggleShowAll"
|
||||
>
|
||||
<div class="flex">
|
||||
<div class="flex showmore">
|
||||
<el-icon color="#fff"><ArrowDown /></el-icon>
|
||||
</div>
|
||||
<span>{{ category.showAll ? "收起" : "展开" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex categorys" :class="{ 'flex-wrap': category.showAll }">
|
||||
<div
|
||||
v-for="(item, index) in category.list"
|
||||
:key="index"
|
||||
@click="changeCategoryId(item)"
|
||||
>
|
||||
<el-tag
|
||||
size="large"
|
||||
type="primary"
|
||||
effect="dark"
|
||||
v-if="goods.query.categoryId === item.id"
|
||||
>
|
||||
{{ item.name }}
|
||||
</el-tag>
|
||||
<el-tag size="large" type="info" v-else effect="plain">{{ item.name }}</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="goods-list">
|
||||
<GoodsItem
|
||||
:item="item"
|
||||
@click="goodsClick(item)"
|
||||
v-for="item in goods.list"
|
||||
:key="item.id"
|
||||
></GoodsItem>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dialogGoodsSel ref="refSelSku"></dialogGoodsSel>
|
||||
<note ref="refNote" @confirm="noteConfirm"></note>
|
||||
<pack ref="refPack" @confirm="packConfirm"></pack>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import Controls from "./components/control.vue";
|
||||
import note from "./components/note.vue";
|
||||
import pack from "./components/pack.vue";
|
||||
import GoodsItem from "./components/goods-item.vue";
|
||||
import dialogGoodsSel from "./components/dialog-goods-sel.vue";
|
||||
import cartsList from "./components/carts/list.vue";
|
||||
import categoryApi from "@/api/product/productclassification";
|
||||
import productApi from "@/api/product/index";
|
||||
//打包
|
||||
const refPack = ref();
|
||||
function showPack(packNumber, max) {
|
||||
refPack.value.open(packNumber * 1, max * 1);
|
||||
}
|
||||
function packConfirm(packNumber) {
|
||||
refCart.value.carts.updateTag("pack_number", packNumber);
|
||||
}
|
||||
|
||||
//备注
|
||||
const refNote = ref(null);
|
||||
function showNote(isOneNote) {
|
||||
const remark = isOneNote ? refCart.value.carts.selCart.remark : "";
|
||||
console.log(remark);
|
||||
refNote.value.open(remark, isOneNote);
|
||||
}
|
||||
function noteConfirm(note, isOneNote) {
|
||||
if (isOneNote) {
|
||||
refCart.value.carts.updateTag("remark", note);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
const keywords = ref("");
|
||||
|
||||
// 就餐类型
|
||||
const diners = reactive({
|
||||
list: [
|
||||
{ label: "堂食", value: 1 },
|
||||
{ label: "自取", value: 2 },
|
||||
],
|
||||
sel: 0,
|
||||
});
|
||||
// 商品分类
|
||||
const category = reactive({
|
||||
list: [],
|
||||
showAll: false,
|
||||
});
|
||||
function toggleShowAll() {
|
||||
category.showAll = !category.showAll;
|
||||
}
|
||||
function changeCategoryId() {}
|
||||
|
||||
function getCategoryList() {
|
||||
categoryApi
|
||||
.getList({
|
||||
page: 1,
|
||||
size: 200,
|
||||
})
|
||||
.then((res) => {
|
||||
category.list = res;
|
||||
});
|
||||
}
|
||||
|
||||
//商品
|
||||
const refSelSku = ref(null);
|
||||
|
||||
const goods = reactive({
|
||||
list: [],
|
||||
query: {
|
||||
categoryId: "",
|
||||
keywords: "",
|
||||
},
|
||||
});
|
||||
|
||||
let goodsMapisFinish = ref(false);
|
||||
|
||||
function getGoods() {
|
||||
productApi
|
||||
.getPage({
|
||||
page: 1,
|
||||
size: 200,
|
||||
...goods.query,
|
||||
})
|
||||
.then((res) => {
|
||||
goods.list = res.records;
|
||||
goodsMapisFinish.value = true;
|
||||
});
|
||||
}
|
||||
|
||||
function goodsClick(item) {
|
||||
//单规格
|
||||
if (item.type == "single") {
|
||||
addCarts({
|
||||
product_id: item.id,
|
||||
sku_id: item.skuList[0].id,
|
||||
number: 1,
|
||||
is_pack: 0,
|
||||
is_gift: 0,
|
||||
is_temporary: 0,
|
||||
discount_sale_amount: 0,
|
||||
discount_sale_note: "",
|
||||
is_print: 0,
|
||||
is_wait_call: 0,
|
||||
product_name: "",
|
||||
remark: "",
|
||||
});
|
||||
}
|
||||
// 多规格
|
||||
if (item.type == "sku") {
|
||||
refSelSku.value.open(item);
|
||||
}
|
||||
}
|
||||
//购物车
|
||||
const refCart = ref(null);
|
||||
function clearCarts() {
|
||||
ElMessageBox.alert("确定要清空点餐列表吗?", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}).then(() => {
|
||||
refCart.value.carts.clear();
|
||||
});
|
||||
}
|
||||
function addCarts(item) {
|
||||
const hasCart = refCart.value.carts.list.find((cartItem) => {
|
||||
return cartItem.product_id == item.product_id && cartItem.sku_id == item.sku_id;
|
||||
});
|
||||
console.log(hasCart);
|
||||
if (hasCart) {
|
||||
refCart.value.carts.update({ ...item, id: hasCart.id });
|
||||
} else {
|
||||
refCart.value.carts.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
getCategoryList();
|
||||
getGoods();
|
||||
}
|
||||
init();
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
$pl: 30px;
|
||||
.box {
|
||||
padding: 20px 20px 10px 20px;
|
||||
height: 100%;
|
||||
.content {
|
||||
background-color: #fff;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 20px 20px 20px 0;
|
||||
.top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #ebebeb;
|
||||
margin-left: $pl;
|
||||
.left {
|
||||
flex: 1;
|
||||
|
||||
.title {
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
.right {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
.diancan {
|
||||
padding-top: 10px;
|
||||
display: flex;
|
||||
max-height: calc(100vh - 256px);
|
||||
.left {
|
||||
width: 350px;
|
||||
padding-right: 14px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.diners {
|
||||
padding-left: $pl;
|
||||
}
|
||||
.perpoles {
|
||||
padding-left: $pl;
|
||||
}
|
||||
}
|
||||
.right {
|
||||
flex: 1;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
}
|
||||
.center {
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.diners .el-button-group .active) {
|
||||
border: 1px solid #409eff !important;
|
||||
color: #409eff !important;
|
||||
background: rgba(24, 144, 255, 0.1) !important;
|
||||
z-index: 10;
|
||||
}
|
||||
:deep(.diners .el-button-group) {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
}
|
||||
:deep(.diners .el-button-group .el-button) {
|
||||
flex: 1;
|
||||
}
|
||||
:deep(.categorys .el-tag--plain.el-tag--info) {
|
||||
border: 1px solid #dcdfe6;
|
||||
color: #000;
|
||||
font-weight: 600;
|
||||
}
|
||||
:deep(.categorys .el-tag) {
|
||||
min-width: 80px;
|
||||
height: 38px;
|
||||
line-height: 38px;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
text-align: center;
|
||||
padding: 0 14px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
border-radius: 2px;
|
||||
user-select: none;
|
||||
margin: 0 10px 10px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.categoty {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background-color: #f7f7fa;
|
||||
z-index: 1;
|
||||
padding-top: 14px;
|
||||
|
||||
.show_more_btn {
|
||||
padding: 0 10px;
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
user-select: none;
|
||||
min-width: 80px;
|
||||
background: #f7f7fa;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 14px;
|
||||
height: 38px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.showmore {
|
||||
transition: all 0.2s;
|
||||
margin-right: 8px;
|
||||
width: 21px;
|
||||
height: 21px;
|
||||
border-radius: 50%;
|
||||
background: #3f9eff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&.showAll {
|
||||
.showmore {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.goods-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 15px;
|
||||
flex: 1;
|
||||
}
|
||||
:deep(.carts) {
|
||||
padding-left: $pl;
|
||||
}
|
||||
:deep(.left) {
|
||||
.bottom {
|
||||
padding-left: $pl;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
export function isTui(item) {
|
||||
return item.status == 'return' || item.status == 'refund' || item.status == 'refunding'
|
||||
}
|
||||
//是否使用会员价
|
||||
export function isUseVipPrice(vipUser,goods){
|
||||
return vipUser.id&&vipUser.isVip&&goods.isMember
|
||||
}
|
||||
|
||||
//计算商品券优惠价格
|
||||
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
||||
const item = goodsArr.find(v => v.productId == coup.proId);
|
||||
if (!item) {
|
||||
return 0
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (isUseVipPrice(vipUser,item) ? memberPrice : item.price) : 0;
|
||||
return price * coup.num
|
||||
|
||||
}
|
||||
//返回新的商品列表,过滤掉退菜的,退单的商品
|
||||
export function returnNewGoodsList(arr) {
|
||||
let goodsMap = {}
|
||||
return arr.filter(v => !isTui(v))
|
||||
}
|
||||
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
|
||||
export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
|
||||
// if(!coup.use){
|
||||
// return false
|
||||
// }
|
||||
const findGoods = goodsArr.filter(v => v.productId == coup.proId)
|
||||
if (!findGoods.length) {
|
||||
return false
|
||||
}
|
||||
const findGoodsTotalNumber = findGoods.reduce((prve, cur) => {
|
||||
return prve + cur.num * 1
|
||||
}, 0)
|
||||
const selCoupNumber = selCoupArr.filter(v => v.proId == coup.proId).reduce((prve, cur) => {
|
||||
return prve + cur.num * 1
|
||||
}, 0)
|
||||
if (selCoupNumber >= findGoodsTotalNumber) {
|
||||
return false
|
||||
}
|
||||
console.log(selCoupNumber,findGoodsTotalNumber);
|
||||
return findGoodsTotalNumber < selCoupNumber ? false : true
|
||||
}
|
||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
|
||||
const newGoodsArr = returnNewGoodsList(goodsArr)
|
||||
const item = newGoodsArr.find(v => v.productId == coup.proId);
|
||||
if (!item) {
|
||||
return {
|
||||
...coup,
|
||||
discountAmount: 0,
|
||||
use: false
|
||||
}
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (isUseVipPrice(vipUser,item) ? memberPrice : item.price) : 0;
|
||||
const discountAmount = (price * coup.num).toFixed(2)
|
||||
console.log(discountAmount);
|
||||
|
||||
// const canUse = !coup.use ? false : (discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr))
|
||||
// const canUse=discountAmount>0
|
||||
const canUse=coup.use
|
||||
return {
|
||||
...coup,
|
||||
discountAmount: discountAmount,
|
||||
use: canUse
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
|
||||
* 1.商品券对应商品数量大于购物车对应商品数量不可用
|
||||
* 2.未在购物车找到相关商品不可用
|
||||
* @param {*} coupArr
|
||||
* @param {*} goodsArr
|
||||
* @param {*} vipUser
|
||||
* @returns
|
||||
*/
|
||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
|
||||
return coupArr.map((v) => {
|
||||
return returnProductCoupon(v, goodsArr, vipUser)
|
||||
})
|
||||
|
||||
}
|
||||
//返回商品实际支付价格
|
||||
export function returnProductPayPrice(goods,vipUser){
|
||||
const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price;
|
||||
const price = isUseVipPrice(vipUser,goods) ? memberPrice : goods.price;
|
||||
return price
|
||||
}
|
||||
//返回商品券抵扣的商品价格
|
||||
export function returnProductCoupAllPrice(productPriceArr,startIndex,num,isMember=true){
|
||||
console.log(productPriceArr);
|
||||
return productPriceArr.slice(startIndex,startIndex+num).reduce((prve,cur)=>{
|
||||
let curPrice=0
|
||||
if(typeof cur==='object'){
|
||||
curPrice=isMember?cur.memberPrice*1:cur.price
|
||||
}else{
|
||||
curPrice=cur*1
|
||||
}
|
||||
return prve+curPrice
|
||||
},0)
|
||||
}
|
||||
|
||||
//返回商品券可抵扣的商品数量
|
||||
export function returnProductCanUseNum(productPriceArr,startIndex,num){
|
||||
console.log(productPriceArr);
|
||||
console.log(num);
|
||||
let n=0;
|
||||
for(let i=0;i<num;i++){
|
||||
if(productPriceArr[startIndex*1+i]){
|
||||
n+=1
|
||||
console.log(n);
|
||||
}else{
|
||||
break
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
//返回同类商品券在同类商品价格数组里的开始位置
|
||||
export function returnProCoupStartIndex(coupArr,index){
|
||||
return coupArr.slice(0,index).reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
}
|
||||
//返回商品数量从0到n每一个对应的价格对照表
|
||||
export function returnGoodsPayPriceMap(goodsArr){
|
||||
return goodsArr.reduce((prve,cur)=>{
|
||||
if(!prve.hasOwnProperty(cur.productId)){
|
||||
prve[cur.productId]=[]
|
||||
}
|
||||
const arr=new Array(cur.num).fill(cur).map(v=>{
|
||||
return {
|
||||
memberPrice:v.memberPrice?v.memberPrice:v.price,
|
||||
price:v.price
|
||||
}
|
||||
})
|
||||
prve[cur.productId].push(...arr)
|
||||
return prve
|
||||
},{})
|
||||
}
|
||||
//计算商品券总优惠价格
|
||||
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
if (coupArr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
//商品分组
|
||||
const goodsMap={}
|
||||
//商品数量从0到n每一个对应的价格
|
||||
const goodsPayPriceMap={}
|
||||
//商品券分组
|
||||
let coupMap={}
|
||||
for(let i in coupArr){
|
||||
const coup=coupArr[i]
|
||||
if(coupMap.hasOwnProperty(coup.proId)){
|
||||
coupMap[coup.proId].push(coup)
|
||||
}else{
|
||||
coupMap[coup.proId]=[coup]
|
||||
}
|
||||
}
|
||||
let total=0
|
||||
for(let key in coupMap){
|
||||
const arr=coupMap[key]
|
||||
for(let i in arr){
|
||||
const coup=arr[i]
|
||||
if(!goodsMap.hasOwnProperty(coup.proId)){
|
||||
goodsMap[coup.proId]=goodsArr.filter(v=>v.productId==coup.proId).map(v=>{
|
||||
return {
|
||||
...v,
|
||||
payPrice:returnProductPayPrice(v,vipUser)
|
||||
}
|
||||
}).sort((a,b)=>{
|
||||
const aPrice=a.payPrice
|
||||
const bPrice=b.payPrice
|
||||
return aPrice-bPrice
|
||||
})
|
||||
goodsPayPriceMap[coup.proId]=goodsMap[coup.proId].reduce((prve,cur)=>{
|
||||
const arr=new Array(cur.num).fill(cur.payPrice)
|
||||
console.log(arr);
|
||||
prve.push(...arr)
|
||||
return prve
|
||||
},[])
|
||||
}
|
||||
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
|
||||
console.log(proCoupStartIndex);
|
||||
const coupNum=Math.min(goodsPayPriceMap[coup.proId].length,coup.num)
|
||||
console.log(coupNum);
|
||||
total+=returnProductCoupAllPrice(goodsPayPriceMap[coup.proId],proCoupStartIndex,coupNum)
|
||||
}
|
||||
}
|
||||
|
||||
return total.toFixed(2);
|
||||
|
||||
}
|
||||
//计算满减券总优惠价格
|
||||
export function returnFullReductionCouponAllPrice(coupArr) {
|
||||
if (coupArr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
|
||||
const price = b.discountAmount
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
}
|
||||
//计算优惠券总价格
|
||||
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
|
||||
const pointAllPrice = returnFullReductionCouponAllPrice(coupArr)
|
||||
return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
|
||||
}
|
||||
|
||||
//返回当前满减券列表可用状态
|
||||
export function returnCanUseFullReductionCoupon(coupArr, payPrice, selCoup) {
|
||||
return coupArr.map(v => {
|
||||
if (v.id == selCoup.id) {
|
||||
return {...v,use:true}
|
||||
}
|
||||
const isfullAmount = payPrice*1 >= v.fullAmount * 1
|
||||
if(payPrice<=0){
|
||||
return {
|
||||
...v,
|
||||
use: false
|
||||
}
|
||||
}
|
||||
return {
|
||||
...v,
|
||||
use: v.use && isfullAmount
|
||||
}
|
||||
}).filter(v => v.use)
|
||||
}
|
||||
|
||||
//根据商品数量还有商品券数量返回优惠券可以使用的数量数组
|
||||
export function returnCanUseNumProductCoup(coupArr,){
|
||||
let productCoup = coupArr.filter(v => v.type == 2)
|
||||
//商品券分组
|
||||
let coupMap={}
|
||||
for(let i in productCoup){
|
||||
const coup=productCoup[i]
|
||||
if(coupMap.hasOwnProperty(coup.proId)){
|
||||
coupMap[coup.proId].push(coup)
|
||||
}else{
|
||||
coupMap[coup.proId]=[coup]
|
||||
}
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
import {isTui} from '../../order_manage/order_goods_util.js'
|
||||
//计算打包费
|
||||
export function returnPackFee(arr, isOld = true) {
|
||||
if (isOld) {
|
||||
return arr.reduce((a, b) => {
|
||||
const bTotal = b.info
|
||||
.filter((v) => v.isGift !== "true" && v.status !== "return")
|
||||
.reduce((prve, cur) => {
|
||||
return prve + (cur.packFee || cur.packAmount || 0);
|
||||
}, 0);
|
||||
return a + bTotal;
|
||||
}, 0);
|
||||
} else {
|
||||
return arr.filter(v => v.status !== 'return' && v.isGift !== 'true').reduce((a, b) => {
|
||||
return a + (b.packFee || b.packAmount || 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
}
|
||||
//判断商品是否可以下单
|
||||
export function isCanBuy(skuGoods, goods) {
|
||||
if (goods.typeEnum == 'normal') {
|
||||
//单规格
|
||||
return goods.isGrounding && goods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true);
|
||||
} else {
|
||||
//多规格
|
||||
return goods.isGrounding && goods.isPauseSale == 0 && skuGoods.isGrounding && skuGoods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true);
|
||||
|
||||
}
|
||||
}
|
||||
//字符匹配
|
||||
export function $strMatch(matchStr, str) {
|
||||
return matchStr.toLowerCase().includes(str.toLowerCase())
|
||||
}
|
||||
|
||||
// 一个数组是否包含另外一个数组全部元素
|
||||
export function arrayContainsAll(arr1, arr2) {
|
||||
for (let i = 0; i < arr2.length; i++) {
|
||||
if (!arr1.includes(arr2[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//n项 n-1项组合,生成全部结果
|
||||
export function generateCombinations(arr, k) {
|
||||
console.log(arr)
|
||||
console.log(k)
|
||||
let result = [];
|
||||
|
||||
function helper(index, current) {
|
||||
if (current.length === k) {
|
||||
result.push(current.slice()); // 使用slice()来避免直接修改原始数组
|
||||
} else {
|
||||
for (let i = index; i < arr.length; i++) {
|
||||
current.push(arr[i]); // 将当前元素添加到组合中
|
||||
helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
|
||||
current.pop(); // 回溯,移除当前元素以便尝试其他组合
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
helper(0, []); // 从索引0开始,初始空数组作为起点
|
||||
return result;
|
||||
}
|
||||
|
||||
export function returnReverseVal(val, isReturnString = true) {
|
||||
const isBol = typeof val === "boolean";
|
||||
const isString = typeof val === "string";
|
||||
let reverseNewval = "";
|
||||
if (isBol) {
|
||||
reverseNewval = !val;
|
||||
}
|
||||
if (isString) {
|
||||
reverseNewval = val === "true" ? "false" : "true";
|
||||
}
|
||||
return reverseNewval;
|
||||
}
|
||||
|
||||
export function returnGiftArr(arr) {
|
||||
let result = []
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const info = arr[i].info
|
||||
for (let j = 0; j < info.length; j++) {
|
||||
if (info[j].isGift === 'true') {
|
||||
result.push(info[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function formatOrderGoodsList(arr) {
|
||||
const goodsMap = {}
|
||||
for (let i in arr) {
|
||||
const goods = arr[i]
|
||||
if (goods.productName != '客座费') {
|
||||
if (goodsMap.hasOwnProperty(goods.placeNum)) {
|
||||
goodsMap[goods.placeNum || 1].push(goods)
|
||||
} else {
|
||||
goodsMap[goods.placeNum || 1] = [goods]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return Object.entries(goodsMap).map(([key, value]) => ({
|
||||
info: value,
|
||||
placeNum: key || 1
|
||||
}))
|
||||
}
|
||||
|
||||
export function returnIsSeatFee(item) {
|
||||
if (!item) {
|
||||
return false
|
||||
}
|
||||
return item.productId == "-999"?true:false;
|
||||
}
|
||||
/**
|
||||
* 计算购物车会员优惠价格
|
||||
*/
|
||||
export function returnVipDiscountPrice() {
|
||||
|
||||
}
|
||||
|
||||
//计算商品券优惠价格
|
||||
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
||||
const item = goodsArr.find(v => v.productId == coup.proId);
|
||||
if(!item){
|
||||
return 0
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
return price*coup.num
|
||||
|
||||
}
|
||||
//返回新的商品列表,过滤掉退菜的,退单的商品
|
||||
export function returnNewGoodsList(arr) {
|
||||
let goodsMap={}
|
||||
return arr.filter(v => !isTui(v))
|
||||
}
|
||||
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
|
||||
export function returnCoupCanUse(goodsArr=[],coup,selCoupArr=[]) {
|
||||
if(!coup.use){
|
||||
return false
|
||||
}
|
||||
const findGoods=goodsArr.filter(v=>v.productId==coup.proId)
|
||||
if(!findGoods.length){
|
||||
return false
|
||||
}
|
||||
const findGoodsTotalNumber=findGoods.reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
const selCoupNumber=selCoupArr.filter(v=>v.proId==coup.proId).reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
if(selCoupNumber>=findGoodsTotalNumber){
|
||||
return false
|
||||
}
|
||||
return findGoodsTotalNumber<(coup.num+selCoupNumber)?false:true
|
||||
}
|
||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||
export function returnProductCoupon(coup, goodsArr, vipUser,selCoupArr=[]) {
|
||||
const newGoodsArr = returnNewGoodsList(goodsArr)
|
||||
const item = newGoodsArr.find(v => v.productId == coup.proId);
|
||||
if(!item){
|
||||
return {...coup, discountAmount: 0,use:false}
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
const discountAmount=(price*coup.num).toFixed(2)
|
||||
console.log(discountAmount);
|
||||
const canUse=!coup.use?false:(discountAmount>0&&returnCoupCanUse(goodsArr,coup,selCoupArr))
|
||||
// const canUse=discountAmount>0
|
||||
return { ...coup, discountAmount: discountAmount,use:canUse}
|
||||
|
||||
}
|
||||
/**
|
||||
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
|
||||
* 1.商品券对应商品数量大于购物车对应商品数量不可用
|
||||
* 2.未在购物车找到相关商品不可用
|
||||
* @param {*} coupArr
|
||||
* @param {*} goodsArr
|
||||
* @param {*} vipUser
|
||||
* @returns
|
||||
*/
|
||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser){
|
||||
return coupArr.map((v) => {
|
||||
return returnProductCoupon(v, goodsArr, vipUser)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//计算商品券总优惠价格
|
||||
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
if(coupArr.length == 0){
|
||||
return 0;
|
||||
}
|
||||
return coupArr.reduce((a, b) => {
|
||||
const price = returnProductCouponPrice(b, goodsArr, vipUser)
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
}
|
||||
//计算满减券总优惠价格
|
||||
export function returnFullReductionCouponAllPrice(coupArr) {
|
||||
if(coupArr.length == 0){
|
||||
return 0;
|
||||
}
|
||||
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
|
||||
const price = b.discountAmount
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
}
|
||||
//计算优惠券总价格
|
||||
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
const poductAllprice=returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
|
||||
const pointAllPrice=returnFullReductionCouponAllPrice(coupArr)
|
||||
return (poductAllprice*1+pointAllPrice*1).toFixed(2);
|
||||
}
|
||||
|
||||
//返回购物车商品价格
|
||||
export function returnCartPrice(goods, vipUser) {
|
||||
const price=goods.price||goods.salePrice
|
||||
if(!vipUser||!vipUser.id ||!vipUser.isVip){
|
||||
return price
|
||||
}
|
||||
const memberPrice = goods.memberPrice ? goods.memberPrice :price;
|
||||
return memberPrice
|
||||
}
|
||||
Loading…
Reference in New Issue