hezhanp пре 7 месеци
родитељ
комит
2f6f5e14c1
1 измењених фајлова са 288 додато и 246 уклоњено
  1. 288 246
      src/views/warehouseManagement/warehouseDefinition/components/WarehouseEdit.vue

+ 288 - 246
src/views/warehouseManagement/warehouseDefinition/components/WarehouseEdit.vue

@@ -27,6 +27,23 @@
           maxlength="16"
         ></el-input>
       </el-form-item>
+      <el-form-item label="仓库" prop="warehouseId">
+        <el-select
+          filterable
+          size="small"
+          class="w100"
+          v-model="formData.warehouseId"
+          placeholder="请选择仓库"
+          :clearable="true"
+        >
+          <el-option
+            v-for="item in warehousetypeList"
+            :key="item.value"
+            :label="item.label"
+            :value="item.value"
+          ></el-option>
+        </el-select>
+      </el-form-item>
       <el-form-item label="仓库类型" prop="inventoryType">
         <!-- <DictSelection
           dictName="仓库类型"
@@ -164,133 +181,81 @@
 </template>
 
 <script>
-  import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
+import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
 
-  // import selectTree from '@/components/selectTree';
-  import DeptSelect from '@/components/CommomSelect/new-dept-select.vue';
+// import selectTree from '@/components/selectTree';
+import DeptSelect from '@/components/CommomSelect/new-dept-select.vue';
 
-  // import city from '@/assets/js/city';
-  import { cityData } from 'ele-admin/packages/utils/regions';
-  // import user from '@/api/main/user';
+import { getByCode } from '@/api/system/dictionary-data';
+// import city from '@/assets/js/city';
+import { cityData } from 'ele-admin/packages/utils/regions';
+// import user from '@/api/main/user';
 
-  export default {
-    components: { DeptSelect },
-    data() {
-      return {
-        visible: false,
-        loading: false,
-        formData: {
-          code: '',
-          name: '',
-          inventoryType: [],
-          inventoryName: [],
-          remarks: '',
-          factoryId: '',
-          status: 1,
-          lockStatus: 0,
-          ownerId: '',
-          departmentId: '',
-          contact: '',
-
-        },
-        rules: {
-          code: [
-            { required: true, message: '请输入仓库编码', trigger: 'blur' }
-          ],
-          name: [
-            { required: true, message: '请输入仓库名称', trigger: 'blur' }
-          ],
-          inventoryType: [
-            { required: true, message: '请选择仓库类型', trigger: 'blur' }
-          ],
-          factoryId: [
-            { required: true, message: '请选择工厂名称', trigger: 'blur' }
-          ],
-          departmentId: [
-            { required: true, message: '请选择权属部门', trigger: 'change' }
-          ],
-          ownerId: [
-            { required: true, message: '请选择权属人', trigger: 'change' }
-          ]
-          // status: [
-          //   { required: true, message: '请选择仓库状态', trigger: 'blur' }
-          // ]
-        },
-        type: '新建',
-        userList: [],
-        deptList: [], //部门集合
-        inventoryTypeList: [],
-        factoryList: [], //工厂集合
-        locationOptions: cityData,
-        loadingVis: false
-      };
-    },
-    watch: {
-      visible: {
-        handler(val) {
-          if (val) {
-            // this.init();
-          }
-        }
+export default {
+  components: { DeptSelect },
+  data() {
+    return {
+      visible: false,
+      loading: false,
+      formData: {
+        code: '',
+        name: '',
+        inventoryType: [],
+        inventoryName: [],
+        remarks: '',
+        factoryId: '',
+        status: 1,
+        lockStatus: 0,
+        ownerId: '',
+        departmentId: '',
+        contact: '',
+        warehouseId: ''
       },
-      loadingVis: {
-        handler(val) {
-          console.log(val);
-          if (!val && this.type == '新建') {
-            this.formData = {
-              code: '',
-              name: '',
-              inventoryType: [],
-              inventoryName: [],
-              remarks: '',
-              factoryId: '',
-              status: 1,
-              lockStatus: 0,
-              ownerId: '',
-              departmentId: ''
-            };
-          }
+      warehousetypeList: [],
+      rules: {
+        code: [{ required: true, message: '请输入仓库编码', trigger: 'blur' }],
+        name: [{ required: true, message: '请输入仓库名称', trigger: 'blur' }],
+        inventoryType: [
+          { required: true, message: '请选择仓库类型', trigger: 'blur' }
+        ],
+        factoryId: [
+          { required: true, message: '请选择工厂名称', trigger: 'blur' }
+        ],
+        departmentId: [
+          { required: true, message: '请选择权属部门', trigger: 'change' }
+        ],
+        ownerId: [
+          { required: true, message: '请选择权属人', trigger: 'change' }
+        ],
+        warehouseId: [
+          { required: true, message: '请选择仓库', trigger: 'change' }
+        ]
+        // status: [
+        //   { required: true, message: '请选择仓库状态', trigger: 'blur' }
+        // ]
+      },
+      type: '新建',
+      userList: [],
+      deptList: [], //部门集合
+      inventoryTypeList: [],
+      factoryList: [], //工厂集合
+      locationOptions: cityData,
+      loadingVis: false
+    };
+  },
+  watch: {
+    visible: {
+      handler(val) {
+        if (val) {
+          // this.init();
         }
       }
     },
-    created() {},
-    methods: {
-      async open(type, row) {
-        console.log(type);
-        this.type = type;
-        this.visible = true;
-        this.init();
-        console.log('locationOptions', this.locationOptions);
-        if (type === '修改') {
-          console.log(1);
-          this.loadingVis = true;
-          this.$nextTick(async () => {
-            setTimeout(async () => {
-              const { warehouseVO } = await warehouseDefinition.warehouseDetail(
-                row.id
-              );
-              if (warehouseVO.departmentId) {
-                let userData = await warehouseDefinition.getUserPage({
-                  groupId: warehouseVO.departmentId,
-                  size: 9999,
-                  pageNum: 1
-                });
-                this.userList = userData.list;
-              }
-              this.formData = {
-                ...warehouseVO,
-                location: [
-                  warehouseVO.province,
-                  warehouseVO.city,
-                  warehouseVO.area
-                ],
-                inventoryType: warehouseVO.inventoryType.split(','),
-                inventoryName: warehouseVO.inventoryName.split(',')
-              };
-              this.loadingVis = false;
-            }, 2000);
-          });
-        } else {
+
+    loadingVis: {
+      handler(val) {
+        console.log(val);
+        if (!val && this.type == '新建') {
           this.formData = {
             code: '',
             name: '',
@@ -304,152 +269,229 @@
             departmentId: ''
           };
         }
+      }
+    }
+  },
+  created() {
+    this.getwarehousetypeCode('warehouse_type');
+  },
+  methods: {
+    async getwarehousetypeCode(code) {
+      console.log(code);
+      try {
+        const res = await getByCode(code);
+        if (res.code == 0) {
+          let list = Object.values(res.data).map((el) => {
+            let k = Object.keys(el)[0];
+            let v = Object.values(el)[0];
+            return { label: v, value: k };
+          });
+          this.warehousetypeList = list;
+          console.log(this.warehousetypeList);
+        }
+      } catch (err) {
+        this.$message.error(err.message);
+      }
+    },
+    async open(type, row) {
+      console.log(type);
+      this.type = type;
+      this.visible = true;
+      this.init();
+      console.log('locationOptions', this.locationOptions);
+      if (type === '修改') {
+        console.log(1);
+        this.loadingVis = true;
+        this.$nextTick(async () => {
+          setTimeout(async () => {
+            const { warehouseVO } = await warehouseDefinition.warehouseDetail(
+              row.id
+            );
+            if (warehouseVO.departmentId) {
+              let userData = await warehouseDefinition.getUserPage({
+                groupId: warehouseVO.departmentId,
+                size: 9999,
+                pageNum: 1
+              });
+              this.userList = userData.list;
+            }
+            this.formData = {
+              ...warehouseVO,
+              location: [
+                warehouseVO.province,
+                warehouseVO.city,
+                warehouseVO.area
+              ],
+              inventoryType: warehouseVO.inventoryType.split(','),
+              inventoryName: warehouseVO.inventoryName.split(',')
+            };
+            this.loadingVis = false;
+          }, 2000);
+        });
+      } else {
+        this.formData = {
+          code: '',
+          name: '',
+          inventoryType: [],
+          inventoryName: [],
+          remarks: '',
+          factoryId: '',
+          status: 1,
+          lockStatus: 0,
+          ownerId: '',
+          departmentId: ''
+        };
+      }
 
-        // if (type === '新建') {
-        //   let num = 1
-        //   const res = await warehouseList()
-        //   if (res?.success && res.data?.length) {
-        //     num = +res.data[0].code.substr(1) + 1
-        //   }
-        // this.formData.code = 'A' + pushZero(num)
-        // }
-      },
-      async init() {
-        // org.tree().then((tree) => {
-        //   if (tree?.success) {
-        //     this.deptList = tree.data;
-        //   }
-        // });
-        // const tree = await warehouseDefinition.tree();
+      // if (type === '新建') {
+      //   let num = 1
+      //   const res = await warehouseList()
+      //   if (res?.success && res.data?.length) {
+      //     num = +res.data[0].code.substr(1) + 1
+      //   }
+      // this.formData.code = 'A' + pushZero(num)
+      // }
+    },
+    async init() {
+      // org.tree().then((tree) => {
+      //   if (tree?.success) {
+      //     this.deptList = tree.data;
+      //   }
+      // });
+      // const tree = await warehouseDefinition.tree();
 
-        // this.deptList = this.$util.toTreeData({
-        //   data: tree,
-        //   idField: 'id',
-        //   parentIdField: 'parentId'
-        // });
+      // this.deptList = this.$util.toTreeData({
+      //   data: tree,
+      //   idField: 'id',
+      //   parentIdField: 'parentId'
+      // });
 
-        //获取工厂车间列表
-        const res = await warehouseDefinition.getFactoryarea({
-          pageNum: 1,
-          size: 9999,
-          type: 1
-        });
+      //获取工厂车间列表
+      const res = await warehouseDefinition.getFactoryarea({
+        pageNum: 1,
+        size: 9999,
+        type: 1
+      });
 
-        // let data = org.factorys({ status: true });
-        this.factoryList = res.list;
+      // let data = org.factorys({ status: true });
+      this.factoryList = res.list;
 
-        const res2 = await warehouseDefinition.getTreeByGroup({ type: 2 });
-        this.inventoryTypeList = res2;
-      },
-      changeInventoryType(val) {
-        console.log(val, '1');
-        // 根据选中的仓库类型ID数组,获取对应的名称数组
-        const inventoryNames = val.map(typeId => {
-          const item = this.inventoryTypeList.find(item => item.id === typeId);
+      const res2 = await warehouseDefinition.getTreeByGroup({ type: 2 });
+      this.inventoryTypeList = res2;
+    },
+    changeInventoryType(val) {
+      console.log(val, '1');
+      // 根据选中的仓库类型ID数组,获取对应的名称数组
+      const inventoryNames = val
+        .map((typeId) => {
+          const item = this.inventoryTypeList.find(
+            (item) => item.id === typeId
+          );
           return item ? item.name : '';
-        }).filter(name => name !== '');
-        
-        this.formData.inventoryName = inventoryNames;
-        console.log('仓库类型名称数组:', this.formData.inventoryName);
-      },
+        })
+        .filter((name) => name !== '');
+
+      this.formData.inventoryName = inventoryNames;
+      console.log('仓库类型名称数组:', this.formData.inventoryName);
+    },
 
-      handleSave() {
-        this.$refs.formRef.validate(async (value) => {
-          if (value) {
-            let params = Object.assign(this.formData);
-            params.inventoryType = params.inventoryType.join(',');
-            params.inventoryName = params.inventoryName.join(',');
+    handleSave() {
+      this.$refs.formRef.validate(async (value) => {
+        if (value) {
+          let params = Object.assign(this.formData);
+          params.inventoryType = params.inventoryType.join(',');
+          params.inventoryName = params.inventoryName.join(',');
 
-            // if (params.location?.length) {
-            //   const [province, city, area] = params.location;
+          // if (params.location?.length) {
+          //   const [province, city, area] = params.location;
 
-            //   Object.assign(params, {
-            //     province,
-            //     city,
-            //     area
-            //   });
-            // }
-            // delete params.location;
-            // console.log(params);
+          //   Object.assign(params, {
+          //     province,
+          //     city,
+          //     area
+          //   });
+          // }
+          // delete params.location;
+          // console.log(params);
 
-            this.loading = true;
-            const res = await warehouseDefinition
-              .saveOrUpdateWarehouse(params)
-              .finally(() => (this.loading = false));
-            if (res.data?.code == '0') {
-              this.$message.success('保存成功!');
-              this.$emit('success');
-              this.cancel();
-            }
+          this.loading = true;
+          const res = await warehouseDefinition
+            .saveOrUpdateWarehouse(params)
+            .finally(() => (this.loading = false));
+          if (res.data?.code == '0') {
+            this.$message.success('保存成功!');
+            this.$emit('success');
+            this.cancel();
           }
-        });
-      },
-      cancel() {
-        this.$refs.formRef.resetFields();
-        // this.$refs.tree.clearHandle();
-        this.visible = false;
-      },
-      async nodeClick(id, data) {
-        // this.formData.departmentCode = data?.code;
-        this.formData.departmentId = id;
-        if (data) {
-          this.formData.departmentName = data.name;
-        }
-        this.formData.ownerName = '';
-        this.formData.ownerId = '';
-        if (id) {
-          let userData = await warehouseDefinition.getUserPage({
-            groupId: id,
-            size: 9999,
-            pageNum: 1
-          });
-          this.userList = userData.list;
         }
-      },
-      changeOwner(val) {
-        this.formData.ownerId = val;
-        let user = this.userList.find((item) => {
-          return item.id == val;
+      });
+    },
+    cancel() {
+      this.$refs.formRef.resetFields();
+      // this.$refs.tree.clearHandle();
+      this.visible = false;
+    },
+    async nodeClick(id, data) {
+      // this.formData.departmentCode = data?.code;
+      this.formData.departmentId = id;
+      if (data) {
+        this.formData.departmentName = data.name;
+      }
+      this.formData.ownerName = '';
+      this.formData.ownerId = '';
+      if (id) {
+        let userData = await warehouseDefinition.getUserPage({
+          groupId: id,
+          size: 9999,
+          pageNum: 1
         });
-        console.log(user);
+        this.userList = userData.list;
+      }
+    },
+    changeOwner(val) {
+      this.formData.ownerId = val;
+      let user = this.userList.find((item) => {
+        return item.id == val;
+      });
+      console.log(user);
 
-        this.formData.ownerName = user.name;
+      this.formData.ownerName = user.name;
 
-        this.formData.contact = user.phone;
+      this.formData.contact = user.phone;
 
-        // this.$nextTick(() => {
-        //   this.$forceUpdate();
-        // });
-        // this.$set(this.formData, 'ownerId', val);
-        // this.$set(
-        //   this.formData,
-        //   'ownerName',
-        //   this.userList.find((item) => {
-        //     return item.id == val;
-        //   }).name
-        // );
-        // console.log(this.formData);
-        // this.$forceUpdate();
-      },
-      changeLocation(val) {
-        console.log(val, '1~~~');
-        this.$set(this.formData, 'province', val[0]); //省
-        this.$set(this.formData, 'city', val[1]); //市
-        this.$set(this.formData, 'area', val[2]); //区
-        // delete this.formData.location;
-      }
+      // this.$nextTick(() => {
+      //   this.$forceUpdate();
+      // });
+      // this.$set(this.formData, 'ownerId', val);
+      // this.$set(
+      //   this.formData,
+      //   'ownerName',
+      //   this.userList.find((item) => {
+      //     return item.id == val;
+      //   }).name
+      // );
+      // console.log(this.formData);
+      // this.$forceUpdate();
+    },
+    changeLocation(val) {
+      console.log(val, '1~~~');
+      this.$set(this.formData, 'province', val[0]); //省
+      this.$set(this.formData, 'city', val[1]); //市
+      this.$set(this.formData, 'area', val[2]); //区
+      // delete this.formData.location;
     }
-  };
+  }
+};
 </script>
 
 <style lang="scss" scoped>
-  ::v-deep .el-form {
-    .el-form-item {
-      margin-bottom: 20px;
-    }
+::v-deep .el-form {
+  .el-form-item {
+    margin-bottom: 20px;
   }
+}
 
-  .el-divider--horizontal {
-    margin: 0 !important;
-  }
+.el-divider--horizontal {
+  margin: 0 !important;
+}
 </style>