提交 bd2116e7 authored 作者: 郑伟娜's avatar 郑伟娜

处理重复添加逻辑

上级 58248eae
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<span v-if="index < scope.row.value.length - 1">,&nbsp;</span> <span v-if="index < scope.row.value.length - 1">,&nbsp;</span>
</span> </span>
</div> </div>
<div v-if="!scope.row.a.length" style="color: #1890ff; cursor: pointer;" @click="editAddress(scope.row, scope.$index)">【点击选择配送地区】</div> <div v-if="!scope.row.a.length" style="color: #1890ff; cursor: pointer;" @click="editAddress(scope.row, scope.$index, 'add')">【点击选择配送地区】</div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
...@@ -120,9 +120,9 @@ ...@@ -120,9 +120,9 @@
label="操作" label="操作"
width="120" width="120"
> >
<template slot-scope="scope" v-if="scope.row.a[0] != 0"> <template slot-scope="scope" v-if="scope.$index > 0">
<el-button type="text" size="small" @click="delDelivery('1', scope.$index)">删除</el-button> <el-button type="text" size="small" @click="delDelivery('1', scope.$index)">删除</el-button>
<el-button type="text" size="small" @click="editAddress(scope.row, scope.$index)">修改地区</el-button> <el-button type="text" size="small" @click="editAddress(scope.row, scope.$index)" v-if="scope.row.a.length">修改地区</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
...@@ -310,16 +310,21 @@ ...@@ -310,16 +310,21 @@
publish: this.option.publish publish: this.option.publish
} }
this.deliveryTableData = this.option.new_dispatching this.deliveryTableData = this.option.new_dispatching
this.deliveryTableData.forEach(item=>{ if (this.option.new_dispatching) {
item.fp = Number(item.fp / 100) this.deliveryTableData.forEach(item=>{
item.np = Number(item.np / 100) item.fp = Number(item.fp / 100)
item.value = this.getSelectData(item.a) item.np = Number(item.np / 100)
item.id = this.getBackData(item.a) item.value = this.getSelectData(item.a)
}) item.id = this.getBackData(item.a)
this.noDeliveryTableData[0] = { })
a: this.option.new_dis_dispatching, }
value: this.getSelectData(this.option.new_dis_dispatching),
id: this.getBackData(this.option.new_dis_dispatching) if (this.option.new_dis_dispatching.length) {
this.noDeliveryTableData[0] = {
a: this.option.new_dis_dispatching,
value: this.getSelectData(this.option.new_dis_dispatching),
id: this.getBackData(this.option.new_dis_dispatching)
}
} }
} }
}, },
...@@ -361,8 +366,50 @@ ...@@ -361,8 +366,50 @@
} }
) )
}, },
// 处理已经添加的数据不可重复添加
async repeatAdd() {
await this.cancelDisabled()
let arr = [] // 已添加的数据合并到一个数组中
this.deliveryTableData.map(item => {
arr = arr.concat(item.a)
})
if (arr.length) {
for(let i = 0; i < arr.length; i++) {
for(let j = 0; j < this.addressOptions.length; j++) {
if (arr[i].city_id) {
if (arr[i].province_id == this.addressOptions[j].id) {
for(let k = 0; k < this.addressOptions[j].children.length; k++) {
if (arr[i].city_id == this.addressOptions[j].children[k].id) {
this.$set(this.addressOptions[j].children[k], 'disabled', true)
}
}
}
} else {
if (arr[i].province_id == this.addressOptions[j].id) {
this.$set(this.addressOptions[j], 'disabled', true)
}
}
}
}
}
},
// 编辑时取消禁用的按钮
cancelDisabled() {
for(let i = 0; i < this.addressOptions.length; i++) {
if (this.addressOptions[i].disabled) {
this.$set(this.addressOptions[i], 'disabled', false)
}
for(let j = 0; j < this.addressOptions[i].children.length; j++) {
if (this.addressOptions[i].children[j].disabled) {
this.$set(this.addressOptions[i].children[j], 'disabled', false)
}
}
}
},
// 添加不配送地区 // 添加不配送地区
addNoDelivery() { addNoDelivery() {
this.cancelDisabled()
this.selectAddress = [] this.selectAddress = []
this.addType = 2 this.addType = 2
this.dialogAddress = true this.dialogAddress = true
...@@ -382,20 +429,76 @@ ...@@ -382,20 +429,76 @@
} }
}, },
// 修改地区 // 修改地区
editAddress(row, index, type) { async editAddress(row, index, type) {
// type 2 限制配送区域 1 配送区域
this.selectAddress = [] this.selectAddress = []
if (type == 2) { if (type == 2) {
this.rowItem2 = row this.rowItem2 = row
this.addType = 2 this.addType = 2
this.cancelDisabled()
} else { } else {
this.rowItem = row this.rowItem = row
this.addType = 1 this.addType = 1
await this.repeatAdd()
// 修改时取消当前行的禁用
let arr = row.a
if (arr.length) {
for(let i = 0; i < arr.length; i++) {
for(let j = 0; j < this.addressOptions.length; j++) {
if (arr[i].city_id) {
if (arr[i].province_id == this.addressOptions[j].id) {
for(let k = 0; k < this.addressOptions[j].children.length; k++) {
if (arr[i].city_id == this.addressOptions[j].children[k].id) {
this.$set(this.addressOptions[j].children[k], 'disabled', false)
}
}
}
} else {
if (arr[i].province_id == this.addressOptions[j].id) {
this.$set(this.addressOptions[j], 'disabled', false)
}
}
}
}
}
// 子元素全部禁用后父级也禁用
for(let i = 0; i < this.addressOptions.length; i++) {
if (!this.addressOptions[i].disabled) {
let isDisabled = true
for(let j = 0; j < this.addressOptions[i].children.length; j++) {
if (!this.addressOptions[i].children[j].disabled) {
isDisabled = false
}
}
this.$set(this.addressOptions[i], 'disabled', isDisabled)
}
}
} }
// 添加时 已添加的不可重复添加
if (type == 'add') {
this.repeatAdd()
}
this.selectAddress = row.id this.selectAddress = row.id
this.dialogAddress = true this.dialogAddress = true
}, },
// 选择的地区赋值 // 选择的地区赋值
saveAddress() { saveAddress() {
let a = []
let b = []
let c = [] // 将每个省的数据组合到一个数组中
for(let i = 0; i < this.selectAddress.length; i++) {
a.push(this.selectAddress[i][0])
}
b = Array.from(new Set(a))
if (b.length == this.addressOptions.length) {
this.$message.warning('已存在全国默认运费')
return
}
if (this.addType == 1) { if (this.addType == 1) {
this.rowItem.a = this.getAfferentData() this.rowItem.a = this.getAfferentData()
this.rowItem.value = [] this.rowItem.value = []
...@@ -403,11 +506,11 @@ ...@@ -403,11 +506,11 @@
this.rowItem.value = this.getSelectData(this.rowItem.a) this.rowItem.value = this.getSelectData(this.rowItem.a)
this.rowItem.id = this.getBackData(this.rowItem.a) this.rowItem.id = this.getBackData(this.rowItem.a)
} else { } else {
this.noDeliveryTableData.push({ this.noDeliveryTableData[0] = {
a: this.getAfferentData(this.getAfferentData()), a: this.getAfferentData(this.getAfferentData()),
value: this.getSelectData(this.getAfferentData()), value: this.getSelectData(this.getAfferentData()),
id: this.getBackData(this.getAfferentData()) id: this.getBackData(this.getAfferentData())
}) }
} }
this.dialogAddress = false this.dialogAddress = false
}, },
...@@ -610,14 +713,27 @@ ...@@ -610,14 +713,27 @@
// name2 = [] // name2 = []
// name3 = [] // name3 = []
// } // }
// console.log('-------------')
// console.log(addressName)
// return addressName // return addressName
// }, // },
// 提交 // 提交
handleSubmit() { handleSubmit() {
// 校验配送区域不能为空
let isContinue = true
if (this.deliveryTableData.length) {
for(let i = 0; i < this.deliveryTableData.length; i++) {
if (!this.deliveryTableData[i].a.length || !this.deliveryTableData[i].f || !this.deliveryTableData[i].fp || !this.deliveryTableData[i].n || !this.deliveryTableData[i].np) {
isContinue = false
}
}
}
this.$refs['ruleForm'].validate((valid) => { this.$refs['ruleForm'].validate((valid) => {
if (valid) { if (valid) {
if (!isContinue) {
this.$message.warning('配送区域不能为空')
return
}
if (this.option.id == 0) { if (this.option.id == 0) {
let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {new_dispatching: this.deliveryTableData}))) let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {new_dispatching: this.deliveryTableData})))
if (params.new_dispatching.length) { if (params.new_dispatching.length) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论