<template>
  <div>
    <Row>
      <!--查询-->
      <Col span="24">
        111111
        <Form id="data-input-contract-right" :label-width="90" inline onsubmit="return false">
          <label class="label-sign"></label>
          <Form-item class="search-item-select">
            <SelectInput ref="selInput1" :optionList="optionList" :judgeList="judgeList"
                         @on-result-change="_selInputResult1" compare-keyword="testBasis"
                         keyword="name"
                         placeholder="请输入检测项目"></SelectInput>
          </Form-item>
          <Form-item class="search-item-select">
            <SelectInput ref="selInput2" :optionList="optionList" :judgeList="judgeList"
                         @on-result-change="_selInputResult2" compare-keyword="name"
                         keyword="testBasis"
                         placeholder="请输入检测依据"></SelectInput>
          </Form-item>
          <Form-item class="search-btn">
            <Button @click="_formSearch" type="primary">搜索</Button>
          </Form-item>
        </Form>
      </Col>
      <!--操作-->
      <Col span="24">
        <btn-list :msg="btn" @on-result-change="_btnClick" :showBtnNum="7" class="contHide"></btn-list>
      </Col>
      <Col span="24">
        <PTVXETableData
          ref="pageTable"
          :tableHeight="tableHeight"
          :getPage="getPage"
          :table-name="tableName"
          :pageColumns="pageColumns"
          @on-result-change="_tableResultChange"
          :rows="100">
          <vxe-table-column
            v-for="item in userColumns.length > 0 ?userColumns:pageColumns"
            :key="item.key"
            :field="item.key"
            :title="item.title"
            :min-width="item.width?item.width:200"
            :fixed="item.fixed?item.fixed:undefined"
            :edit-render="item.editCell?{autofocus: 'input'}:null"
            sortable
          >
            <!--可编辑模板-->
<!--            <template v-slot:edit="{ row,rowIndex }">-->
<!--              <div v-if="item.key === 'name'" :style="{color:colorComputed(row.planEndDate)}">-->
<!--                {{row.key}}-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='testValue'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <el-input v-model="row.testValue" @blur="_save(item.key)" @focus="_handleRow({row:row,index:rowIndex})"-->
<!--                          @keyup.enter.native="_enterSave({scope:{row:row,rowIndex:rowIndex},fieldName:item.key,msg:'enter'})" placeholder="请输入检测值"-->
<!--                          size="small">-->

<!--                </el-input>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='retestValue'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <el-input v-model="row.retestValue" @blur="_save(item.key)" @focus="_handleRow({row:row,index:rowIndex})"-->
<!--                          placeholder="请输入复测测值" size="small"></el-input>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='unit'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <AutoCompletes :value="row.unit" :downData="unitList" @on-result-change="_unitChange"-->
<!--                               :handleObj="{row:row,index:rowIndex}" show-key="name" placeholder="请输入或选择单位"-->
<!--                               blur-->
<!--                ></AutoCompletes>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='qualified'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <Select v-model="row.qualified.value" @on-change="_saveQualified"-->
<!--                        :class="[{'selected-test-red':row.qualified.value==='NOT_OK'},-->
<!--              {'selected-test-green':row.qualified.value==='OK'},-->
<!--              {'selected-test-warn':row.qualified.value==='NO_JUDGE'}]"-->
<!--                        placeholder="结果判定">-->
<!--                  <Option value="WAIT_SYSTEM">待判定</Option>-->
<!--                  <Option value="OK">合格</Option>-->
<!--                  <Option value="NOT_OK">不合格</Option>-->
<!--                  <Option value="NO_JUDGE">不判定</Option>-->
<!--                </Select>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='singleConclusion'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <Select v-model="row.singleConclusion" @on-open-change="_saveSel" multiple>-->
<!--                  <Option v-for="item in singleConclusionList" :value="item.name" :key="item.id">{{item.name}}-->
<!--                  </Option>-->
<!--                </Select>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='testBasisFull'&&edit" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <AutoCompletesTestBasis :value="row.testBasisFull" :downData="testBasisData"-->
<!--                                        @on-result-change="_testBasisChange" :handleObj="{row:row,index:rowIndex}"-->
<!--                                        placeholder="请输入或选择检测依据" focus blur-->
<!--                ></AutoCompletesTestBasis>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='testMethod'&&edit" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <AutoCompletes :value="row.testMethod" :downData="testMethodData" @on-result-change="_testMethodChange"-->
<!--                               :handleObj="{row:row,index:rowIndex}" show-key="testMethod" placeholder="请输入或选择检测方法" blur-->
<!--                               focus-->
<!--                ></AutoCompletes>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='detectionType'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <Select v-model="row.detectionType" @on-change="_save(item.key)" placeholder="请选择检出类别" clearable>-->
<!--                  <Option v-for="item in detectionTypeList" :key="item.name" :value="item.name">-->
<!--                    {{item.name}}-->
<!--                  </Option>-->
<!--                </Select>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='detection'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <el-input v-model="row.detection" @blur="_save(item.key)" @focus="_handleRow({row:row,index:rowIndex})"-->
<!--                          placeholder="请输入检出限" size="small"></el-input>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='judgeBasis'&&edit" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <AutoCompletes :value="row.judgeBasis" :downData="judgeBasisData" @on-result-change="_judgeBasisChange"-->
<!--                               :handleObj="{row:row,index:rowIndex}" show-key="judgeBasis" placeholder="请输入或选择判定依据" focus-->
<!--                               blur-->
<!--                ></AutoCompletes>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='judgeBasisName'&&edit" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <AutoCompletes :value="row.judgeBasisName" :downData="judgeBasisNameData" @on-result-change="_judgeBasisNameChange"-->
<!--                               :handleObj="{row:row,index:rowIndex}" show-key="judgeBasisName" placeholder="请输入或选择判定依据名称" focus-->
<!--                               blur-->
<!--                ></AutoCompletes>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='limitDefault'&&edit" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <el-input v-model="row.limitDefault" @focus="_handleRow({row:row,index:rowIndex})" @change="_handleLimitDefalut"-->
<!--                          placeholder="请输入限量" size="small"></el-input>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='limitType'&&edit" @click="_handleRow({row:row,index:rowIndex})">-->
<!--              <span>-->
<!--              <el-input v-model="row.limitType" @blur="_save(item.key)" @focus="_handleRow({row:row,index:rowIndex})"-->
<!--                        placeholder="请输入限量类别" style="width:70%"-->
<!--                        size="small"></el-input>-->
<!--              </span>-->
<!--                <span>-->
<!--              <el-popover-->
<!--                placement="bottom"-->
<!--                width="700"-->
<!--                trigger="click">-->
<!--              <el-table :data="limitData" @row-click="_selLimit" :height="240" clas="pop-table"-->
<!--                        stripe border size="small" highlight-current-row>-->
<!--              <el-table-column width="80" property="firstClass" label="大类"></el-table-column>-->
<!--              <el-table-column width="80" property="secondClass" label="亚类"></el-table-column>-->
<!--              <el-table-column width="80" property="thirdClass" label="次亚类"></el-table-column>-->
<!--              <el-table-column width="80" property="fourthClass" label="细类"></el-table-column>-->
<!--              <el-table-column width="80" property="testParameter" label="产品"></el-table-column>-->
<!--              <el-table-column width="100" property="limitDefault" label="限量"></el-table-column>-->
<!--              <el-table-column width="100" property="limitType" label="限量类别"></el-table-column>-->
<!--              <el-table-column width="100" property="unit" label="单位"></el-table-column>-->
<!--              </el-table>-->
<!--              <a slot="reference" @click.native.stop="_getLimit(row)">选择</a>-->
<!--              </el-popover>-->
<!--              </span>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='judged'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <Select v-model="row.judged" placeholder="是否判定" disabled>-->
<!--                  <Option :value="0">否</Option>-->
<!--                  <Option :value="1">是</Option>-->
<!--                </Select>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='labRemark'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <el-input v-model="row.labRemark" @blur="_save(item.key)" @focus="_handleRow({row:row,index:rowIndex})"-->
<!--                          placeholder="请输入说明" size="small"></el-input>-->
<!--              </div>-->
<!--              <div v-else-if="item.key==='planEndDate'">-->
<!--                {{ row[item.key]?$dateformat(row[item.key],'yyyy-mm-dd'):''}}-->
<!--              </div>-->
<!--              <div v-else-if="item.date">{{row[item.key]?$dateformat(row[item.key],'yyyy-mm-dd'):''}}</div>-->
<!--              <div v-else-if="item.key==='progress'">{{row[item.key].display}}</div>-->
<!--              <a v-else-if="item.key==='num'" @click="_sampleDetail(row)">{{row[item.key]}}</a>-->
<!--              <div v-else-if="item.key === 'distanceWeekdays'"-->
<!--                   :class="$distanceWeekdaysColor(row[item.key])" style="font-weight: bold">-->
<!--                {{row[item.key]}}-->
<!--              </div>-->
<!--              <div v-else-if="item.key === 'detectionUnit'" @click="_handleRow({row:row,index:rowIndex})">-->
<!--                <el-input v-model="row.detectionUnit" @blur="_save(item.key)" @focus="_handleRow({row:row,index:rowIndex})"-->
<!--                          placeholder="请输入检出限单位" size="small"></el-input>-->
<!--              </div>-->
<!--              <div v-else-if="item.key === 'analysisDate'" @click="_handleRow({row:row,index: rowIndex})">-->
<!--                <AnalysisDate :editAnalysisDateList="row.analysisDateList"-->
<!--                              :analysisDate="row.analysisDate" @on-result-change="_analysisDateResult"></AnalysisDate>-->
<!--              </div>-->
<!--              <div v-else>{{row[item.key]}}</div>-->
<!--            </template>-->
            <!--只读模板-->
            <template v-slot="{ row }">
              <div v-if="item.key === 'name'" :style="{color:colorComputed(row.planEndDate)}">
                {{row.name}}
              </div>
              <div v-else-if="item.key==='qualified'">
                <span v-if="row.qualified.value === 'WAIT_SYSTEM'">待判定</span>
                <span v-else-if="row.qualified.value === 'OK'" class="green-color">合格</span>
                <span v-else-if="row.qualified.value === 'NOT_OK'" class="red-color">不合格</span>
                <span v-else-if="row.qualified.value === 'NO_JUDGE'" class="warning-color">不判定</span>
              </div>
              <div v-else-if="item.key==='singleConclusion'">
                {{row.singleConclusion.join(',')}}
              </div>

              <div v-else-if="item.key==='judged'">
                {{row.judged === 1?'是':'否'}}
              </div>
              <div v-else-if="item.key==='planEndDate'">
                {{ row[item.key]?$dateformat(row[item.key],'yyyy-mm-dd'):''}}
              </div>
              <div v-else-if="item.date">{{row[item.key]?$dateformat(row[item.key],'yyyy-mm-dd'):''}}</div>
              <div v-else-if="item.key==='progress'">{{row[item.key].display}}</div>
              <a v-else-if="item.key==='num'" @click="_sampleDetail(row)">{{row[item.key]}}</a>
              <div v-else-if="item.key === 'distanceWeekdays'"
                   :class="$distanceWeekdaysColor(row[item.key])" style="font-weight: bold">
                {{row[item.key]}}
              </div>
              <div v-else>{{row[item.key]}}</div>
            </template>
          </vxe-table-column>
          <template slot="col">
            <vxe-table-column
              :width="150"
              title="操作"
              align="center"
              fixed="right">
              <template slot-scope="scope">
                <VXEIconList :msg="(scope.row.recordId) ? iconMsg : iconMsgDisable"
                             @on-result-change="_iconClick" :rowData="scope.row"></VXEIconList>
              </template>
            </vxe-table-column>
          </template>
          <VXESettingCol slot="setting" :pageColumns="pageColumns" :userColumns="userColumns"
                         @on-result-change="_page" :table-name="tableName"></VXESettingCol>
        </PTVXETableData>
      </Col>
    </Row>

<!--    <component ref="refModal" :is="currentComponent" @on-result-change="_modalResult" is-change="true"></component>-->

    <ModalConfirm ref="confirmModal" @on-result-change="_confirmResult" :btnModalList="btnModalList"
                  content="该项目已绑定资质项目，请选择更新完善或者新增资质项目！"></ModalConfirm>
    <!--原始记录模板选择-->
    <!--    <OriginalRecordTemplate ref="recordTemp" @on-result-change="_tempResult"></OriginalRecordTemplate>-->
    <!--原始记录填写-->
    <!--    <OriginalRecordWrite ref="recordWrite" @on-result-change="_page"></OriginalRecordWrite>-->
  </div>
</template>
<script>
import { meterManageItem } from '../../../api'
// import AutoCompletes from '../../../components/base/AutoCompletes'
import SelEquip from '../../../components/select-equip/SelEquip'
import AssignPerson from '../../../components/user-info-single/assignPerson'
// import Forward from '../Forward'
// import Judge from '../Judge'
// import DetectionValue from '../DetectionValue'
// import FoodItemRecord from '../../../record/FoodItemRecord'
// import SpecialCharacter from '../SpecialCharacter'
import Global from '../../../api/config'
// import ImportItem from '../ImportItem'
// import AutoCompletesTestBasis from '../../../marketManage/food-item/AutoCompletesTestBasis'
// import FoodSampleCompanyDetail from '../../../marketManage/food-sample-company/FoodSampleCompanyDetail'
// import FoodSampleGovernDetail from '../../../marketManage/food-sample-govern/FoodSampleGovernDetail'
import Reason from '../../../components/base/Reason'
import VXESettingCol from '../../../components/base/VXESettingCol'
// import AddLibOutStd from '../AddLibOutStd'
// import RelevantDataQuery from '../RelevantDataQuery'
// import MaintainInfoModal from '../../../maintainInfo/MaintainInfoModal'
import ModalConfirm from '../../../components/base/ModalConfirm'
import SelectInput from './SelectInput'
// import CopyHisItem from '../copy-his-item/CopyHisItem'
// import OriginalRecordEdit from '../../original-record/OriginalRecordEdit'
// import OriginalRecordWrite from '../../original-record/OriginalRecordWrite'
// import OriginalRecordTemplate from '../../original-record/OriginalRecordTemplate'
// import ItemReset from '../ItemReset'
// import AnalysisDate from '../AnalysisDate'
// import DataInputItemBack from '../DataInputItemBack'
// import SelectTestStep from '../../../../../food/aptutudeManage/food-test-step-manage/SelectTestStep'
// import BatchRecordView from '../../original-record/BatchRecordView'

export default {
  components: {
    // BatchRecordView,
    // SelectTestStep,
    // MaintainInfoModal,
    VXESettingCol,
    // AutoCompletes,
    // AutoCompletesTestBasis,
    // Forward,
    // eslint-disable-next-line vue/no-unused-components
    SelEquip,
    // Judge,
    // DetectionValue,
    // FoodItemRecord,
    // eslint-disable-next-line vue/no-unused-components
    AssignPerson,
    // SpecialCharacter,
    // ImportItem,
    // FoodSampleCompanyDetail,
    // FoodSampleGovernDetail,
    SelectInput,
    // eslint-disable-next-line vue/no-unused-components
    Reason,
    // AddLibOutStd,
    // RelevantDataQuery,
    ModalConfirm
    // CopyHisItem,
    // OriginalRecordTemplate,
    // OriginalRecordEdit,
    // OriginalRecordWrite,
    // ItemReset,
    // AnalysisDate,
    // DataInputItemBack
  },
  data() {
    return {
      formObj: {
        aptitudeId: [],
        name: '',
        code: '',
        standardName: ''
      },
      tableName: 'food-data-input-contract-right',
      // 用户自己选中的列
      userColumns: [],
      currentComponent: '',
      edit: false,
      btnModalList: [
        { type: 'primary', name: '更新' },
        { type: 'primary', name: '新增' },
        { type: '', name: '取消' }
      ],
      optionList: [
        { key: 'name', name: '检测项目', placeholder: '请输入检测项目' },
        { key: 'testBasis', name: '检测依据', placeholder: '请输入检测依据' },
        // {
        //   key: 'qualifiedValue',
        //   name: '结果判定',
        //   placeholder: '请选择结果判定',
        //   multiple: true
        // },
        { key: 'num', name: '样品编号', placeholder: '请输入样品编号' },
        { key: 'code', name: '委托编号', placeholder: '请输入委托编号' },
        { key: 'sampleName', name: '样品名称', placeholder: '请输入样品名称' },
        { key: 'firstClass', name: '大类', placeholder: '请输入大类' },
        { key: 'detectType', name: '细类', placeholder: '请输入细类' },
        {
          key: 'sampleRemark',
          name: '样品备注',
          placeholder: '请输入样品备注'
        },
        {
          key: 'planDate',
          name: '计划完成时间',
          placeholder: '请选择计划完成时间',
          date: true
        },
        {
          key: 'reportDueDate',
          name: '应出报告日期',
          placeholder: '请选择应出报告日期',
          date: true
        },
        {
          key: 'receiveDate',
          name: '接收日期',
          placeholder: '请选择接收日期',
          date: true,
          dateToMin: true
        },
        { key: 'limitDefault', name: '限量', placeholder: '请输入限量' }
      ],
      judgeList: [
        { name: '待判定', value: '0' },
        { name: '不判定', value: '5' },
        { name: '合格', value: '7' },
        { name: '不合格', value: '9' }
      ],
      btn: [
        { type: 'primary', id: 'food-data-input-build-batch', name: '建批' },
        { type: 'primary', id: 'food-data-input-auto-judge', name: '自动判定' },
        {
          type: 'primary',
          id: 'food-data-input-submit-check',
          name: '提交至复核'
        },
        {
          type: 'primary',
          id: 'food-data-input-select-checker',
          name: '选择复核人',
          componentName: 'AssignPerson'
        },
        { type: 'primary', id: 'food-data-input-submit', name: '提交至审核' },
        {
          type: 'primary',
          id: 'food-data-input-select-auditor',
          name: '选择审核人',
          componentName: 'AssignPerson'
        },
        {
          type: 'primary',
          id: 'food-data-input-submit-report',
          name: '提交至报告'
        },
        { type: 'primary', id: 'food-data-input-submit-end', name: '无需报告' },
        {
          type: 'primary',
          id: 'food-data-input-abort',
          name: '终止检测',
          componentName: 'Reason'
        },
        { id: 'food-data-input-judge', name: '判定', componentName: 'Judge' },
        { id: '', name: '仪器', componentName: 'SelEquip' },
        { id: '', name: '批量填写', componentName: 'DetectionValue' },
        { id: 'food-data-input-edit-original-record', name: '填写原始记录' },
        {
          id: 'food-data-input-batch-record-views',
          name: '查看合并记录',
          componentName: 'BatchRecordView'
        },
        { id: '', name: '导出' },
        { id: '', name: '导入', componentName: 'ImportItem' },
        {
          id: 'food-data-input-forward',
          name: '转发',
          componentName: 'Forward'
        },
        { id: '', name: '特殊字符箱', componentName: 'SpecialCharacter' },
        {
          id: 'food-data-input-back',
          name: '退回',
          componentName: 'DataInputItemBack'
        },
        {
          id: 'food-data-input-item-reset',
          name: '检测项目重置',
          componentName: 'ItemReset'
        },
        {
          id: 'food-data-input-copy-his-data',
          name: '复制历史数据',
          componentName: 'CopyHisItem'
        },
        {
          id: 'food-data-input-lib-out-std',
          name: '填写库外检测依据',
          componentName: 'AddLibOutStd'
        },
        {
          id: 'food-data-input-save-to-lab',
          name: '存到资质库',
          componentName: ''
        },
        { type: '', id: 'food-data-input-maintain-info', name: '信息维护' }
      ],
      currentRow: {},
      currentIndex: -1,
      unitList: [],
      unitListTemp: [],
      testBasisData: [],
      testBasisNameData: [],
      judgeBasisData: [],
      judgeBasisNameData: [],
      limitData: [],
      testMethodData: [],
      singleConclusionList: [],
      detectionTypeList: [],
      detectionDate: '',
      getPage: {
        records: []
      },
      pageColumns: [
        { title: '检测项目', key: 'name', width: 120, fixed: 'left' },
        { title: '比较符', key: 'compare', width: 180, fixed: 'left' },
        { title: '限量值', key: 'limitValue', width: 140 },
        { title: '单位', key: 'unit', width: 160 },
        { title: '是否判定', key: 'judged', width: 120, editCell: true },
        { title: '备注', key: 'remark', width: 120, editCell: true }
        // { title: '限量', key: 'limitDefault', width: 120, editCell: true },
        // { title: '限量类别', key: 'limitType', width: 160, editCell: true },
        // { title: '说明', key: 'labRemark', width: 140, editCell: true },
        // { title: '结果判定', key: 'qualified', width: 120, editCell: true },
        // {
        //   title: '单项结论',
        //   key: 'singleConclusion',
        //   width: 200,
        //   editCell: true
        // },
        // { title: '复测值', key: 'retestValue', width: 120, editCell: true },
        // { title: '是否判定', key: 'judged', width: 100 },
        // { title: '委托单位', key: 'cname', width: 180 },
        // { title: '委托编号', key: 'code', width: 180 },
        // { title: '制单日期', key: 'ctime', width: 120, date: true },
        // { title: '数据出具日期', key: 'resultDate', width: 120, date: true },
        // { title: '计划完成时间', key: 'planEndDate', width: 120, date: true },
        // { title: '距离收检工作日', key: 'distanceWeekdays', width: 130 },
        // { title: '应出报告日期', key: 'reportDueDate', width: 120, date: true },
        // { title: '检测依据', key: 'testBasisFull', width: 380, editCell: true },
        // { title: '检测方法', key: 'testMethod', width: 220, editCell: true },
        // { title: '检出类别', key: 'detectionType', width: 140, editCell: true },
        // { title: '检出限', key: 'detection', width: 120, editCell: true },
        // {
        //   title: '检出限单位',
        //   key: 'detectionUnit',
        //   width: 120,
        //   editCell: true
        // },
        // { title: '判定依据', key: 'judgeBasis', width: 160, editCell: true },
        // {
        //   title: '判定依据名称',
        //   key: 'judgeBasisName',
        //   width: 220,
        //   editCell: true
        // },
        // { title: '仪器编号', key: 'equipNum', width: 200 },
        // { title: '仪器名称', key: 'equipName', width: 220 },
        // { title: '分析时间', key: 'analysisDate', width: 240, editCell: true },
        // { title: '排序号', key: 'sortNo', width: 220 },
        // { title: '类别', key: 'firstDetectClass', width: 220 },
        // { title: '项目备注', key: 'remark' },
        // { title: '样品备注', key: 'sampleRemark' },
        // { title: '委托备注', key: 'contractRemark' }
        // {title: '委托编号', key: 'code', width: 180},
        // {title: '状态', key: 'progress', width: 120,},
        // {title: '样品状态', key: 'sampleStatus', width: 120,},
      ],
      iconMsg: [
        {
          type: 'edit',
          id: 'food-data-input-original-record-edit',
          name: '编辑原始记录',
          componentName: 'OriginalRecordEdit'
        },
        {
          type: 'cloud',
          id: '',
          name: '样品附件',
          componentName: 'FileManage'
        },
        {
          type: 'search',
          id: '',
          name: '相关数据查询',
          componentName: 'RelevantDataQuery'
        },
        {
          type: 'ios-clock',
          id: '',
          name: '操作日志',
          componentName: 'FoodItemRecord'
        }
      ],
      iconMsgDisable: [
        {
          type: 'edit',
          id: 'food-data-input-original-record-edit',
          name: '编辑原始记录',
          componentName: 'OriginalRecordEdit',
          disabled: true
        },
        {
          type: 'cloud',
          id: '',
          name: '样品附件',
          componentName: 'FileManage'
        },
        {
          type: 'search',
          id: '',
          name: '相关数据查询',
          componentName: 'RelevantDataQuery'
        },
        {
          type: 'ios-clock',
          id: '',
          name: '操作日志',
          componentName: 'FoodItemRecord'
        }
      ],
      leftSelectIds: [],
      selectIds: [],
      selectData: [],
      selectSampleIds: [],
      personal: '',
      // 检测步骤
      stepId: '',
      // 点击编辑时的当前的key
      currentEditKey: ''
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tabSearch')
    },
    colorComputed() {
      return function(val) {
        return val - new Date().getTime() > this.detectionDate * 86400000
          ? '#606266'
          : val - new Date().getTime() <= 0
            ? '#eb6877'
            : '#f90'
      }
    }
  },
  mounted() {
    // this._dicSearch()
  },
  methods: {
    // 从字典查预警期
    // _dicSearch() {
    //   this.$store.dispatch('LmsBaseDict/getItem', '食品检测预警天数').then(() => {
    //     let result = this.$store.state.LmsBaseDict.item;
    //     if (result.length !== 0) {
    //       this.warningValue = result[0].name;
    //       console.log(this.warningValue)
    //     }
    //   });
    // },
    // 分析时间的回传
    _analysisDateResult(msg, date, dateList) {
      switch (msg) {
        case 'selectDate':
          this.currentRow.analysisDate = date
          this.currentRow.analysisDateList = dateList
          this._save('analysisDate')
          break
      }
    },
    _dicSearch() {
      const data = [
        '数据录入常用单位',
        '允许数据录入改判定依据、检测依据',
        '检测项目单项结论',
        '食品检出类别',
        '食品检测预警天数'
      ]
      for (let i = 0; i < data.length; i++) {
        this.$store.dispatch('LmsBaseDict/getItem', data[i]).then(() => {
          const resultData = this.$store.state.LmsBaseDict.item
          switch (data[i]) {
            case '数据录入常用单位':
              this.unitList = JSON.parse(JSON.stringify(resultData))
              this.unitListTemp = JSON.parse(JSON.stringify(resultData))
              break
            case '允许数据录入改判定依据、检测依据':
              if (resultData.length > 0) {
                this.edit = resultData[0].name === '是'
              } else {
                this.edit = false
              }
              break
            case '检测项目单项结论':
              this.singleConclusionList = resultData
              break
            case '食品检出类别':
              this.detectionTypeList = resultData
              break
            case '食品检测预警天数':
              this.detectionDate = resultData[0].name
              break
          }
        })
      }
    },
    _saveSel(open) {
      if (open === false) {
        this._save('singleConclusion')
      }
    },
    _unitChange(msg, data, handleObj) {
      this._handleRow(handleObj)
      switch (msg) {
        case 'select':
          this.currentRow.unit = data.name
          this._save('unit')
          break
        case 'blur':
          this._save('unit')
          break
        case 'query':
          this.currentRow.unit = data.name
          break
      }
    },
    _modalResult(data, title) {
      switch (this.currentComponent) {
        case 'AssignPerson':
          if (title === '分配复核人') {
            this._checkerResult(data)
          } else {
            this._auditorResult(data)
          }
          break
        case 'SelEquip':
          this._equipResult(data)
          break
        case 'Reason':
          if (title === '终止原因') {
            // 终止原因
            this._itemAbort(data)
          }
          break
        case 'OriginalRecordTemplate':
          this._tempResult(data)
          break
        case 'SelectTestStep':
          this.stepId = data.id
          this._buildEnd()
          break
        case 'DataInputItemBack':
          this._resultChange('退回成功')
          break
        default:
          this._page()
      }
    },
    _resultChange(msg) {
      if (this.$store.state.FoodItem.success) {
        this.$Message.success(msg)
        this._page()
        this.selectIds = []
        this.selectData = []
        this.selectSampleIds = []
      }
    },
    _selInputResult1(msg, data) {
      switch (msg) {
        case 'keyword':
          this.$refs.selInput2._setCompareKeyword(data)
          break
        case 'search':
          this._formSearch()
          break
      }
    },
    _selInputResult2(msg, data) {
      switch (msg) {
        case 'keyword':
          this.$refs.selInput1._setCompareKeyword(data)
          break
        case 'search':
          this._formSearch()
          break
      }
    },
    _open(ids, personal) {
      this.leftSelectIds = ids
      this.personal = personal
      if (ids.length === 0) {
        this.$set(this.getPage, 'records', [])
        this.$set(this.getPage, 'total', 0)
        this.$set(this.getPage, 'current', 1)
        this.selectIds = []
        this.selectData = []
        this.selectSampleIds = []
      } else {
        this._formSearch()
      }
    },
    _searchParams() {
      const obj = {}
      const obj1 = this.$refs.selInput1._getFormObj()
      const obj2 = this.$refs.selInput2._getFormObj()
      const obj3 = { contractIds: this.leftSelectIds.join(',') }
      const obj4 = this.$refs.selInput1._qualifiedValue()
      const obj5 = this.$refs.selInput2._qualifiedValue()
      if (this.personal) {
        obj.personal = this.personal
      }
      Object.assign(obj, obj1, obj2, obj3, obj4, obj5)
      return obj
    },
    _page() {
      this.$refs.pageTable._page(
        'data-input-contract-right',
        'FoodItem/inputSapPage',
        this._searchParams()
      )
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        // case 'page':
        //   this.getPage = {
        //     total: this.$store.state.FoodItem.page.total,
        //     pages: this.$store.state.FoodItem.page.pages,
        //     current: this.$store.state.FoodItem.page.current,
        //     size: this.$store.state.FoodItem.page.size,
        //     records: []
        //   }
        //   let tableList = this.$store.state.FoodItem.page.records
        //   for (let i = 0; i < tableList.length; i++) {
        //     let obj = {
        //       aptitudeItemId:
        //         tableList[i].aptitudeItemId !== undefined
        //           ? tableList[i].aptitudeItemId
        //           : '',
        //       num: tableList[i].num !== undefined ? tableList[i].num : '',
        //       sortNo:
        //         tableList[i].sortNo !== undefined ? tableList[i].sortNo : '',
        //       name: tableList[i].name !== undefined ? tableList[i].name : '',
        //       sampleName:
        //         tableList[i].sampleName !== undefined
        //           ? tableList[i].sampleName
        //           : '',
        //       testValue:
        //         tableList[i].testValue !== undefined
        //           ? tableList[i].testValue
        //           : '',
        //       retestValue:
        //         tableList[i].retestValue !== undefined
        //           ? tableList[i].retestValue
        //           : '',
        //       unit: tableList[i].unit !== undefined ? tableList[i].unit : '',
        //       planEndDate:
        //         tableList[i].planEndDate !== undefined
        //           ? tableList[i].planEndDate
        //           : '',
        //       qualified:
        //         tableList[i].qualified !== undefined
        //           ? tableList[i].qualified
        //           : '',
        //       testBasis:
        //         tableList[i].testBasis !== undefined
        //           ? tableList[i].testBasis
        //           : '',
        //       testBasisId:
        //         tableList[i].testBasisId !== undefined
        //           ? tableList[i].testBasisId
        //           : '',
        //       testBasisName:
        //         tableList[i].testBasisName !== undefined
        //           ? tableList[i].testBasisName
        //           : '',
        //       testBasisFull:
        //         (tableList[i].testBasis ? tableList[i].testBasis : '') +
        //         '  ' +
        //         (tableList[i].testBasisName ? tableList[i].testBasisName : ''),
        //       testMethod:
        //         tableList[i].testMethod !== undefined
        //           ? tableList[i].testMethod
        //           : '',
        //       detection:
        //         tableList[i].detection !== undefined
        //           ? tableList[i].detection
        //           : '',
        //       detectionType:
        //         tableList[i].detectionType !== undefined
        //           ? tableList[i].detectionType
        //           : '',
        //       judgeBasis:
        //         tableList[i].judgeBasis !== undefined
        //           ? tableList[i].judgeBasis
        //           : '',
        //       judgeBasisId:
        //         tableList[i].judgeBasisId !== undefined
        //           ? tableList[i].judgeBasisId
        //           : '',
        //       judgeBasisName:
        //         tableList[i].judgeBasisName !== undefined
        //           ? tableList[i].judgeBasisName
        //           : '',
        //       limitDefault:
        //         tableList[i].limitDefault !== undefined
        //           ? tableList[i].limitDefault
        //           : '',
        //       limitType:
        //         tableList[i].limitType !== undefined
        //           ? tableList[i].limitType
        //           : '',
        //       judged:
        //         tableList[i].judged !== undefined ? tableList[i].judged : '',
        //       equipName:
        //         tableList[i].equipName !== undefined
        //           ? tableList[i].equipName
        //           : '',
        //       equipNum:
        //         tableList[i].equipNum !== undefined
        //           ? tableList[i].equipNum
        //           : '',
        //       code: tableList[i].code !== undefined ? tableList[i].code : '',
        //       remark:
        //         tableList[i].remark !== undefined ? tableList[i].remark : '',
        //       labRemark:
        //         tableList[i].labRemark !== undefined
        //           ? tableList[i].labRemark
        //           : '',
        //       progress:
        //         tableList[i].progress !== undefined
        //           ? tableList[i].progress
        //           : '',
        //       id: tableList[i].id !== undefined ? tableList[i].id : '',
        //       type: tableList[i].type !== undefined ? tableList[i].type : '',
        //       sampleId:
        //         tableList[i].sampleId !== undefined
        //           ? tableList[i].sampleId
        //           : '',
        //       contractId:
        //         tableList[i].contractId !== undefined
        //           ? tableList[i].contractId
        //           : '',
        //       recordId:
        //         tableList[i].recordId !== undefined
        //           ? tableList[i].recordId
        //           : '',
        //       compareSymbol:
        //         tableList[i].compareSymbol !== undefined
        //           ? tableList[i].compareSymbol
        //           : '',
        //       limitValue:
        //         tableList[i].limitValue !== undefined
        //           ? tableList[i].limitValue
        //           : '',
        //       sampleStatus:
        //         tableList[i].sampleStatus !== undefined
        //           ? tableList[i].sampleStatus
        //           : '',
        //       microbeN: tableList[i].microbeN ? tableList[i].microbeN : 0,
        //       microbeC: tableList[i].microbeC ? tableList[i].microbeC : 0,
        //       microbeM: tableList[i].microbeM ? tableList[i].microbeM : 0,
        //       microbeBm: tableList[i].microbeBm ? tableList[i].microbeBm : 0,
        //       subClass: tableList[i].subClass ? tableList[i].subClass : '',
        //       reportDueDate: tableList[i].reportDueDate
        //         ? tableList[i].reportDueDate
        //         : '',
        //       resultDate: tableList[i].resultDate
        //         ? tableList[i].resultDate
        //         : '',
        //       testBasisSm: tableList[i].testBasisSm
        //         ? tableList[i].testBasisSm
        //         : '',
        //       sampleRemark: tableList[i].sampleRemark
        //         ? tableList[i].sampleRemark
        //         : '',
        //       contractRemark: tableList[i].contractRemark
        //         ? tableList[i].contractRemark
        //         : '',
        //       cname: tableList[i].cname ? tableList[i].cname : '',
        //       ctime: tableList[i].ctime ? tableList[i].ctime : '',
        //       distanceWeekdays: tableList[i].distanceWeekdays
        //         ? tableList[i].distanceWeekdays
        //         : '',
        //       singleConclusion: tableList[i].singleConclusion
        //         ? tableList[i].singleConclusion.split(',')
        //         : [],
        //       firstDetectClass: tableList[i].firstDetectClass
        //         ? tableList[i].firstDetectClass
        //         : '',
        //       detectionUnit: tableList[i].detectionUnit
        //         ? tableList[i].detectionUnit
        //         : '',
        //       analysisDate: tableList[i].analysisDate
        //         ? tableList[i].analysisDate
        //         : ''
        //     }
        //     if (tableList[i].analysisDate !== undefined) {
        //       const list = tableList[i].analysisDate.split('~')
        //       if (list.length === 2) {
        //         if (list[0].split(':').length === 2) {
        //           obj.analysisDateList = [list[0], list[1]]
        //         } else {
        //           obj.analysisDateList = [
        //             list[0] + ' 00:00',
        //             list[1] + ' 00:00'
        //           ]
        //         }
        //       } else if (list[0].split(':').length === 2) {
        //             obj.analysisDateList = [list[0], list[0]]
        //           } else {
        //             obj.analysisDateList = [list[0] + ' 00:00', list[0] + ' 00:00']
        //           }
        //       }
        //     } else {
        //       obj.analysisDateList = []
        //     }
        //     this.getPage.records.push(obj)
        //   }
        //   if (this.getPage.records.length === 0) {
        //     this.$emit('on-result-change')
        //   }
        //   this.selectIds = []
        //   this.selectData = []
        //   this.selectSampleIds = []
        //   this.stepId = ''
        //   break
        case 'selectIds':
          this.selectIds = data
          break
        case 'selectData':
          this.selectData = data
          this.selectSampleIds = data.map(({ sampleId: i }) => i)
          break
        // case 'iconClick':
        //   this._iconClick(data.name, data.rowData, data.componentName);
        //   break;
        case 'table-col':
          // 用户选中的表格列
          this.userColumns = data
          break
        case 'changeSize':
          if (this.leftSelectIds.length) {
            this._page()
          }
          break
      }
    },
    // _formSearch() {
    //   // this.$refs.pageTable._pageChange(1)
    // },
    _formSearch: async function() {
      // this.formObj.aptitudeId = this.leftSelectIds[i]
      // Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      // console.log('this.formObj', this.formObj)
      const result = await meterManageItem.page(this.leftSelectIds)
      console.log('请求的结果', result)
      if (result) {
        this.getPage = result
        // this.getPage.records.push(result[i])
        this.$refs.pageTable._hideLoading()
        console.log(result)
      }
    },
    // 获取检测标准
    _testBasisList(data) {
      const obj = {}
      if (this.currentRow.name) {
        obj.name = this.currentRow.name
      } else {
        // 没有填检测项目检测依据的下拉就为空
        this.testBasisData = []
        return
      }
      if (data) {
        obj.testBasis = data
      }
      this.$store.dispatch('FoodAptitudeItem/getTestBasis', obj).then(() => {
        this.testBasisData = this.$store.state.FoodAptitudeItem.list
      })
    },

    // 检测依据结果
    _testBasisChange(msg, data, handleObj) {
      this._handleRow(handleObj)
      switch (msg) {
        case 'select':
          this.currentRow.testBasisFull =
            data.testBasis + '  ' + data.testBasisName
          this.currentRow.testBasis = data.testBasis
          this.currentRow.testBasisId = data.stdId
          this.currentRow.testBasisName = data.testBasisName
          // this.currentRow.groupId = data.groupId;
          // this.currentRow.groupName = data.groupName;
          this.$set(this.currentRow, 'testBasisSm', '#')
          this._setDetection() // 获取检出限
          break
        case 'query':
          this.currentRow.testBasisFull = data

          // 只要搜索就清空已填的值
          this.currentRow.testBasisName = ''
          this.currentRow.testBasisId = ''
          this.currentRow.testBasis = ''
          this.currentRow.testMethod = ''
          this.$set(this.currentRow, 'testBasisSm', '#')
          // if (this.currentRow.aptitudeItemId) {
          //   this.currentRow.aptitudeItemId = '';
          // }
          if (data === '') {
            this.currentRow.testMethod = ''
          }
          this._testBasisList(data)
          break
        case 'focus':
          this._testBasisList()
          break
        case 'blur':
          // 如果没有依据，则清空
          if (this.currentRow.testBasisId === '') {
            this.currentRow.testBasisFull = ''
            this.$set(this.currentRow, 'testBasisSm', '#')
          }
          this._save('testBasisFull')
      }
    },
    // 获取检测方法
    _testMethodList(testMethod) {
      const obj = {}
      if (this.currentRow.name && this.currentRow.testBasisId) {
        obj.name = this.currentRow.name
        obj.stdId = this.currentRow.testBasisId
      } else {
        this.testMethodData = []
        return
      }
      if (testMethod) {
        obj.testMethod = testMethod
      }
      this.$store.dispatch('FoodAptitudeItem/getTestMethod', obj).then(() => {
        this.testMethodData = this.$store.state.FoodAptitudeItem.list
      })
    },
    // 检测方法结果
    _testMethodChange(msg, data, handleObj) {
      this._handleRow(handleObj)
      switch (msg) {
        case 'select':
          this.currentRow.testMethod = data.testMethod
          this.$set(this.currentRow, 'testBasisSm', '#')
          this._save('testMethod')
          break
        case 'query':
          this.currentRow.testMethod = data.testMethod
          this.$set(this.currentRow, 'testBasisSm', '#')
          this._testMethodList(data.testMethod)
          break
        case 'focus':
          this._testMethodList()
          break
        case 'blur':
          this._save('testMethod')
          break
      }
    },
    // 根据检测项目  检测依据获取检出限
    _setDetection() {
      const obj = {
        name: this.currentRow.name,
        stdId: this.currentRow.testBasisId
      }
      this.$store.dispatch('FoodAptitudeItem/getDetection', obj).then(() => {
        const data = this.$store.state.FoodAptitudeItem.model
        if (data) {
          this.currentRow.detection = data.detectionLimit
          this.currentRow.unit = data.unit
        }
        this._save('testBasisFull')
      })
    },

    // 获取判定标准
    _judgeBasisList(msg, data) {
      const obj = { name: this.currentRow.name }
      if (this.currentRow.testBasis) {
        obj.testBasis = this.currentRow.testBasis
      }
      if (msg === 'judgeBasis' && data) {
        obj.judgeBasis = data
      } else if (msg === 'judgeBasisName' && data) {
        obj.judgeBasisName = data
      }
      this.$store.dispatch('FoodAptitudeItem/getJudgeBasis', obj).then(() => {
        if (msg === 'judgeBasis') {
          this.judgeBasisData = this.$store.state.FoodAptitudeItem.list
        } else if (msg === 'judgeBasisName') {
          this.judgeBasisNameData = this.$store.state.FoodAptitudeItem.list
        } else {
          this.judgeBasisData = this.$store.state.FoodAptitudeItem.list
          this.judgeBasisNameData = this.$store.state.FoodAptitudeItem.list
        }
      })
    },

    // 判定依据结果
    _judgeBasisChange(msg, data, handleObj) {
      this._handleRow(handleObj)
      switch (msg) {
        case 'select':
          this.currentRow.judgeBasis = data.judgeBasis
          this.currentRow.judgeBasisId = data.id
          this.currentRow.judgeBasisName = data.judgeBasisName
          this._stdSetLimit() // 查询限量并赋值保存
          break
        case 'query':
          this.currentRow.judgeBasis = data.judgeBasis

          // 手动填或者是选完修改的就清空判定id，满足可选可填
          // this.currentRow.judgeBasisName = '';
          this.currentRow.judgeBasisId = ''
          this._judgeBasisList('judgeBasis', data.judgeBasis)
          break
        case 'focus':
          this._judgeBasisList('judgeBasis')
          break
        case 'blur':
          this._save('judgeBasis')
          break
      }
    },
    // 判定依据名称结果
    _judgeBasisNameChange(msg, data, handleObj) {
      this._handleRow(handleObj)
      switch (msg) {
        case 'select':
          this.currentRow.judgeBasisName = data.judgeBasisName
          this.currentRow.judgeBasisId = data.id
          this.currentRow.judgeBasis = data.judgeBasis
          this._stdSetLimit() // 查询限量并赋值保存
          break
        case 'query':
          this.currentRow.judgeBasisName = data.judgeBasisName

          // 手动填或者是选完修改的的就清空判定id，满足可选可填
          // this.currentRow.judgeBasis = '';
          this.currentRow.judgeBasisId = ''
          this._judgeBasisList('judgeBasisName', data.judgeBasisName)
          break
        case 'focus':
          this._judgeBasisList('judgeBasisName')
          break
        case 'blur':
          this._save('judgeBasisName')
          break
      }
    },
    // 判定依据选了之后设置限量
    _stdSetLimit() {
      if (this.currentRow.aptitudeItemId) {
        const obj = {
          aptitudeItemId: this.currentRow.aptitudeItemId
        }
        if (this.currentRow.judgeBasisId) {
          obj.judgeBasisId = this.currentRow.judgeBasisId
        }
        this.$store.dispatch('FoodAptitudeLimit/getLimitInfo', obj).then(() => {
          const limitData = this.$store.state.FoodAptitudeLimit.limitModel
          if (limitData.length) {
            this.currentRow.limitDefault = limitData[0].limitDefault
            this.currentRow.judged = limitData[0].judged
            this.currentRow.limitType = limitData[0].limitType
            this.currentRow.compareSymbol = limitData[0].compareSymbol
            this.currentRow.limitValue = limitData[0].limitValue
          }
          this._save('judgeBasis')
        })
      } else {
        this._save('judgeBasis')
      }
    },
    // 根据资质和 判定依据 获取限量值
    _getLimit(row) {
      this.currentRow = row
      const obj = {}
      if (row.aptitudeItemId) {
        obj.aptitudeItemId = row.aptitudeItemId
      }
      if (row.judgeBasisId) {
        obj.judgeBasisId = row.judgeBasisId
      }
      this.$store.dispatch('FoodAptitudeLimit/getLimitInfo', obj).then(() => {
        const list = this.$store.state.FoodAptitudeLimit.limitModel
        if (list.length) {
          this.limitData = list
        } else {
          this.limitData = []
        }
      })
    },
    // 选择限量值并保存
    _selLimit(row, event, column) {
      this.$set(this.currentRow, 'limitDefault', row.limitDefault)
      this.$set(this.currentRow, 'limitType', row.limitType)
      this.currentRow.judged = row.judged
      this.currentRow.compareSymbol = row.compareSymbol
      this.currentRow.limitValue = row.limitValue
      this.currentRow.microbeN = row.microbedn ? row.microbedn : 0
      this.currentRow.microbeC = row.microbedc ? row.microbedc : 0
      this.currentRow.microbeM = row.microbedsm ? row.microbedsm : 0
      this.currentRow.microbeBm = row.microbedbm ? row.microbedbm : 0
      this.currentRow.calType = row.computeType ? row.computeType : 0
      // this.currentRow.subClass = row.firstClass ? (row.firstClass + '/' + row.secondClass + '/' + row.thirdClass + '/' + row.fourthClass) : '';
      this.currentRow.subClass = row.testParameter ? row.testParameter : ''
      this._save('limitType')
      // this._enterSave('', this.currentIndex);
      // this._refreshRow(row.id, this.currentIndex);
    },
    // 操作的序号
    _handleRow(data) {
      this.currentRow = data.row
      this.currentIndex = data.index
    },

    // 限量值修改了  是否判定改为否  并保存
    _handleLimitDefalut() {
      this.currentRow.judged = 0
      if (this.currentRow.qualified.value !== 'NO_JUDGE') {
        this.currentRow.qualified.value = 'WAIT_SYSTEM'
      }
      this._save('limitDefault')
      // this._saveQualified();
    },
    // ①保存  除结果判定(除手工判定)，非特殊情况，只更新修改的key,
    // ②如果有其他的参数关联修改在_refreshPage方法内单独追加该key
    _save(key) {
      this.currentEditKey = key
      let tempBool = true
      setTimeout(() => {
        if (tempBool) {
          this.$refs.pageTable._showLoading()
        }
      }, 1500)
      const params = this._saveParams(key)
      this.$store.dispatch('FoodItem/itemEdit', params).then(() => {
        if (this.$store.state.FoodItem.success) {
          tempBool = false
          this.$refs.pageTable._hideLoading()
          // 刷新修改的当前行的数据
          this._refreshPage(params.id)
        } else {
          this.$Message.error('保存失败')
          tempBool = false
          this.$refs.pageTable._hideLoading()
        }
      })
    },
    // 只刷新某一行的特殊字段数据
    _refreshPage(id) {
      const params = JSON.parse(JSON.stringify(this.$refs.pageTable.pageParams))
      params.id = id
      this.$store.dispatch('FoodItem/inputSapPage', params).then(() => {
        const resRows = this.$store.state.FoodItem.page.records[0]
        const index = this.getPage.records.findIndex(item => item.id === id)
        switch (this.currentEditKey) {
          case 'limitType':
            this.$set(this.getPage.records[index], 'judged', resRows.judged)
            break
          case 'testValue':
            this.$set(
              this.getPage.records[index],
              'qualified',
              resRows.qualified
            )
            break
          case 'limitDefault':
            // 限量修改后的重新赋值
            this.$set(
              this.getPage.records[index],
              'qualified',
              resRows.qualified
            )
            this.$set(
              this.getPage.records[index],
              'compareSymbol',
              resRows.compareSymbol
            )
            this.$set(
              this.getPage.records[index],
              'limitValue',
              resRows.limitValue
            )
            this.$set(this.getPage.records[index], 'microbeN', resRows.microbeN)
            this.$set(this.getPage.records[index], 'microbeC', resRows.microbeC)
            this.$set(this.getPage.records[index], 'microbeM', resRows.microbeM)
            this.$set(
              this.getPage.records[index],
              'microbeBm',
              resRows.microbeBm
            )
            this.$set(this.getPage.records[index], 'subClass', resRows.subClass)
            this.$set(this.getPage.records[index], 'judged', resRows.judged)
            break
          case 'testBasisFull':
            this.$set(
              this.getPage.records[index],
              'detection',
              resRows.detection
            )
            this.$set(this.getPage.records[index], 'unit', resRows.unit)
        }
      })
    },
    _refreshRow(id, index) {
      this.$store.dispatch('FoodItem/getById', id).then(() => {
        const result = this.$store.state.FoodItem.model
        if (result) {
          this.currentRow.qualified = result.qualified
          this.$refs.pageTable._hideLoading()
        }
      })
    },
    _saveParams(key) {
      const obj = {}
      const item = this.currentRow
      switch (key) {
        case 'testValue':
          // 检测值
          obj.testValue = item.testValue
          break
        case 'testBasisFull':
          // 检测依据
          obj.groupId = item.groupId
          obj.groupName = item.groupName
          obj.testBasisSm = item.testBasisSm
          obj.detection = item.detection
          obj.unit = item.unit
          obj.testMethod = item.testMethod
          if (item.testBasisId) {
            obj.testBasis = item.testBasis
            obj.testBasisId = item.testBasisId
            obj.testBasisName = item.testBasisName
          }
          break
        case 'testMethod':
          obj.testMethod = item.testMethod
          obj.testBasisSm = item.testBasisSm
          break
        case 'judgeBasis':
        case 'judgeBasisName':
          obj.judgeBasis = item.judgeBasis
          obj.judgeBasisName = item.judgeBasisName
          obj.limitDefault = item.limitDefault
          obj.judged = item.judged
          obj.limitType = item.limitType
          obj.compareSymbol = item.compareSymbol
          obj.limitValue = item.limitValue
          if (item.judgeBasisId) {
            obj.judgeBasisId = item.judgeBasisId
          }
          break
        case 'limitDefault':
          obj.qualified = item.qualified.value
          obj.limitDefault = item.limitDefault
          break
        case 'limitType':
          obj.limitDefault = item.limitDefault
          obj.limitType = item.limitType
          obj.judged = item.judged
          obj.compareSymbol = item.compareSymbol
          obj.limitValue = item.limitValue
          obj.microbeN = item.microbeN
          obj.microbeC = item.microbeC
          obj.microbeM = item.microbeM
          obj.microbeM = item.microbeM
          obj.microbeBm = item.microbeBm
          obj.subClass = item.subClass
          break
        case 'singleConclusion':
          obj.singleConclusion = item.singleConclusion.join(',')
          break
        default:
          // 其他没有特殊处理的单独修改某一个key的值
          obj[key] = item[key]
          break
      }
      const data = {
        id: item.id,
        obj: obj
      }
      return data
    },
    // 单独保存结果判定(手工判定)
    _saveQualified() {
      let tempBool = true
      setTimeout(() => {
        if (tempBool) {
          this.$refs.pageTable._showLoading()
        }
      }, 1500)
      const item = this.currentRow
      const data = {
        id: item.id,
        obj: {
          qualified: item.qualified.value
        }
      }
      this.$store.dispatch('FoodItem/edit', data).then(() => {
        if (this.$store.state.FoodItem.success) {
          tempBool = false
          this.$refs.pageTable._hideLoading()
        } else {
          this.$Message.error('保存失败')
          tempBool = false
          this.$refs.pageTable._hideLoading()
        }
      })
    },
    _btnClick(msg, componentName) {
      this.currentComponent = componentName
      this.$nextTick(function() {
        switch (msg) {
          case '仪器':
            // this._selectEquipment()
            break
          case '判定':
            // this._judge()
            break
          case '批量填写':
            // this._detectionValue()
            break
          case '填写原始记录':
            // this._writeOriginalRecord()
            break
          case '查看合并记录':
            // this._batchRecordView()
            break
          case '转发':
            // this._forward()
            break
          case '提交至报告':
            // this._submitToReport()
            break
          case '无需报告':
            // this._submitToEnd()
            break
          case '终止检测':
            // const ids = this.selectIds
            // if (ids.length === 0) {
            //   this.$Message.warning('请至少选择一条数据！')
            // } else {
            //   this.$refs.refModal._open('终止原因')
            // }
            break
          case '提交至审核':
            // this._submit()
            break
          case '提交至复核':
            // this._submitToCheck()
            break
          case '导入':
            // this._import()
            break
          case '导出':
            // this._export()
            break
          case '特殊字符箱':
            // this._special()
            break
          case '选择复核人':
            // this._selChecker()
            break
          case '选择审核人':
            // this._selAuditor()
            break
          case '自动判定':
            // this._autoJudge()
            break
          case '建批':
            // this._build()
            break
          case '复制历史数据':
            // this._copyHisData()
            break
          case '退回':
            // if (this.selectIds.length === 0) {
            //   this.$Message.warning('请至少选择一条数据')
            // } else {
            //   this.$refs.refModal._open(this.selectIds)
            // }
            break
          case '填写库外检测依据':
            // if (this.selectIds.length === 0) {
            //   this.$Message.warning('请至少选择一条数据')
            // } else {
            //   this.$refs.refModal._open(this.selectIds)
            // }
            break
          case '存到资质库':
            // this._saveToLab()
            break
          case '信息维护':
            // this._maintainInfo()
            break
          case '检测项目重置':
            // this._itemResetInfo()
            break
        }
      })
    },
    // 查看合并记录
    _batchRecordView() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据')
      } else {
        this.$refs.refModal._open(this.selectIds)
      }
    },
    _itemResetInfo() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据')
      } else {
        this.$refs.refModal._open(this.selectIds)
      }
    },
    _build() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        // 判断是否需要弹出检测步骤界面
        this.$store
          .dispatch('FoodItemStep/checkItemStep', {
            itemIds: this.selectIds.join(',')
          })
          .then(() => {
            const resultStep = this.$store.state.FoodItemStep.success
            // 1)如果是true,则需要执行建批操作
            if (resultStep === true) {
              this.stepId = ''
              this._buildEnd()
            } else if (resultStep === false) {
              // 2)如果是false，则需要弹出选择检测步骤界面,然后绑定步骤id
              this.currentComponent = 'SelectTestStep'
              this.$nextTick(() => {
                this.$refs.refModal._open()
              })
            }
          })
      }
    },
    // 建批最终的请求
    _buildEnd() {
      let setTimeoutMsg = ''
      const objTemp = { ids: this.selectIds.join(',') }
      if (this.stepId) {
        // 检测步骤id
        objTemp.stepId = this.stepId
      }
      // 首先判断是否启用sop,后台判断
      this.$store.dispatch('FoodItem/waitBuildGroupGreat', objTemp).then(() => {
        const result = this.$store.state.FoodItem.success
        setTimeoutMsg = result
        if (result === true) {
          this._resultChange('建批成功')
        } else if (result === false) {
          // 否则弹出模板，进行选择
          this.currentComponent = 'OriginalRecordTemplate'
          this.$nextTick(() => {
            this.$refs.refModal._open('', 'build-group')
          })
        }
      })
      setTimeout(() => {
        if (setTimeoutMsg === '') {
          this._sopTip()
        }
      }, 1000)
    },
    // 是否启用字典的提示（1s之内没有返回值就显示提示信息）
    _sopTip() {
      this.$store.dispatch('LmsBaseDict/getItem', '启用SOP').then(() => {
        const resultData = this.$store.state.LmsBaseDict.item
        const msg = !!(resultData.length > 0 && resultData[0].name === '是')
        if (msg) {
          this.$Notice.info({
            title: '提示',
            desc: '正在后台生成原始记录，稍候刷新即可查看。'
          })
        }
      })
    },
    _copyHisData() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据')
      } else {
        this.$refs.refModal._open(this.selectIds)
      }
    },
    _saveToLab() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据')
      } else {
        let type = 0
        let flag = true
        for (let i = 0; i < this.selectData.length; i++) {
          if (this.selectData[i].aptitudeItemId !== '') {
            flag = false
          }
        }
        if (flag) {
          // 都没有资质id
          type = 1
          this._saveToLabOk(type)
        } else {
          // 都有 或 有的有 有的没有
          // this.$Modal.confirm({
          //   title: '提示',
          //   content: '该项目已绑定资质项目，请选择更新完善或者新增资质项目！',
          //   okText: '更新',
          //   cancelText: '新增',
          //   onOk: () => {
          //     type = 0  //更新
          //     this._saveToLabOk(type)
          //   },
          //   onCancel: () => {
          //     type = 1
          //     this._saveToLabOk(type)
          //   }
          // });
          this.$refs.confirmModal._openModal()
        }
      }
    },
    _confirmResult(name) {
      switch (name) {
        case '更新':
          this._saveToLabOk(0)
          break
        case '新增':
          this._saveToLabOk(1)
          break
      }
    },
    _saveToLabOk(type) {
      this.$store
        .dispatch('FoodItem/saveToLab', {
          ids: this.selectIds.join(','),
          type: type
        })
        .then(() => {
          if (this.$store.state.FoodItem.success) {
            this.$Message.success('操作成功！')
            this.$refs.confirmModal._closeModal()
          }
        })
    },
    // 信息维护
    _maintainInfo() {
      if (this.selectSampleIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.currentComponent = 'MaintainInfoModal'
        this.$nextTick(() => {
          this.$refs.refModal._open(this.selectSampleIds, 2)
        })
      }
    },
    _autoJudge() {
      if (this.selectData.length === 0) {
        this.$Message.warning('请至少选择一条数据')
      } else {
        const items = this._getBatchData()
        this.$store.dispatch('FoodItem/batchUpdateItem', items).then(() => {
          if (this.$store.state.FoodItem.success) {
            this.$Message.success('操作成功！')
            this._page()
          }
        })
      }
    },
    _getBatchData() {
      const items = []
      for (let i = 0; i < this.selectData.length; i++) {
        const obj = {
          id: this.selectData[i].id,
          name: this.selectData[i].name,
          testValue: this.selectData[i].testValue,
          retestValue: this.selectData[i].retestValue,
          unit: this.selectData[i].unit,
          testMethod: this.selectData[i].testMethod,
          limitDefault: this.selectData[i].limitDefault,
          limitValue: this.selectData[i].limitValue,
          compareSymbol: this.selectData[i].compareSymbol,
          limitType: this.selectData[i].limitType,
          judged: this.selectData[i].judged,
          detection: this.selectData[i].detection,
          labRemark: this.selectData[i].labRemark,
          microbeN: this.selectData[i].microbeN
            ? this.selectData[i].microbeN
            : 0,
          microbeC: this.selectData[i].microbeC
            ? this.selectData[i].microbeC
            : 0,
          microbeM: this.selectData[i].microbeM
            ? this.selectData[i].microbeM
            : 0,
          microbeBm: this.selectData[i].microbeBm
            ? this.selectData[i].microbeBm
            : 0,
          qualified: this.selectData[i].qualified.value,
          subClass: this.selectData[i].subClass
        }
        if (this.selectData[i].testBasisId) {
          obj.testBasisId = this.selectData[i].testBasisId
          obj.testBasis = this.selectData[i].testBasis
          obj.testBasisName = this.selectData[i].testBasisName
        }
        if (this.selectData[i].judgeBasisId) {
          obj.judgeBasisId = this.selectData[i].judgeBasisId
          obj.judgeBasis = this.selectData[i].judgeBasis
          obj.judgeBasisName = this.selectData[i].judgeBasisName
        } else {
          obj.judgeBasis = this.selectData[i].judgeBasis
          obj.judgeBasisName = this.selectData[i].judgeBasisName
        }
        items.push(obj)
      }
      return items
    },
    // 填写原始记录
    _writeOriginalRecord() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$store
          .dispatch('FoodItem/checkCanWriteOriginal', { ids: this.selectIds })
          .then(() => {
            const result = this.$store.state.FoodItem.recordModel
            if (result === '0') {
              // 选择原始记录模板
              this.currentComponent = 'OriginalRecordTemplate'
              this.$nextTick(() => {
                this.$refs.refModal._open()
              })
            } else if (result !== undefined) {
              this.currentComponent = 'OriginalRecordWrite'
              this.$nextTick(() => {
                this.$refs.refModal._open(this.selectIds, result)
              })
            }
          })
      }
    },
    // 选完模板填写
    _tempResult(data) {
      if (data.msg && data.msg === 'build-group') {
        // 建批保存
        let setTimeoutMsg = ''
        const objTemp = {
          ids: this.selectIds.join(','),
          templateId: data.modelId.id
        }
        if (this.stepId) {
          objTemp.stepId = this.stepId
        }
        this.$store
          .dispatch('FoodItem/waitBuildGroupGreat', objTemp)
          .then(() => {
            const result = this.$store.state.FoodItem.success
            setTimeoutMsg = result
            if (result) {
              this._resultChange('建批成功')
            }
          })
        setTimeout(() => {
          if (setTimeoutMsg === '') {
            this._sopTip()
          }
        }, 1000)
      } else {
        this.currentComponent = 'OriginalRecordWrite'
        this.$nextTick(() => {
          this.$refs.refModal._open(this.selectIds, data.modelId.id)
        })
      }
    },
    // 特殊符号工具箱
    _special() {
      this.$refs.refModal._open(this.selectIds)
    },
    // 批量选择复核人
    _selChecker() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        const user = Global.getUserInfo('userInfo')
        this.$refs.refModal._openGoupByUserId('分配复核人', user.id)
      }
    },
    // 选复核人结果
    _checkerResult(res) {
      this.$store
        .dispatch('FoodItem/checkerSelect', {
          ids: this.selectIds.join(','),
          checkerId: res.userId,
          checker: res.realname
        })
        .then(() => {
          if (this.$store.state.FoodItem.success) {
            this.$Message.success('操作成功！')
            this._page()
          }
        })
    },
    _selAuditor() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        const user = Global.getUserInfo('userInfo')
        this.$refs.refModal._openGoupByUserId('分配审核人', user.id)
      }
    },
    // 选审核人结果
    _auditorResult(res) {
      this.$store
        .dispatch('FoodItem/inputAuditorSelect', {
          ids: this.selectIds.join(','),
          auditorId: res.userId,
          auditor: res.realname
        })
        .then(() => {
          if (this.$store.state.FoodItem.success) {
            this.$Message.success('操作成功！')
            this._page()
          }
        })
    },
    // 导入
    _import() {
      this.$refs.refModal._open()
    },
    // 导出
    _export() {
      if (
        this.getPage.records === undefined ||
        this.getPage.records.length === 0
      ) {
        this.$Message.warning('暂无数据，不可导出!')
      } else {
        // 勾选导出勾选的，未勾选导出全部的
        const obj = {
          param: 'ids',
          ids: this.selectIds,
          url: '/food/v1/item/item_export',
          queryObj: this.$serializeFormSearch(this._searchParams()),
          msgContent: '确定要导出数据（最多20000条数据）？'
        }
        this.$exportByQuery(obj)
      }
    },
    // 批量转发
    _forward() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$refs.refModal._open(this.selectIds)
      }
    },

    // 批量提交
    _submit() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$Modal.confirm({
          title: '提示',
          content: '确定该操作？',
          onOk: () => {
            this.$store
              .dispatch('FoodItem/inputSubmit', {
                ids: this.selectIds.join(',')
              })
              .then(() => {
                if (this.$store.state.FoodItem.success) {
                  this.$Message.success('提交成功！')
                  this._page()
                }
              })
          }
        })
      }
    },
    _submitToCheck() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$Modal.confirm({
          title: '提示',
          content: '确定该操作？',
          onOk: () => {
            this.$store
              .dispatch('FoodItem/inputSubmitToCheck', {
                ids: this.selectIds.join(',')
              })
              .then(() => {
                if (this.$store.state.FoodItem.success) {
                  this.$Message.success('提交成功！')
                  this._page()
                }
              })
          }
        })
      }
    },
    // 批量提交到报告
    _submitToReport() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$Modal.confirm({
          title: '提示',
          content: '确定该操作？',
          onOk: () => {
            this.$store
              .dispatch('FoodItem/inputSubmitToReport', {
                ids: this.selectIds.join(',')
              })
              .then(() => {
                if (this.$store.state.FoodItem.success) {
                  this.$Message.success('提交成功！')
                  this._page()
                }
              })
          }
        })
      }
    },
    // 批量完成
    _submitToEnd() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$Modal.confirm({
          title: '提示',
          loading: true,
          okText: '是',
          cancelText: '否',
          content: '数据将跳过报告编制，直接至完成，是否继续？',
          onOk: () => {
            this.$store
              .dispatch('FoodItem/inputSubmitToEnd', {
                ids: this.selectIds.join(',')
              })
              .then(() => {
                if (this.$store.state.FoodItem.success) {
                  this.$Message.success('操作成功！')
                  this._page()
                  this.$Modal.remove()
                }
              })
          }
        })
      }
    },
    // 终止检测
    _itemAbort(data) {
      this.$store
        .dispatch('FoodItem/itemAbort', {
          ids: this.selectIds.join(','),
          reason: data
        })
        .then(() => {
          if (this.$store.state.FoodItem.success) {
            this.$Message.success('终止成功！')
            this.selectIds = []
            this._page()
          }
        })
    },
    // 批量选择仪器
    _selectEquipment() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$refs.refModal._open('sample-input')
      }
    },
    // 仪器选择保存
    _equipResult(res) {
      const equipIds = []
      for (let i = 0; i < res.length; i++) {
        equipIds.push(res[i].id)
      }
      this.$store
        .dispatch('FoodItem/selectEquip', {
          ids: this.selectIds.join(','),
          equipIds: equipIds.join(',')
        })
        .then(() => {
          if (this.$store.state.FoodItem.success) {
            this.$Message.success('操作成功！')
            this._page()
          }
        })
    },

    // 批量判定
    _judge() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$refs.refModal._open(this.selectIds)
      }
    },
    // 批量填写检测值
    _detectionValue() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请至少选择一条数据！')
      } else {
        this.$refs.refModal._open(this.selectIds)
      }
    },

    _iconClick(res, data, componentName) {
      this.currentComponent = componentName
      this.$nextTick(function() {
        switch (res) {
          case '样品附件':
            this._upload(data.sampleId)
            break
          case '编辑原始记录':
            this._originalRecordEdit(data)
            break
          case '操作日志':
            this._record(data.id)
            break
          case '相关数据查询':
            this.$refs.refModal._open(data.id)
            break
        }
      })
    },
    // 操作日志
    _record(id) {
      this.$refs.refModal._open(id)
    },
    // 样品详情
    _sampleDetail(data) {
      this.$nextTick(function() {
        if (data.type === 1) {
          this.currentComponent = 'FoodSampleGovernDetail'
          this.$store
            .dispatch('FoodSample/getByGovernId', data.sampleId)
            .then(() => {
              this.$refs.refModal._open(
                this.$store.state.FoodSample.governModel
              )
            })
        } else {
          this.currentComponent = 'FoodSampleCompanyDetail'
          this.$store
            .dispatch('FoodSample/getByCompanyId', data.sampleId)
            .then(() => {
              this.$refs.refModal._open(
                this.$store.state.FoodSample.companyModel
              )
            })
        }
      })
    },
    // 编辑原始记录
    _originalRecordEdit(data) {
      if (!data.recordId) {
        this.$Message.warning('该检测项目暂无原始记录！')
      } else {
        this.$refs.refModal._open(data.recordId)
      }
    },
    _upload(id) {
      // 上传文件
      this.$refs.refModal._open(id, 'sampleId')
    },
    /** ************************检测值回车进入下一行并且保存***********************************/
    _enterSave(data) {
      const tempData = this._saveParams(data.fieldName)
      if (tempData.obj.testValue !== '') {
        // 有值则进行保存
        this.$refs.pageTable._showLoading()
        this.$store.dispatch('FoodItem/itemEdit', tempData).then(() => {
          if (this.$store.state.FoodItem.success) {
            this._refreshRowFocusNext(data, tempData.id)
          } else {
            this.$Message.error('保存失败')
            this.$refs.pageTable._hideLoading()
          }
        })
      } else {
        // 无值则进行单纯的跳转
        this._nextRow(data)
      }
    },
    _refreshRowFocusNext(data, id) {
      this.$store.dispatch('FoodItem/getById', id).then(() => {
        const result = this.$store.state.FoodItem.model
        if (result) {
          this.currentRow.qualified = result.qualified
          this.$refs.pageTable._hideLoading()
          this._nextRow(data)
        }
      })
    },
    // 跳转到下一行
    _nextRow(data) {
      const field = data.fieldName // 当前单元格英文名称
      let currentNextRow = data.scope.row // 当前行数据
      const index = data.scope.rowIndex // 当前行索引
      switch (data.msg) {
        case 'enter':
          // 回车下一行的数据
          currentNextRow = this.getPage.records[index + 1]
          break
      }
      if (currentNextRow && field) {
        this.$refs.pageTable._activeCell({
          row: currentNextRow,
          field: field,
          msg: data.msg
        })
      }
    }
    /** ************************检测值回车进入下一行并且保存***********************************/
  }
}
</script>
