|
@@ -41,7 +41,7 @@
|
|
<!-- 子级 -->
|
|
<!-- 子级 -->
|
|
<div v-show="item.isOpen==1" class="tree-child">
|
|
<div v-show="item.isOpen==1" class="tree-child">
|
|
<div v-for="child in item.children" :key="child.id">
|
|
<div v-for="child in item.children" :key="child.id">
|
|
- <a-checkbox v-model="child.checked" style="width: 100%;" @change="onChange(child,$event)">
|
|
|
|
|
|
+ <a-checkbox v-model="child.checked" style="width: 100%;" @change="onChange(child,$event,item)">
|
|
{{ child.checked }}{{ child.name }}
|
|
{{ child.checked }}{{ child.name }}
|
|
</a-checkbox>
|
|
</a-checkbox>
|
|
</div>
|
|
</div>
|
|
@@ -62,6 +62,7 @@
|
|
import { STable, Upload } from '@/components'
|
|
import { STable, Upload } from '@/components'
|
|
import Editor from '@/components/WEeditor'
|
|
import Editor from '@/components/WEeditor'
|
|
import { getArea } from '@/api/data'
|
|
import { getArea } from '@/api/data'
|
|
|
|
+import { subareaSaveSubareaArea, subareaFindBySn } from '@/api/subarea'
|
|
export default {
|
|
export default {
|
|
name: 'MarketingDivisionSetEditModal',
|
|
name: 'MarketingDivisionSetEditModal',
|
|
components: { STable, Upload, Editor },
|
|
components: { STable, Upload, Editor },
|
|
@@ -104,60 +105,24 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- onChange (item, e) {
|
|
|
|
|
|
+ onChange (item, e, parent) {
|
|
console.log(item, `checked = ${e.target.checked}`)
|
|
console.log(item, `checked = ${e.target.checked}`)
|
|
item.checked = e.target.checked
|
|
item.checked = e.target.checked
|
|
- const hasItemIndex = this.subareaAreaList.findIndex(d => d.areaSn == item.areaSn)
|
|
|
|
- // 已存在,则删除
|
|
|
|
- if (hasItemIndex >= 0) {
|
|
|
|
- this.subareaAreaList.splice(hasItemIndex, 1)
|
|
|
|
- } else {
|
|
|
|
- // 不存在,添加
|
|
|
|
- this.subareaAreaList.push({
|
|
|
|
- areaSn: item.areaSn,
|
|
|
|
- areaName: item.name,
|
|
|
|
- areaType: item.type,
|
|
|
|
- areaParentSn: item.parentId
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- console.log(this.subareaAreaList)
|
|
|
|
-
|
|
|
|
- // 判断是否存在父级
|
|
|
|
- if (item.type == 3) {
|
|
|
|
- // 如何子级全部勾选
|
|
|
|
- const parent = this.addrProvinceList.find(d => d.areaSn == item.parentId)
|
|
|
|
- const plen = parent.children.length
|
|
|
|
- const tjNode = this.subareaAreaList.filter(d => d.areaParentSn == item.parentId)
|
|
|
|
- console.log(tjNode.length == plen)
|
|
|
|
- if (tjNode.length == plen) {
|
|
|
|
- console.log(1)
|
|
|
|
- // 保存父级
|
|
|
|
- this.subareaAreaList.push({
|
|
|
|
- areaSn: parent.areaSn,
|
|
|
|
- areaName: parent.name,
|
|
|
|
- areaType: parent.type,
|
|
|
|
- areaParentSn: parent.parentId
|
|
|
|
- })
|
|
|
|
- // 删除所有子级
|
|
|
|
- this.subareaAreaList = this.subareaAreaList.filter(d => d.areaParentSn != item.parentId)
|
|
|
|
- parent.checked = true
|
|
|
|
- } else {
|
|
|
|
- const hasPIndex = this.subareaAreaList.findIndex(d => d.areaSn == item.parentId)
|
|
|
|
- // 存在则删除父级
|
|
|
|
- if (hasPIndex >= 0) {
|
|
|
|
- this.subareaAreaList.splice(hasPIndex, 1)
|
|
|
|
- }
|
|
|
|
- parent.checked = false
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- console.log(item.checked)
|
|
|
|
- // 父级操作
|
|
|
|
|
|
+ item.noSave = false
|
|
|
|
+ // 父级
|
|
|
|
+ if (item.type == 2) {
|
|
item.children && item.children.map(d => {
|
|
item.children && item.children.map(d => {
|
|
- d.disabled = item.checked
|
|
|
|
d.checked = item.checked
|
|
d.checked = item.checked
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ // 子级
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
this.addrProvinceList = JSON.parse(JSON.stringify(this.addrProvinceList))
|
|
this.addrProvinceList = JSON.parse(JSON.stringify(this.addrProvinceList))
|
|
},
|
|
},
|
|
// 展开收起
|
|
// 展开收起
|
|
@@ -182,14 +147,25 @@ export default {
|
|
if (leve == 'province') {
|
|
if (leve == 'province') {
|
|
this.addrProvinceList = res.data || []
|
|
this.addrProvinceList = res.data || []
|
|
this.addrProvinceList.map(item => {
|
|
this.addrProvinceList.map(item => {
|
|
|
|
+ item.noSave = true
|
|
item.checked = false
|
|
item.checked = false
|
|
item.children = []
|
|
item.children = []
|
|
})
|
|
})
|
|
|
|
+ // 编辑时获取已选数据
|
|
|
|
+ if (this.itemId) {
|
|
|
|
+ this.getChecked()
|
|
|
|
+ }
|
|
} else if (leve == 'city') {
|
|
} else if (leve == 'city') {
|
|
item.children = res.data || []
|
|
item.children = res.data || []
|
|
item.children.map(d => {
|
|
item.children.map(d => {
|
|
- d.disabled = false
|
|
|
|
- d.checked = item.checked
|
|
|
|
|
|
+ // 编辑时回显
|
|
|
|
+ if (this.itemId) {
|
|
|
|
+ d.checked = !!this.subareaAreaList.find(o => o.areaSn == d.areaSn)
|
|
|
|
+ d.noSave = false
|
|
|
|
+ } else {
|
|
|
|
+ d.checked = item.checked
|
|
|
|
+ d.noSave = true
|
|
|
|
+ }
|
|
})
|
|
})
|
|
this.addrProvinceList = JSON.parse(JSON.stringify(this.addrProvinceList))
|
|
this.addrProvinceList = JSON.parse(JSON.stringify(this.addrProvinceList))
|
|
}
|
|
}
|
|
@@ -203,24 +179,77 @@ export default {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ // 过滤数据
|
|
|
|
+ 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 () {
|
|
handleSave () {
|
|
const _this = this
|
|
const _this = this
|
|
_this.$refs.ruleForm.validate(valid => {
|
|
_this.$refs.ruleForm.validate(valid => {
|
|
if (valid) {
|
|
if (valid) {
|
|
const formData = JSON.parse(JSON.stringify(_this.form))
|
|
const formData = JSON.parse(JSON.stringify(_this.form))
|
|
|
|
+ this.subareaAreaList = []
|
|
|
|
+ this.filterData(this.addrProvinceList)
|
|
console.log(this.subareaAreaList)
|
|
console.log(this.subareaAreaList)
|
|
- // dealerProductBrandSave(formData).then(res => {
|
|
|
|
- // if (res.status == 200) {
|
|
|
|
- // _this.$message.success(res.message)
|
|
|
|
- // _this.$emit('ok')
|
|
|
|
- // _this.isShow = false
|
|
|
|
- // }
|
|
|
|
- // })
|
|
|
|
|
|
+ // 编辑
|
|
|
|
+ if (this.itemId) {
|
|
|
|
+ formData.subareaSn = this.itemId
|
|
|
|
+ }
|
|
|
|
+ formData.subareaAreaList = this.subareaAreaList
|
|
|
|
+ console.log(formData, 'formData')
|
|
|
|
+ subareaSaveSubareaArea(formData).then(res => {
|
|
|
|
+ if (res.status == 200) {
|
|
|
|
+ _this.$message.success(res.message)
|
|
|
|
+ _this.$emit('ok')
|
|
|
|
+ _this.isShow = false
|
|
|
|
+ }
|
|
|
|
+ })
|
|
} else {
|
|
} else {
|
|
return false
|
|
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
|
|
|
|
+ })
|
|
|
|
+ // 市回显
|
|
|
|
+ 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.expend(pre)
|
|
|
|
+ })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|