diff --git a/src/api/account/table.ts b/src/api/account/table.ts index 58d620c..7db43e3 100644 --- a/src/api/account/table.ts +++ b/src/api/account/table.ts @@ -7,6 +7,7 @@ const API = { return request({ url: `${baseURL}/code?num=` + num, method: "post", + responseType: 'blob' }); }, getList(data: getListRequest) { diff --git a/src/api/order/order.ts b/src/api/order/order.ts index f48d9f7..765bef8 100644 --- a/src/api/order/order.ts +++ b/src/api/order/order.ts @@ -24,12 +24,12 @@ const OrderApi = { params: params, }); }, - // 订单全额退款 只传订单id + // 订单退款 只传订单id refundOrder(data: refundOrderRequest) { return request({ url: `${baseURL}/refundOrder`, method: "post", - params: data, + data }); }, diff --git a/src/api/order/pay.ts b/src/api/order/pay.ts new file mode 100644 index 0000000..660effb --- /dev/null +++ b/src/api/order/pay.ts @@ -0,0 +1,100 @@ +import request from "@/utils/request"; +import { Order_BaseUrl } from "@/api/config"; +const baseURL = Order_BaseUrl + "/pay"; +const Api = { + // h5支付 + + h5Pay(data: h5PayRequest) { + return request({ + url: `${baseURL}/h5Pay`, + method: "post", + data + }); + }, + //反扫 + microPay(data: any) { + return request({ + url: `${baseURL}/microPay`, + method: "post", + data + }); + }, + //现金支付 + cashPay(data: any) { + return request({ + url: `${baseURL}/cashPay`, + method: "post", + data + }); + } + +}; + +export default Api; + +export interface h5PayRequest { + /** + * 支付备注 + */ + buyerRemark?: string; + checkOrderPay?: CheckOrderPay; + /** + * 跳转地址 + */ + returnUrl?: string; + shopId: number; + [property: string]: any; +} + +/** +* CheckOrderPay +*/ +export interface CheckOrderPay { + /** + * 用户使用的卡券 + */ + couponList?: number[]; + /** + * 手动优惠金额 + */ + discountAmount?: number; + /** + * 折扣比例(计算时 向上取整保留 两位小数) + */ + discountRatio?: number; + /** + * 满减优惠券抵扣金额 + */ + fullCouponDiscountAmount?: number; + /** + * 订单金额 + */ + orderAmount?: number; + orderId: number; + /** + * 订单原金额(包含打包费+餐位费) 不含折扣价格 + */ + originAmount?: number; + /** + * 积分抵扣金额(tb_points_basic_setting表) + */ + pointsDiscountAmount?: number; + /** + * 使用的积分数量 (扣除各类折扣 enable_deduction后使用) + */ + pointsNum?: number; + /** + * 商品优惠券抵扣金额 + */ + productCouponDiscountAmount?: number; + /** + * 抹零金额 减免多少钱 + */ + roundAmount?: number; + /** + * 用餐人数 + */ + seatNum?: number; + userId?: number; + [property: string]: any; +} \ No newline at end of file diff --git a/src/api/system/user.ts b/src/api/system/user.ts index e893e3d..5c11ef6 100644 --- a/src/api/system/user.ts +++ b/src/api/system/user.ts @@ -1,4 +1,5 @@ import request from "@/utils/request"; +import { property } from "lodash"; const USER_BASE_URL = "/api/v1/users"; @@ -237,6 +238,7 @@ export interface UserInfo { /** 店铺logo */ logo: string; + [property: string]: any } /** diff --git a/src/layout/components/NavBar/components/NavbarRight.vue b/src/layout/components/NavBar/components/NavbarRight.vue index d6713d1..dbe906b 100644 --- a/src/layout/components/NavBar/components/NavbarRight.vue +++ b/src/layout/components/NavBar/components/NavbarRight.vue @@ -15,7 +15,7 @@ - + diff --git a/src/router/index.ts b/src/router/index.ts index 785814d..890531c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -650,7 +650,7 @@ export const constantRoutes: RouteRecordRaw[] = [ { path: "index", component: () => import("@/views/mytemplate/index.vue"), - name: "mytemplate", + name: "mytemplateIndex", meta: { title: "我的模板", affix: false, diff --git a/src/store/modules/carts.ts b/src/store/modules/carts.ts index a2de3d2..120aea5 100644 --- a/src/store/modules/carts.ts +++ b/src/store/modules/carts.ts @@ -1,20 +1,38 @@ import { store } from "@/store"; import WebSocketManager, { type ApifoxModel, msgType } from "@/utils/websocket"; +import orderApi from "@/api/order/order"; +import { useUserStore } from "@/store/modules/user"; +const shopUser = useUserStore(); export interface CartsState { id: string | number; [property: string]: any; } export const useCartsStore = defineStore("carts", () => { + //选择用户 + const vipUser = ref<{ id?: string | number, isVip?: boolean }>({}); + function changeUser(user: any) { + vipUser.value = user; + } - + //是否启用会员价 + const useVipPrice = computed(() => { + return shopUser.userInfo.isMemberPrice && vipUser.value.id && vipUser.value.isVip + }) //台桌id const table_code = ref(''); + //当前购物车数据 const list = useStorage("carts", []); + //历史订单数据 + const oldOrder = useStorage("Instead_olold_order", { + detailMap: [], + originAmount: 0 + }); + //代客下单页面商品缓存 const goods = useStorage("Instead_goods", []); //赠菜 @@ -22,8 +40,13 @@ export const useCartsStore = defineStore("carts", () => { let goodsMap: { [key: string]: any } = useStorage('Instead_goods_map', {}); //当前选中cart let selListIndex = ref(-1); + //当前选中商品是否是赠菜 const isSelGift = ref(false); + //当前选中是否是历史订单 + const isOldOrder = ref(false); + //选中历史订单中的第几次下单 + const selPlaceNum = ref(-1); const defaultCart = { id: '', number: 0, @@ -34,6 +57,9 @@ export const useCartsStore = defineStore("carts", () => { }) //当前购物车选中数据 const selCart = computed(() => { + if (isOldOrder.value && selPlaceNum.value >= 0) { + return oldOrder.value.detailMap[selPlaceNum.value][selListIndex.value] + } if (isSelGift.value) { return giftList.value[selListIndex.value] || defaultCart } @@ -56,6 +82,29 @@ export const useCartsStore = defineStore("carts", () => { return acc + cur.number * cur.salePrice }, 0) }) + //打包数量 + const packNum = computed(() => { + const nowCartNumber = list.value.reduce((acc: number, cur: any) => { + return acc + cur.pack_number * 1 + }, 0) + const giftNumber = giftList.value.reduce((acc: number, cur: any) => { + return acc + cur.pack_number * 1 + }, 0) + return nowCartNumber + giftNumber + }) + //打包费 + const packFee = computed(() => { + const nowPackFee = list.value.reduce((acc: number, cur: any) => { + return acc + (cur.packFee || 0) * cur.pack_number + }, 0) + const giftPackFee = giftList.value.reduce((acc: number, cur: any) => { + return acc + (cur.packFee || 0) * cur.pack_number + }, 0) + return nowPackFee + giftPackFee + }) + + + // 优惠 const yiyouhui = computed(() => { const youhui = giftMoney.value if (youhui > 0) { @@ -67,14 +116,11 @@ export const useCartsStore = defineStore("carts", () => { //支付总价 const payMoney = computed(() => { const money = list.value.reduce((acc: number, cur: any) => { - if (cur.is_temporary) { - //临时菜 - return acc + cur.number * (cur.discount_sale_amount) - } else { - return acc + cur.number * (cur.salePrice) - } + const memberPrice = cur.skuData ? (cur.skuData.memberPrice || cur.skuData.salePrice) : 0 + const price = (cur.discount_sale_amount * 1 || cur.salePrice || 0) + return acc + cur.number * (useVipPrice.value ? memberPrice : price) }, 0) - return money.toFixed(2) + return (money + packFee.value).toFixed(2) }) //总计数量 const totalNumber = computed(() => { @@ -102,6 +148,21 @@ export const useCartsStore = defineStore("carts", () => { if (!cart.id) { return } + if (cart.placeNum) { + selPlaceNum.value = cart.placeNum + isOldOrder.value = true + console.log(oldOrder.value.detailMap[cart.placeNum]) + selListIndex.value = oldOrder.value.detailMap[cart.placeNum].findIndex((item: CartsState) => { + return item.id == cart.id + }) + return + } + if (cart.is_gift) { + isSelGift.value = true + } else { + isSelGift.value = false + } + if (cart.is_gift) { isSelGift.value = true selListIndex.value = giftList.value.findIndex((item: CartsState) => item.id === cart.id); @@ -119,7 +180,8 @@ export const useCartsStore = defineStore("carts", () => { is_temporary: 0, discount_sale_amount: 0, discount_sale_note: "", - is_print: 0, + is_print: 1, + pro_group_info: '', is_wait_call: 0, product_name: "", remark: "", @@ -156,6 +218,8 @@ export const useCartsStore = defineStore("carts", () => { new_table_code: newVal, id: list.value[0].id }); + } else { + table_code.value = `${newVal}`; } } @@ -176,9 +240,19 @@ export const useCartsStore = defineStore("carts", () => { } sendMessage('edit', { ...cart, [key]: val }); } + function clear() { sendMessage('cleanup', {}); } + function dataReset() { + list.value = []; + giftList.value = []; + selListIndex.value = -1 + selPlaceNum.value = 1 + isOldOrder.value = false + selListIndex.value = -1; + isSelGift.value = false + } // 寻找套餐商品sku interface GroupSnap { @@ -200,19 +274,25 @@ export const useCartsStore = defineStore("carts", () => { return undefined } let skuData = undefined; - if (goods.type == 'package') { - //套餐商品 - const SnapSku = findInGroupSnapSku(goods.groupSnap, v.sku_id) - skuData = { ...SnapSku, salePrice: SnapSku ? SnapSku.price : 0 } - } else { - skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id); - } + skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id); + + // if (goods.type == 'package') { + // //套餐商品 + // const SnapSku = findInGroupSnapSku(goods.groupSnap, v.sku_id) + // skuData = { ...SnapSku, salePrice: SnapSku ? SnapSku.price : 0 } + // } else { + // skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id); + // } + skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id); + if (skuData) { return { salePrice: skuData ? skuData.salePrice : 0, + memberPrice: skuData ? skuData.memberPrice : 0, coverImg: goods.coverImg, name: goods.name, specInfo: skuData.specInfo, + packFee: goods.packFee || 0, skuData } } else { @@ -220,10 +300,42 @@ export const useCartsStore = defineStore("carts", () => { } } - function init(initParams: ApifoxModel, $goodsMap: any) { + function returnDetailMap(data: any) { + const newData: { [key: string]: any } = {} + for (let i in data) { + newData[i] = data[i].map((v: any) => { + + const skuData = getProductDetails({ product_id: v.productId, sku_id: v.skuId }) + + return { + ...skuData, + placeNum: v.placeNum, + number: v.num, + id: v.id + } + }) + } + return newData + } + /** + * + * @param initParams 购物车初始化参数 + * @param $goodsMap 商品id对应的map + * @param oldOrder 历史订单数据 + */ + + function init(initParams: ApifoxModel, $goodsMap: any, $oldOrder: any) { // 商品id对应的数据map goodsMap = $goodsMap + + oldOrder.value = { + ...$oldOrder, + detailMap: returnDetailMap($oldOrder.detailMap) + } + console.log('initParams', initParams) + table_code.value = initParams && initParams.table_code ? initParams.table_code : ''; + WebSocketManager.subscribeToTopic(initParams, (msg) => { console.log("收到消息:", msg); if (msg.hasOwnProperty('status') && msg.status != 1) { @@ -236,11 +348,17 @@ export const useCartsStore = defineStore("carts", () => { if (msg.data.table_code) { table_code.value = table_code.value ? table_code.value : msg.data.table_code } + } + + // 初始化 if (msg.operate_type === "manage_init") { // 设置单价 list.value = msg.data.filter((v: Record) => { + if (v.is_temporary) { + return v + } const skuData = getProductDetails({ product_id: v.product_id, sku_id: v.sku_id }) if (skuData) { (Object.keys(skuData) as (keyof typeof skuData)[]).forEach((key) => { @@ -253,6 +371,9 @@ export const useCartsStore = defineStore("carts", () => { return !v.is_gift }) giftList.value = msg.data.filter((v: Record) => { + if (v.is_temporary) { + return v && v.is_gift + } const skuData = getProductDetails({ product_id: v.product_id, sku_id: v.sku_id }) if (skuData) { (Object.keys(skuData) as (keyof typeof skuData)[]).forEach((key) => { @@ -335,13 +456,17 @@ export const useCartsStore = defineStore("carts", () => { if (msg.operate_type === "manage_cleanup") { list.value = [] giftList.value = [] + oldOrder.value = { + detailMap: [], + originAmount: 0 + } table_code.value = '' } console.log(list.value) }); } - const delArr = ['skuData', 'coverImg', 'specInfo'] + const delArr = ['skuData', 'coverImg', 'specInfo', 'placeNum', 'update_time', 'create_time', 'packFee', 'memberPrice'] function sendMessage(operate_type: msgType, message: any) { const msg = { ...message, operate_type: operate_type, table_code: table_code.value } if (operate_type == 'edit') { @@ -349,9 +474,16 @@ export const useCartsStore = defineStore("carts", () => { delete msg[delArr[i]] } } + console.log('send msg', msg) WebSocketManager.sendMessage(msg); } return { + dataReset, + useVipPrice, + changeUser, + packNum, packFee, + isOldOrder, + oldOrder, isCanSelectGroup, goods, selGoods, diff --git a/src/utils/request.ts b/src/utils/request.ts index a7cc189..c1a1442 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -31,9 +31,10 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( (response: AxiosResponse) => { + // 如果响应是二进制流,则直接返回,用于下载文件、Excel 导出等 if (response.config.responseType === "blob") { - return response; + return response.data; } const { code, data, msg } = response.data; diff --git a/src/utils/websocket.ts b/src/utils/websocket.ts index 7ecfea5..a4997e6 100644 --- a/src/utils/websocket.ts +++ b/src/utils/websocket.ts @@ -120,7 +120,15 @@ class WebSocketManager { ...this.initParams, ...message, }) - this.client.send(msg); + try { + this.client.send(msg); + + } catch (error) { + ElMessage.error('发送失败') + this.disconnect() + this.setupWebSocket(); + + } } } public canSendMessage() { diff --git a/src/views/order/index/components/detail.vue b/src/views/order/index/components/detail.vue new file mode 100644 index 0000000..dd1c41a --- /dev/null +++ b/src/views/order/index/components/detail.vue @@ -0,0 +1,478 @@ + + + + + diff --git a/src/views/order/index/components/orderEnum.js b/src/views/order/index/components/orderEnum.js new file mode 100644 index 0000000..c472261 --- /dev/null +++ b/src/views/order/index/components/orderEnum.js @@ -0,0 +1,84 @@ +export default { + status: [ + { + key: 'unpaid', + label: '待支付' + }, + { + key: 'unsend', + label: '待发货' + }, + { + key: 'closed', + label: '订单完成' + }, + { + key: 'send', + label: '已发' + }, + { + key: 'refunding', + label: '申请退单' + }, + { + key: 'refund', + label: '退单' + }, + { + key: 'cancelled', + label: '取消订单' + }, + { + key: 'merge', + label: '合台' + }, + { + key: 'pending', + label: '挂单' + }, + { + key: 'activate', + label: '激活' + }, + { + key: 'paying', + label: '支付中' + } + ], + sendType: [ + { + key: 'post', + label: '快递' + }, + { + key: 'takeaway', + label: '外卖' + }, + { + key: 'takeself', + label: '自提' + }, + { + key: 'table', + label: '堂食' + } + ], + orderType: [ + { + key: 'cash', + label: '收银' + }, + { + key: 'miniapp', + label: '小程序' + }, + { + key: 'offline', + label: '线下' + }, + { + key: 'return', + label: '退单' + } + ] +} \ No newline at end of file diff --git a/src/views/order/index/components/return-money.vue b/src/views/order/index/components/return-money.vue new file mode 100644 index 0000000..dcb0b5f --- /dev/null +++ b/src/views/order/index/components/return-money.vue @@ -0,0 +1,212 @@ + + + + \ No newline at end of file diff --git a/src/views/order/index/index.vue b/src/views/order/index/index.vue index bff5bb5..a012b49 100644 --- a/src/views/order/index/index.vue +++ b/src/views/order/index/index.vue @@ -69,7 +69,7 @@ + + \ No newline at end of file diff --git a/src/views/tool/Instead/components/carts/item.vue b/src/views/tool/Instead/components/carts/item.vue index e4f9df5..4a35358 100644 --- a/src/views/tool/Instead/components/carts/item.vue +++ b/src/views/tool/Instead/components/carts/item.vue @@ -112,6 +112,10 @@ \ No newline at end of file diff --git a/src/views/tool/Instead/index.vue b/src/views/tool/Instead/index.vue index 03306ae..f54639c 100644 --- a/src/views/tool/Instead/index.vue +++ b/src/views/tool/Instead/index.vue @@ -5,10 +5,10 @@
代客下单
-
- 选择用户 +
+ 选择用户 -
+ +
+
@@ -159,7 +167,14 @@ - +
@@ -180,15 +195,13 @@ - - +
\ No newline at end of file diff --git a/src/views/tool/table/components/addTable.vue b/src/views/tool/table/components/addTable.vue index 719066e..2374760 100644 --- a/src/views/tool/table/components/addTable.vue +++ b/src/views/tool/table/components/addTable.vue @@ -152,13 +152,13 @@ function onSubmitHandle() { let res = form.id ? await tableApi.edit(form) : await tableApi.add(form); console.log(res); emits("success", res); - close(); ElNotification({ title: "成功", message: `${form.id ? "编辑" : "添加"}成功`, type: "success", }); loading.value = false; + close(); } catch (error) { loading.value = false; console.log(error); diff --git a/src/views/tool/table/components/downloadTableCode.vue b/src/views/tool/table/components/downloadTableCode.vue index e453aca..48b354a 100644 --- a/src/views/tool/table/components/downloadTableCode.vue +++ b/src/views/tool/table/components/downloadTableCode.vue @@ -43,6 +43,7 @@ export default { try { this.loading = true; const file = await TableApi.downloadTableCode(this.form.number); + console.log(file); this.loading = false; this.dialogVisible = false; ElMessage.success("下载成功"); diff --git a/src/views/tool/table/index.vue b/src/views/tool/table/index.vue index 9f72151..b34cabc 100644 --- a/src/views/tool/table/index.vue +++ b/src/views/tool/table/index.vue @@ -219,7 +219,7 @@ - +
diff --git a/src/views/user/list/config/add.ts b/src/views/user/list/config/add.ts index 14aaa5b..e39b27a 100644 --- a/src/views/user/list/config/add.ts +++ b/src/views/user/list/config/add.ts @@ -1,6 +1,6 @@ import shopUserApi, { type addRequest } from "@/api/account/shopUser"; import type { IModalConfig } from "@/components/CURD/types"; - +import dayjs from "dayjs"; const modalConfig: IModalConfig = { pageName: "sys:user", dialog: { @@ -16,6 +16,7 @@ const modalConfig: IModalConfig = { }, beforeSubmit(data) { console.log("提交之前处理", data); + data.birthDay = dayjs(data.birthDay).format("YYYY-MM-DD"); }, formItems: [ {