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

View File

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