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

处理重复添加逻辑

上级 58248eae
......@@ -67,7 +67,7 @@
<span v-if="index < scope.row.value.length - 1">,&nbsp;</span>
</span>
</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>
</el-table-column>
<el-table-column
......@@ -120,9 +120,9 @@
label="操作"
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="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>
</el-table-column>
</el-table>
......@@ -310,18 +310,23 @@
publish: this.option.publish
}
this.deliveryTableData = this.option.new_dispatching
if (this.option.new_dispatching) {
this.deliveryTableData.forEach(item=>{
item.fp = Number(item.fp / 100)
item.np = Number(item.np / 100)
item.value = this.getSelectData(item.a)
item.id = this.getBackData(item.a)
})
}
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)
}
}
}
},
// 设置全国选项不可选
selectEnable(row) {
......@@ -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() {
this.cancelDisabled()
this.selectAddress = []
this.addType = 2
this.dialogAddress = true
......@@ -382,20 +429,76 @@
}
},
// 修改地区
editAddress(row, index, type) {
async editAddress(row, index, type) {
// type 2 限制配送区域 1 配送区域
this.selectAddress = []
if (type == 2) {
this.rowItem2 = row
this.addType = 2
this.cancelDisabled()
} else {
this.rowItem = row
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.dialogAddress = true
},
// 选择的地区赋值
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) {
this.rowItem.a = this.getAfferentData()
this.rowItem.value = []
......@@ -403,11 +506,11 @@
this.rowItem.value = this.getSelectData(this.rowItem.a)
this.rowItem.id = this.getBackData(this.rowItem.a)
} else {
this.noDeliveryTableData.push({
this.noDeliveryTableData[0] = {
a: this.getAfferentData(this.getAfferentData()),
value: this.getSelectData(this.getAfferentData()),
id: this.getBackData(this.getAfferentData())
})
}
}
this.dialogAddress = false
},
......@@ -610,14 +713,27 @@
// name2 = []
// name3 = []
// }
// console.log('-------------')
// console.log(addressName)
// return addressName
// },
// 提交
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) => {
if (valid) {
if (!isContinue) {
this.$message.warning('配送区域不能为空')
return
}
if (this.option.id == 0) {
let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {new_dispatching: this.deliveryTableData})))
if (params.new_dispatching.length) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论