Commit 68c0ca16 by zhangquan

修改弹窗逻辑

1 parent 740d0e37
......@@ -8,24 +8,25 @@
@onCancel="handleClose">
<div class="car-container">
<div class="wrap">
<div :class="['item', 'flex-center',{'curItem' : curBrandId==item.id}]" v-for="item in carSeriesData" :key="item.id" @click="selectBrand(item)">
<span>{{ item.name }}</span>
<i class="el-icon-arrow-right"></i>
<div class="item son-brand-wrap" v-for="(item, index) in carSeriesData" :key="item.id">
<el-checkbox :disabled="!(item.childs && item.childs.length)" :indeterminate="isIndeterminate(item, 1)" :value="isChecked(item, 1)" @change="changeBrandStatus($event, item, index)"></el-checkbox>
<span :class="['son-brand-label', {'curItem' : curBrandInfo.id==item.id}]" @click="showSonBrandList(item)">
{{ item.name }}
<i v-if="item.childs && item.childs.length" class="el-icon-arrow-right"></i>
</span>
</div>
</div>
<div class="wrap">
<div class="item son-brand-wrap" v-for="(item, index) in sonBrandList" :key="item.id">
<el-checkbox :indeterminate="isIndeterminate(item)" :value="isChecked(item.id, 'son')" @change="selectSonBrand($event, item, index)"></el-checkbox>
<span :class="['son-brand-label', {'curItem' : curSonBrandId==item.id}]" @click="showCarSeries(item)">
{{ item.name }}{{ isIndeterminate(item) }}
<i class="el-icon-arrow-right"></i>
<el-checkbox :disabled="!(item.childs && item.childs.length)" :indeterminate="isIndeterminate(item, 2)" :value="isChecked(item, 2)" @change="changeSonBrandStatus($event, item, index)"></el-checkbox>
<span :class="['son-brand-label', {'curItem' : curSonBrandInfo.id==item.id}]" @click="showCarSeriesList(item)">
{{ item.name }}
<i v-if="item.childs && item.childs.length" class="el-icon-arrow-right"></i>
</span>
</div>
</div>
<div class="wrap">
<el-checkbox-group v-model="selectdData" @change="selectCarSeries()">
<el-checkbox class="item" v-for="item in carSeriesList" :label="item.id" :key="item.id">{{item.name}}</el-checkbox>
</el-checkbox-group>
<el-checkbox class="item" v-for="item in carSeriesList" :key="item.id" :value="isChecked(item, '3')" @change="changeCarSeriesStatus($event, item, index)">{{item.name}}</el-checkbox>
</div>
</div>
</GLDialog>
......@@ -40,11 +41,15 @@
carSeriesData: [],
sonBrandList: [],
carSeriesList: [],
selectdData: [],
checkedList: [],
curBrandId: '',
curSonBrandId: '',
firstClick: false
selectdData: {},
curBrandInfo: {
id: '',
name: ''
},
curSonBrandInfo: {
id: '',
name: ''
}
}
},
computed:{
......@@ -61,80 +66,117 @@
},
methods:{
isChecked(id, type){
const _target = this.checkedList.find(ele => ele == id)
if(type=='son'){
return !!_target
changeBrandStatus(e, row, idx){
const { id: rootId, name: rootName } = row
if(this.selectdData[rootId]){
this.$delete(this.selectdData, rootId)
}else{
return !!_target?.child?.includes(id)
let targetObj = {}
row?.childs.forEach(item => {
const { id: parentId, name: parentName } = item
targetObj[parentId] = []
item?.childs?.forEach(ele => {
targetObj[item.id].push({rootId, rootName, parentId, parentName, id: ele.id, name: ele.name})
})
})
this.$set(this.selectdData, rootId , targetObj)
}
console.log(this.selectdData)
},
isIndeterminate(item){
const _existItem = item?.childs?.find(row => !this.selectdData.includes(row.id))
const _notExistItem= item?.childs?.find(row => this.selectdData.includes(row.id))
return !!_existItem && !!_notExistItem
},
// 获取数据源
getCarSeriesData() {
this.$apis.case.getCarSeriesApi({needCarSeries:true}).then(res => {
console.log(res)
if(res?.length){
this.carSeriesData = res
changeSonBrandStatus(e, row, idx){
const {id:rootId, name: rootName} = this.curBrandInfo
if(this.selectdData[rootId]){
if(this.selectdData[rootId][row.id]){
this.$delete(this.selectdData[rootId], row.id)
}else{
let carList = []
row?.childs?.forEach(ele => {
carList.push({rootId, rootName, parentId: row.id, parentName: row.name, id: ele.id, name: ele.name})
})
this.$set(this.selectdData[rootId], row.id , carList)
}
})
},
// 切换品牌
selectBrand(item) {
if(this.curBrandId == item.id) return;
this.curBrandId = item.id
this.sonBrandList = item?.childs || []
this.curSonBrandId = ''
this.carSeriesList = []
},
// 选中子品牌
selectSonBrand(e, item , index){
const { id } = item
const _targetIdx = this.checkedList.findIndex(ele => ele == id)
if(_targetIdx>-1){
this.checkedList.splice(_targetIdx, 1)
item.childs.forEach(row => {
const spliceIdx = this.selectdData.findIndex(ele => ele == row.id)
this.selectdData.splice(spliceIdx, 1)
}else{
let targetObj = {
[row.id] : []
}
row?.childs?.forEach(ele => {
targetObj[row.id].push({rootId, rootName, parentId: row.id, parentName: row.name, id: ele.id, name: ele.name})
})
this.$set(this.selectdData, rootId , targetObj)
}
},
changeCarSeriesStatus(e, row, idx){
const {id:rootId, name: rootName} = this.curBrandInfo
const {id: parentId, name: parentName} = this.curSonBrandInfo
if(this.selectdData[rootId]){
if(this.selectdData[rootId][parentId]){
const targetIdx = this.selectdData[rootId][parentId]?.findIndex(item=>item.id == row.id)
if(targetIdx>-1){
this.selectdData[rootId][parentId].splice(targetIdx, 1)
}else{
this.selectdData[rootId][parentId].push({rootId, rootName, parentId, parentName, id: row.id, name: row.name})
}
}else{
this.$set(this.selectdData[rootId], parentId , [{rootId, rootName, parentId, parentName, id: row.id, name: row.name}])
}
}else{
this.checkedList.push(id)
let ids = item.childs.map(item => item.id)
this.selectdData = [...new Set([...this.selectdData, ...ids])]
this.$set(this.selectdData, rootId , {[parentId]: [{rootId, rootName, parentId, parentName, id: row.id, name: row.name}]})
}
console.log(this.selectdData)
},
// 选中车系
selectCarSeries(){
if(!this.firstClick){
this.selectdData = []
this.firstClick = true
showSonBrandList(row){
this.curBrandInfo = {
id: row.id,
name: row.name
}
const unChecked = this.carSeriesList.find(item => !this.selectdData.includes(item.id))
const checked = this.carSeriesList.find(item => this.selectdData.includes(item.id))
const _targetIdx = this.checkedList.findIndex(ele => ele == this.curSonBrandId)
if(!unChecked && _targetIdx==-1) {
this.checkedList.push(this.curSonBrandId)
this.sonBrandList = row?.childs || []
this.carSeriesList = []
},
// 切换子品牌
showCarSeriesList(row){
this.curSonBrandInfo = {
id: row.id,
name: row.name
}
if(!checked && _targetIdx>-1){
this.checkedList.splice(_targetIdx, 1)
this.carSeriesList = row?.childs
},
isChecked(item, type){
const { id } = item
const { id: rootId } = this.curBrandInfo
const { id: parentId } = this.curSonBrandInfo
if(type == 1){
let keyList = Object.keys(this.selectdData[id] || [])
return keyList.length>0
}else if(type == 2 && rootId && this.selectdData[rootId]){
return this.selectdData[rootId][id]?.length>0
}else if(type == 3 && rootId && parentId && this.selectdData[rootId] && this.selectdData[rootId][parentId]){
return !!this.selectdData[rootId][parentId]?.find(item => item.id == id)
}else{
return false
}
},
// 切换子品牌
showCarSeries(item){
if(!this.firstClick){
this.selectdData = []
this.firstClick = true
isIndeterminate(item, type){
const {id} = item
const len = item?.childs?.length
if(type == 1 && this.selectdData[id]){
return Object.keys(this.selectdData[id])?.length != len && Object.keys(this.selectdData[id])?.length !=0
}else if(type==2 && this.curBrandInfo.id && this.selectdData[this.curBrandInfo.id] && this.selectdData[this.curBrandInfo.id][id]){
return Object.keys(this.selectdData[this.curBrandInfo.id][id])?.length != len && Object.keys(this.selectdData[this.curBrandInfo.id][id])?.length !=0
}else{
return false
}
if(this.curSonBrandId == item.id) return;
this.curSonBrandId = item.id
this.carSeriesList = item?.childs
},
// 获取数据源
getCarSeriesData() {
this.$apis.case.getCarSeriesApi({needCarSeries:true}).then(res => {
console.log(res)
if(res?.length){
this.carSeriesData = res
}
})
},
handleConfirm(){
console.log(this.checkedList,155)
console.log(this.selectdData,155)
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!