/* eslint react/no-multi-comp:0, no-console:0, no-alert: 0 */ import '../assets/index.less' import './demo.less' import '../../vc-dialog/assets/index.less' import Dialog from '../../vc-dialog' import TreeSelect, { TreeNode, SHOW_PARENT } from '../index' import { gData } from './util' function isLeaf (value) { if (!value) { return false } let queues = [...gData] while (queues.length) { // BFS const item = queues.shift() if (item.value === value) { if (!item.children) { return true } return false } if (item.children) { queues = queues.concat(item.children) } } return false } function findPath (value, data) { const sel = [] function loop (selected, children) { for (let i = 0; i < children.length; i++) { const item = children[i] if (selected === item.value) { sel.push(item) return } if (item.children) { loop(selected, item.children, item) if (sel.length) { sel.push(item) return } } } } loop(value, data) return sel } export default { data () { return { tsOpen: false, visible: false, inputValue: '0-0-0-label', value: '0-0-0-value1', // value: ['0-0-0-0-value', '0-0-0-1-value', '0-0-0-2-value'], lv: { value: '0-0-0-value', label: 'spe label' }, multipleValue: [], simpleTreeData: [ { key: 1, pId: 0, label: 'test1', value: 'test1' }, { key: 121, pId: 0, label: 'test1', value: 'test121' }, { key: 11, pId: 1, label: 'test11', value: 'test11' }, { key: 12, pId: 1, label: 'test12', value: 'test12' }, { key: 111, pId: 11, label: 'test111', value: 'test111' }, ], treeDataSimpleMode: { id: 'key', rootPId: 0, }, } }, mounted () { // console.log(this.refs.mul.getInputDOMNode()); // this.refs.mul.getInputDOMNode().setAttribute('disabled', true); }, methods: { onClick () { this.visible = true }, onClose () { this.visible = false }, onSearch (value) { console.log(value, arguments) }, onChange (value) { console.log('onChange', arguments) this.value = value }, onChangeChildren (value) { console.log('onChangeChildren', arguments) const pre = value ? this.value : undefined this.value = isLeaf(value) ? value : pre }, onChangeLV (value) { console.log('labelInValue', arguments) if (!value) { this.lv = undefined return } const path = findPath(value.value, gData).map(i => i.label).reverse().join(' > ') this.lv = { value: value.value, label: path } }, onMultipleChange (value) { console.log('onMultipleChange', arguments) this.multipleValue = value }, onSelect () { // use onChange instead console.log(...arguments) }, onDropdownVisibleChange (visible, info) { console.log(visible, this.value, info) if (Array.isArray(this.value) && this.value.length > 1 && this.value.length < 3) { alert('please select more than two item or less than one item.') return false } return true }, filterTreeNode (input, child) { return String(child.title).indexOf(input) === 0 }, }, render () { return (