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

地区数据处理

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