This commit is contained in:
weipengfei 2024-05-09 15:36:33 +08:00
parent 6f5f723409
commit 5449b2301c
4 changed files with 116 additions and 167 deletions

View File

@ -1,4 +1,4 @@
VITE_NOW_TYPE = 'dist' VITE_NOW_TYPE = 'dist'
VITE_BASE_URL = 'http://192.168.1.10:8546' # VITE_BASE_URL = 'http://192.168.1.10:8546'
# VITE_BASE_URL = 'https://erp.lihaink.cn' VITE_BASE_URL = 'https://erp.lihaink.cn'

View File

@ -4,7 +4,7 @@ import request from '@/utils/axios.js'
* @description 加入购物车 * @description 加入购物车
*/ */
export function cartCreateApi(data) { export function cartCreateApi(data) {
return request.post(`user/cart/create`, data) return request.post(`/order/cart/create`, data)
} }
/** /**

View File

@ -1,121 +1,94 @@
<script setup> <script setup>
import { ref, onMounted, onUnmounted } from 'vue' import { ref, onMounted, onUnmounted, nextTick } from "vue";
import { ElMessageBox } from 'element-plus' import { ElMessageBox } from "element-plus";
import { getAttrValue } from "@/api/shop.js" import { getAttrValue } from "@/api/shop.js";
import mitt from "@/utils/mitt.js"; import mitt from "@/utils/mitt.js";
const dialogVisible = ref(false) const dialogVisible = ref(false);
const inputRef = ref(null);
const show = (e) => { const show = (e) => {
dialogVisible.value = e; dialogVisible.value = e;
} };
const form = ref({}); const form = ref({});
const active = ref(null);
const loading = ref(false); const loading = ref(false);
const mode = ref('add'); const mode = ref("add");
const editForm = ref({}); const editForm = ref({});
const setForm = (data, type='add')=>{ const setForm = (data, type = "add") => {
mode.value = type; mode.value = type;
if(type == 'add'){
form.value = data; form.value = data;
active.value = data.attr[0]; };
}
else {
loading.value = true;
editForm.value = data;
getAttrValue(data.product_id).then(res=>{
res.data.attrValue = JSON.parse(JSON.stringify(res.data.attr))
res.data.attr = Object.keys(res.data.sku)
form.value = res.data;
active.value = res.data.attr[0];
loading.value = false;
}).catch(err=>{
loading.value = false;
})
}
}
const emit = defineEmits(['changeItem']) const emit = defineEmits(["changeItem"]);
const changeItem = () => { const changeItem = () => {
if(mode.value == 'add') emit('changeItem', form.value, active.value); return console.log(form.value);
else emit('editItem', editForm.value.cart_id, { if (mode.value == "add") emit("changeItem", form.value);
else
emit("editItem", editForm.value.cart_id, {
cart_num: editForm.value.cart_num, cart_num: editForm.value.cart_num,
product_attr_unique: form.value.sku[active.value].unique,
}); });
dialogVisible.value = false dialogVisible.value = false;
} };
const changeActive = (item)=>{
active.value = item;
}
defineExpose({ defineExpose({
show, show,
setForm setForm,
}) });
//
const aleft = () => {
if(!dialogVisible.value) return;
let index = form.value.attr.indexOf(active.value);
if(index>0) return changeActive(form.value.attr[index-1]);
};
const aright = () => {
if(!dialogVisible.value) return;
let index = form.value.attr.indexOf(active.value);
if(index<form.value.attr.length-1) return changeActive(form.value.attr[index+1]);
};
const aenter = () => { const aenter = () => {
if (!dialogVisible.value) return; if (!dialogVisible.value) return;
changeItem(); changeItem();
} };
onMounted(() => { onMounted(() => {
mitt.on("left", aleft);
mitt.on("right", aright);
mitt.on("enter", aenter); mitt.on("enter", aenter);
}); });
onUnmounted(() => { onUnmounted(() => {
mitt.off("left", aleft);
mitt.off("right", aright);
mitt.off("enter", aenter); mitt.off("enter", aenter);
}); });
const close = () => { const close = () => {
console.log('sss'); console.log("sss");
} };
</script> </script>
<template> <template>
<el-dialog <el-dialog v-model="dialogVisible" title="购买数量" width="650" @opened="inputRef.focus()">
v-model="dialogVisible"
title="商品规格"
width="650"
>
<div class="shop" v-loading="loading"> <div class="shop" v-loading="loading">
<div class="shop-info" v-if="form.sku"> <div class="shop-info">
<div class="shop-info-left"> <div class="shop-info-left">
<el-image loading="lazy" :src="form.sku[active]?.image || form.image"></el-image> <el-image loading="lazy" :src="form.imgs"></el-image>
</div> </div>
<div class="shop-info-right"> <div class="shop-info-right">
<div class="shop-info-right-top">{{ form.store_name }}</div> <div class="shop-info-right-top">{{ form.name }}</div>
<div class="shop-info-right-center">库存{{ form.sku[active]?.stock || 0 }}</div> <div class="shop-info-right-price">
<div class="shop-info-right-price">¥<span>{{form.sku[active]?.price || form.price}}</span></div> ¥<span>{{ form.sell }}</span
><span style="font-size: 1rem; color: #777">
/ {{ form.unit_name }}</span
>
</div>
</div> </div>
</div> </div>
<div class="shop-sku"> <div class="shop-sku">
<div class="title">产品</div> <div class="title">购买数量 ( {{ form.unit_name }} )</div>
<div class="sku"> <div class="sku">
<el-space wrap :size="20"> <el-input-number
<div class="sku-item " :class="{'sku-item_active': active==item}" @click="changeActive(item)" v-for="(item, index) in form.attr" :key="index">{{ item || '默认规格' }}</div> ref="inputRef"
</el-space> v-model="form.cart_num"
step-strictly
:min="1"
:step="1"
style="width: 20rem"
/>
</div> </div>
</div> </div>
</div> </div>
<template #footer v-if="!(mode != 'add' && form.attr && form.attr.length==1)"> <template
#footer
v-if="!(mode != 'add' && form.attr && form.attr.length == 1)"
>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button class="ok-btn" type="primary" @click="changeItem"> <el-button class="ok-btn" type="primary" @click="changeItem">
确定 (Enter) 确定 (Enter)
@ -172,24 +145,10 @@ const close = ()=>{
} }
} }
.shop-sku { .shop-sku {
min-height: 20rem; display: flex;
.title{ align-items: center;
font-size: 1.1rem; justify-content: space-between;
font-weight: bold; margin: 1rem 0;
padding: 1rem 0 0.5rem 0;
}
.sku{
.sku-item{
cursor: pointer;
padding: 0.5rem 1rem;
background-color: #f5f5f5;
border-radius: 3rem;
&_active{
background-color: #1890ff;
color: #fff;
}
}
}
} }
} }
</style> </style>

View File

@ -45,7 +45,7 @@ const getStoreList = (data = {}, reload = false) => {
isAllDigits(data.bar_code) isAllDigits(data.bar_code)
) { ) {
shopRef.value.bar_code = ""; shopRef.value.bar_code = "";
changeItem(storeList.value[0], storeList.value[0].attr[0]); changeItem(storeList.value[0]);
} }
where.value.page_no++; where.value.page_no++;
}); });
@ -64,15 +64,9 @@ function isAllDigits(str) {
const cartAddInfo = (item, change = "") => { const cartAddInfo = (item, change = "") => {
// console.log(item, change); // console.log(item, change);
let q = { let q = {
goods_id: item.id,
is_new: 0, is_new: 0,
product_id: item.product_id, cart_num: 1
cart_num: 1,
product_attr_unique:
item.sku[change] !== undefined ? item.sku[change].unique : "",
staff_id: userStore.userInfo.service.service_id,
product_type: 0,
sale_type: 2,
// spread_id: this.currSpid,
}; };
cartCreateApi(q).then((res) => { cartCreateApi(q).then((res) => {
orderRef.value.getList(); orderRef.value.getList();
@ -80,13 +74,9 @@ const cartAddInfo = (item, change = "") => {
}; };
const changeItem = (item, change) => { const changeItem = (item, change) => {
if (!item.attr || item.attr.length == 0 || item.attr.length == 1) item.cart_num = 1;
return cartAddInfo(item, item.attr[0] ? item.attr[0] : "");
else if (change) return cartAddInfo(item, change);
else {
pupopRef.value.setForm(item, "add"); pupopRef.value.setForm(item, "add");
pupopRef.value.show(true); pupopRef.value.show(true);
}
}; };
const editItem = (id, data) => { const editItem = (id, data) => {