|
|
@ -65,8 +65,8 @@ |
|
|
</uni-forms-item> |
|
|
</uni-forms-item> |
|
|
<uni-forms-item label="商品属性" name="attributeList1"> |
|
|
<uni-forms-item label="商品属性" name="attributeList1"> |
|
|
<view style="display: flex;flex-direction: column;"> |
|
|
<view style="display: flex;flex-direction: column;"> |
|
|
<view v-for="(value,key) in Array.from(formData.attributeList1)" :key="index" style="display: flex;"> |
|
|
<view v-for="(value,key) in Array.from(formData.attributeList1)" :key="key" style="display: flex;flex-wrap: wrap;align-items: center;margin-bottom: 10rpx;"> |
|
|
{{value[0]}}: |
|
|
{{value[0]}}(可选{{value[1].canbuy || 1}}个): |
|
|
<view v-for="(item,index) in value[1].title" :key="index"> |
|
|
<view v-for="(item,index) in value[1].title" :key="index"> |
|
|
{{item}}、 |
|
|
{{item}}、 |
|
|
</view> |
|
|
</view> |
|
|
@ -135,11 +135,13 @@ |
|
|
<view v-for="(item,index) in categorySonData" :key="index" @tap="checkSpecValue(index)" class="content-low" :class="item.checked?'checked':''"> |
|
|
<view v-for="(item,index) in categorySonData" :key="index" @tap="checkSpecValue(index)" class="content-low" :class="item.checked?'checked':''"> |
|
|
{{item.title}} |
|
|
{{item.title}} |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
<view> |
|
|
|
|
|
<uni-forms-item label="可选数量" name="currentCanbuy"> |
|
|
|
|
|
<input type="digit" class="content-input" v-model="currentCanbuy" placeholder="该分类可选几个(默认1)"> |
|
|
|
|
|
</uni-forms-item> |
|
|
|
|
|
</view> |
|
|
</view> |
|
|
</view> |
|
|
<view slot="footer" style="display: flex;padding-left: 40rpx;margin-top: 20rpx;"> |
|
|
<view slot="footer" style="display: flex;padding-left: 40rpx;margin-top: 20rpx;"> |
|
|
<uni-forms-item label="设置最大选择数" name="maxSelect"> |
|
|
|
|
|
<input type="digit" class="content-input" v-model="maxSelect" placeholder="可设置最大选择数"> |
|
|
|
|
|
</uni-forms-item> |
|
|
|
|
|
<button type="text" @tap="$refs.addTypeDialog.close()" style="margin-right: 20rpx;">取消</button> |
|
|
<button type="text" @tap="$refs.addTypeDialog.close()" style="margin-right: 20rpx;">取消</button> |
|
|
<button type="text" @tap="guigeSubmit">提交</button> |
|
|
<button type="text" @tap="guigeSubmit">提交</button> |
|
|
</view> |
|
|
</view> |
|
|
@ -155,6 +157,8 @@ |
|
|
dataList: {}, |
|
|
dataList: {}, |
|
|
modalType:0, |
|
|
modalType:0, |
|
|
maxSelect:1, |
|
|
maxSelect:1, |
|
|
|
|
|
currentCanbuy:1, |
|
|
|
|
|
canbuyMap:{}, |
|
|
categoryData:[], |
|
|
categoryData:[], |
|
|
categoryIndex: 0, |
|
|
categoryIndex: 0, |
|
|
modalclassType:'', |
|
|
modalclassType:'', |
|
|
@ -430,23 +434,32 @@ |
|
|
}, |
|
|
}, |
|
|
guigeSubmit(){ |
|
|
guigeSubmit(){ |
|
|
if(this.modalclassType == 'shuxing'){ |
|
|
if(this.modalclassType == 'shuxing'){ |
|
|
|
|
|
// 保存当前分类的canbuy值 |
|
|
|
|
|
if(this.typeToAttrName){ |
|
|
|
|
|
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1 |
|
|
|
|
|
} |
|
|
for(let i=0;i<this.attrValueArr.length;i++){ |
|
|
for(let i=0;i<this.attrValueArr.length;i++){ |
|
|
|
|
|
let parentName = this.attrValueArr[i].parentName |
|
|
|
|
|
let canbuyVal = parseInt(this.canbuyMap[parentName]) || 1 |
|
|
if(this.formData.attributeList1.size == 0){ |
|
|
if(this.formData.attributeList1.size == 0){ |
|
|
//set has get |
|
|
//set has get |
|
|
let data = { |
|
|
let data = { |
|
|
title:[] |
|
|
title:[], |
|
|
|
|
|
canbuy: canbuyVal |
|
|
} |
|
|
} |
|
|
data.title.push(this.attrValueArr[i].title) |
|
|
data.title.push(this.attrValueArr[i].title) |
|
|
this.formData.attributeList1.set(this.attrValueArr[i].parentName,data) |
|
|
this.formData.attributeList1.set(parentName,data) |
|
|
}else{ |
|
|
}else{ |
|
|
if(this.formData.attributeList1.has(this.attrValueArr[i].parentName) && this.formData.attributeList1.get(this.attrValueArr[i].parentName).title.indexOf(this.attrValueArr[i].title) == -1){ |
|
|
if(this.formData.attributeList1.has(parentName) && this.formData.attributeList1.get(parentName).title.indexOf(this.attrValueArr[i].title) == -1){ |
|
|
this.formData.attributeList1.get(this.attrValueArr[i].parentName).title.push(this.attrValueArr[i].title) |
|
|
this.formData.attributeList1.get(parentName).title.push(this.attrValueArr[i].title) |
|
|
|
|
|
this.formData.attributeList1.get(parentName).canbuy = canbuyVal |
|
|
}else{ |
|
|
}else{ |
|
|
let data = { |
|
|
let data = { |
|
|
title:[] |
|
|
title:[], |
|
|
|
|
|
canbuy: canbuyVal |
|
|
} |
|
|
} |
|
|
data.title.push(this.attrValueArr[i].title) |
|
|
data.title.push(this.attrValueArr[i].title) |
|
|
this.formData.attributeList1.set(this.attrValueArr[i].parentName,data) |
|
|
this.formData.attributeList1.set(parentName,data) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -522,11 +535,33 @@ |
|
|
let data = JSON.parse(str); |
|
|
let data = JSON.parse(str); |
|
|
console.log('111111',data) |
|
|
console.log('111111',data) |
|
|
this.formData = data; |
|
|
this.formData = data; |
|
|
this.formData.attributeList1 = JSON.parse(this.formData.attributeList) |
|
|
|
|
|
this.formData.attributeList1 = new Map(Object.entries(this.formData.attributeList1)); |
|
|
|
|
|
this.formData.attributeListPrice = JSON.parse(this.formData.attributeListPrice) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 解析attributeList(商品属性),兼容string和已解析的对象 |
|
|
|
|
|
let attrObj = this.formData.attributeList |
|
|
|
|
|
if (typeof attrObj === 'string' && attrObj !== '') { |
|
|
|
|
|
attrObj = JSON.parse(attrObj) |
|
|
|
|
|
} |
|
|
|
|
|
if (!attrObj || typeof attrObj !== 'object') { |
|
|
|
|
|
attrObj = {} |
|
|
|
|
|
} |
|
|
|
|
|
this.formData.attributeList1 = new Map(Object.entries(attrObj)); |
|
|
|
|
|
|
|
|
|
|
|
// 解析attributeListPrice(商品规格价格),兼容string和已解析的数组 |
|
|
|
|
|
let priceArr = this.formData.attributeListPrice |
|
|
|
|
|
if (typeof priceArr === 'string' && priceArr !== '') { |
|
|
|
|
|
priceArr = JSON.parse(priceArr) |
|
|
|
|
|
} |
|
|
|
|
|
if (!Array.isArray(priceArr)) { |
|
|
|
|
|
priceArr = [{specPrice: "", specNum: 9999}] |
|
|
|
|
|
} |
|
|
|
|
|
this.formData.attributeListPrice = priceArr |
|
|
|
|
|
|
|
|
|
|
|
// 初始化canbuyMap,历史数据没有canbuy字段的默认为1 |
|
|
|
|
|
this.canbuyMap = {} |
|
|
|
|
|
this.attrValueArr = [] |
|
|
this.formData.attributeList1.forEach((value, key) => { |
|
|
this.formData.attributeList1.forEach((value, key) => { |
|
|
|
|
|
value.canbuy = value.canbuy || 1 |
|
|
|
|
|
this.canbuyMap[key] = value.canbuy |
|
|
for(let i = 0;i<value.title.length;i++){ |
|
|
for(let i = 0;i<value.title.length;i++){ |
|
|
this.attrValueArr.push({ |
|
|
this.attrValueArr.push({ |
|
|
parentName:key, |
|
|
parentName:key, |
|
|
@ -534,7 +569,8 @@ |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
this.specValueArr = this.formData.attributeListPrice |
|
|
// 深拷贝attributeListPrice作为specValueArr,避免引用问题 |
|
|
|
|
|
this.specValueArr = JSON.parse(JSON.stringify(this.formData.attributeListPrice)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.formData.sellTime = this.formData.sellBeginTime != '' ? 1 : 0 |
|
|
this.formData.sellTime = this.formData.sellBeginTime != '' ? 1 : 0 |
|
|
@ -569,6 +605,10 @@ |
|
|
}, |
|
|
}, |
|
|
//点击左侧菜单切换 |
|
|
//点击左侧菜单切换 |
|
|
clickLeftBtn(index) { |
|
|
clickLeftBtn(index) { |
|
|
|
|
|
// 切换前保存当前分类的canbuy |
|
|
|
|
|
if(this.typeToAttrName){ |
|
|
|
|
|
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1 |
|
|
|
|
|
} |
|
|
for (var i = 0; i < this.categoryData.length; i++) { |
|
|
for (var i = 0; i < this.categoryData.length; i++) { |
|
|
if (i == index) { |
|
|
if (i == index) { |
|
|
this.categoryData[i].parentId = true |
|
|
this.categoryData[i].parentId = true |
|
|
@ -578,6 +618,8 @@ |
|
|
} |
|
|
} |
|
|
this.categoryIndex = index |
|
|
this.categoryIndex = index |
|
|
this.typeToAttrName = this.categoryData[this.categoryIndex].title |
|
|
this.typeToAttrName = this.categoryData[this.categoryIndex].title |
|
|
|
|
|
// 恢复该分类之前设置的canbuy值 |
|
|
|
|
|
this.currentCanbuy = this.canbuyMap[this.typeToAttrName] || 1 |
|
|
this.getCateGorySon(this.categoryData[this.categoryIndex].id) |
|
|
this.getCateGorySon(this.categoryData[this.categoryIndex].id) |
|
|
}, |
|
|
}, |
|
|
pictureAdd(id, huan) { |
|
|
pictureAdd(id, huan) { |
|
|
@ -620,6 +662,8 @@ |
|
|
} |
|
|
} |
|
|
//如果是选择属性,需要拿一个分类名,保存成parent |
|
|
//如果是选择属性,需要拿一个分类名,保存成parent |
|
|
this.typeToAttrName = res.result.content[this.categoryIndex].title |
|
|
this.typeToAttrName = res.result.content[this.categoryIndex].title |
|
|
|
|
|
// 恢复该分类之前设置的canbuy值 |
|
|
|
|
|
this.currentCanbuy = this.canbuyMap[this.typeToAttrName] || 1 |
|
|
this.getCateGorySon(res.result.content[this.categoryIndex].id) |
|
|
this.getCateGorySon(res.result.content[this.categoryIndex].id) |
|
|
} |
|
|
} |
|
|
}).catch(() => {}); |
|
|
}).catch(() => {}); |
|
|
@ -636,40 +680,31 @@ |
|
|
}, false, true).then((res) => { |
|
|
}, false, true).then((res) => { |
|
|
if(res.code == 200){ |
|
|
if(res.code == 200){ |
|
|
this.categorySonData = res.result.content |
|
|
this.categorySonData = res.result.content |
|
|
|
|
|
// 先给所有子项初始化checked为false,确保Vue响应性 |
|
|
|
|
|
console.log("111111",this.specValueArr) |
|
|
|
|
|
console.log("22222",this.attrValueArr) |
|
|
|
|
|
for (var i = 0; i < this.categorySonData.length; i++) { |
|
|
|
|
|
this.$set(this.categorySonData[i], 'checked', false) |
|
|
|
|
|
} |
|
|
if(this.modalclassType == 'shuxing'){ |
|
|
if(this.modalclassType == 'shuxing'){ |
|
|
for (var i = 0; i < this.categorySonData.length; i++) { |
|
|
for (var i = 0; i < this.categorySonData.length; i++) { |
|
|
if(this.attrValueArr.length>0){ |
|
|
for (var m = 0; m < this.attrValueArr.length; m++) { |
|
|
let index1 = false |
|
|
if(this.attrValueArr[m].title == this.categorySonData[i].title && this.attrValueArr[m].parentName == this.typeToAttrName){ |
|
|
for (var m = 0; m < this.attrValueArr.length; m++) { |
|
|
this.$set(this.categorySonData[i], 'checked', true) |
|
|
if(this.attrValueArr[m].title == this.categorySonData[i].title && this.attrValueArr[m].parentName == this.typeToAttrName){ |
|
|
|
|
|
index1 = true |
|
|
|
|
|
this.categorySonData[i].checked = true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
if(index1){ |
|
|
|
|
|
this.categorySonData[i].checked = true |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
this.categorySonData[i].checked = false |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
//guige |
|
|
//guige |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < this.categorySonData.length; i++) { |
|
|
for (var i = 0; i < this.categorySonData.length; i++) { |
|
|
if(this.specValueArr.length>0){ |
|
|
for (var m = 0; m < this.specValueArr.length; m++) { |
|
|
for (var m = 0; m < this.specValueArr.length; m++) { |
|
|
if(this.specValueArr[m].id == this.categorySonData[i].id){ |
|
|
if(this.specValueArr[m].id == this.categorySonData[i].id){ |
|
|
this.$set(this.categorySonData[i], 'checked', true) |
|
|
this.categorySonData[i].checked = true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
}else{ |
|
|
|
|
|
this.categorySonData[i].checked = false |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
this.$forceUpdate() |
|
|
} |
|
|
} |
|
|
}).catch(() => {}); |
|
|
}).catch(() => {}); |
|
|
}, |
|
|
}, |
|
|
|