|
@@ -54,11 +54,6 @@ export default {
|
|
|
return (this.itemId ? '编辑' : '新增') + '分区'
|
|
|
}
|
|
|
},
|
|
|
- filters: {
|
|
|
- hasCheckChild: function (value) {
|
|
|
- return value.filter(item => item.checked).length
|
|
|
- }
|
|
|
- },
|
|
|
data () {
|
|
|
return {
|
|
|
isShow: this.openModal, // 是否打开弹框
|
|
@@ -74,122 +69,10 @@ export default {
|
|
|
subareaName: [
|
|
|
{ required: true, message: '请输入分区名称', trigger: 'blur' }
|
|
|
]
|
|
|
- },
|
|
|
- addrProvinceList: [], // 省下拉
|
|
|
- subareaAreaList: []
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- filterEmpty () {
|
|
|
- let str = this.zoneForm.subareaName
|
|
|
- str = str.replace(/\ +/g, '')
|
|
|
- str = str.replace(/[ ]/g, '')
|
|
|
- str = str.replace(/[\r\n]/g, '')
|
|
|
- this.zoneForm.subareaName = str
|
|
|
- },
|
|
|
- onChange (item, e, parent) {
|
|
|
- // console.log(item, `checked = ${e.target.checked}`)
|
|
|
- item.checked = e.target.checked
|
|
|
- item.noSave = false
|
|
|
- // 父级
|
|
|
- if (item.type == 2) {
|
|
|
- item.children && item.children.map(d => {
|
|
|
- d.checked = item.checked
|
|
|
- })
|
|
|
- item.indeterminate = false
|
|
|
- }
|
|
|
- // 子级
|
|
|
- if (item.type == 3) {
|
|
|
- // 父级节点
|
|
|
- const hasCheckd = parent.children.filter(k => k.checked)
|
|
|
- // 是否全选
|
|
|
- parent.checked = hasCheckd.length == parent.children.length
|
|
|
- parent.children.map(d => d.noSave = parent.checked)
|
|
|
- // indeterminate为true,则为全选,false则为部分选择或者空
|
|
|
- parent.indeterminate = ((hasCheckd.length < parent.children.length) && (hasCheckd.length != 0))
|
|
|
- }
|
|
|
- this.addrProvinceList = JSON.parse(JSON.stringify(this.addrProvinceList))
|
|
|
- },
|
|
|
- // 展开收起
|
|
|
- expend (item) {
|
|
|
- if (item.children && item.children.length == 0) {
|
|
|
- item.isOpen = 1
|
|
|
- this.getArea('city', item, 1)
|
|
|
- } else {
|
|
|
- item.isOpen = !item.isOpen
|
|
|
- }
|
|
|
- },
|
|
|
- // 省/市/区
|
|
|
- getArea (leve, item, openType) {
|
|
|
- let params
|
|
|
- if (leve == 'province') {
|
|
|
- params = { type: '2' }
|
|
|
- } else {
|
|
|
- params = { parentId: item.areaSn, type: leve == 'city' ? '3' : '4' }
|
|
|
- }
|
|
|
- getArea(params).then(res => {
|
|
|
- if (res.status == 200) {
|
|
|
- if (leve == 'province') {
|
|
|
- this.addrProvinceList = res.data || []
|
|
|
- this.addrProvinceList.map(item => {
|
|
|
- item.noSave = true
|
|
|
- item.checked = false
|
|
|
- item.children = []
|
|
|
- item.indeterminate = false
|
|
|
- })
|
|
|
- // 编辑时获取已选数据
|
|
|
- if (this.itemId) {
|
|
|
- this.getChecked()
|
|
|
- }
|
|
|
- document.getElementById('treeNode').scrollTop = 0
|
|
|
- } else if (leve == 'city') {
|
|
|
- item.children = res.data || []
|
|
|
- item.children.map(d => {
|
|
|
- // 编辑时回显
|
|
|
- if (this.itemId && openType == 0) {
|
|
|
- d.checked = !!this.subareaAreaList.find(o => o.areaSn == d.areaSn)
|
|
|
- d.noSave = false
|
|
|
- } else {
|
|
|
- d.checked = item.checked
|
|
|
- d.noSave = true
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- // 首次加载子级
|
|
|
- if (openType == 1) {
|
|
|
- this.addrProvinceList = JSON.parse(JSON.stringify(this.addrProvinceList))
|
|
|
- } else {
|
|
|
- item.isOpen = 1
|
|
|
- item.indeterminate = true
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (leve == 'province') {
|
|
|
- this.addrProvinceList = []
|
|
|
- } else if (leve == 'city') {
|
|
|
- item.children = []
|
|
|
- item.isOpen = 0
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- // 过滤数据
|
|
|
- filterData (list) {
|
|
|
- list.map(item => {
|
|
|
- if (item.checked && !item.noSave) {
|
|
|
- this.subareaAreaList.push({
|
|
|
- areaSn: item.areaSn,
|
|
|
- areaName: item.name,
|
|
|
- areaType: item.type,
|
|
|
- areaParentSn: item.parentId
|
|
|
- })
|
|
|
- } else {
|
|
|
- if (item.children && item.children.length) {
|
|
|
- this.filterData(item.children)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
// 保存
|
|
|
handleSave () {
|
|
|
const _this = this
|
|
@@ -224,35 +107,6 @@ export default {
|
|
|
return false
|
|
|
}
|
|
|
})
|
|
|
- },
|
|
|
- // 编辑
|
|
|
- getChecked () {
|
|
|
- subareaFindBySn({ sn: this.itemId }).then(res => {
|
|
|
- // console.log(res.data)
|
|
|
- this.form.subareaName = res.data.subareaName
|
|
|
- this.subareaAreaList = res.data.subareaAreaList
|
|
|
- this.form.subareaSn = res.data.subareaSn
|
|
|
- this.form.id = res.data.id
|
|
|
- // 回显数据
|
|
|
- this.showChecked()
|
|
|
- })
|
|
|
- },
|
|
|
- showChecked () {
|
|
|
- // 省回显
|
|
|
- this.addrProvinceList.map(item => {
|
|
|
- item.checked = !!this.subareaAreaList.find(d => d.areaSn == item.areaSn)
|
|
|
- item.noSave = false
|
|
|
- item.indeterminate = false
|
|
|
- })
|
|
|
- // 市回显
|
|
|
- const hasCity = this.nowData.subareaAreaList.filter(item => item.citySubareaAreaList && item.citySubareaAreaList.length)
|
|
|
- // console.log(hasCity, 'hasCity.nowData')
|
|
|
- hasCity.map(item => {
|
|
|
- // 省
|
|
|
- const pre = this.addrProvinceList.find(k => k.areaSn == item.areaSn)
|
|
|
- // 获取子级
|
|
|
- this.getArea('city', pre, 0)
|
|
|
- })
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
@@ -264,11 +118,6 @@ export default {
|
|
|
isShow (newValue, oldValue) {
|
|
|
if (!newValue) {
|
|
|
this.$emit('close')
|
|
|
- this.form.subareaName = ''
|
|
|
- this.form.subareaSn = ''
|
|
|
- delete this.form.id
|
|
|
- } else {
|
|
|
- this.getArea('province')
|
|
|
}
|
|
|
}
|
|
|
}
|