tianyi 4 weeks ago
parent
commit
c7d0268c70
  1. 197
      pages/shop/addGoods.vue
  2. 2
      pages/shop/attributeList.vue

197
pages/shop/addGoods.vue

@ -23,7 +23,7 @@
</view> </view>
<view style="overflow-x: scroll;display: flex;width: 350rpx;"> <view style="overflow-x: scroll;display: flex;width: 350rpx;">
<view v-if="formData.productPicture !=''" style="width: 160rpx;height: 160rpx;margin-left: 20rpx;"> <view v-if="formData.productPicture !=''" style="width: 160rpx;height: 160rpx;margin-left: 20rpx;">
<img :src="formData.productPicture" alt="" class="upload-img"> <image :src="formData.productPicture" alt="" class="upload-img">
</view> </view>
</view> </view>
</uni-forms-item> </uni-forms-item>
@ -66,11 +66,17 @@
</view> </view>
</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 class="selected-attr-list">
<view v-for="(value,key) in Array.from(formData.attributeList1)" :key="key" style="display: flex;flex-wrap: wrap;align-items: center;margin-bottom: 10rpx;"> <view v-for="(value,key) in Array.from(formData.attributeList1)" :key="key" class="selected-attr-row">
{{value[0]}}(可选{{value[1].canbuy || 1}}): <view class="selected-attr-category" @tap.stop="confirmDeleteAttributeCategory(value[0])">
<view v-for="(item,index) in value[1].title" :key="index"> <text>{{value[0]}}(可选{{value[1].canbuy || 1}})</text>
{{item}} <text class="selected-attr-close">x</text>
</view>
<view class="selected-attr-values">
<view v-for="(item,index) in (value[1].title || [])" :key="index" class="selected-attr-value" @tap.stop="confirmDeleteAttributeValue(value[0], item)">
<text>{{item}}</text>
<text class="selected-attr-close">x</text>
</view>
</view> </view>
</view> </view>
<view @click="checkSpec('shuxing')" style="width: 160rpx;height: 60rpx;text-align: center;line-height: 60rpx;background: rgba(0, 35, 28, 1);border-radius: 60rpx;color: rgba(166, 255, 234, 1);"> <view @click="checkSpec('shuxing')" style="width: 160rpx;height: 60rpx;text-align: center;line-height: 60rpx;background: rgba(0, 35, 28, 1);border-radius: 60rpx;color: rgba(166, 255, 234, 1);">
@ -254,9 +260,7 @@
this.getGategoryList() this.getGategoryList()
if (option.dataList != undefined && option.dataList != null && option.dataList != 'undefined') { if (option.dataList != undefined && option.dataList != null && option.dataList != 'undefined') {
this.dataList = JSON.parse(option.dataList) this.dataList = JSON.parse(option.dataList)
this.NB.sendRequest("/app/product/getById/" + this.dataList.id, { this.NB.sendRequest("/app/product/getById/" + this.dataList.id, {}, false, 'post', 'application/x-www-form-urlencoded').then((res) => {
}, false, 'post', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) { if (res.code == 200) {
this.modalType = 1 this.modalType = 1
this.formData.id = res.result.id this.formData.id = res.result.id
@ -432,6 +436,9 @@
submit() { submit() {
let that = this; let that = this;
this.syncLunchBoxByMoreBuy() this.syncLunchBoxByMoreBuy()
if (!this.validateRequiredProductFields()) {
return
}
if (!this.validateProductSpecs()) { if (!this.validateProductSpecs()) {
return return
} }
@ -481,6 +488,43 @@
// } // }
// }); // });
}, },
validateRequiredProductFields() {
const productName = String(this.formData.productName || '').trim()
if (!productName) {
uni.showToast({
title: '请输入商品名称',
icon: 'none'
})
return false
}
if (!this.formData.productPicture) {
uni.showToast({
title: '请上传商品主图',
icon: 'none'
})
return false
}
for (let i = 0; i < this.formData.attributeListPrice.length; i++) {
const specPrice = String(this.formData.attributeListPrice[i].specPrice || '').trim()
if (!specPrice) {
uni.showToast({
title: '请输入商品价格',
icon: 'none'
})
return false
}
}
const startPayNum = String(this.formData.startPayNum || '').trim()
if (!startPayNum) {
uni.showToast({
title: '请输入起售数量',
icon: 'none'
})
return false
}
this.formData.productName = productName
return true
},
back() { back() {
uni.navigateBack() uni.navigateBack()
}, },
@ -602,37 +646,82 @@
this.formData.sellEndTime = e.detail.value this.formData.sellEndTime = e.detail.value
} }
}, },
confirmDeleteAttributeCategory(categoryName){
uni.showModal({
title: '提示',
content: '确定删除“' + categoryName + '”分类及其下所有属性吗?',
success: (res) => {
if(res.confirm){
this.removeAttributeCategory(categoryName)
}
}
})
},
confirmDeleteAttributeValue(categoryName, attributeTitle){
uni.showModal({
title: '提示',
content: '确定删除“' + attributeTitle + '”属性吗?',
success: (res) => {
if(res.confirm){
this.removeAttributeValue(categoryName, attributeTitle)
}
}
})
},
removeAttributeCategory(categoryName){
let attributeListMap = new Map(this.formData.attributeList1)
attributeListMap.delete(categoryName)
this.formData.attributeList1 = attributeListMap
this.attrValueArr = this.attrValueArr.filter(item => item.parentName != categoryName)
delete this.canbuyMap[categoryName]
this.$forceUpdate()
},
removeAttributeValue(categoryName, attributeTitle){
let attributeListMap = new Map(this.formData.attributeList1)
let attributeGroup = attributeListMap.get(categoryName)
if(!attributeGroup){
return
}
let nextTitle = (attributeGroup.title || []).filter(item => item != attributeTitle)
if(nextTitle.length == 0){
attributeListMap.delete(categoryName)
delete this.canbuyMap[categoryName]
}else{
attributeListMap.set(categoryName, Object.assign({}, attributeGroup, {
title: nextTitle
}))
}
this.formData.attributeList1 = attributeListMap
this.attrValueArr = this.attrValueArr.filter(item => !(item.parentName == categoryName && item.title == attributeTitle))
this.$forceUpdate()
},
guigeSubmit(){ guigeSubmit(){
if(this.modalclassType == 'shuxing'){ if(this.modalclassType == 'shuxing'){
// canbuy // canbuy
if(this.typeToAttrName){ if(this.typeToAttrName){
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1 this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1
} }
let attributeListMap = new Map()
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 parentName = this.attrValueArr[i].parentName
let canbuyVal = parseInt(this.canbuyMap[parentName]) || 1 let title = this.attrValueArr[i].title
if(this.formData.attributeList1.size == 0){ if(!parentName || !title){
//set has get continue
let data = {
title:[],
canbuy: canbuyVal
} }
data.title.push(this.attrValueArr[i].title) let canbuyVal = parseInt(this.canbuyMap[parentName]) || 1
this.formData.attributeList1.set(parentName,data) if(!attributeListMap.has(parentName)){
}else{
if(this.formData.attributeList1.has(parentName) && this.formData.attributeList1.get(parentName).title.indexOf(this.attrValueArr[i].title) == -1){
this.formData.attributeList1.get(parentName).title.push(this.attrValueArr[i].title)
this.formData.attributeList1.get(parentName).canbuy = canbuyVal
}else{
let data = { let data = {
title:[], title:[],
canbuy: canbuyVal canbuy: canbuyVal
} }
data.title.push(this.attrValueArr[i].title) attributeListMap.set(parentName,data)
this.formData.attributeList1.set(parentName,data)
} }
attributeListMap.get(parentName).canbuy = canbuyVal
if(attributeListMap.get(parentName).title.indexOf(title) == -1){
attributeListMap.get(parentName).title.push(title)
} }
} }
this.formData.attributeList1 = attributeListMap
}else{ }else{
//guige //guige
let message = [] let message = []
@ -754,8 +843,9 @@
this.attrValueArr.push(this.categorySonData[index]) this.attrValueArr.push(this.categorySonData[index])
}else{ }else{
for(let i=0;i<this.attrValueArr.length;i++){ for(let i=0;i<this.attrValueArr.length;i++){
if(this.categorySonData[index].title == this.attrValueArr[i].title){ if(this.categorySonData[index].title == this.attrValueArr[i].title && this.attrValueArr[i].parentName == this.typeToAttrName){
this.attrValueArr.splice(i,1) this.attrValueArr.splice(i,1)
break
} }
} }
} }
@ -879,6 +969,7 @@
}) })
} }
}) })
}, },
deldantiaoguige(index){ deldantiaoguige(index){
for (var m = 0; m < this.specValueArr.length; m++) { for (var m = 0; m < this.specValueArr.length; m++) {
@ -1043,6 +1134,62 @@
box-sizing: border-box; box-sizing: border-box;
min-width: 0; min-width: 0;
} }
.selected-attr-list {
display: flex;
flex-direction: column;
}
.selected-attr-row {
display: block;
margin-bottom: 16rpx;
padding: 16rpx;
border: 2rpx solid rgba(154, 84, 18, 0.18);
border-radius: 18rpx;
background: #fffdf6;
box-sizing: border-box;
}
.selected-attr-category {
display: inline-flex;
align-items: center;
max-width: 100%;
height: 58rpx;
line-height: 58rpx;
margin: 0 10rpx 10rpx 0;
padding: 0 18rpx;
border-radius: 58rpx;
background: #fff1bf;
color: #9a5412;
font-size: 26rpx;
font-weight: 700;
box-sizing: border-box;
}
.selected-attr-values {
display: flex;
flex-wrap: wrap;
width: 100%;
min-width: 0;
padding-top: 4rpx;
}
.selected-attr-value {
display: inline-flex;
align-items: center;
max-width: 100%;
height: 56rpx;
line-height: 56rpx;
margin: 0 10rpx 10rpx 0;
padding: 0 16rpx;
border: 1px solid rgba(0, 35, 28, 0.12);
border-radius: 56rpx;
background: rgba(247, 248, 248, 0.9);
color: #00231C;
font-size: 26rpx;
box-sizing: border-box;
}
.selected-attr-close {
margin-left: 10rpx;
font-size: 24rpx;
font-weight: 700;
opacity: 0.7;
}
.group-delete-btn { .group-delete-btn {
flex: 0 0 70rpx; flex: 0 0 70rpx;
width: 70rpx; width: 70rpx;

2
pages/shop/attributeList.vue

@ -656,7 +656,7 @@
this.editItem = item this.editItem = item
this.NB.sendRequest("/app/productAttributeValue/selectByAttributeId", { this.NB.sendRequest("/app/productAttributeValue/selectByAttributeId", {
id: item.id, id: item.id,
}, false, 'post', 'application/x-www-form-urlencoded').then((res) => { }, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) { if (res.code == 200) {
this.defaultList = res.result; this.defaultList = res.result;
this.$refs.attrValueDialog.open(); this.$refs.attrValueDialog.open();

Loading…
Cancel
Save