Просмотр исходного кода

重构编码申请功能,优化API请求方式并完善编码段选择逻辑

yusheng 7 месяцев назад
Родитель
Сommit
b4cfc61edb

+ 7 - 10
src/components/addDoc/api/index.js

@@ -91,10 +91,8 @@ export async function pageSegment(data) {
 }
 
 // 生成编码
-export async function getCode(id) {
-  const res = await request.get(
-    `/main/business_code_category/applyForCode/` + id
-  );
+export async function getCode(data) {
+  const res = await request.post(`/main/business_code_category/applyForCode`,data);
   if (res.data.code == 0) {
     return res.data.data;
   }
@@ -116,14 +114,13 @@ export async function uploadFileNew(data) {
   return Promise.reject(new Error(res.data.message));
 }
 // 编码方案
-export async function listCode(data = {}) {
-  const res = await request.get(
-    `/main/business_code_category/listCode/${data.id || '0'}` +
-      '?parentId=' +
-      (data.parentId || '')
-  );
+export async function listCode(data={}) {
+  console.log(data?.parentId,'data?.parentId')
+   
+  const res = await request.get(`/main/business_code_category/listCode/${data.id||'0'}`+'?parentId='+(data.parentId||''));
   if (res.data.code == 0) {
     return res.data.data;
   }
   return Promise.reject(new Error(res.data.message));
 }
+

+ 84 - 15
src/components/addDoc/getCode.vue

@@ -8,8 +8,6 @@
     append-to-body
     @close="cancel"
     title="申请编码"
-    :maxable="true"
-    :resizable="true"
   >
     <el-form ref="form" :model="form" :rules="rules" label-width="82px">
       <el-row :gutter="15">
@@ -51,9 +49,39 @@
             <el-input v-model="form.code" disabled></el-input>
           </el-form-item>
         </el-col>
+
+        <el-col :span="24">
+          <headerTitle title="编码码段"></headerTitle>
+          <template v-for="item in segmentList">
+            <el-form-item :label="item.name" :prop="item.id" :key="item.id">
+              <el-input
+                v-if="item.roughRule == 5 || item.roughRule == 4"
+                :disabled="true"
+                v-model="item.currentValue"
+              ></el-input>
+              <el-select
+                v-else
+                v-model="item.currentValue"
+                placeholder="请选择"
+                style="width: 100%"
+              >
+                <el-option
+                  v-for="(segmentValue, index) in item.value"
+                  :key="index"
+                  :label="segmentValue.value"
+                  :value="segmentValue.value"
+                  @click.native="
+                    segmentValueChange(item.id, segmentValue.value, index)
+                  "
+                >
+                </el-option>
+              </el-select>
+            </el-form-item>
+          </template>
+        </el-col>
       </el-row>
     </el-form>
-    <headerTitle title="编码码段"></headerTitle>
+
     <template v-slot:footer>
       <el-button @click="cancel">取消</el-button>
       <el-button type="primary" @click="save"> 确认 </el-button>
@@ -62,7 +90,13 @@
 </template>
 
 <script>
-  import { selectTreeList, listParentId, getCode } from './api';
+  import {
+    selectTreeList,
+    listParentId,
+    pageSegment,
+    getCode
+  } from './api/index.js';
+  import headerTitle from '@/components/header-title/index.vue';
 
   export default {
     data() {
@@ -74,28 +108,26 @@
         },
         list: [],
         options: [],
+        segmentList: [],
         // 表单数据
         form: {
           type: '',
           code: '',
           type1: ''
         },
-
+        nodeData: null,
         showEditFlag: false
       };
     },
-    computed: {
-      // 是否开启响应式布局
-      styleResponsive() {
-        return this.$store.state.theme.styleResponsive;
-      }
-    },
+    computed: {},
     components: {
+      headerTitle
     },
     created() {},
     methods: {
-      async open() {
+      async open(nodeData) {
         this.list = await selectTreeList();
+        this.nodeData = nodeData;
         this.setTree(this.list);
         this.showEditFlag = true;
       },
@@ -109,28 +141,65 @@
           }
         });
       },
+
       async typeChange(val) {
         let data = await listParentId({
           pageNum: 1,
           size: 100,
-          parentId: val
+          parentId: val,
+          objId: this.nodeData?.id,
+          objParentId: this.nodeData?.parentId
         });
         this.options = data.list.filter((item) => item.type == 2);
         this.form.type1 = '';
+        this.form.code = '';
+        this.segmentList = [];
       },
       async type1Change(val) {
-        // this.form.code = await getCode(val);
+        let codeData = await getCode({
+          categoryId: val
+        });
+        this.form.code = codeData.codeStr;
+
+        let data = await pageSegment({
+          pageNum: 1,
+          size: 100,
+          businessCodeCategoryId: val
+        });
+        this.segmentList = data.list.map((item, index) => {
+          item['currentValue'] = codeData.values[index];
+          return item;
+        });
+      },
+      async segmentValueChange() {
+        // codeManageId:id,
+        //   code:value,
+        let codeData = await getCode({
+          categoryId: this.form.type1,
+
+          codeManageArray: this.segmentList.map((item) => {
+            return {
+              codeManageId: item.id,
+              code: item.currentValue
+            };
+          }),
+          isUpdateNo: 1
+        });
+        this.form.code = codeData.codeStr;
       },
       /* 保存编辑 */
       save() {
-        this.$emit('success', this.form.code);
+        this.$emit('setCode', this.form.code);
         this.cancel();
       },
 
       cancel() {
         this.form.type = '';
         this.form.code = '';
+        this.form.type1 = '';
         this.showEditFlag = false;
+        this.segmentList = [];
+        this.options = [];
       }
     }
   };

+ 74 - 23
src/views/material/product/detail.vue

@@ -26,14 +26,20 @@
 
           <el-col :span="8">
             <el-form-item label="编码" prop="code">
-              <el-input
+              <!-- <el-input
                 v-if="ruleCode == '自定义'"
                 v-model="form.code"
                 readonly
                 @click.native="openCode"
                 :disabled="status == 0"
-              />
-              <el-input v-else v-model="form.code" :disabled="status == 0" />
+              /> -->
+              <el-input v-model="form.code" :disabled="status == 0">
+                <template slot="append" v-if="status != 0">
+                  <el-link :underline="false" @click.native="getCodeOpen"
+                    >申请编码
+                  </el-link></template
+                >
+              </el-input>
             </el-form-item>
           </el-col>
 
@@ -356,12 +362,12 @@
     </el-card>
 
     <!--  自定义编码 -->
-    <CodeDialog
+    <!-- <CodeDialog
       ref="codeRefs"
       v-if="codeShow"
       @close="codeShow = false"
       @chooseCode="chooseCode"
-    />
+    /> -->
     <!-- 分类选择弹窗 -->
     <CategoryDialog ref="categoryRefs" @chooseCategory="confirmCategory" />
     <!-- 仓储配置 -->
@@ -406,6 +412,9 @@
       :categoryLevelGroupId="form.categoryLevelGroupId"
       :code="form.code"
     />
+    <!-- 申请编码 -->
+
+    <GetCodeDialog ref="GetCodeDialogRef" @setCode="setCode"></GetCodeDialog>
   </div>
 </template>
 
@@ -413,7 +422,7 @@
   import SalesInfos from './components/SalesInfos.vue';
   import PurchasingInfo from './components/PurchasingInfo.vue';
   import GroupDialog from './components/GroupDialog.vue';
-  import CodeDialog from './components/codeDialog.vue';
+  // import CodeDialog from './components/codeDialog.vue';
   import CategoryDialog from './components/CategoryDialog.vue';
   import WarehouseInfo from './components/WarehouseInfo.vue';
   import ProcureInfo from './components/ProcureInfo.vue';
@@ -431,7 +440,7 @@
   import { getDetails } from '@/api/classifyManage/itemInformation';
   import { getByCode } from '@/api/system/dictionary-data';
   import {
-    getCode,
+    // getCode,
     rootCategoryCode,
     fieldModel,
     checkExist
@@ -443,6 +452,8 @@
   import { produceTypeList } from '@/enum/dict.js';
   import { copyObj } from '@/utils/util';
   import { parameterGetByCode } from '@/api/system/dictionary/index.js';
+  import GetCodeDialog from '@/components/addDoc/getCode.vue';
+  import { getCode, listCode } from '@/components/addDoc/api/index.js';
   const defCategoryQms = [
     {
       categoryId: '',
@@ -517,7 +528,8 @@
       MoldInfo,
       RemarkInfo,
       CategoryDialog,
-      CodeDialog
+      // CodeDialog,
+      GetCodeDialog
     },
     data() {
       return {
@@ -806,11 +818,13 @@
       this.form.categoryLevelPathId = this.$route.query.categoryLevelPathId;
 
       this.ruleCode = this.$route.query.ruleCode;
-      if (this.ruleCode && this.ruleCode != '自定义' && this.status != 0) {
-        const code = await getCode(this.ruleCode);
-        this.$set(this.form, 'code', code);
+      // if (this.ruleCode && this.ruleCode != '自定义' && this.status != 0) {
+      //   const code = await getCode(this.ruleCode);
+      //   this.$set(this.form, 'code', code);
+      // }
+      if (this.status != 0) {
+        this.getCode();
       }
-
       this.getFieldModel();
 
       // this.getDictList('zeroPartPros');
@@ -859,11 +873,13 @@
       );
       this.status = this.$route.query.status;
       this.ruleCode = this.$route.query.ruleCode;
-      if (this.ruleCode && this.ruleCode != '自定义' && this.status != 0) {
-        const code = await getCode(this.ruleCode);
-        this.$set(this.form, 'code', code);
+      // if (this.ruleCode && this.ruleCode != '自定义' && this.status != 0) {
+      //   const code = await getCode(this.ruleCode);
+      //   this.$set(this.form, 'code', code);
+      // }
+      if (this.status != 0) {
+        this.getCode();
       }
-
       this.getFieldModel();
       this.getAttributeList('inventory_type');
 
@@ -1162,9 +1178,6 @@
       },
       // 确定分类
       async confirmCategory(node, title, PathInfo, ruleCode) {
-        if (this.status != 0) {
-          this.$set(this.form, 'code', null);
-        }
         this.categoryLevelPathId = PathInfo.categoryLevelPathId.split(',')[0];
 
         if (title == '选择产品分类') {
@@ -1179,16 +1192,54 @@
 
           this.ruleCode = ruleCode;
 
-          if (ruleCode && ruleCode != '自定义' && this.status != 0) {
-            const code = await getCode(ruleCode);
-            this.$set(this.form, 'code', code);
+          // if (ruleCode && ruleCode != '自定义' && this.status != 0) {
+          //   const code = await getCode(ruleCode);
+          //   this.$set(this.form, 'code', code);
+          // }
+          // console.log(this.form, 'this.form');
+          if (this.status != 0) {
+            this.getCode();
           }
-          console.log(this.form, 'this.form');
         }
 
         this.$forceUpdate();
       },
 
+      getCodeOpen() {
+        let parentId = [];
+        if (this.form.categoryLevelPathId?.length) {
+          parentId = this.form.categoryLevelPathId?.split(',');
+        }
+        this.$refs.GetCodeDialogRef.open({
+          id: this.form.categoryLevelId,
+          parentId: parentId.length > 1 ? parentId[parentId.length - 2] : ''
+        });
+      },
+      setCode(val) {
+        this.$set(this.form, 'code', val);
+      },
+
+      async getCode() {
+        let parentId = [];
+        let categoryLevelPathId = this.PathInfo?.categoryLevelPathId
+          ? this.PathInfo.categoryLevelPathId
+          : this.form.categoryLevelPathId;
+        if (categoryLevelPathId?.length) {
+          parentId = categoryLevelPathId.split(',');
+        }
+        const options = await listCode({
+          id: this.form.categoryLevelId,
+          parentId: parentId.length > 1 ? parentId[parentId.length - 2] : ''
+        });
+        if (options.length > 0) {
+          getCode({
+            categoryId: options[0].id
+          }).then((res) => {
+            this.$set(this.form, 'code', res.codeStr);
+          });
+        }
+      },
+
       async getDictList(code) {
         let { data: res } = await getByCode(code);