diff --git a/src/components/DialogWithMenu.vue b/src/components/DialogWithMenu.vue index f4031ab..898b593 100644 --- a/src/components/DialogWithMenu.vue +++ b/src/components/DialogWithMenu.vue @@ -57,6 +57,13 @@ + { + const currentNode = listObj[key]; + currentNode.label = currentNode.name; + currentNode.value = currentNode.id; + if (currentNode.parentId === "0") { + entry.push(listObj[key]); + return; // return { label: currentNode.name, value: currentNode.id, children: currentNode.children ?? [] }; + } + const parentNode = listObj[currentNode.parentId]; + if (!parentNode.children) { + parentNode.children = []; + } + parentNode.children.push(currentNode); + }); + return entry; +} + export default { name: "DialogWithMenu", components: { SmallDialog, BaseListTable }, @@ -175,13 +201,20 @@ export default { else if (col.fetchTreeData) { // 获取设备类型时触发的,用于前端构建属性结构,约定,parentId 为0时是顶级节点 col.fetchTreeData().then(({ data: res }) => { - console.log("[Fetch Tree Data]", res.data.list); - if (res.code === 0 && res.data.list) { + console.log("[Fetch Tree Data]", res.data); + if (res.code === 0) { // 先把数据先重构成一个对象 const obj = {}; - res.data.list.map((item) => { - obj[item.id] = item; - }); + + if ("list" in res.data) { + res.data.list.map((item) => { + obj[item.id] = item; + }); + } else if (Array.isArray(res.data)) { + res.data.map((item) => { + obj[item.id] = item; + }); + } // 再过滤这个对象 let filteredList = reConstructTreeData(obj); console.log("** filteredList **", filteredList); @@ -189,6 +222,7 @@ export default { this.$set(col, "options", filteredList); } else { col.options.splice(0); + this.$message.error(res.msg); } }); } @@ -514,7 +548,8 @@ export default { padding-bottom: 0 !important; } -.el-select { +.el-select, +.el-cascader { width: 100% !important; } diff --git a/src/views/modules/pms/material/config.js b/src/views/modules/pms/material/config.js index cc302dd..4713851 100644 --- a/src/views/modules/pms/material/config.js +++ b/src/views/modules/pms/material/config.js @@ -81,11 +81,11 @@ export default function () { rules: { required: true, message: "not empty", trigger: "blur" }, elparams: { placeholder: "请输入物料编码" }, }, - { input: true, label: "规格", prop: "description", elparams: { placeholder: "规格" } }, + { input: true, label: "规格", prop: "specifications", elparams: { placeholder: "规格" } }, ], [ { - select: true, + cascader: true, label: "父级物料", prop: "parentId", // TODO: 待解决:DialogWithMenu 中设置default只在初始化的时候有效,一旦清空过就无效了 @@ -93,7 +93,14 @@ export default function () { // rules: { required: true, message: "not empty", trigger: "blur" }, options: [{ id: '0', name: '无' }], // 手动注入额外选项,用到的场景不多... fetchData: () => this.$http.get('/pms/material/page', { params: { page: 1, limit: 999, key: '' } }), - elparams: { placeholder: "请选择父级物料" }, + elparams: { placeholder: "请选择父级物料", filterable: true, clearable: true }, + // fetchTreeData: () => { + // // TODO:前提是工厂里总的设备类型数不会超过 999 + // return this.$http.get('/pms/material/tree', { + // params: { rootId: '0' } + // }) + // }, + // elparams: { placeholder: "请选择父级物料", 'show-all-levels': false, props: { checkStrictly: true } }, }, { select: true,