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);
cart_num: editForm.value.cart_num, else
product_attr_unique: form.value.sku[active.value].unique, emit("editItem", editForm.value.cart_id, {
cart_num: editForm.value.cart_num,
}); });
dialogVisible.value = false dialogVisible.value = false;
} };
const changeActive = (item)=>{
active.value = item;
}
defineExpose({ defineExpose({
show, show,
setForm setForm,
}) });
// const aenter = () => {
const aleft = () => { if (!dialogVisible.value) return;
if(!dialogVisible.value) return; changeItem();
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 = ()=>{
if(!dialogVisible.value) return;
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 class="shop-info-right">
<div class="shop-info-right-top">{{ form.store_name }}</div>
<div class="shop-info-right-center">库存{{ form.sku[active]?.stock || 0 }}</div>
<div class="shop-info-right-price">¥<span>{{form.sku[active]?.price || form.price}}</span></div>
</div>
</div> </div>
<div class="shop-sku"> <div class="shop-info-right">
<div class="title">产品</div> <div class="shop-info-right-top">{{ form.name }}</div>
<div class="sku"> <div class="shop-info-right-price">
<el-space wrap :size="20"> ¥<span>{{ form.sell }}</span
<div class="sku-item " :class="{'sku-item_active': active==item}" @click="changeActive(item)" v-for="(item, index) in form.attr" :key="index">{{ item || '默认规格' }}</div> ><span style="font-size: 1rem; color: #777">
</el-space> / {{ form.unit_name }}</span
>
</div> </div>
</div> </div>
</div>
<div class="shop-sku">
<div class="title">购买数量 ( {{ form.unit_name }} )</div>
<div class="sku">
<el-input-number
ref="inputRef"
v-model="form.cart_num"
step-strictly
:min="1"
:step="1"
style="width: 20rem"
/>
</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)
@ -126,70 +99,56 @@ const close = ()=>{
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.dialog-footer{ .dialog-footer {
.ok-btn{ .ok-btn {
width: 100%; width: 100%;
height: 2.5rem; height: 2.5rem;
border-radius: 2.5rem; border-radius: 2.5rem;
} }
} }
.shop{ .shop {
border-top: 1px solid #eee; border-top: 1px solid #eee;
padding-top: 1rem; padding-top: 1rem;
.shop-info{ .shop-info {
display: flex; display: flex;
.shop-info-left{ .shop-info-left {
flex-shrink: 0; flex-shrink: 0;
margin-right: 0.8rem; margin-right: 0.8rem;
height: 8rem; height: 8rem;
width: 8rem; width: 8rem;
overflow: hidden; overflow: hidden;
border-radius: 0.5rem; border-radius: 0.5rem;
}
.shop-info-right{
display: flex;
flex-direction: column;
justify-content: space-between;
.shop-info-right-top{
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
-webkit-line-clamp: 2; /* 限制文本显示为两行 */
font-size: 1.1rem;
}
.shop-info-right-center{
font-size: 0.8rem;
}
.shop-info-right-price{
color: #ff4a00;
font-size: 1.2rem;
font-weight: bold;
span{
font-size: 1.4rem;
margin-left: 0.2rem;
}
}
}
} }
.shop-sku{ .shop-info-right {
min-height: 20rem; display: flex;
.title{ flex-direction: column;
font-size: 1.1rem; justify-content: space-between;
font-weight: bold; .shop-info-right-top {
padding: 1rem 0 0.5rem 0; display: -webkit-box;
} -webkit-box-orient: vertical;
.sku{ overflow: hidden;
.sku-item{ -webkit-line-clamp: 2; /* 限制文本显示为两行 */
cursor: pointer; font-size: 1.1rem;
padding: 0.5rem 1rem; }
background-color: #f5f5f5; .shop-info-right-center {
border-radius: 3rem; font-size: 0.8rem;
&_active{ }
background-color: #1890ff; .shop-info-right-price {
color: #fff; color: #ff4a00;
} font-size: 1.2rem;
} font-weight: bold;
span {
font-size: 1.4rem;
margin-left: 0.2rem;
} }
}
} }
}
.shop-sku {
display: flex;
align-items: center;
justify-content: space-between;
margin: 1rem 0;
}
} }
</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] : ""); pupopRef.value.setForm(item, "add");
else if (change) return cartAddInfo(item, change);
else {
pupopRef.value.setForm(item, "add");
pupopRef.value.show(true); pupopRef.value.show(true);
}
}; };
const editItem = (id, data) => { const editItem = (id, data) => {