Component({ mixins: [], data: { lableTree: [], locationName: '全部区域',//区域name locationId: '',// 区域id }, props: { locationName: '',//区域name locationId: '',// 区域id areTreeList: [] }, didMount() { const addKey = data => data.map(item => ({ ...item, status: true, children: addKey(item.children) })) const lableTree = addKey(this.props.areTreeList) this.setData({ lableTree: lableTree, locationId: this.props.locationId, locationName: this.props.locationName, }) }, didUpdate() {}, didUnmount() {}, methods: { onChangeStatus(e) { let index = e.target.dataset.index let cycleTimes = e.target.dataset.cycle if (cycleTimes == 1) { let listStr = `lableTree[${index[0]}].status` this.setData({ [listStr]: this.data.lableTree[index[0]].status ? false : true }) } else if (cycleTimes == 2) { let listStr = `lableTree[${index[0]}].children[${index[1]}].status` this.setData({ [listStr]: this.data.lableTree[index[0]].children[index[1]].status ? false : true }) } // else if (cycleTimes == 3) { // let listStr = `lableTree[${index[0]}].children[${index[1]}].children[${index[2]}].status` // this.setData({ // [listStr]: this.data.lableTree[index[0]].children[index[1]].children[index[2]].status ? false : true // }) // } }, onChangeAreId(e){ this.setData({ locationId: this.data.locationId === e.target.dataset.id ? '' : e.target.dataset.id, locationName: this.data.locationId === e.target.dataset.id ? '全部区域' : e.target.dataset.name }) }, cancelSelectAre() { let data = { type: 'cancel' } this.props.onPropsCS(data) }, sureSelectAre() { let data = { type: 'sure', id: this.data.locationId, name: this.data.locationName } this.props.onPropsCS(data) } }, });