商品规格回显

master
rouchen 2024-03-23 08:33:01 +08:00
parent 8520ca21ea
commit c24b09d95a
1 changed files with 67 additions and 12 deletions

View File

@ -335,14 +335,15 @@
<el-table <el-table
:data="skuList" :data="skuList"
border border
max-height="500"
style="width: 100%"> style="width: 100%">
<el-table-column v-for="title in titleList" :prop="title.prop" :label="title.label"> <el-table-column v-for="title in titleList" :prop="title.prop" :label="title.label">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-if="title.prop.indexOf('prop') > -1">{{scope.row[title.prop]}}</span> <span v-if="title.prop.indexOf('prop') > -1">{{scope.row[title.prop]}}</span>
<el-input-number v-else-if="['stock','price'].indexOf(title.prop) > -1" v-model="scope.row[title.prop]" :precision="2" :step="0.01"></el-input-number> <el-input-number v-else-if="['stock','price'].indexOf(title.prop) > -1" v-model="scope.row[title.prop]" :precision="2" :step="0.01"></el-input-number>
<image-upload v-else-if="['image'].indexOf(title.prop) > -1" v-model="scope.row[title.prop]" <image-upload v-else-if="['image'].indexOf(title.prop) > -1" v-model="scope.row[title.prop]"
:limit="1" :limit="1"
:is-show-tip="false" :is-show-tip="false"
></image-upload> ></image-upload>
</template> </template>
</el-table-column> </el-table-column>
@ -410,7 +411,14 @@ export default {
brandId: null, brandId: null,
}, },
// //
form: {}, form: {
mianType: '',
parentType: '',
type:'',
image: '',
price: '',
stock: ''
},
// //
rules: { rules: {
name: [ name: [
@ -495,7 +503,6 @@ export default {
}, },
"form.type": { "form.type": {
handler(value) { handler(value) {
console.log(value)
if (value != null){ if (value != null){
getTemplateAttribute(value).then(response => { getTemplateAttribute(value).then(response => {
const {data} = response; const {data} = response;
@ -515,6 +522,7 @@ export default {
methods: { methods: {
oneSetting(){ oneSetting(){
this.skuList.forEach(skuInfo => { this.skuList.forEach(skuInfo => {
console.log(skuInfo)
skuInfo.image = this.oneSettingForm.image; skuInfo.image = this.oneSettingForm.image;
skuInfo.stock = this.oneSettingForm.stock; skuInfo.stock = this.oneSettingForm.stock;
skuInfo.price = this.oneSettingForm.price; skuInfo.price = this.oneSettingForm.price;
@ -523,7 +531,11 @@ export default {
changeRule(ruleId){ changeRule(ruleId){
this.titleList = [] this.titleList = []
let ruleInfo = this.ruleList.find(ruleInfo => ruleInfo.id === ruleId); let ruleInfo = this.ruleList.find(ruleInfo => ruleInfo.id === ruleId);
const {ruleAttrList} = ruleInfo; const {ruleAttrList} = ruleInfo;
console.log(ruleInfo)
console.log(ruleAttrList)
let skuTotal = 1; let skuTotal = 1;
for (let ruleAttrListKey in ruleAttrList) { for (let ruleAttrListKey in ruleAttrList) {
let ruleAttrInfo = ruleAttrList[ruleAttrListKey]; let ruleAttrInfo = ruleAttrList[ruleAttrListKey];
@ -534,7 +546,6 @@ export default {
skuTotal = skuTotal * ruleAttrInfo.valueList.length; skuTotal = skuTotal * ruleAttrInfo.valueList.length;
} }
this.titleList.push(...this.templateTitleList) ; this.titleList.push(...this.templateTitleList) ;
console.log(this.titleList);
this.skuList = []; this.skuList = [];
for (let i = 0; i < skuTotal; i++) { for (let i = 0; i < skuTotal; i++) {
this.skuList.push( this.skuList.push(
@ -573,9 +584,9 @@ export default {
if (response.code === 200){ if (response.code === 200){
// //
let attributeId = response.data, let attributeId = response.data,
code = this.customAttributeForm.code, code = this.customAttributeForm.code,
name = this.customAttributeForm.name, name = this.customAttributeForm.name,
value = this.customAttributeForm.value; value = this.customAttributeForm.value;
// categoryCommonElement / attributeIdCheckedList / attributeCheckedList // categoryCommonElement / attributeIdCheckedList / attributeCheckedList
this.categoryCommonElement.attributeList.push({ this.categoryCommonElement.attributeList.push({
"id": attributeId, "id": attributeId,
@ -626,7 +637,6 @@ export default {
listCategory().then(response => { listCategory().then(response => {
this.categoryOptions = []; this.categoryOptions = [];
this.categoryOptions = this.handleTree(response.data, "id", "parentId"); this.categoryOptions = this.handleTree(response.data, "id", "parentId");
console.log(this.categoryOptions)
}); });
}, },
remoteSearchBrandList(queryValue){ remoteSearchBrandList(queryValue){
@ -640,7 +650,7 @@ export default {
next() { next() {
let isValidate = true; let isValidate = true;
this.$refs["form"].validateField(this.rulesTemplateMap[this.stepNumber],(valid) => { this.$refs["form"].validateField(this.rulesTemplateMap[this.stepNumber],(valid) => {
console.log(valid)
if (valid) { if (valid) {
isValidate = false; isValidate = false;
} }
@ -713,24 +723,69 @@ export default {
handleUpdate(row) { handleUpdate(row) {
this.reset(); this.reset();
const id = row.id || this.ids const id = row.id || this.ids
getInfo(id).then(response => { getInfo(id).then(response => {
console.log(response)
this.form = response.data; this.form = response.data;
this.initCategoryTree()
this.form.mianType=parseInt(response.data.mianType)
this.form.type=parseInt(response.data.type)
this.oneSettingForm = response.data.productSkuModel
this.changeRule(response.data.ruleId)
this.oneSetting()
this.open = true; this.open = true;
this.title = "修改商品信息"; this.title = "修改商品信息";
}); });
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
let attrValueList = [];
for (const templateAttributeGroup of this.categoryCommonElement.templateAttributeGroupList) {
templateAttributeGroup.attributeList.map(attribute => attrValueList.push({id: attribute.id, value: attribute.value}))
}
this.categoryCommonElement.templateAttributeList.map(attribute => attrValueList.push({id: attribute.id, value: attribute.value}))
this.attributeCheckedList.map(attribute => attrValueList.push({id: attribute.id, value: attribute.value}))
let ruleInfo = this.ruleList.find(ruleInfo => ruleInfo.id === this.form.ruleId);
const {ruleAttrList} = ruleInfo;
let ruleAttrSize = ruleAttrList.length;
let productSkuList = this.skuList.map(skuInfo => {
let sku = "";
for (let index = 0; ; index++) {
sku += skuInfo["prop"+index];
if (index+1 >= ruleAttrSize){
break;
}else {
sku += "-";
}
}
return {
sku: sku,
image: skuInfo.image,
stock: skuInfo.stock,
price: skuInfo.price
}
})
let productAddReq = {
projectAddModel: this.form,
attrValueList: attrValueList,
productSkuList: productSkuList
};
console.log(productAddReq)
if (this.form.id != null) { if (this.form.id != null) {
updateInfo(this.form).then(response => { updateInfo(productAddReq).then(response => {
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
this.open = false; this.open = false;
this.getList(); this.getList();
}); });
} else { } else {
addInfo(this.form).then(response => { addInfo(productAddReq).then(response => {
this.$modal.msgSuccess("新增成功"); this.$modal.msgSuccess("新增成功");
this.open = false; this.open = false;
this.getList(); this.getList();