Crunchy
2025-04-29 e5454b769d44a34af423bf87ac8a740bf8c20341
src/views/structural/capabilityAndLaboratory/capability/index.vue
@@ -3,633 +3,402 @@
    <div>
      <el-row class="title">
        <el-col :span="12" style="text-align: left">
          <el-radio-group v-model="radio" @input="selectorSwitch" size="medium" fill="#409EFF">
          <el-radio-group v-model="radio" size="medium" fill="#409EFF" @change="refreshTable">
            <el-radio-button :label="0">检验项目参数</el-radio-button>
            <el-radio-button :label="1">检验对象</el-radio-button>
          </el-radio-group>
        </el-col>
        <el-col :span="12" style="text-align: right;">
<!--          <el-button size="medium" @click="$refs.itemParameterTable.openUpload()" v-if="inPower">-->
<!--            <i class="el-icon-upload2" style="color: #3A7BFA;"></i>-->
<!--            <span style="color: #3A7BFA;">导入</span></el-button>-->
          <el-button size="medium" type="primary" v-if="radio == 1 && importExcel" @click="uploadDia = true">导入</el-button>
          <el-button size="medium" type="primary" @click="openAdd()" v-if="addPower">新增</el-button>
          <!-- <el-button size="medium" icon="el-icon-delete">删除</el-button> -->
          <el-upload v-if="radio === 0" ref='upload1'
                     style="display: inline;margin-right: 8px"
                     :action="uploadAction1"
                     :before-upload="beforeUpload1" :headers="token" :on-error="onError1"
                     :on-success="handleSuccessUp1" :show-file-list="false" accept='.doc,.docx,.xls,.xlsx'>
            <el-button size="small" type="primary">导入</el-button>
          </el-upload>
          <el-button size="small" type="primary" v-if="radio === 1" @click="uploadDia = true">导入</el-button>
          <el-button size="small" type="primary" @click="openAdd()">新增</el-button>
        </el-col>
      </el-row>
    </div>
    <div v-if="radio==0" class="bodys">
      <div class="search">
        <div class="search_thing">
          <div class="search_label">检验项:</div>
          <div class="search_input"><el-input size="small" placeholder="请输入" clearable
                                              v-model="itemParameterForm.inspectionItem" @keyup.enter.native="refreshTable()"></el-input></div>
        </div>
        <div class="search_thing">
          <div class="search_label">检验子项:</div>
          <div class="search_input"><el-input size="small" placeholder="请输入" clearable
                                              v-model="itemParameterForm.inspectionItemSubclass" @keyup.enter.native="refreshTable()"></el-input>
          </div>
        </div>
        <div class="search_thing">
          <div class="search_label">检验对象:</div>
          <div class="search_input"><el-input size="small" placeholder="请输入" clearable
                                              v-model="itemParameterForm.sample" @keyup.enter.native="refreshTable()"></el-input>
          </div>
        </div>
        <div class="search_thing" style="padding-left: 30px;">
          <el-button size="small" @click="refresh()">重 置</el-button>
          <el-button size="small" type="primary" @click="refreshTable()">查 询</el-button>
        </div>
    <div>
      <el-form :model="itemParameterForm" ref="itemParameterForm" size="small" :inline="true">
        <el-form-item label="检验项" prop="inspectionItem" v-if="radio===0">
          <el-input size="small" placeholder="请输入" clearable
                    v-model="itemParameterForm.inspectionItem" @keyup.enter.native="refreshTable()">
          </el-input>
        </el-form-item>
        <el-form-item label="检验子项" prop="inspectionItemSubclass" v-if="radio===0">
          <el-input size="small" placeholder="请输入" clearable
                    v-model="itemParameterForm.inspectionItemSubclass" @keyup.enter.native="refreshTable()">
          </el-input>
        </el-form-item>
        <el-form-item label="检验对象" prop="sample" v-if="radio===0">
          <el-input size="small" placeholder="请输入" clearable
                    v-model="itemParameterForm.sample" @keyup.enter.native="refreshTable()">
          </el-input>
        </el-form-item>
        <el-form-item label="检验对象" prop="specimenName" v-if="radio===1">
          <el-input size="small" placeholder="请输入" clearable
                    v-model="itemParameterForm.specimenName" @keyup.enter.native="refreshTable()">
          </el-input>
        </el-form-item>
        <el-form-item label="零件号" prop="partNo" v-if="radio===1">
          <el-input size="small" placeholder="请输入" clearable
                    v-model="itemParameterForm.partNo" @keyup.enter.native="refreshTable()">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="refreshTable">查询</el-button>
          <el-button size="mini" @click="refresh">重置</el-button>
        </el-form-item>
      </el-form>
<!--      检验项目参数表格-->
      <div class="table" v-if="radio===0">
        <lims-table :tableData="tableData" :column="column" key="tableData"
                    @pagination="pagination" :height="'calc(100vh - 290px)'"
                    :page="page" :tableLoading="tableLoading"></lims-table>
      </div>
      <div class="table">
<!--        <ValueTable ref="itemParameterTable"-->
<!--                    :url="$api.capacityScope.selectItemParameterList" v-if="PROJECT === '检测中心'"-->
<!--                    :upUrl="$api.capacityScope.upItemParameter" :delUrl="$api.capacityScope.delItemParameter"-->
<!--                    :inputUrl="$api.capacityScope.importData" :componentData="itemParameterData" :key="upIndex" />-->
<!--        <ValueTable ref="itemParameterTable" :url="$api.capacityScope.selectItemParameterList" v-if="PROJECT === '装备电缆'"-->
<!--                    :upUrl="$api.capacityScope.upItemParameter" :delUrl="$api.capacityScope.delItemParameter"-->
<!--                    :inputUrl="$api.capacityScope.importEquipData" :componentData="itemParameterData" :key="upIndex" />-->
<!--      检验对象表格-->
      <div class="table" v-if="radio===1">
        <lims-table :tableData="testObjectTableData" :column="testObjectColumn" key="testObjectTableData"
                    @pagination="pagination" :height="'calc(100vh - 290px)'"
                    :page="testObjectPage" :tableLoading="tableLoading"></lims-table>
      </div>
    </div>
    <div class="bodys">
      <div class="search" v-if="radio==1">
        <div class="search_thing">
          <div class="search_label">检验对象:</div>
          <div class="search_input"><el-input size="small" placeholder="请输入" clearable
                                              v-model="testObjectData.entity.specimenName" @keyup.enter.native="refreshTable()"></el-input></div>
        </div>
        <div class="search_thing" style="padding-left: 30px;">
          <el-button size="small" @click="refresh()">重 置</el-button>
          <el-button size="small" type="primary" @click="refreshTable()">查 询</el-button>
        </div>
      </div>
      <div class="table" v-if="radio==1">
<!--        <ValueTable ref="testObjectTable" :url="$api.capacityScope.selectTestObjectList"-->
<!--                    :upUrl="$api.capacityScope.upTestObject" :delUrl="$api.capacityScope.delTestObject"-->
<!--                    :componentData="testObjectData" :key="upIndex" />-->
      </div>
    </div>
    <el-dialog title="产品维护" :visible.sync="diaProduct" width="600px">
      <div class="body" v-if="diaProduct" style="height: 350px;overflow-y: auto;padding: 5px 0;">
<!--        <ValueTable ref="productData" :url="$api.capacityScope.selectProductListByObjectId"-->
<!--                    :upUrl="$api.capacityScope.upProduct" :delUrl="$api.capacityScope.delProduct"-->
<!--                    :componentData="productData" :key="upIndex"/>-->
      </div>
    <!--产品维护弹框-->
    <el-dialog title="产品维护" :visible.sync="diaProduct" width="900px">
      <lims-table :tableData="productData" :column="productColumn" height="460"
                  @pagination="productPagination"
                  :page="productPage" :tableLoading="productableLoading"></lims-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="diaProduct = false">取 消</el-button>
        <el-button type="primary" @click="openAdd2" :loading="productLoad">新 增</el-button>
        <el-button type="primary" @click="editProduct('add')" :loading="productLoad">新 增</el-button>
      </span>
    </el-dialog>
    <el-dialog title="数据导入" :visible.sync="uploadDia" width="500px">
<!--      <div style="margin: 0 auto;">-->
<!--        <el-upload ref="upload" drag :action="javaApi + $api.capacityScope.importExcel" :headers="token" :file-list="fileList" name="file"-->
<!--                   :auto-upload="false" accept=".xlsx" :limit="1" :on-change="beforeUpload" :on-success="onSuccess"-->
<!--                   :on-error="onError">-->
<!--          <i class="el-icon-upload"></i>-->
<!--          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>-->
<!--        </el-upload>-->
<!--      </div>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadDia = false">取 消</el-button>
        <el-button type="primary" @click="submitUpload()" :loading="uploading">上 传</el-button>
      </span>
    </el-dialog>
    <!-- 编辑 新增 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose">
      <el-form :model="addOrupdateForm" label-width="120px" :rules="rules" inline ref="addOrupdateForm"  size="mini">
        <el-form-item label="检验项" prop="inspectionItem">
          <el-input v-model="addOrupdateForm.inspectionItem" placeholder="请输入检验项" size="mini" style="width: 220px;"></el-input>
    <!--产品维护编辑-->
    <el-dialog title="操作产品维护" :visible.sync="productEditDia" width="400px">
      <el-form :model="productEditForm" ref="productEditForm" :rules="productRules" label-position="right" label-width="100px">
        <el-form-item label="产品名称" prop="name">
          <el-input size="small" placeholder="请输入" clearable v-model="productEditForm.name"></el-input>
        </el-form-item>
        <el-form-item label="检验项EN" >
          <el-input v-model="addOrupdateForm.inspectionItemEn" placeholder="请输入检验项EN" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="检验项子项" >
          <el-input v-model="addOrupdateForm.inspectionItemSubclass" placeholder="请输入检验项子项" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="检验子项EN" >
          <el-input v-model="addOrupdateForm.inspectionItemSubclassEn" placeholder="请输入检验子项EN" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="检验对象" >
          <el-cascader
            size="mini" style="width: 220px;"
            filterable
            v-model="addOrupdateForm.sample"
            :options="tree"
            :props="{value:'name',label: 'name', multiple: true, checkStrictly: true }"
            clearable></el-cascader>
          <!-- <el-input v-model="addOrupdateForm.sample" placeholder="请输入检验对象" size="mini" style="width: 220px;"></el-input> -->
        </el-form-item>
        <el-form-item label="单价(元)" >
          <el-input v-model="addOrupdateForm.price" placeholder="请输入单价" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="场所" >
          <el-select v-model="addOrupdateForm.laboratory" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in laboratory"
              :key="item.value"
              :label="item.label"
              :value="item.label">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="试验室" prop="sonLaboratory">
          <el-select v-model="addOrupdateForm.sonLaboratory" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.sonLaboratory"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="要求描述" >
          <el-input v-model="addOrupdateForm.askTell" placeholder="请输入要求描述" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="要求值" >
          <el-input v-model="addOrupdateForm.ask" placeholder="请输入要求值" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="计量单位" prop="unit">
          <el-select v-model="addOrupdateForm.unit" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.unit"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工时(H)" >
          <el-input v-model="addOrupdateForm.manHour" placeholder="请输入工时" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="预计时间(H)" prop="manDay">
          <el-input v-model="addOrupdateForm.manDay" placeholder="请输入预计时间" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="工时分组" >
          <el-input v-model="addOrupdateForm.manHourGroup" placeholder="请输入工时分组" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="检验项类型" prop="inspectionItemType">
          <el-select v-model="addOrupdateForm.inspectionItemType" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.inspectionItemType"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检验值类型" prop="inspectionValueType">
          <el-select v-model="addOrupdateForm.inspectionValueType" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.inspectionValueType"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="字典类型" >
          <el-select v-model="addOrupdateForm.dic" clearable filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.dic"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="特殊标识符">
          <el-select v-model="addOrupdateForm.bsm" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.bsm"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="原始记录模板" prop="templateId">
          <el-select v-model="addOrupdateForm.templateId" filterable size="small" style="width: 220px;">
            <el-option
              v-for="item in dicList.templateId"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检验项分类" >
          <el-input v-model="addOrupdateForm.inspectionItemClass" placeholder="请输入检验项分类" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="检验项分类EN" >
          <el-input v-model="addOrupdateForm.inspectionItemClassEn" placeholder="请输入检验项分类EN" size="mini" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="试验方法" prop="method">
          <el-select v-model="addOrupdateForm.method" filterable multiple  size="small" style="width: 220px;">
            <el-option
              v-for="(item,index) in dicList.method"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        <el-form-item label="产品名称EN" prop="nameEn">
          <el-input size="small" placeholder="请输入" clearable v-model="productEditForm.nameEn">
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="saveOrEnit">确 定</el-button>
    </span>
        <el-button @click="closeProduct">取 消</el-button>
        <el-button :loading="uploading" type="primary" @click="submitProduct">确 认</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="uploadDia" title="数据导入" width="500px">
      <div style="margin: 0 auto;">
        <el-upload ref="upload" :action="uploadAction"
                   :auto-upload="false" :file-list="fileList"
                   :headers="token" :limit="1"
                   :on-change="beforeUpload" :on-error="onError" :on-success="onSuccess" accept=".xlsx" drag
                   name="file">
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
        </el-upload>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadDia = false">取 消</el-button>
        <el-button :loading="uploading" type="primary" @click="submitUpload()">上 传</el-button>
      </span>
    </el-dialog>
    <!--检验项目参数-编辑弹框-->
    <EditForm ref="editForm" @refreshList="refreshList1"></EditForm>
    <testObjectEditForm ref="testObjectEditForm" @refreshList="refreshList"></testObjectEditForm>
    <BindPartDialog v-if="bindPartDialog" :bindPartDialog="bindPartDialog"
                    :currentRow="currentRow"
                    :type="type"
                    @closeBindPartDialog="closeBindPartDialog"></BindPartDialog>
    <BindSupplierDensityDialog v-if="bindSupplierDensityDialog"
                               :bindSupplierDensityDialog="bindSupplierDensityDialog"
                               :currentRow="currentSupplierDensityRow"
                               @closeBindPartDialog="closeBindSupplierDensityDialog"></BindSupplierDensityDialog>
  </div>
</template>
<script>
// import ValueTable from '../tool/value-table.vue'
import {addItemParameter, getItemTree, upItemParameter} from "@/api/structural/capability";
import {obtainItemParameterList} from "@/api/structural/laboratoryScope";
import {selectStandardMethods} from "@/api/structural/standardMethod";
import BindPartDialog from "@/views/structural/capabilityAndLaboratory/capabilityComponents/bindPartDialog.vue"
import BindSupplierDensityDialog from "@/views/structural/capabilityAndLaboratory/capabilityComponents/bindSupplierDensityDialog.vue"
import {
  addProduct,
  delItemParameter, delProduct, delTestObject, selectItemParameterList, selectProductListByObjectId,
  selectTestObjectList, upProduct,
} from "@/api/structural/capability";
import limsTable from "@/components/Table/lims-table.vue";
import EditForm from "@/views/structural/capabilityAndLaboratory/capabilityComponents/EditForm.vue";
import testObjectEditForm from "@/views/structural/capabilityAndLaboratory/capabilityComponents/testObjectEditForm.vue";
import {getToken} from "@/utils/auth";
import { obtainItemParameterList } from '@/api/structural/laboratoryScope'
export default {
  name: 'Capability',
  components: {limsTable, EditForm, testObjectEditForm, BindPartDialog, BindSupplierDensityDialog},
  data() {
    return {
      dicList: {
        inspectionItemType: [],
        inspectionValueType: [],
        bsm: [],
        sonLaboratory: [],
        unit: [],
        dic: [],
        method: [],
      uploadAction: process.env.VUE_APP_BASE_API + '/capacityScope/importExcel',
      uploadAction1: process.env.VUE_APP_BASE_API + '/capacityScope/importEquipData',
      tableData: [],
      tableLoading: false,
      column: [
        {label: '检验项', prop: 'inspectionItem'},
        {label: '检验项EN', prop: 'inspectionItemEn'},
        {label: '检验子项', prop: 'inspectionItemSubclass'},
        {label: '检验子项EN', prop: 'inspectionItemSubclassEn'},
        {label: '检验项分类', prop: 'inspectionItemClass'},
        {label: '检验项分类EN', prop: 'inspectionItemClassEn'},
        {label: '检验对象', prop: 'sample'},
        {label: '单价(元)', prop: 'price'},
        {label: '试验室', prop: 'sonLaboratory'},
        {label: '要求描述', prop: 'askTell'},
        {label: '要求值', prop: 'ask'},
        {label: '计量单位', prop: 'unit'},
        {label: '工时(H)', prop: 'manHour'},
        {label: '预计时间(H)', prop: 'manDay'},
        {label: '工时分组', prop: 'manHourGroup'},
        {label: '创建时间', prop: 'createTime'},
        {label: '修改时间', prop: 'updateTime'},
        {label: '条件', prop: 'radiusList'},
        {
          dataType: 'action',
          fixed: 'right',
          label: '操作',
          width: '140px',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.editForm(row);
              },
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.delete(row);
              },
            },
          ]
        }
      ],
      page: {
        total:0,
        size:10,
        current:1
      },
      testObjectTableData: [],
      testObjectColumn: [
        {
          dataType: 'tag',
          label: '场所',
          prop: 'laboratoryId',
          minWidth: '130',
          formatData: (params) => {
            let index = this.laboratoryList.findIndex(item => item.value == params)
            if(index > -1) {
              return this.laboratoryList[index].label
            }else {
              return null
            }
            // if (params == 1) {
            //   return '装备电缆试验室'
            // } else if (params == 5) {
            //   return '通信产品实验室'
            // } else if (params == 6) {
            //   return '电力产品实验室'
            // } else if (params == 8) {
            //   return '储能产品实验室'
            // } else {
            //   return '射频线缆实验室'
            // }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params == 5) {
              return 'info'
            } else if (params == 6) {
              return 'warning'
            } else if (params == 8) {
              return 'danger'
            } else {
              return null
            }
          }
        },
        {label: '检验对象', prop: 'specimenName'},
        {label: '检验对象EN', prop: 'specimenNameEn'},
        {label: '产品', prop: 'product'},
        {label: '对象代号', prop: 'code'},
        {label: '对象类型', prop: 'objectType',
          dataType: 'tag',
          formatData: (params) => {
            if (params == 1) {
              return '原材料'
            } else if (params == 2) {
              return '成品'
            } else {
              return '辅材'
            }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params == 2) {
              return 'info'
            } else {
              return 'warning'
            }
          }},
        {label: '创建人', prop: 'createUserName'},
        {label: '更新人', prop: 'updateUserName'},
        {label: '创建时间', prop: 'createTime'},
        {label: '更新时间', prop: 'updateTime'},
        {
          dataType: 'action',
          fixed: 'right',
          label: '操作',
          width: '240px',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.editTestObjectForm(row);
              },
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.deleteTest(row);
              },
            },
            {
              name: '产品维护',
              type: 'text',
              clickFun: (row) => {
                this.upProduct(row);
              },
            },
            {
              name: '零件绑定',
              type: 'text',
              clickFun: (row) => {
                this.bindPartFirst(row);
              },
            },
          ]
        }
      ],
      testObjectPage: {
        total:0,
        size:10,
        current:0
      },
      addOrUpdate: '',
      addOrupdateForm:{
        inspectionItem: '',
        inspectionItemEn: '',
        inspectionItemSubclass: '',
        inspectionItemSubclassEn: '',
        sample: null,
        price: '',
        laboratory: '',
        sonLaboratory: '',
        askTell: '',
        ask: '',
        unit: '',
        manHour: '',
        manDay: '',
        manHourGroup: '',
        inspectionItemType: '',
        inspectionValueType: '',
        dic: '',
        bsm: '',
        templateId: '',
        inspectionItemClass: '',
        inspectionItemClassEn: '',
        method: []
      },
      tree: null,
      rules:{
        inspectionItem: [
          { required: true, message: '请输入检验项', trigger: 'blur' }
        ],
        sonLaboratory: [
          { required: true, message: '请输入试验室', trigger: 'change' }
        ],
        unit: [
          { required: true, message: '请输入计量单位', trigger: 'change' }
        ],
        manDay: [
          { required: true, message: '请输入预计时间', trigger: 'blur' }
        ],
        inspectionItemType: [
          { required: true, message: '请输入检验项类型', trigger: 'change' }
        ],
        inspectionValueType: [
          { required: true, message: '请输入检验值类型', trigger: 'change' }
        ],
        method: [
          { required: true, message: '请选择试验方法', trigger: 'change' }
        ],
        templateId: [
          { required: true, message: '请输入原始记录模板', trigger: 'change' }
        ],
      },
      dialogVisible: false,
      loading: true,
      itemParameterForm: {
        inspectionItem: null,
        inspectionItemSubclass: null,
        sample: null
        sample: null,
        specimenName: null,
        partNo: null
      },
      logining:false,
      radio: 0,
      showItemParameter: true,
      showTestObject: false,
      itemParameterData: {
        entity: {
          inspectionItem: null,
          inspectionItemSubclass: null,
          sample: null,
          orderBy: {
            field: 'id',
            order: 'asc'
          }
        },
        isIndex: true,
        showSelect: false,
        select: true,
        row: 2,
        do: [{
          id: 'update',
          font: '编辑',
          type: 'text',
          method: 'openAdd',
          field: []
        }, {
          id: 'delete',
          font: '删除',
          type: 'text',
          method: 'doDiy'
        }],
        tagField: {
        },
        selectField: {
          inspectionItemType: {
            select: []
          },
          bsm: {
            select: []
          },
          inspectionValueType: {
            select: []
          },
          laboratory: {
            select: []
          },
          templateId: {
            select: []
          },
          method: {
            select: [],
            choose: true
          },
          sonLaboratory: {
            select: []
          },
          unit: {
            select: []
          },
          dic: {
            select: []
          },
        },
        cascaderField:{
          sample:{
            tree:[]
          },
          // 字段配置
          props:{
            value:'name',
            label:'name',
            checkStrictly: true,
            multiple: true
          }
        },
        requiredAdd: ['sonLaboratory', 'inspectionItem', 'inspectionItemType', 'inspectionValueType',
          'unit', 'method', 'manDay', 'templateId'
        ],
        requiredUp: ['sonLaboratory', 'inspectionItem', 'inspectionItemType', 'inspectionValueType',
          'unit', 'method', 'manDay', 'templateId'
        ],
        accept: '.xlsx',
        inputType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        needSort: ['createTime', 'updateTime', 'inspectionItem', 'inspectionItemSubclass', 'sample'],
      },
      testObjectData: {
        entity: {
          specimenName: null,
          orderBy: {
            field: 'id',
            order: 'asc'
          }
        },
        isIndex: true,
        showSelect: false,
        select: true,
        do: [{
          id: 'update',
          font: '编辑',
          type: 'text',
          method: 'doDiy',
          field: ['createUserName', 'updateUserName', 'product']
        }, {
          id: 'delete',
          font: '删除',
          type: 'text',
          method: 'doDiy'
        }, {
          font: '产品维护',
          type: 'text',
          method: 'upProduct'
        }],
        tagField: {
          laboratoryId: {
            select: []
          }
        },
        selectField: {
          laboratoryId: {
            select: []
          }
        },
        requiredAdd: ['specimenName', 'code', 'laboratoryId'],
        requiredUp: ['specimenName', 'code', 'laboratoryId'],
        needSort: ['createTime', 'updateTime', 'specimenName'],
      },
      itemParameterEntityCopy: {},
      testObjectDataEntityCopy: {},
      upIndex: 0,
      addDia: false,
      addPower: true,
      select: 0,
      laboratory: [],
      productLoad: false,
      diaProduct: false,
      productData: {
        entity: {
          objectId: 0,
          orderBy: {
            field: 'id',
            order: 'asc'
          }
        },
        isPage: false,
        isIndex: true,
        showSelect: false,
        select: true,
        do: [{
          id: 'update',
          font: '编辑',
          type: 'text',
          method: 'doDiy',
          field: []
        }, {
          id: 'delete',
          font: '删除',
          type: 'text',
          method: 'doDiy'
        }],
        tagField: {},
        selectField: {},
        requiredAdd: ['name','nameEn'],
        requiredUp: ['name','nameEn'],
      productColumn: [
        {label: '产品名称', prop: 'name'},
        {label: '产品名称EN', prop: 'nameEn'},
        {
          dataType: 'action',
          label: '操作',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.editProduct('edit', row);
              },
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.deleteProduct(row);
              },
            },
            {
              name: '零件绑定',
              type: 'text',
              clickFun: (row) => {
                this.bindPartSecond(row);
              },
            },
            {
              name: '厂家密度绑定',
              type: 'text',
              clickFun: (row) => {
                this.bindSupplierDensitySecond(row);
              },
            },
          ]
        }
      ],
      productData: [],
      productPage: {
        total:0,
        size:10,
        current:1,
        partNo: null,
        layout: 'total, prev, pager, next'
      },
      inPower: true,
      importExcel: false,
      productableLoading: false,
      productEditDia: false,
      operationType: '',
      productEditForm: {
        objectId: '',
        id: '',
        name: '',
        nameEn: ''
      },
      objectId: '',
      productRules: {
        name: [{ required: true, message: '请填写产品名称', trigger: 'blur' }],
        nameEn: [{ required: true, message: '请填写产品名称EN', trigger: 'blur' }]
      },
      uploadDia: false,
      fileList: [],
      token: null,
      token: {Authorization: "Bearer " + getToken()},
      uploading: false,
      currentRow: {}, // 选择零件绑定本条数据的信息
      currentSupplierDensityRow: {}, // 选择零件绑定本条数据的信息
      bindSupplierDensityDialog: false,
      bindPartDialog: false,
      type: null,  // 零件绑定的类型--0:检验对象,1:产品维护,
      laboratoryList:[]
    }
  },
  created() {
    if (this.PROJECT === '装备电缆') {
      this.itemParameterData.requiredUp = ['sonLaboratory', 'inspectionItem', 'inspectionItemType', 'inspectionValueType',
        'unit', 'manDay', 'templateId'
      ]
    }
  },
  mounted() {
    this.token = {
      'token': sessionStorage.getItem('token')
    }
    this.itemParameterEntityCopy = this.HaveJson(this.itemParameterData.entity)
    this.testObjectDataEntityCopy = this.HaveJson(this.testObjectData.entity)
    this.obtainItemParameterList() //场所
    this.selectStandardMethods()    // 试验方法
    this.selectTestObjectByName()
    this.getStandardTemplate() // 原始记录模板
    this.selectDocUnit()
    this.selectAllNeedEnum()
    this.getItemParameterList()
    this.refreshTable()
  },
  computed: {
    title() {
      return this.addOrUpdate == 1 ? '新增' : '编辑'
      return this.addOrUpdate === 1 ? '新增' : '编辑'
    }
  },
  methods: {
    //查询需要的全部枚举
    selectAllNeedEnum(){
      // this.$axios.post(this.$api.enums.selectEnumListByCategory,
      //   {categoryList:['检验项类型','取值类型','是否','检验值类型','子实验室','单位']},{
      //     headers: {
      //       'Content-Type': 'application/json'
      //     }
      //   }).then(res => {
      //   res.data['检验项类型'].forEach(ele => {
      //     if(ele.label.indexOf('非采集')==0)ele.type='info'
      //   });
      //   this.dicList.sonLaboratory = res.data['子实验室']
      //   this.dicList.unit = res.data['单位']
      //   this.dicList.inspectionItemType = res.data['检验项类型']
      //   this.dicList.inspectionValueType = res.data['检验值类型']
      //   this.dicList.bsm = res.data['是否']
      // })
    },
    saveOrEnit() {
      console.log('this.addOrupdateForm', this.addOrupdateForm.sample);
      let flag = true
      this.$refs['addOrupdateForm'].validate((valid) => {
        if (valid) {
          flag = false
          return false
        }
      });
      if(flag) return
      if(this.addOrupdateForm.sample != null && this.addOrupdateForm.sample != '' && this.addOrupdateForm.sample != undefined ) {
        if(this.addOrupdateForm.sample.length > 0) {
          this.addOrupdateForm.sample = JSON.stringify(this.addOrupdateForm.sample)
        }else{
          this.addOrupdateForm.sample = '[]'
        }
      }else{
        this.addOrupdateForm.sample = '[]'
      }
      // 1是新增
      if(this.addOrUpdate == 1) {
        this.addOrupdateForm.method = JSON.stringify(this.addOrupdateForm.method)
        addItemParameter(this.addOrupdateForm).then(res => {
          if(res.code == 200) {
            this.$message.success('新增成功')
            this.refreshTable()
            this.handleClose()
            this.dialogVisible = false
          } else {
            // 报错 将转换的method 以及 sample 转换回来
            this.addOrupdateForm.method = JSON.parse(this.addOrupdateForm.method)
            this.addOrupdateForm.sample = JSON.parse(this.addOrupdateForm.sample)
            this.$message.error(res.message)
          }
        })
      }else{
        this.addOrupdateForm.method = JSON.stringify(this.addOrupdateForm.method)
        upItemParameter(this.addOrupdateForm).then(res => {
          if(res.code == 200) {
            this.$message.success('编辑成功')
            this.refreshTable()
            this.handleClose()
            this.dialogVisible = false
          } else {
            // 报错 将转换的method 以及 sample 转换回来
            this.addOrupdateForm.method = JSON.parse(this.addOrupdateForm.method)
            this.addOrupdateForm.sample = JSON.parse(this.addOrupdateForm.sample)
            this.$message.error(res.message)
          }
        })
      }
    },
    handleClose() {
      this.dialogVisible = false
      this.addOrupdateForm = {
        inspectionItem: '',
        inspectionItemEn: '',
        inspectionItemSubclass: '',
        inspectionItemSubclassEn: '',
        sample: null,
        price: '',
        laboratory: '',
        sonLaboratory: '',
        askTell: '',
        ask: '',
        unit: '',
        manHour: '',
        manDay: '',
        manHourGroup: '',
        inspectionItemType: '',
        inspectionValueType: '',
        dic: '',
        bsm: '',
        templateId: '',
        inspectionItemClass: '',
        inspectionItemClassEn: '',
        method: null
      }
      this.$refs['addOrupdateForm'].resetFields();
      this.addOrUpdate = ''
    },
    submitUpload() {
      if (this.$refs.upload.uploadFiles.length == 0) {
      if (this.$refs.upload.uploadFiles.length === 0) {
        this.$message.error('未选择文件')
        return
      }
@@ -640,12 +409,11 @@
      this.$refs.upload.clearFiles()
      this.uploadDia = false
      this.uploading = false
      if (response.code == 201) {
        this.$message.error(response.message)
      if (response.code !== 200) {
        this.$message.error(response.msg)
        return
      }
      this.$message.success('上传成功')
      this.standardList = []
      this.productList = []
      this.refreshTable()
    },
@@ -655,143 +423,263 @@
      this.uploading = false
    },
    beforeUpload(file, fileList) {
      if (file.raw.type != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
        this.$message.error('上传文件格式不正确');
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        return false;
      } else {
        return true;
      }
    },
    selectorSwitch(radio) {
      if (this.radio === '0') {
        this.showItemParameter = true;
        this.showTestObject = false;
        this.selectTestObjectByName()
        /* this.$nextTick(() => {
          this.$refs.itemParameterTable.selectList()
        }) */
    onError1(err, file, fileList) {
      this.$message.error('上传失败')
      this.$refs.upload1.clearFiles()
      this.uploading = false
    },
    beforeUpload1(file, fileList) {
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload1.clearFiles()
        return false;
      } else {
        this.showTestObject = true;
        this.showItemParameter = false;
        return true;
      }
    },
    handleSuccessUp1 (response, file, fileList) {
      this.$refs.upload1.clearFiles()
      if (response.code !== 200) {
        this.$message.error(response.msg)
        return
      }
      this.$message.success('上传成功')
      this.refreshTable()
    },
    refreshList () {
      this.refreshTable()
    },
    refreshList1 () {
      this.refreshTable()
    },
    refreshTable() {
      this.itemParameterData.entity.inspectionItem = this.itemParameterForm.inspectionItem
      this.itemParameterData.entity.inspectionItemSubclass = this.itemParameterForm.inspectionItemSubclass
      this.itemParameterData.entity.sample = this.itemParameterForm.sample
      if (this.radio === '0') {
        // this.$refs['itemParameterTable'].selectList()
      this.tableLoading = true
      if (this.radio === 0) {
        selectItemParameterList({...this.page, ...this.itemParameterForm}).then(res => {
          this.tableLoading = false
          if (res.code === 200) {
            this.tableData = res.data.records
            this.page.total = res.data.total
          }
        }).catch(err => {
          this.tableLoading = false
        })
      } else {
        // this.$refs['testObjectTable'].selectList()
        selectTestObjectList({...this.testObjectPage, ...this.itemParameterForm}).then(res => {
          this.tableLoading = false
          if (res.code === 200) {
            this.testObjectTableData = res.data.records
            this.testObjectPage.total = res.data.total
          }
        }).catch(err => {
          this.tableLoading = false
        })
      }
    },
    refresh() {
      this.itemParameterData.entity = this.HaveJson(this.itemParameterEntityCopy)
      this.testObjectData.entity = this.HaveJson(this.testObjectDataEntityCopy)
      this.upIndex++
      this.resetForm('itemParameterForm')
      this.page.current = 1
      this.refreshTable()
    },
    openAdd(row) {
      //0代表检验参数tab
      if (this.radio === '0') {
        // this.$refs.itemParameterTable.openAddDia(this.$api.capacityScope.addItemParameter);
        if(!row) {
          this.addOrUpdate = 1
        }else{
          if(typeof row.sample == 'string') {
            row.sample = JSON.parse(row.sample)
          }
          this.addOrUpdate = ''
          this.addOrupdateForm = JSON.parse(JSON.stringify(row))
        }
        this.dialogVisible = true
    pagination (page) {
      this.page.size = page.limit
      this.refreshTable()
    },
    // 检验项目参数新增
    openAdd() {
      if (this.radio === 0) {
        this.$refs.editForm.openDia('add')
      } else {
        // this.$refs.testObjectTable.openAddDia(this.$api.capacityScope.addTestObject);
        this.$refs.testObjectEditForm.openDia('add')
      }
    },
    selectDocUnit() {
      // this.$axios.post(this.$api.enums.getDic).then(res => {
      //   this.dicList.dic = res.data.map(m => {
      //     return {
      //       label: m,
      //       value: m
      //     }
      //   })
      // })
    // 检验项目参数-打开修改弹框
    editForm (row) {
      this.$refs.editForm.openDia('edit', row)
    },
    obtainItemParameterList() {
    // 检验项目参数-删除
    delete (row) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delItemParameter({id:row.id}).then(res => {
          if (res.code === 200) {
            this.$message.success('删除成功')
            this.refreshTable();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      })
    },
    // 检验对象-打开修改弹框
    editTestObjectForm (row) {
      this.$refs.testObjectEditForm.openDia('edit', row)
    },
    // 检验项目参数-删除
    deleteTest (row) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delTestObject({id:row.id}).then(res => {
          if (res.code === 200) {
            this.$message.success('删除成功')
            this.refreshTable();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      })
    },
    // 产品维护
    upProduct(row) {
      this.diaProduct = true
      this.objectId = row.id
      this.productPage.current = 1
      this.productPage.partNo = this.itemParameterForm.partNo
      this.getProductList(row)
    },
    // 查询产品维护列表数据
    getProductList () {
      const params = {
        objectId: this.objectId,
      }
      this.productableLoading = true
      selectProductListByObjectId({...params, ...this.productPage}).then(res => {
        this.productableLoading = false
        this.productData = res.data.records
        this.productPage.total = res.data.total
      }).catch(err => {
        this.productableLoading = false
      })
    },
    // 产品维护列表分页
    productPagination(page) {
      this.productPage.current = page.page
      this.getProductList()
    },
    // 产品维护-新增-编辑
    editProduct (type, row) {
      this.productEditDia = true
      this.operationType = type
      if (type === 'edit') {
        this.productEditForm = this.HaveJson(row)
      }
    },
    // 提交产品维护修改
    submitProduct () {
      this.$refs['productEditForm'].validate((valid) => {
        if (valid) {
          this.uploading = true
          this.productEditForm.objectId = this.objectId
          if (this.operationType === 'add') {
            addProduct(this.productEditForm).then(res => {
              this.uploading = false
              if (res.code === 200) {
                this.$message.success('新增成功')
                this.closeProduct()
                this.getProductList();
              }
            }).catch(err => {
              this.uploading = false
            })
          } else {
            upProduct(this.productEditForm).then(res => {
              this.uploading = false
              if (res.code === 200) {
                this.$message.success('新增成功')
                this.closeProduct()
                this.getProductList();
              }
            }).catch(err => {
              this.uploading = false
            })
          }
        }
      })
    },
    closeProduct() {
      this.resetForm('productEditForm')
      this.productEditDia = false
    },
    // 产品维护-删除
    deleteProduct (row) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delProduct({id:row.id}).then(res => {
          if (res.code === 200) {
            this.$message.success('删除成功')
            this.getProductList();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      })
    },
    // 零件绑定
    bindPartFirst (row) {
      this.bindPart(row, 0)
    },
    bindPartSecond (row) {
      this.bindPart(row, 1)
    },
    // 厂家密度绑定
    bindSupplierDensitySecond (row) {
      this.bindSupplierDensity(row)
    },
    // 打开厂家密度绑定弹框
    bindSupplierDensity (row) {
      this.currentSupplierDensityRow = row
      this.bindSupplierDensityDialog = true
    },
    // 打开零件绑定弹框
    bindPart (row, index) {
      this.type = index
      this.currentRow = row
      this.bindPartDialog = true
    },
    closeBindPartDialog () {
      this.bindPartDialog = false
    },
    closeBindSupplierDensityDialog () {
      this.bindSupplierDensityDialog = false
    },
    getItemParameterList(){
      obtainItemParameterList().then(res => {
        let data = []
        let data0 = []
        res.data.forEach(a => {
          data.push({
            label: a.laboratoryName,
            value: a.id
          })
          data0.push({
            label: a.laboratoryName,
            value: a.laboratoryName
          })
        })
        // this.itemParameterData.selectField.laboratory.select = data0
        // this.itemParameterData.tagField.laboratory.select = data0
        this.testObjectData.selectField.laboratoryId.select = data
        this.testObjectData.tagField.laboratoryId.select = data
        this.laboratory = data
        this.laboratoryList = data
      })
    },
    selectStandardMethods() {
      selectStandardMethods().then(res => {
        let data = []
        res.data.forEach(a => {
          data.push({
            label: a.code,
            value: a.code
          })
        })
        this.dicList.method = data
      })
    },
    selectTestObjectByName() {
      getItemTree().then(res => {
        res.data.forEach(a=>{
          this.cascaderFieldData(a)
        })
        this.itemParameterData.cascaderField.sample.tree = res.data
        this.tree = res.data
      })
    },
    cascaderFieldData(val){
      if(val.children === undefined) {
        return
      }else if(val.children.length==0){[
        delete val.children
      ]}else{
        val.children.forEach(a=>{
          this.cascaderFieldData(a)
        })
      }
    },
    getStandardTemplate() {
      // this.$axios.get(this.$api.StandardTemplate.getStandardTemplate).then(res => {
      //   let data = []
      //   res.data.forEach(a => {
      //     data.push({
      //       label: a.name,
      //       value: a.id,
      //       type: 'success'
      //     })
      //   })
      //   // this.itemParameterData.selectField.templateId.select = data
      //   // this.itemParameterData.tagField.templateId.select = data
      //   this.dicList.templateId = data
      // })
    },
    upProduct(row) {
      this.productData.entity.objectId = row.id
      this.diaProduct = true
    },
    openAdd2(){
      // this.$refs.productData.openAddDia(this.$api.capacityScope.addProduct, {objectId: this.productData.entity.objectId});
    },
    }
  }
}
</script>