baishaojie 2 months ago
parent
commit
178babd489

+ 33 - 40
src/views/productManagement/assetBasicInfo/index.vue

@@ -1,61 +1,54 @@
 <template>
-<el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
+    <el-row :gutter="20">
+      <el-col :span="3">
+        <div>
+<el-tree :data="goodsTypeData"  :props="defaultProps" @node-click="handleNodeClick"></el-tree>
+</div>
+</el-col>
+</el-row>
 </template>
 
 
 <script>
+  import { PostDataByName, ExecDataByConfig, failproccess, GetDataByName, transData } from '@/api/common';
+  import TreeSelect from '@/components/TreeSelect'; // 确保路径正确
+
   export default {
     data() {
       return {
-        data: [{
-          label: '一级 1',
-          children: [{
-            label: '二级 1-1',
-            children: [{
-              label: '三级 1-1-1'
-            }]
-          }]
-        }, {
-          label: '一级 2',
-          children: [{
-            label: '二级 2-1',
-            children: [{
-              label: '三级 2-1-1'
-            }]
-          }, {
-            label: '二级 2-2',
-            children: [{
-              label: '三级 2-2-1'
-            }]
-          }]
-        }, {
-          label: '一级 3',
-          children: [{
-            label: '二级 3-1',
-            children: [{
-              label: '三级 3-1-1'
-            }]
-          }, {
-            label: '二级 3-2',
-            children: [{
-              label: '三级 3-2-1'
-            }]
-          }]
-        }],
+        getGoodsTypeParm: { name: 'GetGoodsTypeList' },
+        goodsTypeData:[],
         defaultProps: {
           children: 'children',
-          label: 'label'
+          label: 'goodsTypeName'
         }
       };
     },
     methods: {
       handleNodeClick(data) {
         console.log(data);
-      }
-    }
+      },
+
+      get_goods_type_data() {
+        GetDataByName(this.getGoodsTypeParm).then((response) => {
+          if (response.data && response.data.list) {
+            const list = response.data.list.map(item => ({
+              ...item,
+              pid: parseInt(item.pid),
+              id: parseInt(item.id),
+            }));
+            this.goodsTypeData = transData(list, 'id', 'pid', 'children');
+          }
+        });
+      },
+     
+    },
+    created() {
+      this.get_goods_type_data();
+    },
   };
 </script>
 
 
 <style>
-</style>
+</style>

+ 267 - 76
src/views/productManagement/assetType/index.vue

@@ -31,61 +31,76 @@
       </el-table-column>
       <el-table-column label="操作" min-width="80px" header-align="center" align="center">
         <template slot-scope="scope">
-          <el-button @click="handleEdit(scope.row)">编辑</el-button>
-          <el-button @click="handleDelete(scope.row)">删除</el-button>
+          <el-button type="primary" size="mini" @click="handleEdit(scope.row)">修改</el-button>
+          <el-button type="primary" size="mini" @click="handleDel(scope.row)">删除</el-button>
         </template>
       </el-table-column>
     </el-table>
 
     <el-dialog
-      title="添加货品分类"
+      :title="dialogTitle"
       :visible.sync="dialogFormVisible"
       :close-on-click-modal="false"
-      :center="true"
-      class="add-item"
+      width="40%"
+      :style="{ maxHeight: '80vh', overflowY: 'auto' }"
     >
-      <div class="form-container">
-        <div class="form-row">
-          <div class="form-item">
-            <div class="form-item-name"><span class="required-label">*</span>货品名称</div>
-            <el-input v-model="input" placeholder="请输入内容" class="input-field"></el-input>
-          </div>
-          <div class="form-item">
-            <div class="form-item-name"><span class="required-label">*</span>上级分类</div>
-            <tree-select
-              :disabled="disabled"
-              size="small"
-              clearable
-              :data="parentDept"
-              :default-props="defaultProps"
-              :node-key="id"
-              :checked-keys="defaultCheckedKeys"
-              @popoverHide="popoverHide"
-              class="select-field"
-              width="180px"
-
-            />
-          </div>
+      <el-form ref="form" label-position="top" :rules="rules" label-width="80px" :model="formLabelAlign">
+        <el-row :gutter="20">
+          <el-col :span="14">
+            <el-form-item label="货品名称" prop="name">
+              <el-input v-model="formLabelAlign.name"></el-input>
+            </el-form-item>
+          </el-col>
+          <el-col :span="10">
+            <el-form-item label="上级分类" prop="pid">
+              <tree-select
+                class="typeSelect"
+                :height="300"
+                :width="250"
+                size="small"
+                clearable
+                :data="parentDept"
+                :placeholder="placeholder"
+                style="display:inline-block;"
+                :default-props="defaultProps"
+                :node-key="nodeKey"
+                :checked-keys="defaultCheckedKeys"
+                @popoverHide="popoverHide"
+                :disabled="disabled"
+              />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="20">
+          <el-col :span="12">
+            <el-form-item label="货品编码" prop="type">
+              <el-input v-model="formLabelAlign.type" placeholder="请输入编码">
+                <template slot="prepend">{{ deptform.parammaps.goodsTypeCode }}</template>
+              </el-input>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="20">
+          <el-col :span="24">
+            <el-form-item label="说明">
+              <el-input type="textarea" v-model="deptform.parammaps.describe" style="margin-bottom: 20px;" :rows="6"></el-input>
+            </el-form-item>
+          </el-col>
+        </el-row>
+
+        <div class="dialog-footer">
+          <el-button class="add-button" @click="handleCancel">取消</el-button>
+          <el-button class="add-button" @click="handleAdd">保存</el-button>
         </div>
-        <!-- 确保货品编码标签的 div 正确闭合 -->
-        <div>
-  <div class="form-item-name" style="margin-top: 40px;">
-     <span class="required-label">*</span>货品编码
-   </div>
-   <el-form-item label="类别编号" prop="temptypeCode" style="width:300px">
-     <el-input ref="temptypeCode" placeholder="请输入编码">
-       <template slot="prepend">11111</template>
-     </el-input>
-   </el-form-item>
-</div>
-      </div>
+      </el-form>
     </el-dialog>
   </div>
 </template>
 
 <script>
-import { PostDataByName, GetDataByName, transData } from '@/api/common';
+import { PostDataByName, ExecDataByConfig, failproccess, GetDataByName, transData } from '@/api/common';
 import TreeSelect from '@/components/TreeSelect'; // 确保路径正确
+import { MessageBox } from 'element-ui';
 
 export default {
   components: { TreeSelect },
@@ -96,65 +111,235 @@ export default {
         children: 'children',
         label: 'goodsTypeName', // 根据实际字段名调整
       },
+      list: [{ deptname: '公司', id: 1, parentid: -1 }],
       nodeKey: 'id', // 节点的唯一标识字段
       defaultCheckedKeys: [], // 默认选中的节点
       disabled: false, // 是否禁用
-
+      editVisible: false, // 编辑模式
+      placeholder: '请选择上级分类',
       getGoodsTypeParm: { name: 'GetGoodsTypeList' },
+      requestParam: {},
+      deleteGoodsType: {
+        name: "DeleteGoodsType",
+        parammaps: {
+          id: -1,
+        },
+      },
       tableData: [],
-      parentDeptVisible: true,
-      selectedValue: null,
-      cascaderProps: {
-        checkStrictly: true,
-        expandTrigger: 'hover',
-        multiple: false, // 确保单选
-        emitPath: false, // 只返回最后一级的值
+      dialogTitle: "",
+      deptform: {
+        name: "InsertGoodsType",
+        parammaps: {
+          pid: -1,
+          goodsTypeName: "",
+          goodsTypeCode: "",
+          describe: "",
+          enable: 1,
+        },
       },
       dialogFormVisible: false,
-      input: '', // 绑定输入框的值
+      formLabelAlign: {
+        name: '',
+        pid: '',
+        type: '',
+        id: '',
+      },
+      rules: {
+        name: [
+          { required: true, message: '请输入货品名称', trigger: 'blur' },
+          { min: 1, max: 20, message: '长度在 3 到 5 个字符', trigger: 'blur' },
+        ],
+        pid: [
+          { required: true, message: '请选择货品类别', trigger: 'change' },
+        ],
+        type: [
+          { required: true, message: '请输入编码', trigger: 'change' },
+        ],
+      },
     };
   },
   methods: {
+    // 删除操作
+    handleDel(row) {
+      MessageBox.confirm('名称:' + row.goodsTypeName, '确认删除?', {
+        confirmButtonText: '确认',
+        cancelButtonText: '取消',
+        type: 'warning',
+      }).then(() => {
+        this.deleteGoodsType.parammaps.id = row.id;
+        PostDataByName(this.deleteGoodsType).then(response => {
+          if (response.msg !== 'fail') {
+            this.get_table_data();
+            this.$notify({
+              title: '成功',
+              message: '删除成功',
+              type: 'success',
+              duration: 2000,
+            });
+          } else {
+            failproccess(response, this.$notify);
+          }
+        });
+      });
+    },
+
+    // 上级分类选择回调
     popoverHide(checkedIds, checkedData) {
-      this.deptform.pid = checkedIds; // 将选中的节点 ID 赋值给表单
-      if (checkedIds !== null) {
-        this.deptform.typeCode = checkedData.typeCode; // 根据实际字段名调整
-      } else {
-        this.deptform.pid = -1; // 如果没有选中节点,设置为 -1
-      }
+      this.formLabelAlign.pid = checkedData.id;
+      this.deptform.parammaps.pid = checkedData.id;
+      this.deptform.parammaps.goodsTypeCode = checkedData.goodsTypeCode;
     },
-    handleEdit(row) {
-      console.log('编辑', row);
+
+    // 保存操作
+    handleAdd() {
+      this.$refs.form.validate((valid) => {
+        if (valid) {
+          this.deptform.parammaps.goodsTypeName = this.formLabelAlign.name;
+          const requestParam = this.editVisible ? this.buildUpdateRequest() : this.buildInsertRequest();
+
+          ExecDataByConfig(requestParam).then(response => {
+            if (response.msg !== 'fail') {
+              this.resetForm();
+              this.get_table_data();
+              this.$notify({
+                title: '成功',
+                message: '操作成功',
+                type: 'success',
+                duration: 2000,
+              });
+            } else {
+              this.$notify({
+                title: '失败',
+                message: response.data,
+                type: 'error',
+                duration: 2000,
+              });
+            }
+          });
+        } else {
+          console.log('表单验证未通过');
+        }
+      });
     },
-    handleDelete(row) {
-      console.log('删除', row);
+
+    // 构建插入请求参数
+    buildInsertRequest() {
+      return {
+        common: { returnmap: "0" },
+        data: [
+          {
+            name: "CheckGoodsTypeNameUniqueOnInsert",
+            type: "v",
+            parammaps: { goodsTypeName: this.deptform.parammaps.goodsTypeName },
+          },
+          {
+            name: "CheckGoodsTypeCodeUniqueOnInsert",
+            type: "v",
+            parammaps: { goodsTypeCode: this.deptform.parammaps.goodsTypeCode },
+          },
+          {
+            name: "InsertGoodsType",
+            type: "e",
+            parammaps: {
+              pid: this.deptform.parammaps.pid,
+              goodsTypeName: this.deptform.parammaps.goodsTypeName,
+              goodsTypeCode: this.deptform.parammaps.goodsTypeCode + "." + this.formLabelAlign.type,
+              describe: this.deptform.parammaps.describe,
+              enable: 1,
+            },
+          },
+        ],
+      };
     },
+
+    // 构建更新请求参数
+    buildUpdateRequest() {
+      return {
+        common: { returnmap: "0" },
+        data: [
+          {
+            name: "CheckGoodsTypeNameUniqueOnInsert",
+            type: "v",
+            parammaps: { goodsTypeName: this.deptform.parammaps.goodsTypeName },
+          },
+          {
+            name: "CheckGoodsTypeCodeUniqueOnInsert",
+            type: "v",
+            parammaps: { goodsTypeCode: this.deptform.parammaps.goodsTypeCode },
+          },
+          {
+            name: "UpdateGoodsType",
+            type: "e",
+            parammaps: {
+              pid: this.deptform.parammaps.pid,
+              goodsTypeName: this.deptform.parammaps.goodsTypeName,
+              goodsTypeCode: this.deptform.parammaps.goodsTypeCode + "." + this.formLabelAlign.type,
+              describe: this.deptform.parammaps.describe,
+              enable: 1,
+              id: this.formLabelAlign.id,
+            },
+          },
+        ],
+      };
+    },
+
+    // 重置表单
+    resetForm() {
+      this.deptform.parammaps = { pid: -1, goodsTypeName: "", goodsTypeCode: "", describe: "", enable: 1 };
+      this.formLabelAlign = { name: '', pid: '', type: '', id: '' };
+      this.defaultCheckedKeys = [];
+      this.dialogFormVisible = false;
+      this.editVisible = false;
+    },
+
+    // 取消操作
+    handleCancel() {
+      this.resetForm();
+    },
+
+    // 获取表格数据
     get_table_data() {
       GetDataByName(this.getGoodsTypeParm).then((response) => {
-        if (response.data.tableData !== null) {
-          for (let i = 0; i < response.data.list.length; i++) {
-            response.data.list[i].goodsTypeName = response.data.list[i].goodsTypeName;
-            response.data.list[i].goodsTypeCode = response.data.list[i].goodsTypeCode;
-            response.data.list[i].pid = parseInt(response.data.list[i].pid);
-            response.data.list[i].id = parseInt(response.data.list[i].id);
-            response.data.list[i].describe = response.data.list[i].describe;
-          }
+        if (response.data && response.data.list) {
+          const list = response.data.list.map(item => ({
+            ...item,
+            pid: parseInt(item.pid),
+            id: parseInt(item.id),
+          }));
+          this.tableData = transData(list, 'id', 'pid', 'children');
+          this.parentDept = this.tableData;
         }
-        this.tableData = transData(response.data.list, 'id', 'pid', 'children');
-        this.parentDept = this.tableData;
       });
     },
+
+    // 打开添加弹窗
     form_add() {
+      this.dialogTitle = "添加货品分类";
       this.dialogFormVisible = true;
     },
-    handleCascaderChange(value) {
-      console.log('选中的值:', value);
-      // 这里处理选中的数据
-      this.$refs.cascader.dropDownVisible = false; // 关闭下拉框
+
+    // 打开编辑弹窗
+    handleEdit(row) {
+      this.editVisible = true;
+      this.defaultCheckedKeys = [row.pid];
+      this.dialogTitle = "修改货品分类";
+      this.dialogFormVisible = true;
+      this.formLabelAlign = {
+        pid: row.pid,
+        name: row.goodsTypeName,
+        type: row.parentGoodsTypeCode,
+        id: row.id,
+      };
+      this.deptform.parammaps = {
+        pid: row.pid,
+        goodsTypeName: row.goodsTypeName,
+        goodsTypeCode: row.goodsTypeCode,
+        describe: row.describe,
+        enable: 1,
+      };
     },
   },
   created() {
-    console.log('111111');
     this.get_table_data();
   },
 };
@@ -195,7 +380,7 @@ export default {
 }
 
 .add-item {
- 
+
   position: absolute;
   top: 35%; /* 垂直居中 */
   left: 50%; /* 水平居中 */
@@ -238,7 +423,7 @@ export default {
 .form-row {
   display: flex;
   justify-content: space-between;
- 
+
 }
 
 /* 表单项样式 */
@@ -248,4 +433,10 @@ export default {
   flex-direction: column;
   gap: 10px; /* 调整内部间距 */
 }
+
+.dialog-footer{
+  right:10px;
+  position:absolute;
+  bottom:10px;
+}
 </style>