<template>
  <div class="mod-config">
    <!-- 条件查询 -->
    <el-form :inline="true"  label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'物料编码'">
        <el-input v-model="searchData.partNo"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料名称'">
        <el-input v-model="searchData.partDesc"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'检验模板编码'">
        <el-input v-model="searchData.codeNo"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'检验模板名称'">
        <el-input v-model="searchData.codeDesc"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'检验类型名称'">
        <el-input v-model="searchData.inspectionTypeName"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'是否在用'">
        <el-select filterable v-model="searchData.active" style="width: 130px">
          <el-option label="请选择" value=""></el-option>
          <el-option label="是" value="Y"></el-option>
          <el-option label="否" value="N"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item  :label="' '">
        <el-button @click="doEmpty()">清空</el-button>
        <el-button type="primary" @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="addModal()">新增</el-button>
      </el-form-item>
    </el-form>

    <!-- 展示列表 -->
    <el-table
      :height="height"
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="160"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="updateModal(scope.row)">修改</a>
          <a type="text" size="small" @click="detailModal(scope.row)">检验项目</a>
          <a type="text" size="small" @click="deletePropertiesModel(scope.row)">删除</a>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页栏 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 检验模板新增/修改 -->
    <el-dialog title="检验模板"  :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="430px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(1043)"><a herf="#">物料编码</a></span>
          <el-input v-model="modalData.partNo" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="物料名称:">
          <el-input v-model="modalData.partDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>

      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(1045)"><a herf="#">检验类型编码</a></span>
          <el-input v-model="modalData.inspectionTypeNo" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="检验类型名称:">
          <el-input v-model="modalData.inspectionTypeName" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>

      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="检验模板编码:">
          <el-input v-model="modalData.codeNo" :disabled="modalDisableFlag" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="检验模板名称:">
          <el-input v-model="modalData.codeDesc"  style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="是否在用:">
          <el-select filterable v-model="modalData.active" style="width: 120px">
            <el-option label="是" value="Y"></el-option>
            <el-option label="否" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveData()">保存</el-button>
        <el-button type="primary" @click="modalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 检验项目 -->
    <el-dialog title="检验项目清单" :close-on-click-modal="false" v-drag :visible.sync="detailModelFlag" width="830px">
      <el-form :inline="true"  label-position="top"  @keyup.enter.native="getDataList()">
        <el-form-item :label="'检验模板编码'">
          <el-input v-model="detailData.codeNo"  readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'检验模板名称'">
          <el-input v-model="detailData.codeDesc"  readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item  :label="' '">
          <el-button  type="primary" @click="addDetailModal()">新增</el-button>
          <el-button  type="primary" @click="addFastModal()">快速新增</el-button>
        </el-form-item>
      </el-form>
      <!-- 检验项目展示列表 -->
      <el-table
        :height="300"
        :data="detailList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in columnDetailList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed==''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="130"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" v-if="scope.row.valueChooseFlag=='Y'" @click="chooseModal(scope.row)">可选值</a>
            <a type="text" size="small"  @click="deleteModalDetails(scope.row)">删除项目</a>
          </template>
        </el-table-column>

      </el-table>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="detailModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 检验项目->新增 -->
    <el-dialog title="添加项目" :close-on-click-modal="false" v-drag :visible.sync="addDetailModalFlag" width="300px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(1034)"><a herf="#">检验项目编码</a></span>
          <el-input v-model="detailData.itemNo"  @blur="itemNoBlur"  style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="检验项目名称:">
          <el-input v-model="detailData.itemDesc"  disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveModalDetails()">保存</el-button>
        <el-button type="primary" @click="addDetailModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 检验项目->快速新增 -->
    <el-dialog title="快速添加" @close="refreshDetailList" :close-on-click-modal="false" v-drag :visible.sync="fastAddFlag" width="800px">
      <div style="font-size: 12px">
        检验模板编码：<el-input v-model="detailData.codeNo" readonly style="width: 120px"></el-input>
        检验模板名称：<el-input v-model="detailData.codeDesc" readonly style="width: 120px"></el-input>
      </div>
      <el-container style="margin-top: -12px;">
        <el-main style="width: 300px">
          <span  style="font-size: 12px" >可选项目：</span>
          <el-table
            height="300px"
            :data="itemList1"
            border
            @row-click="clickItem1"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              prop="itemNo"
              header-align="center"
              align="left"
              min-width="110"
              label="项目编码">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="left"
              min-width="170"
              label="项目名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 100px">
          <div style="margin-top: 100px">
            <el-button type="primary" @click="addItem()">添加>></el-button>
          </div>
          <div style="margin-top: 20px">
            <el-button type="primary" @click="deleteItem()">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 300px">
          <span  style="font-size: 12px" >已有项目：</span>
          <el-table
            height="300px"
            :data="itemList2"
            border
            @row-click="clickItem2"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              prop="itemNo"
              header-align="center"
              align="left"
              min-width="110"
              label="项目编码">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="left"
              min-width="170"
              label="项目名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
            <el-footer  style="height:40px;margin-top: 20px;text-align:center">
              <el-button type="primary" @click="fastAddFlag = false">关闭</el-button>
            </el-footer>
    </el-dialog>

    <!-- 检验项目->可选值 -->
    <el-dialog title="可选值" :close-on-click-modal="false" v-drag :visible.sync="chooseModalFlag" width="350px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="检验项目名称:">
          <el-input v-model="chooseModalData.itemDesc"  disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'检测值类型'">
          <el-select filterable v-model="chooseModalData.valueTypeDb" disabled style="width: 120px">
            <el-option label="文本" value="T"></el-option>
            <el-option label="数字" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-table
        :height="300"
        :data="chooseTableData"
        border
        style="width: 100%">
        <el-table-column
          prop="availableValue"
          header-align="center"
          align="left"
          min-width="200"
          label="属性值">
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    qcPartModelSearch,
    qcPartModelSave,
    qcPartModelUpdate,
    qcPartModelDelete,
    searchItemAvailable,
    searchModalDetails,
    saveModalDetails,
    deleteModalDetails,
    qcCheckOutItemSearch, // 搜索项目
    getItemLists // 获取项目列表
  } from "@/api/qc/qc.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  export default {
    components: {
      Chooselist
    },
    watch: {
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.codeNo = this.searchData.codeNo.toUpperCase()
        }
      },

      itemData: {
        deep: true,
        handler: function (newV, oldV) {
          this.itemData.itemNo = this.itemData.itemNo.toUpperCase()
        }
      },
      modalData: {
        deep: true,
        handler: function (newV, oldV) {
          this.modalData.codeNo = this.modalData.codeNo.toUpperCase()
        }
      },
      detailData: {
        deep: true,
        handler: function (newV, oldV) {
          this.detailData.codeNo = this.detailData.codeNo.toUpperCase()
          this.detailData.itemNo = this.detailData.itemNo.toUpperCase()
        }
      }
    },
    data () {
      return {
        tagNo:'',
        searchData: {
          codeNo: '',
          codeDesc: '',
          active:'',
          familyName:'',
          functionType:'E',
          inspectionTypeName:'',
          page: 1,
          limit: 10,
        },
        height: 200,
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        addDetailModalFlag:false,
        modalFlag:false,
        modalDisableFlag:false,
        modalData:{
          flag:'',
          codeNo:'',
          codeDesc:'',
          partNo:'',
          partDesc:'',
          active:'',
          functionType:'E',
          inspectionTypeNo:'',
          inspectionTypeName:'',
          createdBy:this.$store.state.user.name
        },
        detailData:{
          codeNo:'',
          codeDesc:'',
          functionType:'E',
          itemNo:'',
          itemDesc:'',
          itemType:'D',
          createdBy:this.$store.state.user.name
        },
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableCodeNo',
            tableId: "301003Table",
            tableName: "检验模板表",
            columnProp: 'codeNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验模板编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableCodeDesc',
            tableId: "301003Table",
            tableName: "检验模板表",
            columnProp: 'codeDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验模板名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableCodeNo',
            tableId: "301003Table",
            tableName: "检验模板表",
            columnProp: 'partNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableCodeNo',
            tableId: "301003Table",
            tableName: "检验模板表",
            columnProp: 'partDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '物料名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 160,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableCodeDesc',
            tableId: "301003Table",
            tableName: "检验模板表",
            columnProp: 'inspectionTypeName',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验类型名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableActive',
            tableId: "301003Table",
            tableName: "检验模板表",
            columnProp: 'active',
            headerAlign: "center",
            align: "left",
            columnLabel: '在用',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 40,
          },
        ],
        detailModelFlag:false,
        detailList: [],
        chooseTableData:[],
        dataListLoading: false,
        dataListSelections: [],

        // modalDisableFlag:false,
        chooseModalFlag:false,
        itemFlag:'text',
        itemData:{
          itemNo:'',
          valueNo:'',
          availableValue:'',
          itemType:'D',
          createdBy: this.$store.state.user.name
        },
        dataList:[],
        departmentList:[],
        // 展示列集
        columnDetailList: [
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003Table2EamPropertiesItemID',
            tableId: "301003Table2",
            tableName: "检验项目表",
            columnProp: 'itemNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验项目编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003Table2EamPropertiesItemDesc',
            tableId: "301003Table2",
            tableName: "检验项目表",
            columnProp: 'itemDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '检验项目名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003Table2ValueType',
            tableId: "301003Table2",
            tableName: "检验项目表",
            columnProp: 'valueType',
            headerAlign: "center",
            align: "left",
            columnLabel: '检测值类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003Table2DefaultValue',
            tableId: "301003Table2",
            tableName: "检验项目表",
            columnProp: 'defaultValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '参照值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003Table2MaxValue',
            tableId: "301003Table2",
            tableName: "检验项目表",
            columnProp: 'maxValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '最大值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003Table2MinValue',
            tableId: "301003Table2",
            tableName: "检验项目表",
            columnProp: 'minValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '最小值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 301003,
            serialNumber: '301003TableValueChooseFlag',
            tableId: "301003Table2",
            tableName: "common",
            columnProp: 'valueChooseFlag',
            headerAlign: "center",
            align: "left",
            columnLabel: '是否值可选',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
        ],
        levelList:[],
        chooseModalData:{
          itemNo: '',
          itemDesc: '',
          itemType:'D',
          valueTypeDb:'',
        },
        // 快速添加
        fastAddFlag:false,
        itemList1:[],
        itemList2:[],
        itemListRow1:{},
        itemListRow2:{},
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },
    created () {
      this.getDataList();
    },
    methods: {
      // 清空搜索栏
      doEmpty(){
        this.searchData = {
          codeNo: '',
          codeDesc: '',
          active:'',
          familyName:'',
          functionType:'E',
          inspectionTypeName:'',
          page: 1,
          limit: 10,
        }
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 1034) {
            strVal = this.detailData.itemNo
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1043) {
            strVal = this.modalData.partNo
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1045) {
            strVal = this.modalData.inspectionTypeNo
            this.$refs.baseList.init(val, strVal)
          }
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1034) {
          this.detailData.itemNo = val.ItemNo
          this.detailData.itemDesc = val.ItemDesc
        }
        if (this.tagNo === 1043) {
          this.modalData.partNo = val.part_no
          this.modalData.partDesc = val.part_desc
        }
        if (this.tagNo === 1045) {
          this.modalData.inspectionTypeNo = val.inspection_type_no
          this.modalData.inspectionTypeName = val.inspection_type_name
        }
      },
      // 获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        qcPartModelSearch(this.searchData).then(({data}) => {
          if (data.code == 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      addModal(){
        this.modalData={
          flag:'1',
          codeNo:'',
          codeDesc:'',
          active:'Y',
          partNo: '',
          partDesc: '',
          functionType:'E',
          inspectionTypeNo:'',
          inspectionTypeName:'',
          createdBy:this.$store.state.user.name
        };
        this.modalDisableFlag = false;
        this.modalFlag = true;
      },
      updateModal(row){
        this.modalData={
          flag:'2',
          codeNo:row.codeNo,
          codeDesc:row.codeDesc,
          active:row.active,
          partNo: row.partNo,
          partDesc: row.partDesc,
          inspectionTypeNo: row.inspectionTypeNo,
          inspectionTypeName:row.inspectionTypeName,
          functionType:'E',
          createdBy:this.$store.state.user.name
        };
        this.modalDisableFlag=true;
        this.modalFlag=true;
      },
      // 删除
      deletePropertiesModel (row) {
        this.$confirm(`是否删除这个检验模板?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          qcPartModelDelete(row).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      saveData(){
        if (this.modalData.codeNo == '' || this.modalData.codeNo == null) {
          this.$alert('请输入检验模板编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.codeDesc == '' || this.modalData.codeDesc == null) {
          this.$alert('请输入检验模板名称！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.partNo == '' || this.modalData.partNo == null) {
          this.$alert('请选择物料编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.inspectionTypeNo == '' || this.modalData.inspectionTypeNo == null) {
          this.$alert('请选择检验类型！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.active == '' || this.modalData.active == null) {
          this.$alert('选择是否在用！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.modalData.flag == '1'){
          qcPartModelSave(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.modalFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }else {
          qcPartModelUpdate(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.modalFlag=false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },
      //打开检验项目清单
      detailModal(row){
        this.detailData.codeNo = row.codeNo
        this.detailData.codeDesc = row.codeDesc
        searchModalDetails(this.detailData).then(({data}) => {
          this.detailList = data.rows
        })
        this.detailModelFlag = true;
      },

      // 普通新增
      addDetailModal(){
        this.detailData.itemNo = '';
        this.detailData.itemDesc = '';
        this.addDetailModalFlag = true;
      },

      // 快速新增
      addFastModal(){
        this.itemListRow2 = null
        this.itemListRow1 = null
        getItemLists(this.detailData).then(({data}) => {
          this.itemList1 = data.row1;
          this.itemList2 = data.row2;
        })
        this.fastAddFlag = true;
      },

      clickItem1(row){
        this.itemListRow1 = JSON.parse(JSON.stringify(row));
      },
      clickItem2(row){
        this.itemListRow2 = JSON.parse(JSON.stringify(row));
      },
      // 添加项目
      addItem(){
        if(this.itemListRow1==null){
          this.$alert("请选择可选项目！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let inData={
          codeNo:this.detailData.codeNo,
          codeDesc:this.detailData.codeDesc,
          functionType:this.detailData.functionType,
          itemNo: this.itemListRow1.itemNo,
          itemDesc:this.itemListRow1.itemDesc,
          itemType:this.detailData.itemType,
          userId:this.$store.state.user.name
        }
        saveModalDetails(inData).then(({data}) => {
          if (data && data.code == 0) {
            getItemLists(this.detailData).then(({data}) => {
              this.itemList1=data.row1;
              this.itemList2=data.row2;
            })
            this.itemListRow1=null
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      // 删除项目
      deleteItem(){
        if(this.itemListRow2 == null){
          this.$alert("请选择已选项目！", '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        let inData = {
          codeNo:this.detailData.codeNo,
          codeDesc:this.detailData.codeDesc,
          functionType:this.detailData.functionType,
          itemNo: this.itemListRow2.itemNo,
          itemDesc:this.itemListRow2.itemDesc,
          itemType:this.detailData.itemType,
          userId:this.$store.state.user.name
        }
        deleteModalDetails(inData).then(({data}) => {
          if (data && data.code === 0) {
            getItemLists(this.detailData).then(({data}) => {
              this.itemList1 = data.row1;
              this.itemList2 = data.row2;
            })
            this.itemListRow2 = null
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      // 关闭后刷新列表
      refreshDetailList(){
        searchModalDetails(this.detailData).then(({data}) => {
          this.detailList = data.rows
        })
      },

      // 保存模板中的项目明细
      saveModalDetails(){
        if(this.detailData.itemNo == "" || this.detailData.itemNo == null){
          this.$alert('请选择检验项目编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        saveModalDetails(this.detailData).then(({data}) => {
          if (data && data.code == 0) {
            searchModalDetails(this.detailData).then(({data}) => {
              this.detailList = data.rows
            })
            this.addDetailModalFlag=false;
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      itemNoBlur(){
        let inData={
          itemType:'D',
          itemNo:this.detailData.itemNo
        }
        qcCheckOutItemSearch(inData).then(({data}) => {
         if(data.rows.length>0){
           this.detailData.itemDesc = data.rows[0].itemDesc
         }else {
           this.detailData.itemDesc=''
         }
        })
      },
      // 删除模板中的项目
      deleteModalDetails(row){
        console.log(row)
        this.$confirm(`是否删除这个检验项目?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteModalDetails(row).then(({data}) => {
            if (data && data.code === 0) {
              searchModalDetails(this.detailData).then(({data}) => {
                this.detailList = data.rows
              })
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      chooseModal(row){
        this.chooseModalData.itemNo=row.itemNo;
        this.chooseModalData.itemDesc=row.itemDesc;
        this.chooseModalData.valueTypeDb=row.valueTypeDb;
        searchItemAvailable(this.chooseModalData).then(({data}) => {
          this.chooseTableData = data.rows
        })
        this.chooseModalFlag=true;
      },

    }
  }
</script>
