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,CAAC,CAAC;aAC7D;iBAAM;gBACL,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjD;YACD,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,CAAC;QACD,cAAc,CAAC,CAAC;YACd,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC5D,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3B,CAAC;KACF;CACF,CAAC,CAAC","file":"dropdown-item.js","sourcesContent":["import TComponent from '../common/component';\nimport config from '../common/config';\n\nconst { prefix } = config;\nconst name = `${prefix}-dropdown-item`;\n\nTComponent({\n properties: {\n title: {\n type: String,\n value: '',\n },\n options: {\n type: Array,\n value: [],\n },\n selectMode: {\n type: String,\n value: 'single', // single | multi\n },\n optionsLayout: {\n type: String,\n value: 'columns', // columns | tree | slot\n },\n optionsColumns: {\n type: Number,\n optionalTypes: [String],\n value: 1,\n },\n value: {\n type: Array,\n optionalTypes: [String, Number],\n value: [],\n },\n disabled: {\n type: Boolean,\n value: false,\n },\n itemId: {\n type: String,\n value: '',\n },\n },\n data: {\n classBasePrefix: prefix,\n classPrefix: name,\n show: false,\n isBtnDisabled: true,\n bar: null,\n top: 0,\n contentClasses: '',\n treeColumns: 3,\n selected: [],\n treeState: {\n leafLevel: 0,\n selectList: [],\n select: [],\n },\n treeOptions: [],\n isTree: false,\n },\n relations: {\n './dropdown-menu': {\n type: 'parent',\n linked(target) {\n this._getParentBottom(target);\n this.setData({\n bar: target,\n });\n },\n },\n },\n attached() {\n const { selectMode } = this.data;\n const { optionsLayout } = this.data;\n const layoutCol = +this.data.optionsColumns;\n const isTree = optionsLayout === 'tree';\n const treeCol = isTree ? +this.data.treeColumns : 0;\n const contentClassesObj: Object = {\n [`${prefix}-is-tree`]: isTree,\n [`${prefix}-is-single`]: !isTree && selectMode === 'single',\n [`${prefix}-is-multi`]: !isTree && selectMode === 'multi',\n [`${prefix}-is-col1`]: layoutCol === 1 || treeCol === 1,\n [`${prefix}-is-col2`]: layoutCol === 2 || treeCol === 2,\n [`${prefix}-is-col3`]: layoutCol === 3 || treeCol === 3,\n };\n const contentClasses = Object.keys(contentClassesObj)\n .filter((e) => contentClassesObj[e] === true)\n .join(' ');\n this.setData({\n contentClasses,\n isTree,\n selected: this.data.value,\n });\n\n if (isTree) {\n this.data.treeState.selectList = this.data.selected || [];\n this._buildTreeOptions();\n }\n this.updateButtonState();\n },\n methods: {\n _buildTreeOptions() {\n const { options, selectMode } = this.data;\n const { selectList } = this.data.treeState;\n const newTreeOptions = [];\n let level = -1;\n let node = { options };\n while (node.options) {\n // 当前层级节点的列表\n const list = node.options;\n newTreeOptions.push([...list]);\n level += 1;\n // 当前层级列表选中项\n const thisValue: [] | string | number | null = selectList[level];\n if (thisValue === undefined) {\n const [firstChild] = list;\n if (firstChild.options) {\n // 还有子节点,当前层级作为单选处理\n this._selectTreeNode(level, firstChild.value);\n node = firstChild;\n } else {\n // 没有子节点,结束处理\n this._selectTreeNode(level, selectMode === 'multi' ? [] : undefined);\n break;\n }\n } else {\n const child: any =\n !Array.isArray(thisValue) && list.find((child: any) => child.value === thisValue);\n node = child;\n }\n }\n this.setData({\n 'treeState.leafLevel': Math.max(0, level),\n treeOptions: newTreeOptions,\n });\n },\n\n _closeDropdown() {\n this.data.bar.setData({\n activeIdx: -1,\n });\n this.setData({\n show: false,\n });\n },\n _getParentBottom(parent) {\n const query = wx.createSelectorQuery().in(parent);\n query\n .select(`#${prefix}-bar`)\n .boundingClientRect((res) => {\n this.setData({\n top: res.bottom,\n });\n })\n .exec();\n },\n\n _selectTreeNode(level: number, value: any) {\n // console.log('level:', level, 'value:', value);\n // 当前节点\n const tempValue: any = this.data.treeState.selectList.slice(0, level);\n tempValue[level] = value;\n this.setData({\n 'treeState.selectList': tempValue,\n });\n },\n clickOverlay() {\n this._closeDropdown();\n },\n updateSelected(e) {\n if (this.data.isTree) {\n this._selectTreeNode(\n e.target.dataset.level,\n this.data.selectMode === 'single' ? e.detail.name : e.detail.names,\n );\n } else {\n const data = {\n selected: this.data.selectMode === 'single' ? e.detail.name : e.detail.names,\n };\n this.setData(data);\n if (this.data.bar && this.data.selectMode === 'single') {\n this.confirmSelect();\n }\n }\n\n this.updateButtonState();\n },\n updateButtonState() {\n if (this.data.isTree) {\n let isEmpty = false;\n if (this.data.selectMode === 'single') {\n isEmpty = this.data.treeState.selectList[this.data.treeState.leafLevel] === undefined;\n }\n if (this.data.selectMode === 'multi') {\n const selectList = this.data.treeState.selectList[this.data.treeState.leafLevel] as [];\n isEmpty = selectList && selectList.length <= 0;\n }\n this.setData({\n isBtnDisabled: isEmpty,\n });\n } else {\n const isEmpty = this.data.selected?.length === 0;\n this.setData({\n isBtnDisabled: isEmpty,\n });\n }\n },\n resetSelect() {\n if (this.data.isTree) {\n this.setData({\n treeState: {\n leafLevel: 0,\n selectList: [],\n select: [],\n },\n });\n this._buildTreeOptions();\n this.updateButtonState();\n } else {\n this.updateSelected({ detail: { names: [], name: null } });\n }\n },\n confirmSelect() {\n if (this.data.isTree) {\n this.triggerEvent('change', this.data.treeState.selectList);\n } else {\n this.triggerEvent('change', this.data.selected);\n }\n this._closeDropdown();\n },\n selectTreeNode(e) {\n this._selectTreeNode(e.target.dataset.level, e.detail.name);\n this._buildTreeOptions();\n },\n },\n});\n"]}
|