| | |
| | | <!-- |
| | | * @Date: 2024-04-18 19:53:35 |
| | | * @LastEditors: gaoshp |
| | | * @LastEditTime: 2024-11-04 19:55:07 |
| | | * @LastEditTime: 2024-11-04 20:05:01 |
| | | * @FilePath: /cps-web/src/views/mdc/MYTree.vue |
| | | --> |
| | | <template> |
| | | <el-input v-model="word" style="max-width: 600px" @change="search" placeholder="" class="input-with-select"> |
| | | <el-input v-model="word" style="max-width: 600px" placeholder="" @change="search" class="input-with-select"> |
| | | <template #append> |
| | | <el-button :icon="ElementPlusIconsVue.Search" /> |
| | | </template> |
| | |
| | | }, |
| | | methods: { |
| | | search() { |
| | | console.log('Search') |
| | | this.getList() |
| | | }, |
| | | switchFn(val) { |
| | |
| | | }).then(({ code, data }) => { |
| | | if (code === 200) { |
| | | this.tableData = data.filter(v => v.isWorkstation && v.title.indexOf(this.word) > -1) |
| | | this.data = this.formatData(data) |
| | | this.data = this.formatData(data.filter(v => !v.isWorkstation || (v.isWorkstation && v.title.indexOf(this.word) > -1))) |
| | | this.$nextTick(() => { |
| | | this.currentNodeKey = this.firstWorkKey |
| | | this.$emit('loaded', this.firstWorkKey) |
| | | this.setCurrentKey(data) |
| | | this.$emit('loaded', this.currentNodeKey) |
| | | this.$emit('request', data) |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | | setCurrentKey(v) { |
| | | if (this.firstWorkKey) return |
| | | if (v.isWorkstation) { |
| | | this.firstWorkKey = v.id |
| | | } |
| | | setCurrentKey(data) { |
| | | this.currentNodeKey = data.find(v => v.isWorkstation && v.title.indexOf(this.word) > -1).id |
| | | }, |
| | | formatData(data, current) { |
| | | let newData = [] |
| | | if (!current) { |
| | | newData = data.filter(item => item.parentId == 0).map(v => { |
| | | if (!v.isWorkstation) v.disabled = true |
| | | let children = this.formatData(data, v).sort((a, b) => { |
| | | v.children = this.formatData(data, v).sort((a, b) => { |
| | | return b.sort - a.sort |
| | | }) |
| | | v.children = children.filter(v => { |
| | | if (v.isWorkstation) { |
| | | return v.title.indexOf(this.word) > -1 |
| | | } else { |
| | | return true |
| | | } |
| | | }) |
| | | this.setCurrentKey(v) |
| | | // this.setCurrentKey(v) |
| | | return v |
| | | }) |
| | | } else { |
| | | let res = data.filter(v => v.parentId == current.id) |
| | | res = res.map(item => { |
| | | if (!item.isWorkstation) item.disabled = true |
| | | let children = this.formatData(data, item).sort((a, b) => { |
| | | item.children = this.formatData(data, item).sort((a, b) => { |
| | | return b.sort - a.sort |
| | | }) |
| | | item.children = children.filter(v => { |
| | | if (v.isWorkstation) { |
| | | return v.title.indexOf(this.word) > -1 |
| | | } else { |
| | | return true |
| | | } |
| | | }) |
| | | this.setCurrentKey(item) |
| | | // this.setCurrentKey(item) |
| | | return item |
| | | }) |
| | | return res |