diff --git a/.env.production b/.env.production index 97f10d4..91638dd 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ VITE_NOW_TYPE = 'build' -VITE_PUSH_URL ='wss://multi-store.lihaink.cn/pull' +VITE_PUSH_URL = 'wss://multi-store.lihaink.cn/pull' VITE_BASE_URL = 'https://multi-store.lihaink.cn' \ No newline at end of file diff --git a/src/views/saleHome/component/classify.vue b/src/views/saleHome/component/classify.vue index 49c2b1e..f31fcb8 100644 --- a/src/views/saleHome/component/classify.vue +++ b/src/views/saleHome/component/classify.vue @@ -145,6 +145,7 @@ const changeActive = (index = -1, type = 1) => { .list { display: flex; + flex-wrap: wrap; div { margin-right: 1rem; diff --git a/src/views/saleHome/component/order.vue b/src/views/saleHome/component/order.vue index 1d0399e..7f401cf 100644 --- a/src/views/saleHome/component/order.vue +++ b/src/views/saleHome/component/order.vue @@ -5,6 +5,7 @@ import price from "./price.vue"; import mitt from "@/utils/mitt.js"; import { useUserStore } from "@/store/user.js"; import userList from "@/components/userList.vue"; +import { ElMessage } from "element-plus"; const list = ref([]); const allPrice = ref(0); //商品总价 @@ -15,367 +16,380 @@ const userStore = useUserStore(); const userListRef = ref(null); const clearAll = () => { - let id = []; - list.value.map((item) => { - id.push(item.id); - }); - if (id.length == 0) return; - deleteShop(id); + let id = []; + list.value.map((item) => { + id.push(item.id); + }); + if (id.length == 0) return; + deleteShop(id); }; const deleteOne = (id) => { - list.value = list.value.filter((item) => item.id != id); - deleteShop([id]); + list.value = list.value.filter((item) => item.id != id); + deleteShop([id]); }; const deleteShop = (arr) => { - cartDeleteApi({ - id: arr, - }).then((res) => { - console.log(res); - getList(); - }); + cartDeleteApi({ + id: arr, + }).then((res) => { + console.log(res); + getList(); + }); }; const getList = () => { - allPrice.value = 0; - costPrice.value = 0; - discounts.value = 0; - cartListApi().then((res) => { - if (res.data?.lists?.length > 0) { - list.value = res.data.lists; - allPrice.value = res.data?.lists.reduce((previous, current) => { - return previous + Number(current.total_price); - }, 0) - costPrice.value = allPrice.value; - } else list.value = []; - }); + allPrice.value = 0; + costPrice.value = 0; + discounts.value = 0; + cartListApi().then((res) => { + if (res.data?.lists?.length > 0) { + list.value = res.data.lists; + allPrice.value = res.data?.lists.reduce((previous, current) => { + return previous + Number(current.total_price); + }, 0) + costPrice.value = allPrice.value; + } else list.value = []; + }); }; getList(); const emit = defineEmits(["goPay", "editAttr"]); const goPay = () => { - emit("goPay"); + emit("goPay"); }; const changeCartNum = (val, old) => { - cartCreateApi({ - product_id: val.product_id, - cart_num: val.cart_num - }).then((res) => { - allPrice.value = 0; - list.value.forEach((item) => { - allPrice.value += item.price*item.cart_num; + cartCreateApi({ + product_id: val.product_id, + cart_num: val.cart_num + }).then((res) => { + allPrice.value = 0; + list.value.forEach((item) => { + allPrice.value += item.price * item.cart_num; + }); + costPrice.value = allPrice.value; + }).catch((err)=>{ + val.cart_num = err?.msg?.match(/\d+\.\d+/) || 1; }); - costPrice.value = allPrice.value; - }); }; const editAttr = (data) => { - emit("editPupop", data); + emit("editPupop", data); }; const changeAllPrice = (price) => { - discounts.value = costPrice.value - price; - allPrice.value = +price; - nextTick(() => { - setTimeout(() => { - showPrice(false); - }, 150); - }); + discounts.value = costPrice.value - price; + allPrice.value = +price; + nextTick(() => { + setTimeout(() => { + showPrice(false); + }, 150); + }); }; const nowPrice = ref(0); const priceRef = ref(null); const showPrice = (type = true) => { - priceRef.value.show(type, costPrice.value); + priceRef.value.show(type, costPrice.value); }; const userInfo = ref({ uid: '' }) -const setUser = (row)=>{ +const setUser = (row) => { userInfo.value = row; userInfo.value.uid = row.id; } defineExpose({ - getList, - list, - discounts, - allPrice, - userInfo + getList, + list, + discounts, + allPrice, + userInfo }); // 键盘事件 const ainsert = () => { - if (priceRef.value.dialogVisible) priceRef.value.dialogVisible = false; - else showPrice(); + if (priceRef.value.dialogVisible) priceRef.value.dialogVisible = false; + else showPrice(); }; const adelete = () => { - if (list.value.length > 0) clearAll(); + if (list.value.length > 0) clearAll(); }; onMounted(() => { - mitt.on("insert", ainsert); - mitt.on("delete", adelete); + mitt.on("insert", ainsert); + mitt.on("delete", adelete); }); onUnmounted(() => { - mitt.off("insert", ainsert); - mitt.off("delete", adelete); + mitt.off("insert", ainsert); + mitt.off("delete", adelete); }); diff --git a/src/views/saleHome/component/pupop.vue b/src/views/saleHome/component/pupop.vue index 8f23c89..739f955 100644 --- a/src/views/saleHome/component/pupop.vue +++ b/src/views/saleHome/component/pupop.vue @@ -22,7 +22,7 @@ const setForm = (data, type = "add") => { const emit = defineEmits(["changeItem"]); const changeItem = () => { - if(!form.value.cart_num) form.value.cart_num = 1; + if(!form.value.cart_num) form.value.cart_num = form.value.batch > 0 ? form.value.batch : 1; emit("changeItem", form.value); dialogVisible.value = false; }; @@ -71,10 +71,10 @@ const close = () => {
{ - where.value = { - ...where.value, - ...data, - }; - if (reload) { - storeList.value = []; - where.value.page_no = 1; - loadEnd.value = false; - } - loading.value = true; - saleStoreListApi(where.value).then((res) => { - loading.value = false; - if (res.data?.lists?.length < where.value.page_size) loadEnd.value = true; - storeList.value = storeList.value.concat(res.data.lists); - if ( - data.code && - storeList.value.length == 1 && - isAllDigits(data.code) - ) { - shopRef.value.code = ""; - shopRef.value.inputBlur(); - changeItem(storeList.value[0]); + where.value = { + ...where.value, + ...data, + }; + if (reload) { + storeList.value = []; + where.value.page_no = 1; + loadEnd.value = false; } - where.value.page_no++; - }); + loading.value = true; + saleStoreListApi(where.value).then((res) => { + loading.value = false; + if (res.data?.lists?.length < where.value.page_size) loadEnd.value = true; + storeList.value = storeList.value.concat(res.data.lists); + if ( + data.code && + storeList.value.length == 1 && + isAllDigits(data.code) + ) { + shopRef.value.code = ""; + shopRef.value.inputBlur(); + changeItem(storeList.value[0]); + } + where.value.page_no++; + }); }; const loadEnd = ref(false); const loadMore = (data) => { - if (loadEnd.value) return; - getStoreList(data); + if (loadEnd.value) return; + getStoreList(data); }; function isAllDigits(str) { - return /^\d+$/.test(str); + return /^\d+$/.test(str); } const cartAddInfo = (item, change = "") => { - console.log(item, change); - let q = { - product_id: item.product_id, - cart_num: item.cart_num, - }; - cartCreateApi(q).then((res) => { - orderRef.value.getList(); - }); + console.log(item, change); + let q = { + product_id: item.product_id, + cart_num: item.cart_num, + }; + cartCreateApi(q).then((res) => { + orderRef.value.getList(); + }); }; const changeItem = (item, change) => { - pupopRef.value.setForm(item, "add"); - pupopRef.value.show(true); + pupopRef.value.setForm(item, "add"); + pupopRef.value.show(true); }; const editPupop = (item) => { - pupopRef.value.setForm(item, "edit"); - pupopRef.value.show(true); + pupopRef.value.setForm(item, "edit"); + pupopRef.value.show(true); }; const orderForm = ref({}); // 结算 const checkOut = () => { - let cart_id = orderRef.value.list.map((item) => item.id); - let query = { - cart_id: cart_id, - uid: orderRef.value?.userInfo?.uid || "" - }; - if (orderRef.value.discounts > 0) { - query.deduction_price = orderRef.value.discounts.toFixed(2); - query.pay_type = "micropay"; - } - orderCheckApi(query).then((res) => { - orderForm.value = res.data.order; - payRef.value.setForm({ - data: res.data.order, - cart_id: cart_id, - uid: orderRef.value?.userInfo?.uid || "" + let cart_id = orderRef.value.list.map((item) => item.id); + let query = { + cart_id: cart_id, + uid: orderRef.value?.userInfo?.uid || "" + }; + if (orderRef.value.discounts > 0) { + query.deduction_price = orderRef.value.discounts.toFixed(2); + query.pay_type = "micropay"; + } + orderCheckApi(query).then((res) => { + orderForm.value = res.data.order; + payRef.value.setForm({ + data: res.data.order, + cart_id: cart_id, + uid: orderRef.value?.userInfo?.uid || "" + }); }); - }); }; const goPay = () => { - checkOut(); - payRef.value.drawer = true; + if (orderRef.value.allPrice < 500) return ElMessage.error('订单金额不能低于500元'); + checkOut(); + payRef.value.drawer = true; }; const paySuccess = (data = null) => { - // data = { - // out_trade_no: "PF171568087790938356", //单号 - // create_time: "2024-05-14 17:59:05", //下单时间 - // trade_type: "MICROPAY", //支付方式 - // transaction_id: "4200002159202405159003084211", //支付单号 - // } -// if(data) onPrint(data); - setTimeout(()=>{ - orderRef.value.getList(); - }) + // data = { + // out_trade_no: "PF171568087790938356", //单号 + // create_time: "2024-05-14 17:59:05", //下单时间 + // trade_type: "MICROPAY", //支付方式 + // transaction_id: "4200002159202405159003084211", //支付单号 + // } + // if(data) onPrint(data); + setTimeout(() => { + orderRef.value.getList(); + }) }; // 打印小票 -const onPrint = (data)=>{ - let goods = []; - orderRef.value.list.forEach((item) => { - goods.push({ - name: item.goods_name, //商品名称 - sell: item.sell, //单价 - nums: item.cart_num, //数量 - unit_name: item.unit_name, //单位 - total: item.goods_total_price, //小计 +const onPrint = (data) => { + let goods = []; + orderRef.value.list.forEach((item) => { + goods.push({ + name: item.goods_name, //商品名称 + sell: item.sell, //单价 + nums: item.cart_num, //数量 + unit_name: item.unit_name, //单位 + total: item.goods_total_price, //小计 + }); }); - }); - let paytype = "现金支付"; - if(data.pay_type==13) paytype = "支付宝支付"; - if(data.pay_type==9) paytype = "微信支付"; - let obj = { - mer_name: userStore.userInfo.mer_name, //商户名称 - service_phone: userStore.userInfo.service_phone, //客服电话 - number: data.out_trade_no, //单号 - create_time: data.create_time, //下单时间 - total_price: orderForm.value.total, //总价 - pay_price: orderForm.value.total, //实付 - pay_type: paytype, //支付方式 - pay_number: data.transaction_id, //支付单号 - goods: goods, //商品列表 - }; - if (goods.length > 0 && data.out_trade_no) { - let str = printTicket(obj); - console.log(str); - uni.getEnv((res) => { - if (res.app) { - APPprint(content); - setTimeout(() => { - isPrint = false; - }, 4000); - } - }); - uni.postMessage({ - data: { - type: "print", - content: str, - }, - }); - } + let paytype = "现金支付"; + if (data.pay_type == 13) paytype = "支付宝支付"; + if (data.pay_type == 9) paytype = "微信支付"; + let obj = { + mer_name: userStore.userInfo.mer_name, //商户名称 + service_phone: userStore.userInfo.service_phone, //客服电话 + number: data.out_trade_no, //单号 + create_time: data.create_time, //下单时间 + total_price: orderForm.value.total, //总价 + pay_price: orderForm.value.total, //实付 + pay_type: paytype, //支付方式 + pay_number: data.transaction_id, //支付单号 + goods: goods, //商品列表 + }; + if (goods.length > 0 && data.out_trade_no) { + let str = printTicket(obj); + console.log(str); + uni.getEnv((res) => { + if (res.app) { + APPprint(content); + setTimeout(() => { + isPrint = false; + }, 4000); + } + }); + uni.postMessage({ + data: { + type: "print", + content: str, + }, + }); + } } // 键盘事件 const aF9 = () => { - if (route.name != "saleHome") return; - if (!payRef.value.drawer && orderRef.value.list.length > 0) goPay(); - else payRef.value.beforeClose(); + if (route.name != "saleHome") return; + if (!payRef.value.drawer && orderRef.value.list.length > 0) goPay(); + else payRef.value.beforeClose(); }; onMounted(() => { - getStoreList(); - mitt.on("F9", aF9); + getStoreList(); + mitt.on("F9", aF9); }); onUnmounted(() => { - mitt.off("F9", aF9); + mitt.off("F9", aF9); }); -