fix: 处理添加商品的逻辑问题

This commit is contained in:
lzhizhao 2025-07-16 23:16:50 +08:00
parent 071941ef8a
commit 2bc3713b92
2 changed files with 39 additions and 94 deletions

View File

@ -1,14 +1,7 @@
<template>
<div>
<obj-modal
class="obj-modal"
ref="modal"
labelWidth="120px"
:modalCols="modalCols"
:modalConfig="modalConfig"
:modalData="modalData"
:modalHandles="modalHandles"
>
<obj-modal class="obj-modal" ref="modal" labelWidth="120px" :modalCols="modalCols" :modalConfig="modalConfig"
:modalData="modalData" :modalHandles="modalHandles">
<template slot="dialog__before">
<el-tabs :before-leave="beforeTabLeave" v-model="currentPanel">
<el-tab-pane label="基础信息" name="基础信息"></el-tab-pane>
@ -18,15 +11,9 @@
</template>
</obj-modal>
<!-- 添加规格 -->
<addSpecifications
@getSpecs="getSpecs"
ref="addSpecifications"
></addSpecifications>
<addSpecifications @getSpecs="getSpecs" ref="addSpecifications"></addSpecifications>
<!-- 属性 -->
<addAttribute
@getAttribute="getAttribute"
ref="addAttribute"
></addAttribute>
<addAttribute @getAttribute="getAttribute" ref="addAttribute"></addAttribute>
</div>
</template>
<script>
@ -306,7 +293,8 @@ export default {
//
getSpecs(tableData, AttributeData) {
console.log(tableData);
this.modalData.specType = 1;
// specType10
this.modalData.specType = (tableData && tableData.length > 0) || (AttributeData && AttributeData.length > 0) ? 1 : 0;
let AttributeList = AttributeData.map(item => {
return {
attributeName: item.attributeName,
@ -601,9 +589,9 @@ export default {
label: "成本",
prop: "costPrice",
type: "jsx",
required: true,
required: this.modalData.specType === 0,
rules: {
required: true,
required: this.modalData.specType === 0,
message: "请输入成本价格",
trigger: "blur"
},
@ -611,7 +599,7 @@ export default {
return (
<el-input
readonly={this.modalData.specType != 0}
placeholder="请输入价格"
placeholder={this.modalData.specType != 0 ? "多规格商品在规格中设置" : "请输入价格"}
v-model={this.modalData.costPrice}
>
<template slot="append">单位</template>
@ -623,9 +611,9 @@ export default {
label: "市场价",
prop: "marketPrice",
type: "jsx",
required: true,
required: this.modalData.specType === 0,
rules: {
required: true,
required: this.modalData.specType === 0,
message: "请输入市场价",
trigger: "blur"
},
@ -633,7 +621,7 @@ export default {
return (
<el-input
readonly={this.modalData.specType != 0}
placeholder="请输入市场价"
placeholder={this.modalData.specType != 0 ? "多规格商品在规格中设置" : "请输入市场价"}
v-model={this.modalData.marketPrice}
>
<template slot="append">单位</template>
@ -645,9 +633,9 @@ export default {
label: "库存",
prop: "stockNum",
type: "jsx",
required: true,
required: this.modalData.specType === 0,
rules: {
required: true,
required: this.modalData.specType === 0,
message: "请输入库存",
trigger: "blur"
},
@ -655,7 +643,7 @@ export default {
return (
<el-input
readonly={this.modalData.specType != 0}
placeholder="请输入库存"
placeholder={this.modalData.specType != 0 ? "多规格商品在规格中设置" : "请输入库存"}
v-model={this.modalData.stockNum}
></el-input>
);
@ -665,9 +653,9 @@ export default {
label: "重量",
prop: "weight",
type: "jsx",
required: true,
required: this.modalData.specType === 0,
rules: {
required: true,
required: this.modalData.specType === 0,
message: "请输入重量",
trigger: "blur"
},
@ -675,7 +663,7 @@ export default {
return (
<el-input
readonly={this.modalData.specType != 0}
placeholder="请输入重量"
placeholder={this.modalData.specType != 0 ? "多规格商品在规格中设置" : "请输入重量"}
v-model={this.modalData.weight}
>
<template slot="append">KG</template>
@ -687,9 +675,9 @@ export default {
label: "体积",
prop: "volume",
type: "jsx",
required: true,
required: this.modalData.specType === 0,
rules: {
required: true,
required: this.modalData.specType === 0,
message: "请输入体积",
trigger: "blur"
},
@ -697,7 +685,7 @@ export default {
return (
<el-input
readonly={this.modalData.specType != 0}
placeholder="请输入体积"
placeholder={this.modalData.specType != 0 ? "多规格商品在规格中设置" : "请输入体积"}
v-model={this.modalData.volume}
>
<template slot="append">立方米</template>

View File

@ -1,76 +1,30 @@
<template>
<div>
<obj-modal
ref="modal"
labelWidth="150px"
:modalConfig="modalConfig"
:modalData="modalData"
:modalHandles="modalHandles"
>
<obj-modal ref="modal" labelWidth="150px" :modalConfig="modalConfig" :modalData="modalData"
:modalHandles="modalHandles">
<div slot="dialog__content">
<div v-for="(item, index) in AttributeData" :key="index">
<el-row>
<el-input
style="width: 80%; margin: 0 20px 0 0"
placeholder="请输入属性"
v-model="item.attributeName"
clearable
>
<el-input style="width: 80%; margin: 0 20px 0 0" placeholder="请输入属性" v-model="item.attributeName" clearable>
</el-input>
<el-button
@click="deleteAttribute(index)"
type="danger"
icon="el-icon-delete"
circle
></el-button>
<el-button @click="deleteAttribute(index)" type="danger" icon="el-icon-delete" circle></el-button>
</el-row>
<el-row>
<el-tag
:key="tag"
v-for="tag in item.attributeValue"
closable
:disable-transitions="false"
@close="handleClose(index, tag)"
>
<el-tag :key="tag" v-for="tag in item.attributeValue" closable :disable-transitions="false"
@close="handleClose(index, tag)">
{{ tag }}
</el-tag>
<el-input
class="input-new-tag"
v-if="item.inputVisible"
v-model="inputValue"
:ref="`saveTagInput${index}`"
size="small"
@keyup.enter.native="handleInputConfirm(index)"
@blur="handleInputConfirm(index)"
>
<el-input class="input-new-tag" v-if="item.inputVisible" v-model="inputValue" :ref="`saveTagInput${index}`"
size="small" @keyup.enter.native="handleInputConfirm(index)" @blur="handleInputConfirm(index)">
</el-input>
<el-button
v-else
class="button-new-tag"
size="small"
@click="showInput(index)"
>+新增规格</el-button
></el-row
>
<el-button v-else class="button-new-tag" size="small" @click="showInput(index)">+新增规格</el-button></el-row>
</div>
<el-row type="flex" justify="center">
<el-button @click="addAttribute" type="text"
>+添加其他属性</el-button
></el-row
>
<obj-table-plus
slot="dialog__after"
style="height: 50vh"
ref="oTable"
@query="queryTableData"
v-model="tableData"
:tableCols="tableCols"
:tableProp="tableProp"
:toolbarProp="toolbarProp"
:tableEvent="tableEvent"
:enableAutoQuery="false"
>
<el-button @click="addAttribute" type="text">+添加其他属性</el-button></el-row>
<obj-table-plus slot="dialog__after" style="height: 50vh" ref="oTable" @query="queryTableData"
v-model="tableData" :tableCols="tableCols" :tableProp="tableProp" :toolbarProp="toolbarProp"
:tableEvent="tableEvent" :enableAutoQuery="false">
<!-- <div slot="tableTop" class="mb-2">
<el-button type="primary" size="mini" @click="calculation"
>计算属性</el-button
@ -415,7 +369,7 @@ export default {
label: this.isAdd ? "确认添加" : "确认修改",
type: "primary",
loading: this.isLoading,
disabled: () => this.tableData.length <= 0,
// disabled: () => this.tableData.length <= 0,
// submit: true,
handle: () => {
this.$emit(
@ -436,9 +390,11 @@ export default {
.el-row {
margin-bottom: 10px;
}
.el-tag+.el-tag {
margin-left: 10px;
}
.button-new-tag {
margin-left: 10px;
height: 32px;
@ -446,6 +402,7 @@ export default {
padding-top: 0;
padding-bottom: 0;
}
.input-new-tag {
width: 90px;
margin-left: 10px;