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

地区数据处理

上级 52f250f1
...@@ -172,12 +172,16 @@ ...@@ -172,12 +172,16 @@
// 处理最后一级显示暂无数据 // 处理最后一级显示暂无数据
getTreeData(data) { getTreeData(data) {
for(let i = 0, len = data.length; i < len; i++ ) { for(let i = 0, len = data.length; i < len; i++ ) {
if (data[i].type >= 2) {
data[i].children = undefined
} else {
if (!data[i].children.length) { if (!data[i].children.length) {
data[i].children = undefined data[i].children = undefined
} else { } else {
this.getTreeData(data[i].children) this.getTreeData(data[i].children)
} }
} }
}
return data return data
}, },
closeDialog(val) { closeDialog(val) {
......
...@@ -59,9 +59,15 @@ ...@@ -59,9 +59,15 @@
label="配送区域" label="配送区域"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<span v-if="scope.row.a.length && scope.row.a[0] == 0">【默认】全国</span> <div v-if="scope.row.a.length && scope.row.a[0].province_id == 0">【默认】全国</div>
<span v-if="scope.row.a.length && scope.row.a[0] != 0">【指定】{{ scope.row.value }}</span> <div v-if="scope.row.a.length && scope.row.a[0].province_id != 0">
<span v-if="!scope.row.a.length" style="color: #1890ff; cursor: pointer;" @click="editAddress(scope.row, scope.$index)">【点击选择配送地区】</span> 【指定】
<span v-for="(item, index) in scope.row.value" :key="index">
<span>{{ item.province_name }}{{ item.city_name.length ? `(${ item.city_name.join() })` : '' }}</span>
<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>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
...@@ -149,7 +155,11 @@ ...@@ -149,7 +155,11 @@
prop="dis_dispatching" prop="dis_dispatching"
> >
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.value }} <!-- {{ scope.row.value }} -->
<span v-for="(item, index) in scope.row.value" :key="index">
<span>{{ item.province_name }}{{ item.city_name.length ? `(${ item.city_name.join() })` : '' }}</span>
<span v-if="index < scope.row.value.length - 1">,&nbsp;</span>
</span>
</template> </template>
</el-table-column> </el-table-column>
<!-- 样式占位 --> <!-- 样式占位 -->
...@@ -202,7 +212,6 @@ ...@@ -202,7 +212,6 @@
</template> </template>
<script> <script>
import { addressList } from '@/api/module/freight'
import { addFreight, updateFreight} from '@/api/module/freight' import { addFreight, updateFreight} from '@/api/module/freight'
export default { export default {
...@@ -237,8 +246,10 @@ ...@@ -237,8 +246,10 @@
}, },
deliveryTableData: [ deliveryTableData: [
{ {
a: [0], a: [{
value: '', province_id: 0,
province_name: '全国'
}],
f: '', f: '',
fp: '', fp: '',
n: '', n: '',
...@@ -263,7 +274,6 @@ ...@@ -263,7 +274,6 @@
mounted() { mounted() {
this.addressOptions = this.addressAll this.addressOptions = this.addressAll
this.initData() this.initData()
// this.getaddressList()
}, },
methods: { methods: {
// 初始化数据 // 初始化数据
...@@ -279,8 +289,10 @@ ...@@ -279,8 +289,10 @@
} }
this.deliveryTableData = [ this.deliveryTableData = [
{ {
a: [0], a: [{
value: '', province_id: 0,
province_name: '全国'
}],
f: '', f: '',
fp: '', fp: '',
n: '', n: '',
...@@ -297,39 +309,23 @@ ...@@ -297,39 +309,23 @@
charge_type: this.option.charge_type, charge_type: this.option.charge_type,
publish: this.option.publish publish: this.option.publish
} }
this.deliveryTableData = this.option.dispatching this.deliveryTableData = this.option.new_dispatching
this.deliveryTableData.forEach(item=>{ this.deliveryTableData.forEach(item=>{
item.fp = Number(item.fp / 100) item.fp = Number(item.fp / 100)
item.np = Number(item.np / 100) item.np = Number(item.np / 100)
item.value = this.getSelectData(item.a)
item.id = this.getBackData(item.a)
}) })
this.noDeliveryTableData[0] = { this.noDeliveryTableData[0] = {
a: this.option.dis_dispatching, a: this.option.new_dis_dispatching,
value: '' value: this.getSelectData(this.option.new_dis_dispatching),
} id: this.getBackData(this.option.new_dis_dispatching)
} }
},
// 获取全部地区
getaddressList() {
addressList().then(res => {
if (res.code == 1) {
this.addressOptions = this.getTreeData(res.data)
} }
})
},
// 处理最后一级显示暂无数据
getTreeData(data) {
for(let i = 0, len = data.length; i < len; i++ ) {
if (!data[i].children.length) {
data[i].children = undefined
} else {
this.getTreeData(data[i].children)
}
}
return data
}, },
// 设置全国选项不可选 // 设置全国选项不可选
selectEnable(row) { selectEnable(row) {
if (row.a.length && row.a[0] == 0) { if (row.a.length && row.a[0].province_id == 0) {
return false return false
} else { } else {
return true return true
...@@ -358,7 +354,6 @@ ...@@ -358,7 +354,6 @@
this.deliveryTableData.push( this.deliveryTableData.push(
{ {
a: [], a: [],
value: '',
f: '', f: '',
fp: '', fp: '',
n: '', n: '',
...@@ -396,24 +391,83 @@ ...@@ -396,24 +391,83 @@
this.rowItem = row this.rowItem = row
this.addType = 1 this.addType = 1
} }
this.selectAddress = row.a this.selectAddress = row.id
this.dialogAddress = true this.dialogAddress = true
}, },
// 选择的地区赋值 // 选择的地区赋值
saveAddress() { saveAddress() {
if (this.addType == 1) { if (this.addType == 1) {
this.rowItem.a = this.selectAddress this.rowItem.a = this.getAfferentData()
this.rowItem.value = this.getAddressName() this.rowItem.value = []
this.rowItem.id = []
this.rowItem.value = this.getSelectData(this.rowItem.a)
this.rowItem.id = this.getBackData(this.rowItem.a)
} else { } else {
this.noDeliveryTableData.push({ this.noDeliveryTableData.push({
a: this.selectAddress, a: this.getAfferentData(this.getAfferentData()),
value: this.getAddressName(), value: this.getSelectData(this.getAfferentData()),
id: this.getBackData(this.getAfferentData())
}) })
} }
this.dialogAddress = false this.dialogAddress = false
}, },
// 将数据组合成省市县及是否选中的是全部地区 山东省【济南市(市中区,天桥区,长清区,济阳县)】 河北省(全部地区) // 获取对应数据显示的地址名称
getAddressName() { getSelectData(data) {
let a = []
let b = []
let c = [] // 地址名称 省 市
for(let i = 0; i < data.length; i++) {
a.push(data[i].province_id)
}
b = Array.from(new Set(a))
for(let i = 0; i < b.length; i++) {
let name = ''
let arr = []
for(let j = 0; j < data.length; j++) {
if (b[i] == data[j].province_id) {
if (data[j].city_id) {
name = data[j].province_name
arr.push(data[j].city_name)
} else {
name = data[j].province_name
}
}
}
c.push({
province_name: name,
city_name: arr
})
}
return c
},
// 将后台返回的格式处理成组件需要的格式
getBackData(data) {
let arr = []
for(let i = 0; i < data.length; i++) {
let arrItem = []
if (data[i].city_id) {
arrItem.push(data[i].province_id)
arrItem.push(data[i].city_id)
arr.push(arrItem)
} else {
for(let j = 0; j < this.addressOptions.length; j++) {
if (data[i].province_id == this.addressOptions[j].id) {
for(let k = 0; k < this.addressOptions[j].children.length; k++) {
arrItem.push(data[i].province_id)
arrItem.push(this.addressOptions[j].children[k].id)
arr.push(arrItem)
arrItem = []
}
}
}
}
}
return arr
},
// 组装成后台需要的格式 省市
getAfferentData() {
let a = [] let a = []
let b = [] let b = []
let c = [] // 将每个省的数据组合到一个数组中 let c = [] // 将每个省的数据组合到一个数组中
...@@ -429,18 +483,12 @@ ...@@ -429,18 +483,12 @@
} }
} }
} }
let selectData = []
let addressName = []
for(let i = 0; i < c.length; i++) { for(let i = 0; i < c.length; i++) {
let name1 = [] let arr1 = []
let name2 = []
let name3 = []
let str = ''
for(let j = 0; j < this.addressOptions.length; j++) { for(let j = 0; j < this.addressOptions.length; j++) {
if (c[i][0][0] == this.addressOptions[j].id) { if (c[i][0][0] == this.addressOptions[j].id) {
name1.push(this.addressOptions[j].name)
let d = [] let d = []
let e = [] let e = []
c[i].map(item => { c[i].map(item => {
...@@ -449,75 +497,142 @@ ...@@ -449,75 +497,142 @@
e = Array.from(new Set(d)) e = Array.from(new Set(d))
if (e.length == this.addressOptions[j].children.length) { if (e.length == this.addressOptions[j].children.length) {
name2.push('全部地区') arr1.push({
province_id: this.addressOptions[j].id,
province_name: this.addressOptions[j].name
})
} else { } else {
if ('children' in this.addressOptions[j]) { for (let k = 0; k < e.length; k++) {
for(let k = 0; k < e.length; k++) {
let data = ''
let h = []
for(let p = 0; p < d.length; p++) {
if (e[k] == d[p]) {
h.push(d[p])
}
}
for(let l = 0; l < this.addressOptions[j].children.length; l++) { for(let l = 0; l < this.addressOptions[j].children.length; l++) {
if (e[k] == this.addressOptions[j].children[l].id) { if (e[k] == this.addressOptions[j].children[l].id) {
data += (this.addressOptions[j].children[l].name) arr1.push({
province_id: this.addressOptions[j].id,
let f = [] province_name: this.addressOptions[j].name,
let g = [] city_id: this.addressOptions[j].children[l].id,
c[i].map(item => { city_name: this.addressOptions[j].children[l].name
if (e[k] == item[1]) {
g.push(item[2])
}
}) })
if ('children' in this.addressOptions[j].children[l]) {
if (h.length == this.addressOptions[j].children[l].children.length) {
name3.push('全部地区')
} else {
for(let m = 0; m < g.length; m++) {
for(let n = 0; n < this.addressOptions[j].children[l].children.length; n++) {
if (g[m] == this.addressOptions[j].children[l].children[n].id) {
name3.push(this.addressOptions[j].children[l].children[n].name)
}
} }
} }
} }
} }
} }
} }
data += `(${name3.join()})` selectData = selectData.concat(arr1)
name2.push(data)
data = []
name3 = []
} }
} return selectData
}
}
}
str = name1.join() + `【${name2.join()}】`
addressName.push(str)
name2 = []
name3 = []
}
console.log('-------------')
console.log(addressName)
return addressName.join()
}, },
// 将数据组合成省市县及是否选中的是全部地区 山东省【济南市(市中区,天桥区,长清区,济阳县)】 河北省(全部地区)
// getAddressName() {
// 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))
// for(let i = 0; i < b.length; i++) {
// c[i] = []
// for(let j = 0; j < this.selectAddress.length; j++) {
// if (b[i] == this.selectAddress[j][0]) {
// c[i].push(this.selectAddress[j])
// }
// }
// }
// let addressName = []
// for(let i = 0; i < c.length; i++) {
// let name1 = []
// let name2 = []
// let name3 = []
// let str = ''
// for(let j = 0; j < this.addressOptions.length; j++) {
// if (c[i][0][0] == this.addressOptions[j].id) {
// name1.push(this.addressOptions[j].name)
// let d = []
// let e = []
// c[i].map(item => {
// d.push(item[1])
// })
// e = Array.from(new Set(d))
// if (e.length == this.addressOptions[j].children.length) {
// name2.push('全部地区')
// } else {
// if ('children' in this.addressOptions[j]) {
// for(let k = 0; k < e.length; k++) {
// let data = ''
// let h = []
// for(let p = 0; p < d.length; p++) {
// if (e[k] == d[p]) {
// h.push(d[p])
// }
// }
// for(let l = 0; l < this.addressOptions[j].children.length; l++) {
// if (e[k] == this.addressOptions[j].children[l].id) {
// data += (this.addressOptions[j].children[l].name)
// let f = []
// let g = []
// c[i].map(item => {
// if (e[k] == item[1]) {
// g.push(item[2])
// }
// })
// if ('children' in this.addressOptions[j].children[l]) {
// if (h.length == this.addressOptions[j].children[l].children.length) {
// name3.push('全部地区')
// } else {
// for(let m = 0; m < g.length; m++) {
// for(let n = 0; n < this.addressOptions[j].children[l].children.length; n++) {
// if (g[m] == this.addressOptions[j].children[l].children[n].id) {
// name3.push(this.addressOptions[j].children[l].children[n].name)
// }
// }
// }
// }
// }
// }
// }
// data += `(${name3.join()})`
// name2.push(data)
// data = []
// name3 = []
// }
// }
// }
// }
// }
// str = name1.join() + `${name2.join()}】`
// addressName.push(str)
// name2 = []
// name3 = []
// }
// console.log('-------------')
// console.log(addressName)
// return addressName
// },
// 提交 // 提交
handleSubmit() { handleSubmit() {
this.$refs['ruleForm'].validate((valid) => { this.$refs['ruleForm'].validate((valid) => {
if (valid) { if (valid) {
if (this.option.id == 0) { if (this.option.id == 0) {
let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {dispatching: this.deliveryTableData}))) let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {new_dispatching: this.deliveryTableData})))
if (params.dispatching.length) { if (params.new_dispatching.length) {
params.dispatching.forEach(item=>{ params.new_dispatching.forEach(item=>{
item.fp = Number(item.fp * 100) item.fp = Number(item.fp * 100)
item.np = Number(item.np * 100) item.np = Number(item.np * 100)
item.value = undefined
item.id = undefined
}) })
} }
params.dis_dispatching = this.noDeliveryTableData.length ? this.noDeliveryTableData[0].a : [] params.new_dis_dispatching = this.noDeliveryTableData.length ? this.noDeliveryTableData[0].a : []
if (params.new_dis_dispatching.length) {
this.noDeliveryTableData[0].value = undefined
this.noDeliveryTableData[0].id = undefined
}
addFreight(params).then(res => { addFreight(params).then(res => {
if (res.code == 1) { if (res.code == 1) {
this.$message.success('新增成功') this.$message.success('新增成功')
...@@ -525,14 +640,20 @@ ...@@ -525,14 +640,20 @@
} }
}) })
} else { } else {
let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {dispatching: this.deliveryTableData}))) let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {new_dispatching: this.deliveryTableData})))
if (params.dispatching.length) { if (params.new_dispatching.length) {
params.dispatching.forEach(item=>{ params.new_dispatching.forEach(item=>{
item.fp = Number(item.fp * 100) item.fp = Number(item.fp * 100)
item.np = Number(item.np * 100) item.np = Number(item.np * 100)
item.value = undefined
item.id = undefined
}) })
} }
params.dis_dispatching = this.noDeliveryTableData.length ? this.noDeliveryTableData[0].a : [] params.new_dis_dispatching = this.noDeliveryTableData.length ? this.noDeliveryTableData[0].a : []
if (params.new_dis_dispatching.length) {
this.noDeliveryTableData[0].value = undefined
this.noDeliveryTableData[0].id = undefined
}
updateFreight(params).then(res => { updateFreight(params).then(res => {
if (res.code == 1) { if (res.code == 1) {
this.$message.success('修改成功') this.$message.success('修改成功')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论