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

质检模板新增工序选择功能

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

+ 7 - 1
src/api/aps/index.js

@@ -18,7 +18,13 @@ export async function getProduceTaskList(params) {
     return res.data.data;
   }
 }
-
+//工序分页
+export async function producetask(params) {
+  const res = await request.get('/main/producetask/page', { params });
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+}
 /**
  * 生产计划
  */

+ 346 - 0
src/components/procedure/taskinstanceDialog.vue

@@ -0,0 +1,346 @@
+<!-- 用户编辑弹窗 -->
+<template>
+  <ele-modal
+    width="1060px"
+    :visible="visible"
+    :append-to-body="true"
+    :close-on-click-modal="false"
+    custom-class="ele-dialog-form"
+    title="工序"
+    :maxable="true"
+    :resizable="true"
+    @update:visible="updateVisible(false)"
+  >
+    <header-title title="基本信息"> </header-title>
+    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
+      <el-row>
+        <el-col :span="8">
+          <el-form-item label="加工方式:" prop="produceType">
+            <el-select
+              v-model="form.produceType"
+              style="width: 100%"
+              @change="changeProduceType"
+            >
+              <el-option
+                v-for="item of producedList"
+                :key="item.code"
+                :label="item.name"
+                :value="item.code"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+        <el-col :span="8">
+          <el-form-item label="BOM版本:" prop="bomCategoryId">
+            <el-select
+              v-model="form.bomCategoryId"
+              style="width: 100%"
+              @change="changeBomId"
+            >
+              <el-option
+                v-for="item of bomVersionList"
+                :key="item.id"
+                :label="item.name + '(V' + item.versions + '.0)'"
+                :value="item.id"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+        <el-col :span="8">
+          <el-form-item label="工艺路线:" prop="produceRoutingId">
+            <!--  @click.native="openVersion"   -->
+            <el-select
+              v-model="form.produceRoutingId"
+              style="width: 100%"
+              @change="changeRoute"
+            >
+              <el-option
+                v-for="item of routingList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+        </el-col>
+      </el-row>
+    </el-form>
+
+    <ele-pro-table
+      ref="table"
+      :needPage="false"
+      :columns="columns"
+      :datasource="datasource"
+      @cell-click="cellClick"
+      v-if="form.produceRoutingId"
+      row-key="id"
+    >
+      <template v-slot:action="{ row }">
+        <el-radio class="radio" v-model="radio" :label="row.id"
+          ><i></i
+        ></el-radio>
+      </template>
+    </ele-pro-table>
+    <ele-pro-table
+      ref="table"
+      :columns="columns1"
+      :datasource="datasource"
+      @cell-click="cellClick"
+      v-if="!form.produceRoutingId"
+      row-key="id"
+    >
+      <template v-slot:action="{ row }">
+        <el-radio class="radio" v-model="radio" :label="row.id"
+          ><i></i
+        ></el-radio>
+      </template>
+    </ele-pro-table>
+    <template v-slot:footer>
+      <el-button type="primary" @click="save"> 确定 </el-button>
+      <el-button @click="updateVisible(false)"> 返回 </el-button>
+    </template>
+  </ele-modal>
+</template>
+
+<script>
+  import {
+    bomListByPlan,
+    bomRoutingList,
+    taskinstanceList,
+    producetask
+  } from '@/api/aps';
+
+  export default {
+    components: {},
+    props: {
+      // 弹窗是否打开
+      visible: Boolean
+    },
+    data() {
+      const defaultForm = {
+        produceType: '',
+        bomCategoryId: '',
+        produceRoutingId: ''
+      };
+      return {
+        defaultForm,
+        radio: null,
+        current: {},
+        producedList: [
+          { code: 2, name: '加工(MBOM)' },
+          { code: 3, name: '装配(ABOM)' }
+        ],
+        index: '',
+        bomVersionList: [],
+        routingList: [],
+        // 表单数据
+        form: { ...defaultForm },
+        // 表单验证规则
+        rules: {},
+        versionList: [],
+        // 提交状态
+        loading: false,
+        // 是否是修改
+        isUpdate: false,
+        columns1: [
+          {
+            action: 'action',
+            slot: 'action',
+            align: 'center',
+            label: '选择',
+            width: 80
+          },
+          {
+            prop: 'code',
+            label: '工序编码',
+            // sortable: 'custom',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 110
+          },
+
+          {
+            prop: 'name',
+            label: '工序名称',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 110
+          },
+          {
+            align: 'center',
+            prop: 'controlName',
+            label: '工序控制码',
+            showOverflowTooltip: true,
+            minWidth: 110
+          },
+          {
+            prop: 'workCenterName',
+            label: '所属工作中心',
+            align: 'center',
+            showOverflowTooltip: true,
+            minWidth: 110
+          }
+        ],
+        columns: [
+          {
+            action: 'action',
+            slot: 'action',
+            align: 'center',
+            label: '选择',
+            width: 80
+          },
+          {
+            prop: 'orderNum',
+            label: '排序',
+            align: 'center',
+            slot: 'orderNum',
+            width: 80
+          },
+          {
+            prop: 'code',
+            label: '工序编码',
+            // sortable: 'custom',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 110
+          },
+
+          {
+            prop: 'name',
+            label: '工序名称',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 110
+          },
+          {
+            align: 'center',
+            prop: 'controlName',
+            label: '工序控制码',
+            showOverflowTooltip: true,
+            minWidth: 110
+          },
+          {
+            prop: 'workCenterName',
+            label: '所属工作中心',
+            align: 'center',
+            showOverflowTooltip: true,
+            minWidth: 110
+          }
+        ]
+      };
+    },
+    computed: {
+      // 是否开启响应式布局
+      styleResponsive() {
+        return this.$store.state.theme.styleResponsive;
+      }
+    },
+    methods: {
+      open(row, index) {
+        this.data = row;
+        this.index = index;
+      },
+      changeProduceType() {
+        this.form.bomCategoryId = '';
+        this.form['bomCategoryName'] = '';
+        this.form['bomCategoryVersions'] = '';
+
+        this.bomVersionList = [];
+        this.routingList = [];
+        this.form.produceRoutingId = '';
+        this.form.produceRoutingName = '';
+        this.form.produceVersionName = '';
+        this.bomListVersion();
+      },
+      bomListVersion() {
+        let param = {
+          bomType: this.form.produceType,
+          categoryId: this.data.productId
+        };
+        bomListByPlan(param).then((res) => {
+          this.bomVersionList = res || [];
+        });
+      },
+      changeBomId() {
+        this.routingList = [];
+        this.form.produceRoutingId = '';
+        this.form.produceRoutingName = '';
+        this.form.produceVersionName = '';
+        this.bomVersionList.forEach((f) => {
+          if (f.id == this.form.bomCategoryId) {
+            this.$set(this.form, 'bomCategoryName', f.name);
+            this.$set(this.form, 'bomCategoryVersions', f.versions);
+          }
+        });
+        this.getPlanRouting();
+      },
+      getPlanRouting() {
+        bomRoutingList(this.form.bomCategoryId).then((res) => {
+          this.routingList = res || [];
+        });
+      },
+      changeRoute(val) {
+        if (!val) return;
+        this.routingList.forEach((f) => {
+          if (f.id == this.form.produceRoutingId) {
+            this.$set(this.form, 'produceRoutingName', f.name);
+            this.$set(this.form, 'produceVersionName', f.version);
+          }
+        });
+        this.$refs.table.reload();
+      },
+      /* 表格数据源 */
+      async datasource({ page, limit, where, order }) {
+
+        if (this.form.produceRoutingId) {
+          const res = await taskinstanceList({
+            routingId: this.form.produceRoutingId,
+            isDetail: true,
+            pageNum: 1,
+            size: -1
+          });
+
+          let arr = res.list.map((it) => {
+            it.detail.orderNum = it.orderNum;
+            return it.detail;
+          });
+          return {
+            list: arr
+          };
+        } else {
+       
+          return await producetask({
+            pageNum: page,
+            size: limit,
+            ...where
+          });
+          
+        }
+
+        //this.$refs.table.reload()
+      },
+      // 单击获取id
+      cellClick(row) {
+        this.current = row;
+        this.radio = row.id;
+      },
+      /* 保存编辑 */
+      save() {
+        if (!this.radio) return this.$message.warning('请选择工序');
+        this.$emit('saveTaskInstance', {
+          ...this.current,
+          index: this.index,
+          produceRoutingId: this.form.produceRoutingId
+        });
+        this.updateVisible(false);
+      },
+
+      /* 更新visible */
+      updateVisible(value) {
+        this.$emit('update:visible', value);
+      }
+    },
+
+    watch: {}
+  };
+</script>

+ 374 - 325
src/views/inspectionTemplate/AddorUpdate.vue

@@ -23,7 +23,7 @@
       label-width="80px"
     >
       <el-row style="margin-bottom: 10px">
-        <el-col :span="4"
+        <el-col :span="6"
           ><el-form-item label="类型 " prop="type">
             <el-select
               clearable
@@ -39,7 +39,7 @@
               />
             </el-select> </el-form-item
         ></el-col>
-        <el-col :span="8">
+        <el-col :span="7">
           <el-form-item label="名称" prop="qualitySchemeTemplateName">
             <el-input
               v-model="dataForm.qualitySchemeTemplateName"
@@ -47,7 +47,7 @@
             ></el-input>
           </el-form-item>
         </el-col>
-        <el-col :span="8">
+        <el-col :span="7">
           <el-form-item label="编码" prop="qualitySchemeTemplateCode">
             <el-input
               v-model="dataForm.qualitySchemeTemplateCode"
@@ -70,7 +70,23 @@
         ></el-col>
       </el-row>
       <el-row>
-        <el-col :span="24">
+        <el-col :span="6">
+          <el-form-item label="工序" prop="taskName">
+            <el-input
+              v-model="dataForm.taskName"
+              placeholder="请选择"
+              style="width: calc(100% - 56px); margin-right: 10px"
+              disabled
+            ></el-input>
+            <el-button
+              size="small"
+              type="primary"
+              @click.native="handleTaskinstance"
+              >选择
+            </el-button>
+          </el-form-item>
+        </el-col>
+        <el-col :span="18">
           <el-form-item label="备注" prop="templateRemark">
             <el-input
               type="textarea"
@@ -86,23 +102,34 @@
         </el-col>
       </el-row>
       <el-row>
-        <el-col style="width: 370px">
+        <el-col style="width: 260px">
+          <el-form-item label="检验方式" prop="qualityMode">
+            <DictSelection
+              dictName="检验方案"
+              clearable
+              v-model="dataForm.qualityMode"
+            >
+            </DictSelection>
+          </el-form-item>
+        </el-col>
+
+        <el-col style="width: 360px" v-if="dataForm.qualityMode == 2">
           <el-form-item label="取样数量" prop="sampleProportion">
             <el-input
               type="number"
               v-model="dataForm.sampleProportion"
               placeholder="请输入"
-              style="width: 200px"
+              style="width: 180px"
             ></el-input>
             <DictSelection
-              style="width: 85px"
+              style="width: 95px"
               dictName="计量单位"
               placeholder=" "
               v-model="dataForm.sampleProportionUnit"
             ></DictSelection>
           </el-form-item>
         </el-col>
-        <el-col style="width: 450px">
+        <el-col style="width: 430px">
           <el-form-item
             label="质检报告有效期"
             prop="validityPeriod"
@@ -112,7 +139,7 @@
               type="number"
               v-model="dataForm.validityPeriod"
               placeholder="请输入"
-              style="width: 200px"
+              style="width: 180px"
             ></el-input>
             <el-select
               style="width: 85px"
@@ -224,7 +251,7 @@
           </template>
         </ele-pro-table>
       </el-row>
-      <el-row v-if="dataForm.type !== 2">
+      <el-row>
         <ele-pro-table
           ref="table"
           :columns="categoryColumns"
@@ -274,348 +301,370 @@
       :disabledCode="templateCategoryList.map((item) => item.code)"
     >
     </EquipmentDialog>
+    <taskinstance-dialog
+      ref="taskinstanceDialogRef"
+      v-if="taskinstanceDialogFlag"
+      @saveTaskInstance="saveTaskInstance"
+      :visible.sync="taskinstanceDialogFlag"
+    ></taskinstance-dialog>
   </ele-modal>
 </template>
 
 <script>
-import termPop from '@/views/inspectionTemplate/inspectionClassify/index.vue';
-import EquipmentDialog from '@/views/unqualifiedProduct/unqualifiedList/components/EquipmentDialog.vue';
-import { getByCode } from '@/api/system/dictionary-data';
-import tabMixins from '@/mixins/tableColumnsMixin';
+  import termPop from '@/views/inspectionTemplate/inspectionClassify/index.vue';
+  import EquipmentDialog from '@/views/unqualifiedProduct/unqualifiedList/components/EquipmentDialog.vue';
+  import { getByCode } from '@/api/system/dictionary-data';
+  import tabMixins from '@/mixins/tableColumnsMixin';
+  import taskinstanceDialog from '@/components/procedure/taskinstanceDialog.vue';
 
-import {
-  save,
-  update,
-  getById,
-  templatecategoryPage
-} from '@/api/inspectionTemplate';
-import { getCode } from '@/api/login';
-export default {
-  components: { termPop, EquipmentDialog },
-  mixins: [tabMixins],
-  data() {
-    return {
-      cacheKeyUrl: 'qms-c2e9664a-inspectionTemplate-AddorUpdate',
-      columnsVersion: 1,
-      visible: false,
-      dataForm: {
-        id: 0,
-        type: null,
-        qualitySchemeTemplateName: '',
-        qualitySchemeTemplateCode: '',
-        inspectionItemVOList: [],
-        status: 1,
-        templateRemark: '',
-        sampleProportion: '',
-        sampleProportionUnit: '%',
-        validityPeriod: '',
-        validityPeriodUnit: ''
-      },
-      columns: [
-        {
-          width: 45,
-          type: 'selection',
-          columnKey: 'selection',
-          align: 'center',
-          reserveSelection: true
-        },
-        {
-          columnKey: 'index',
-          label: '序号',
-          type: 'index',
-          width: 55,
-          align: 'center',
-          showOverflowTooltip: true,
-          fixed: 'left'
-        },
-        {
-          label: '排序',
-          width: 100,
-          align: 'center',
-          slot: 'sort',
-          prop: 'sort',
-          fixed: 'left'
-        },
-        {
-          prop: 'categoryLevelClassName',
-          label: '质检类型',
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'inspectionCode',
-          label: '编码',
-          showOverflowTooltip: true,
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'inspectionName',
-          slot: 'inspectionName',
-          label: '名称',
-          showOverflowTooltip: true,
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'defaultValue',
-          slot: 'defaultValue',
-          label: '工艺参数',
-          align: 'center',
-          minWidth: 400,
-          columnKey: 'defaultValue'
+  import {
+    save,
+    update,
+    getById,
+    templatecategoryPage
+  } from '@/api/inspectionTemplate';
+  import { getCode } from '@/api/login';
+  export default {
+    components: { termPop, EquipmentDialog, taskinstanceDialog },
+    mixins: [tabMixins],
+    data() {
+      return {
+        cacheKeyUrl: 'qms-c2e9664a-inspectionTemplate-AddorUpdate',
+        columnsVersion: 1,
+        visible: false,
+        taskinstanceDialogFlag: false,
+        dataForm: {
+          id: 0,
+          type: null,
+          qualitySchemeTemplateName: '',
+          qualitySchemeTemplateCode: '',
+          inspectionItemVOList: [],
+          status: 1,
+          templateRemark: '',
+          sampleProportion: '',
+          sampleProportionUnit: '%',
+          validityPeriod: '',
+          validityPeriodUnit: '',
+          qualityMode: '',
+          taskId:'',  
+          taskName:'', 
         },
+        columns: [
+          {
+            width: 45,
+            type: 'selection',
+            columnKey: 'selection',
+            align: 'center',
+            reserveSelection: true
+          },
+          {
+            columnKey: 'index',
+            label: '序号',
+            type: 'index',
+            width: 55,
+            align: 'center',
+            showOverflowTooltip: true,
+            fixed: 'left'
+          },
+          {
+            label: '排序',
+            width: 100,
+            align: 'center',
+            slot: 'sort',
+            prop: 'sort',
+            fixed: 'left'
+          },
+          {
+            prop: 'categoryLevelClassName',
+            label: '质检类型',
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'inspectionCode',
+            label: '编码',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'inspectionName',
+            slot: 'inspectionName',
+            label: '名称',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'defaultValue',
+            slot: 'defaultValue',
+            label: '工艺参数',
+            align: 'center',
+            minWidth: 400,
+            columnKey: 'defaultValue'
+          },
 
-        {
-          columnKey: 'action',
-          label: '操作',
-          width: 80,
-          align: 'center',
-          resizable: false,
-          slot: 'action',
-          fixed: 'right'
-        }
-      ],
-      categoryColumns: [
-        {
-          width: 45,
-          type: 'selection',
-          columnKey: 'selection',
-          align: 'center',
-          reserveSelection: true
-        },
-        {
-          columnKey: 'index',
-          label: '序号',
-          type: 'index',
-          width: 55,
-          align: 'center',
-          showOverflowTooltip: true,
-          fixed: 'left'
-        },
-        {
-          prop: 'categoryLevelPath',
-          label: '分类',
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'code',
-          label: '编码',
-          showOverflowTooltip: true,
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'name',
-          label: '名称',
-          showOverflowTooltip: true,
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'specification',
-          label: '规格',
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'modelType',
-          label: '型号',
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          prop: 'brandNum',
-          label: '牌号',
-          align: 'center',
-          minWidth: 150
-        },
-        {
-          columnKey: 'action',
-          label: '操作',
-          width: 80,
-          align: 'center',
-          resizable: false,
-          slot: 'action',
-          fixed: 'right'
-        }
-      ],
-      dataRule: {
-        type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
-        qualitySchemeTemplateName: [
-          { required: true, message: '请输入质检方案名称', trigger: 'blur' }
+          {
+            columnKey: 'action',
+            label: '操作',
+            width: 80,
+            align: 'center',
+            resizable: false,
+            slot: 'action',
+            fixed: 'right'
+          }
         ],
-        status: [
+        categoryColumns: [
+          {
+            width: 45,
+            type: 'selection',
+            columnKey: 'selection',
+            align: 'center',
+            reserveSelection: true
+          },
           {
-            required: true,
-            message: '请选择状态',
-            trigger: 'blur'
+            columnKey: 'index',
+            label: '序号',
+            type: 'index',
+            width: 55,
+            align: 'center',
+            showOverflowTooltip: true,
+            fixed: 'left'
+          },
+          {
+            prop: 'categoryLevelPath',
+            label: '分类',
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'code',
+            label: '编码',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'name',
+            label: '名称',
+            showOverflowTooltip: true,
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'specification',
+            label: '规格',
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'modelType',
+            label: '型号',
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            prop: 'brandNum',
+            label: '牌号',
+            align: 'center',
+            minWidth: 150
+          },
+          {
+            columnKey: 'action',
+            label: '操作',
+            width: 80,
+            align: 'center',
+            resizable: false,
+            slot: 'action',
+            fixed: 'right'
           }
-        ]
-      },
-      list: [],
-      templateCategoryList: [],
-      typeList: []
-    };
-  },
-  methods: {
+        ],
+        dataRule: {
+          type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
+          qualitySchemeTemplateName: [
+            { required: true, message: '请输入质检方案名称', trigger: 'blur' }
+          ],
+          status: [
+            {
+              required: true,
+              message: '请选择状态',
+              trigger: 'blur'
+            }
+          ]
+        },
+        list: [],
+        templateCategoryList: [],
+        typeList: []
+      };
+    },
+    methods: {
       //失去焦点自动排序
       handleSortBlur() {
-      this.list = this.list.map(item => ({
-        ...item,
-        sort: item.sort === '' || item.sort == null ? 0 : Number(item.sort)
-      }));
+        this.list = this.list.map((item) => ({
+          ...item,
+          sort: item.sort === '' || item.sort == null ? 0 : Number(item.sort)
+        }));
 
-      this.list.sort((a, b) => a.sort - b.sort);
-    },
-    async getTnspectionPlanType() {
-      let res = await getByCode('inspection_plan_type');
-      if (res?.code == 0) {
-        let list = res.data.map((item) => {
-          let key = Object.keys(item)[0];
-          return { value: key, label: item[key] };
+        this.list.sort((a, b) => a.sort - b.sort);
+      },
+      handleTaskinstance() {
+        this.taskinstanceDialogFlag = true;
+        this.$nextTick(() => {
+          this.$refs.taskinstanceDialogRef.open();
         });
-        this.typeList = list;
-      }
-    },
-    handAdd(type) {
-      if (type == 1) {
-        this.$refs.termRef.open(this.list);
-      }
-      if (type == 2) {
-        this.$refs.equipmentRefs.open();
-      }
-    },
-    handleClose() {
-      this.visible = false;
-      this.templateCategoryList = [];
-    },
-    selectionChange(selection) {
-      console.log(selection, 'selection');
-    },
-    selectChange(list) {
-      this.list = list.map((item) => {
-        item['sort'] = item['sort'] || 0;
-        return item;
-      });
-    },
-    handDel(index, type) {
-      if (type == 1) {
-        this.list.splice(index, 1);
-      }
-      if (type == 2) {
-        this.templateCategoryList.splice(index, 1);
-      }
-    },
-    confirmChoose(list) {
-      let categoryList = list.map((item) => {
-        item['name'] = item.name;
-        item['categoryId'] = item.id;
-        item['id'] = '';
-        return item;
-      });
-      this.templateCategoryList.push(...categoryList);
-    },
-    init(id) {
-      this.getTnspectionPlanType();
-      this.dataForm.id = id || 0;
-      this.visible = true;
-      this.$nextTick(async () => {
-        this.$refs['dataForm'].resetFields();
-        if (this.dataForm.id) {
-          getById(this.dataForm.id).then(({ data }) => {
-            this.dataForm = data;
-            let itemVOList = [];
-            if (data.inspectionItemVOList.length > 0) {
-              itemVOList = data.inspectionItemVOList.map((item) => {
-                item.inspectionItemId = this.dataForm.id;
-                // item.push({
-                //   inspectionItemId: this.dataForm.id
-                // });
-                return item;
-              });
-            }
-            // this.list = data.inspectionItemVOList;
-            this.list = itemVOList;
-            console.log(this.list);
-          });
-          templatecategoryPage({
-            templateId: this.dataForm.id,
-            size: -1
-          }).then((data) => {
-            console.log(data, 'data');
-            this.templateCategoryList = data.list;
+      },
+      async getTnspectionPlanType() {
+        let res = await getByCode('inspection_plan_type');
+        if (res?.code == 0) {
+          let list = res.data.map((item) => {
+            let key = Object.keys(item)[0];
+            return { value: key, label: item[key] };
           });
-          // this.templateCategoryList=data.templateCategoryList||[];
-        } else {
-          const code = await getCode('template_code');
-          this.dataForm.qualitySchemeTemplateCode = code;
-          this.list = [];
+          this.typeList = list;
         }
-      });
-    },
-    // 表单提交
-    dataFormSubmit() {
-      this.$refs['dataForm'].validate((valid) => {
-        if (valid) {
-          if (!this.dataForm.id) {
-            delete this.dataForm.id;
-          }
-          const saveOrUpdate = this.dataForm.id ? update : save;
+      },
+      handAdd(type) {
+        if (type == 1) {
+          this.$refs.termRef.open(this.list);
+        }
+        if (type == 2) {
+          this.$refs.equipmentRefs.open();
+        }
+      },
+      handleClose() {
+        this.visible = false;
+        this.templateCategoryList = [];
+      },
+      selectionChange(selection) {
+        console.log(selection, 'selection');
+      },
+      selectChange(list) {
+        this.list = list.map((item) => {
+          item['sort'] = item['sort'] || 0;
+          return item;
+        });
+      },
+      handDel(index, type) {
+        if (type == 1) {
+          this.list.splice(index, 1);
+        }
+        if (type == 2) {
+          this.templateCategoryList.splice(index, 1);
+        }
+      },
+      confirmChoose(list) {
+        let categoryList = list.map((item) => {
+          item['name'] = item.name;
+          item['categoryId'] = item.id;
+          item['id'] = '';
+          return item;
+        });
+        this.templateCategoryList.push(...categoryList);
+      },
+      init(id) {
+        this.getTnspectionPlanType();
+        this.dataForm.id = id || 0;
+        this.visible = true;
+        this.$nextTick(async () => {
+          this.$refs['dataForm'].resetFields();
           if (this.dataForm.id) {
-            this.dataForm.inspectionItemVOList = this.list.map((item) => {
-              if (!item.inspectionItemId) {
-                item.inspectionItemId = this.dataForm.id;
-                item.id = '';
+            getById(this.dataForm.id).then(({ data }) => {
+              this.dataForm = data;
+              let itemVOList = [];
+              if (data.inspectionItemVOList.length > 0) {
+                itemVOList = data.inspectionItemVOList.map((item) => {
+                  item.inspectionItemId = this.dataForm.id;
+                  // item.push({
+                  //   inspectionItemId: this.dataForm.id
+                  // });
+                  return item;
+                });
               }
-              return item;
+              // this.list = data.inspectionItemVOList;
+              this.list = itemVOList;
+              console.log(this.list);
             });
-          } else {
-            this.dataForm.inspectionItemVOList = this.list.map((item) => {
-              item.id = '';
-              return item;
+            templatecategoryPage({
+              templateId: this.dataForm.id,
+              size: -1
+            }).then((data) => {
+              console.log(data, 'data');
+              this.templateCategoryList = data.list;
             });
+            // this.templateCategoryList=data.templateCategoryList||[];
+          } else {
+            const code = await getCode('template_code');
+            this.dataForm.qualitySchemeTemplateCode = code;
+            this.list = [];
           }
+        });
+      },
+      saveTaskInstance(data) {
+        console.log(data, 'data');
+        this.dataForm.taskId = data.id;
+        this.dataForm.taskName = data.name;
+      },
+      // 表单提交
+      dataFormSubmit() {
+        this.$refs['dataForm'].validate((valid) => {
+          if (valid) {
+            if (!this.dataForm.id) {
+              delete this.dataForm.id;
+            }
+            const saveOrUpdate = this.dataForm.id ? update : save;
+            if (this.dataForm.id) {
+              this.dataForm.inspectionItemVOList = this.list.map((item) => {
+                if (!item.inspectionItemId) {
+                  item.inspectionItemId = this.dataForm.id;
+                  item.id = '';
+                }
+                return item;
+              });
+            } else {
+              this.dataForm.inspectionItemVOList = this.list.map((item) => {
+                item.id = '';
+                return item;
+              });
+            }
 
-          this.dataForm.templateCategoryList = this.templateCategoryList;
+            this.dataForm.templateCategoryList = this.templateCategoryList;
 
-          saveOrUpdate(this.dataForm)
-            .then((msg) => {
-              this.loading = false;
-              this.$refs['dataForm'].resetFields();
-              // this.dataForm = {};
-              const info = this.dataForm.id ? '修改成功' : '新增成功';
-              this.$message.success(info);
-              this.visible = false;
+            saveOrUpdate(this.dataForm)
+              .then((msg) => {
+                this.loading = false;
+                this.$refs['dataForm'].resetFields();
+                // this.dataForm = {};
+                const info = this.dataForm.id ? '修改成功' : '新增成功';
+                this.$message.success(info);
+                this.visible = false;
 
-              this.templateCategoryList = []; // 必加:清空物品列表
-              this.list = []; // 可选:若需清空质检项列表,可添加这行
-              // this.updateVisible(false);
-              this.$emit('refreshDataList');
-            })
-            .catch((e) => {
-              this.loading = false;
-            });
-        }
-      });
-    }
-  },
-  watch: {
-    'dataForm.type': {
-      handler(val) {
-        if (val == 2) {
-          this.templateCategoryList = [];
+                this.templateCategoryList = []; // 必加:清空物品列表
+                this.list = []; // 可选:若需清空质检项列表,可添加这行
+                // this.updateVisible(false);
+                this.$emit('refreshDataList');
+              })
+              .catch((e) => {
+                this.loading = false;
+              });
+          }
+        });
+      }
+    },
+    watch: {
+      'dataForm.type': {
+        handler(val) {
+          if (val == 2) {
+            this.templateCategoryList = [];
+          }
         }
       }
     }
-  }
-};
+  };
 </script>
 <style lang="scss" scoped>
-.title {
-  font-weight: bold;
-  padding-bottom: 20px;
-  padding-top: 20px;
-}
+  .title {
+    font-weight: bold;
+    padding-bottom: 20px;
+    padding-top: 20px;
+  }
 </style>