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_BASE_URL = 'http://192.168.1.10:8546'
# VITE_BASE_URL = 'https://erp.lihaink.cn'
# VITE_BASE_URL = 'http://192.168.1.10:8546'
VITE_BASE_URL = 'https://erp.lihaink.cn'

View File

@ -4,7 +4,7 @@ import request from '@/utils/axios.js'
* @description 加入购物车
*/
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>
import { ref, onMounted, onUnmounted } from 'vue'
import { ElMessageBox } from 'element-plus'
import { getAttrValue } from "@/api/shop.js"
import { ref, onMounted, onUnmounted, nextTick } from "vue";
import { ElMessageBox } from "element-plus";
import { getAttrValue } from "@/api/shop.js";
import mitt from "@/utils/mitt.js";
const dialogVisible = ref(false)
const dialogVisible = ref(false);
const inputRef = ref(null);
const show = (e)=>{
dialogVisible.value = e;
}
const show = (e) => {
dialogVisible.value = e;
};
const form = ref({});
const active = ref(null);
const loading = ref(false);
const mode = ref('add');
const mode = ref("add");
const editForm = ref({});
const setForm = (data, type='add')=>{
mode.value = type;
if(type == 'add'){
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 setForm = (data, type = "add") => {
mode.value = type;
form.value = data;
};
const emit = defineEmits(['changeItem'])
const emit = defineEmits(["changeItem"]);
const changeItem = ()=>{
if(mode.value == 'add') emit('changeItem', form.value, active.value);
else emit('editItem', editForm.value.cart_id, {
cart_num: editForm.value.cart_num,
product_attr_unique: form.value.sku[active.value].unique,
const changeItem = () => {
return console.log(form.value);
if (mode.value == "add") emit("changeItem", form.value);
else
emit("editItem", editForm.value.cart_id, {
cart_num: editForm.value.cart_num,
});
dialogVisible.value = false
}
const changeActive = (item)=>{
active.value = item;
}
dialogVisible.value = false;
};
defineExpose({
show,
setForm
})
show,
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 aenter = () => {
if (!dialogVisible.value) return;
changeItem();
};
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(() => {
mitt.on("left", aleft);
mitt.on("right", aright);
mitt.on("enter", aenter);
});
onUnmounted(() => {
mitt.off("left", aleft);
mitt.off("right", aright);
mitt.off("enter", aenter);
});
const close = ()=>{
console.log('sss');
}
const close = () => {
console.log("sss");
};
</script>
<template>
<el-dialog
v-model="dialogVisible"
title="商品规格"
width="650"
>
<el-dialog v-model="dialogVisible" title="购买数量" width="650" @opened="inputRef.focus()">
<div class="shop" v-loading="loading">
<div class="shop-info" v-if="form.sku">
<div class="shop-info-left">
<el-image loading="lazy" :src="form.sku[active]?.image || form.image"></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 class="shop-info">
<div class="shop-info-left">
<el-image loading="lazy" :src="form.imgs"></el-image>
</div>
<div class="shop-sku">
<div class="title">产品</div>
<div class="sku">
<el-space wrap :size="20">
<div class="sku-item " :class="{'sku-item_active': active==item}" @click="changeActive(item)" v-for="(item, index) in form.attr" :key="index">{{ item || '默认规格' }}</div>
</el-space>
</div>
<div class="shop-info-right">
<div class="shop-info-right-top">{{ form.name }}</div>
<div class="shop-info-right-price">
¥<span>{{ form.sell }}</span
><span style="font-size: 1rem; color: #777">
/ {{ form.unit_name }}</span
>
</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>
<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">
<el-button class="ok-btn" type="primary" @click="changeItem">
确定 (Enter)
@ -126,70 +99,56 @@ const close = ()=>{
</template>
<style scoped lang="scss">
.dialog-footer{
.ok-btn{
width: 100%;
height: 2.5rem;
border-radius: 2.5rem;
}
.dialog-footer {
.ok-btn {
width: 100%;
height: 2.5rem;
border-radius: 2.5rem;
}
}
.shop{
border-top: 1px solid #eee;
padding-top: 1rem;
.shop-info{
display: flex;
.shop-info-left{
flex-shrink: 0;
margin-right: 0.8rem;
height: 8rem;
width: 8rem;
overflow: hidden;
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 {
border-top: 1px solid #eee;
padding-top: 1rem;
.shop-info {
display: flex;
.shop-info-left {
flex-shrink: 0;
margin-right: 0.8rem;
height: 8rem;
width: 8rem;
overflow: hidden;
border-radius: 0.5rem;
}
.shop-sku{
min-height: 20rem;
.title{
font-size: 1.1rem;
font-weight: bold;
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;
}
}
.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 {
display: flex;
align-items: center;
justify-content: space-between;
margin: 1rem 0;
}
}
</style>

View File

@ -45,7 +45,7 @@ const getStoreList = (data = {}, reload = false) => {
isAllDigits(data.bar_code)
) {
shopRef.value.bar_code = "";
changeItem(storeList.value[0], storeList.value[0].attr[0]);
changeItem(storeList.value[0]);
}
where.value.page_no++;
});
@ -64,15 +64,9 @@ function isAllDigits(str) {
const cartAddInfo = (item, change = "") => {
// console.log(item, change);
let q = {
goods_id: item.id,
is_new: 0,
product_id: item.product_id,
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,
cart_num: 1
};
cartCreateApi(q).then((res) => {
orderRef.value.getList();
@ -80,13 +74,9 @@ const cartAddInfo = (item, change = "") => {
};
const changeItem = (item, change) => {
if (!item.attr || item.attr.length == 0 || item.attr.length == 1)
return cartAddInfo(item, item.attr[0] ? item.attr[0] : "");
else if (change) return cartAddInfo(item, change);
else {
pupopRef.value.setForm(item, "add");
item.cart_num = 1;
pupopRef.value.setForm(item, "add");
pupopRef.value.show(true);
}
};
const editItem = (id, data) => {