Browse Source

项目立项所属单位改为下拉组件

ljb 9 months ago
parent
commit
9e5e5e5e1e

+ 96 - 0
src/components/second-unit-cascader/index.vue

@@ -0,0 +1,96 @@
+<template>
+  <avue-cascader placeholder="请选择" check-strictly v-model="cascaderVal" :dic="list"></avue-cascader>
+</template>
+
+<script>
+import { getList } from "@/api/basicResource/compDeptList";
+
+export default {
+  name: 'wwProjectCascader',
+  props: {
+    value: [Array],
+    // 搜索条件
+    yearAndMonth: [String, Number],
+    disabled: {
+      type: Boolean,
+      default: false
+    },
+  },
+  data() {
+    return {
+      cascaderVal: [],
+      list: []
+    }
+  },
+  watch: {
+    cascaderVal(newVal) {
+      this.$emit('input', newVal);
+    },
+    yearAndMonth(newVal) {
+      this.getListFunc();
+    },
+  },
+  methods: {
+    buildTree(flatList, options = {}) {
+      const {
+        idKey = "id", // 节点ID的键名
+        parentKey = "parentId", // 父节点ID的键名
+        childrenKey = "children", // 子节点列表的键名
+      } = options;
+
+      const nodeMap = {}; // 用于快速查找节点的映射表
+      const tree = []; // 最终生成的树
+
+      // 第一次遍历:创建所有节点的映射
+      flatList.forEach((node) => {
+        nodeMap[node[idKey]] = {
+          ...node,
+          label: node.name,
+          value: node.id,
+          [childrenKey]: [],
+        };
+      });
+
+      // 第二次遍历:构建父子关系
+      flatList.forEach((node) => {
+        const parentId = node[parentKey];
+        if (
+          parentId !== null &&
+          parentId !== undefined &&
+          nodeMap[parentId]
+        ) {
+          // 如果有父节点,则将当前节点添加到父节点的children中
+          nodeMap[parentId][childrenKey].push(nodeMap[node[idKey]]);
+        } else {
+          // 如果没有父节点或父节点不存在,则作为根节点
+          tree.push(nodeMap[node[idKey]]);
+        }
+      });
+
+      return tree;
+    },
+    loopData(data) {
+      return data.map(item => {
+        item.children = item.children.length ? item.children : undefined;
+
+        this.loopData(item.children || []);
+        return item;
+      });
+    },
+    getListFunc() {
+      if (!this.yearAndMonth) {
+        return;
+      }
+      getList({ yearAndMonth: this.yearAndMonth }).then(({ data }) => {
+        if (data.success) {
+          let treeData = this.buildTree(data.data);
+
+          this.list = this.loopData(treeData);
+
+          this.cascaderVal = this.value || [];
+        }
+      })
+    },
+  }
+}
+</script>

+ 19 - 22
src/option/basicResource/compDeptList.js

@@ -11,40 +11,37 @@ export default {
   delBtn: false,
   refreshBtn: false,
   columnBtn: false,
+  editBtn: false,
   gridBtn: false,
+  addBtn: false,
   dialogClickModal: false,
   dialogWidth: 500,
   dialogType: "drawer",
+  rowKey: "id",
+  rowParentKey: "parentId",
+  defaultExpandAll: true,
   column: [
     {
+      label: '二级单位',
+      prop: 'secondUnitName',
+      span: 24,
+      hide: true,
+    },
+    {
+      label: '部门/科室/项目部',
+      prop: 'deptName',
+      span: 24,
+      display: false,
+      hide: true,
+    },
+    {
       label: '所属二级单位/部门',
       prop: 'name',
       type: 'input',
       span: 24,
       minWidth: 160,
       showOverflowTooltip: true,
-      rules: [
-        {
-          required: true,
-          message: '请输入科目代码',
-          trigger: 'blur',
-        },
-      ],
+      display: false,
     },
-    // {
-    //   label: '部门/科室/项目部',
-    //   prop: 'name',
-    //   type: 'input',
-    //   span: 24,
-    //   minWidth: 260,
-    //   showOverflowTooltip: true,
-    //   rules: [
-    //     {
-    //       required: true,
-    //       message: '请输入',
-    //       trigger: 'blur',
-    //     },
-    //   ],
-    // },
   ],
 };

+ 62 - 21
src/views/basic-resource/comp-basic-info/components/comp-dept-list.vue

@@ -1,5 +1,23 @@
 <template>
-  <avue-crud v-bind="bindVal" v-on="onEvent" v-model="form"> </avue-crud>
+  <avue-crud v-bind="bindVal" v-on="onEvent" v-model="form">
+    <template slot="menuLeft">
+      <el-button
+        type="primary"
+        icon="el-icon-plus"
+        size="small"
+        @click="handleAddParent">新增二级单位</el-button>
+    </template>
+    <template slot="menu" slot-scope="{ row, size, type }">
+      <el-button
+        v-if="!row.parentId"
+        :size="size"
+        :type="type"
+        @click="handleAddChild(row)"
+      >
+        新增部门/科室/项目部
+      </el-button>
+    </template>
+  </avue-crud>
 </template>
 
 <script>
@@ -13,29 +31,38 @@ export default window.$crudCommon(
         this.loadData();
       },
     },
+    data() {
+      return {
+        parentId: ''
+      }
+    },
     methods: {
       buildTree(flatList, options = {}) {
         const {
-          idKey = 'id',          // 节点ID的键名
-          parentKey = 'parentId', // 父节点ID的键名
-          childrenKey = 'children' // 子节点列表的键名
+          idKey = "id", // 节点ID的键名
+          parentKey = "parentId", // 父节点ID的键名
+          childrenKey = "children", // 子节点列表的键名
         } = options;
-        
-        const nodeMap = {};      // 用于快速查找节点的映射表
-        const tree = [];         // 最终生成的树
-        
+
+        const nodeMap = {}; // 用于快速查找节点的映射表
+        const tree = []; // 最终生成的树
+
         // 第一次遍历:创建所有节点的映射
-        flatList.forEach(node => {
+        flatList.forEach((node) => {
           nodeMap[node[idKey]] = {
             ...node,
-            [childrenKey]: []
+            [childrenKey]: [],
           };
         });
-        
+
         // 第二次遍历:构建父子关系
-        flatList.forEach(node => {
+        flatList.forEach((node) => {
           const parentId = node[parentKey];
-          if (parentId !== null && parentId !== undefined && nodeMap[parentId]) {
+          if (
+            parentId !== null &&
+            parentId !== undefined &&
+            nodeMap[parentId]
+          ) {
             // 如果有父节点,则将当前节点添加到父节点的children中
             nodeMap[parentId][childrenKey].push(nodeMap[node[idKey]]);
           } else {
@@ -43,22 +70,36 @@ export default window.$crudCommon(
             tree.push(nodeMap[node[idKey]]);
           }
         });
-        
+
         return tree;
       },
       loadData() {
         this.loading = true;
-        this.api[this.option.list || "getList"](
-          { yearAndMonth: this.yearAndMonth }
-        ).then(({ data }) => {
-          console.log(this.buildTree(data.data))
+        this.api[this.option.list || "getList"]({
+          yearAndMonth: this.yearAndMonth,
+        }).then(({ data }) => {
+          console.log(this.buildTree(data.data));
           this.data = this.buildTree(data.data);
           this.loading = false;
         });
       },
-      // getSearchParams() {
-      //   return { yearAndMonth: this.yearAndMonth };
-      // },
+      handleAddParent() {
+        const column = this.findObject(this.option.column, "secondUnitName");
+        const deptColumn = this.findObject(this.option.column, "deptName");
+        column.value = '';
+        column.disabled = false;
+        deptColumn.display = false;
+        this.$refs.crud.rowAdd();
+      },
+      handleAddChild(row) {
+        const column = this.findObject(this.option.column, "secondUnitName");
+        const deptColumn = this.findObject(this.option.column, "deptName");
+        deptColumn.display = true;
+        column.value = row.name;
+        column.disabled = true;
+        this.form.parentId = row.id;
+        this.$refs.crud.rowAdd();
+      },
     },
   },
   {

+ 37 - 17
src/views/project-manage/components/apply-form.vue

@@ -29,10 +29,11 @@
         <tr>
           <td class="doc-label">项目申请单位</td>
           <td colspan="3">
-            <el-input
+            <!-- <el-input
               v-model="formData.xmsqdw"
               placeholder="请选择项目申请单位"
-            />
+            /> -->
+            <second-unit-cascader v-model="formData.xmsqdwid" :yearAndMonth="yearAndMonth" style="width: 100%;"></second-unit-cascader>
           </td>
         </tr>
         <tr>
@@ -162,6 +163,7 @@
 </template>
 
 <script>
+import secondUnitCascader from "@/components/second-unit-cascader";
 import { getDictionary } from "@/api/system/dictbiz";
 import { getList as getTechnicanRosterList } from "@/api/basicResource/technicianRoster";
 import { add, update, getDetail } from "@/api/projectManage/projectList";
@@ -169,6 +171,9 @@ import moment from "moment";
 import { deepClone } from "@/util/util";
 
 export default {
+  components: {
+    secondUnitCascader
+  },
   props: {
     projectId: [String, Number]
   },
@@ -218,10 +223,10 @@ export default {
               window.open(file.url, "_blank");
               return;
             },
-            rules: [{
-              required: true,
-              message: "请上传立项批文"
-            }]
+            // rules: [{
+            //   required: true,
+            //   message: "请上传立项批文"
+            // }]
           },
           {
             label: "立项报告",
@@ -240,10 +245,10 @@ export default {
               window.open(file.url, "_blank");
               return;
             },
-            rules: [{
-              required: true,
-              message: "请上传立项报告"
-            }]
+            // rules: [{
+            //   required: true,
+            //   message: "请上传立项报告"
+            // }]
           },
           {
             label: "其他资料",
@@ -270,6 +275,9 @@ export default {
   watch: {
     'formData.xmkssj'(newVal) {
       this.yearList = this.getDateRangeYear(newVal, this.formData.xmjssj);
+      if (!newVal) {
+        return;
+      }
       let cMonth = moment(newVal).format('yyyyMM');
       if (cMonth != this.xmStartDateYearAndMonth) {
         this.xmStartDateYearAndMonth = cMonth;
@@ -306,6 +314,10 @@ export default {
       }
       return `年 月 日至 年 月 日`;
     },
+    yearAndMonth() {
+      console.log(!!this.formData.xmkssj)
+      return !!this.formData.xmkssj ? moment(this.formData.xmkssj).format('yyyy') : '';
+    }
   },
   mounted() {
     this.getDictList("study_type", "studyTypeList");
@@ -322,7 +334,6 @@ export default {
       this.loading = true;
       getDetail({ id: xmId }).then(({ data }) => {
         this.loading = false;
-        console.log(data)
         if (data.code == 200) {
           let beanData = { ...data.data };
           console.log(beanData)
@@ -389,6 +400,10 @@ export default {
      * 获取人员花名册
      */
     getTechnicanRosterListFunc(yearAndMonth) {
+      if (!yearAndMonth) {
+        this.fzrList = [];
+        return;
+      }
       getTechnicanRosterList(1, 99999, { yearAndMonth }).then(res => {
         if (res.data.success) {
           this.fzrList = res.data.data.records.map(item => {
@@ -404,7 +419,9 @@ export default {
       } else if (/技改|技术改造|推广|打样|翻新|产业化|生产线|改造|年产|示范/g.test(this.formData.xmmc)) {
         errorText = '研发项目名称,不符合统计部门的命名要求';
       } else if (!this.formData.xmbh) {
-        errorText = '请输入项目编号'
+        errorText = '请输入项目编号';
+      } else if (!this.formData.xmsqdwid || !this.formData.xmsqdwid.length) {
+        errorText = '请选择项目申请单位';
       } else if (!this.formData.yjlx) {
         errorText = '请选择研究类型'
       } else if (!this.formData.xmfzr) {
@@ -415,11 +432,13 @@ export default {
         errorText = '请选择项目结束时间';
       } else if (!this.formData.xmysze) {
         errorText = '请输入项目预算总额';
-      } else if (!this.formData.lxpw.length) {
-        errorText = '请上传立项批文!';
-      } else if (!this.formData.lxbg.length) {
-        errorText = '请上传立项报告!';
-      } else {
+      }
+      // else if (!this.formData.lxpw.length) {
+      //   errorText = '请上传立项批文!';
+      // } else if (!this.formData.lxbg.length) {
+      //   errorText = '请上传立项报告!';
+      // }
+      else {
         let yearAmount = 0;
         this.yearList.forEach(year => {
           let account = this.formData[year] || 0;
@@ -442,6 +461,7 @@ export default {
       let params = deepClone(this.formData);
       params.yqcgxs = params.yqcgxs ? params.yqcgxs.join(',') : '';
       params.xmjsjjmb = params.xmjsjjmb ? params.xmjsjjmb.join(',') : '';
+      params.xmsqdwid = params.xmsqdwid ? params.xmsqdwid[params.xmsqdwid.length - 1] : '';
       params.lxbg = JSON.stringify(params.lxbg);
       params.lxpw = JSON.stringify(params.lxpw);
       params.qtzl = JSON.stringify(params.qtzl);