update 基本完成物料表
This commit is contained in:
		@@ -57,6 +57,13 @@
 | 
			
		||||
                <el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length">
 | 
			
		||||
                  <el-form-item :label="col.label" :prop="col.prop" :rules="col.rules || null">
 | 
			
		||||
                    <el-input v-if="col.input" v-model="dataForm[col.prop]" clearable :disabled="disableCondition(col.prop)" v-bind="col.elparams" />
 | 
			
		||||
                    <el-cascader
 | 
			
		||||
                      v-if="col.cascader"
 | 
			
		||||
                      v-model="dataForm[col.prop]"
 | 
			
		||||
                      :options="col.options"
 | 
			
		||||
                      :disabled="detailMode"
 | 
			
		||||
                      v-bind="col.elparams"
 | 
			
		||||
                    ></el-cascader>
 | 
			
		||||
                    <el-select
 | 
			
		||||
                      v-if="col.select"
 | 
			
		||||
                      v-model="dataForm[col.prop]"
 | 
			
		||||
@@ -124,6 +131,25 @@ import { pick as __pick } from "@/utils/filters";
 | 
			
		||||
import SmallDialog from "@/components/SmallDialog.vue";
 | 
			
		||||
import BaseListTable from "@/components/BaseListTable.vue";
 | 
			
		||||
 | 
			
		||||
function reConstructTreeData(listObj) {
 | 
			
		||||
  const entry = [];
 | 
			
		||||
  Object.keys(listObj).map((key) => {
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user