<template>
  <div class="app-container">
    <el-card>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
        <el-form-item label="畜种" prop="animalType">
          <el-select v-model="queryParams.animalType">
            <el-option v-for="(item, i) in animalList" :key="i" :value="item.typeValue" :label="item.typeName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="留存时间" prop="timeRange">
          <el-date-picker
            v-model="queryParams.timeRange"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="样品编号" prop="sampleNum">
          <el-input
            v-model="queryParams.sampleNum"
            placeholder="请输入样品编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['app:sample:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDeleteAll"
            v-hasPermi="['app:sample:remove']"
          >删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    </el-card>
    <br>
    <el-card>
      <el-table border stripe height="600" v-loading="loading" ref="multipleTable" :data="disposalList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"  />
        <!--  <el-table-column label="ID"  prop="id" width="80" />  -->
        <el-table-column width="180" fixed label="留存时间"  prop="keepTime" />
        <el-table-column width="150" label="样品编号"  prop="sampleNum" />
        <el-table-column label="畜种">
          <template slot-scope="scope">
            {{animalName(scope.row.animalType)}}
          </template>
        </el-table-column>
        <el-table-column width="100" label="产品名称"  prop="produceName" />
        <el-table-column width="100" label="供应商"  prop="supplierName" />
        <el-table-column width="150" label="检疫证号"  prop="animalCertNo" />
        <el-table-column width="100" label="留样人"  prop="userName" />
        <el-table-column width="150" label="样品处理去向"  prop="sampleDeal" />
        <el-table-column width="180" label="处理时间"  prop="dealTime" />
        <el-table-column width="180" label="检测项目"  prop="examineItems" >
          <template slot-scope="scope">
            <template v-if="scope.row.examineItems">
              <div class="text-blue" @click="openModal(scope.row.examineItems)">查看详细检测项目</div>
            </template>
            <template v-else>
              <span>暂无检测项目</span>
            </template>
          </template>
        </el-table-column>
        <el-table-column width="180" label="清除日期"  prop="clearDate" >
          <template slot-scope="scope">
            <span>{{changeDate(scope.row.clearDate)}}</span>
          </template>
        </el-table-column>
        <el-table-column width="150" label="清除人"  prop="clearPerson" />
        <el-table-column width="150" label="复检日期"  prop="recheckTime" />
        <el-table-column width="180" label="复检项目"  prop="examineItems" >
          <template slot-scope="scope">
            <template v-if="scope.row.recheckItem">
              <div class="text-blue" @click="openModal(scope.row.recheckItem)">查看详细复检项目</div>
            </template>
            <template v-else>
              <span>暂无复检项目</span>
            </template>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="240"  fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
            >查看</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['app:sample:edit']"
              style="margin-right: 10px"
            >修改</el-button>
            <el-button
              v-if="scope.row.recheckTime === null"
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleFujian(scope.row)"
              v-hasPermi="['app:sample:edit']"
              style="margin-right: 10px"
            >复检</el-button>
            <el-popconfirm
              v-hasPermi="['app:sample:remove']"
              :title="'是否确认删除所选数据项？'"
              @confirm="handleDelete(scope.row)"
            >
              <el-button
                size="mini"
                type="text"
                slot="reference"
                icon="el-icon-delete"
              >删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改死淘处理方式对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" label-position="left" :model="form" :rules="rules" :disabled="isView" label-width="120px">
        <el-form-item label="分圈批次" prop="entranceBatchId">
          <el-select v-model="form.entranceBatchId" :disabled="form.id !== null" style="width: 100%">
            <el-option v-for="item in batchList" :key="item.entranceBatchId" :value="item.entranceBatchId" :label="item.desc"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="供应商" prop="supplierName">
          <el-input v-model="form.supplierName" disabled placeholder="选择进场批次自动填充"></el-input>
        </el-form-item>
        <el-form-item label="留存时间" prop="keepTime">
          <el-date-picker
            v-model="form.keepTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="样品编号" prop="sampleNum">-->
<!--          <el-input v-model="form.sampleNum" placeholder="请输入样品编号" />-->
<!--        </el-form-item>-->

        <el-form-item label="畜种" prop="animalType">
          <el-select v-model="form.animalType" disabled>
            <el-option v-for="(item, i) in animalList" :key="i" :value="item.typeValue" :label="item.typeName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="produceName">
          <el-select v-model="form.produceName" :disabled="form.animalType === null"  style="width: 100%" placeholder="请选择产品名称">
            <el-option v-for="item in proList" :key="item.id" :value="item.productName" :label="item.productName"></el-option>
          </el-select>
        </el-form-item>

<!--        <el-form-item label="检疫证号" prop="animalCertNo">-->
<!--          <el-input v-model="form.animalCertNo" disabled placeholder="选择进场批次自动填充"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="留样人" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入留样人"></el-input>
        </el-form-item>
        <el-form-item label="样品处理去向" prop="sampleDeal">
          <el-input type="textarea" :autosize="{ minRows: 2 }"   v-model="form.sampleDeal" maxlength="50" show-word-limit placeholder="请输入样品处理去向" />
        </el-form-item>
        <el-form-item label="处理时间" prop="dealTime">
          <el-date-picker
            v-model="form.dealTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-divider content-position="left">检测项目列表</el-divider>
        <el-row class="mb20" :gutter="16">
          <el-col :offset="2" :span="8">
            <div>检测项目</div>
          </el-col>
          <el-col :span="8">
            <div>检测值</div>
          </el-col>
        </el-row>
        <el-row
          v-for="(itemRow, i) in form.examineItemsArr"
          :key="i"
          :gutter="20"
        >
          <el-col :offset="2" :span="8">
<!--            <el-form-item-->
<!--              label=""-->
<!--              label-width="0"-->
<!--              :prop="'examineItemsArr.' + i + '.name'"-->
<!--              :rules="[{ required: true, message: '检测项目不能为空', trigger: 'blur' }]"-->
<!--            >-->
<!--              <el-input v-model="itemRow.name" placeholder="请输入检测项目" />-->
<!--            </el-form-item>-->
            <el-form-item
              label=""
              label-width="0"
              :prop="'examineItemsArr.' + i + '.name'"
              :rules="[{ required: true, message: '检测项目不能为空', trigger: 'blur' }]">
              <el-select v-model="itemRow.name" placeholder="请选择检测项目" @change="(e) => changeRowName(e, i)">
                <el-option v-for="(item, i) in inspectionList" :key="i" :value="item.projectName" :label="item.projectName"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label=""
              label-width="0"
              :prop="'examineItemsArr.' + i + '.value'"
              :rules="[{ required: true, message: '检测值不能为空', trigger: 'blur' }]"
            >
              <template  v-if="itemRow.checkType === 0">
                <el-select v-model="itemRow.value">
                  <el-option v-for="(item ,i) in getResultList(itemRow.name)" :key="i" :value="item.name" :label="item.name"></el-option>
                </el-select>
              </template>
              <template v-else>
                <el-input v-model="itemRow.value" placeholder="请输入检测值" />
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button
              class="item-add"
              size="small"
              type="primary"
              v-if="i == form.examineItemsArr.length - 1"
              @click="addItem(i)"
            ><i class="el-icon-plus"></i
            ></el-button>
            <el-button
              class="item-del"
              type="danger"
              size="small"
              v-if="i > 0 || form.examineItemsArr.length > 1"
              @click="removeItem(i)"
            ><i class="el-icon-minus"></i
            ></el-button>
          </el-col>
        </el-row>
<!--        <el-form-item label="检测项目" prop="examineItem">-->
<!--          <el-input v-model="form.examineItem" show-word-limit maxlength="20" placeholder="请输入检测项目"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="水份值" prop="moisture">-->
<!--          <el-input v-model="form.moisture" placeholder="请输入水份值"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="清除日期" prop="clearDate">
          <el-date-picker
            style="width: 100%"
            v-model="form.clearDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="清除人" prop="clearPerson">
          <el-input v-model="form.clearPerson" placeholder="请输入清除人" show-word-limit maxlength="10" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!isView">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="检测项目详情" :visible.sync="show" width="550px" append-to-body @close="resetShow">
      <el-table border stripe  :data="selectList">
        <el-table-column label="检测项目" prop="name" />
        <el-table-column label="检测值" prop="value" />
      </el-table>
    </el-dialog>
    <el-dialog title="复检" :visible.sync="showFuJian" width="600px" append-to-body>
      <el-form ref="form" label-position="left" :model="form" :rules="rules" :disabled="isView" label-width="120px">
        <el-form-item label="复检日期" prop="recheckTime">
          <el-date-picker
            style="width: 100%"
            v-model="form.recheckTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-divider content-position="left">检测项目列表</el-divider>
        <el-row class="mb20" :gutter="16">
          <el-col :offset="2" :span="8">
            <div>检测项目</div>
          </el-col>
          <el-col :span="14">
            <div>检测值</div>
          </el-col>
        </el-row>
        <el-row
          v-for="(itemRow, i) in form.recheckItemsArr"
          :key="i"
          :gutter="20"
        >
          <el-col :offset="2" :span="8">
            <el-form-item
              label=""
              label-width="0"
              :prop="'recheckItemsArr.' + i + '.name'"
              :rules="[{ required: true, message: '检测项目不能为空', trigger: 'blur' }]"
            >
              <el-input v-model="itemRow.name" disabled placeholder="请输入检测项目" />
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item
              label=""
              label-width="0"
              :prop="'recheckItemsArr.' + i + '.value'"
              :rules="[{ required: true, message: '检测值不能为空', trigger: 'blur' }]"
            >
              <el-input v-model="itemRow.value" placeholder="请输入检测值" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFujian">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getSamplePage, getSampleDetail, addSamplePage, editSamplePage, delSamplePage } from "../../../api/app/sample";
import { listProductCategoryAll } from "../../../api/app/productCategory";
import { getProducePlanDetail} from "../../../api/app/producePlan";
import {required, rules} from "../../../utils/formRules";
import {formatDate, changeDate,getFindByKey} from "@/utils/index";
import {getUserProfile} from "../../../api/system/user";
import { getPartItem } from "../../../api/app/part";
import { getInspectionList } from "../../../api/app/inspection";
import moment from "moment";
import {mapState} from "vuex";

export default {
  name: "",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      disposalList: [],
      // 弹出层标题
      title: "",
      isView:false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        timeRange: null,
        sampleNum: null,
        startTime: null,
        endTime: null,
        animalType: null
      },
      pickerOptions: {
        disabledDate(time) {
          // 获取当前日期
          const today = new Date();
          today.setHours(0, 0, 0, 0); // 将时间设置为当天的 00:00:00

          // 禁用今天之后的日期
          return time.getTime() > today.getTime();
        }
      },
      // 表单参数
      form: {
        id: null,
        animalCertNo: null,
        dealTime: moment(new Date().getTime() + 1000 * 60 * 60 * 24 * 30 * 3).format('YYYY-MM-DD HH:mm:ss'),
        entranceBatchId: null,
        keepTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
        produceName: null,
        sampleDeal: '无害化处理',
        sampleNum: null,
        supplierId: null,
        supplierName: null,
        userName: null,
        examineItem: null,
        moisture: null,
        animalType: null,
        clearDate: moment(new Date().getTime() + 1000 * 60 * 60 * 24 * 30 * 3).format('YYYY-MM-DD'),
        clearPerson: null,
        examineItemsArr: [],
        examineItems:null,
        recheckTime: null,
        recheckItem: null,
        recheckItemsArr: [],
      },
      rules: {
        keepTime: [required('留存时间不能为空')],
        sampleNum: [required('样品编号不能为空')],
        produceName: [required('产品名称不能为空')],
        entranceBatchId: [required('分圈批次不能为空')],
        userName: [required('留样人不能为空')],
        sampleDeal: [required('样品处理去向不能为空')],
        // examineItem: [required('检测项目不能为空')],
        // moisture: [required('水份值不能为空'), rules.decimals],
        clearDate: [required('清除时间不能为空')],
        clearPerson: [required('清除人不能为空')],
        recheckTime: [required('复检日期不能为空')]
      },
      // 产品列表
      proList: [],
      // 入场批次
      batchList: [],
      user: {},
      show: false,
      selectList: [],
      showFuJian: false,
      inspectionList: [],
      // 标记是否正在从详情回填
      isFromDetail: false
    }
  },
  watch: {
    "queryParams.timeRange": {
      handler(newVal) {
        if (newVal) {
          this.queryParams.startTime = newVal[0]
          this.queryParams.endTime = newVal[1]
        } else {
          this.queryParams.startTime = null
          this.queryParams.endTime = null
        }
      },
      deep: true
    },
    "form.entranceBatchId": {
      handler(newVal) {
        if (newVal) {
          //根据入场ID获取该批次的屠宰开始时间作为样品留存时间
          this.getProducePlan();
          let item = getFindByKey(this.batchList, newVal, 'entranceBatchId')
          if (item) {
            this.form.supplierName = item.supplierName
            this.form.supplierId = item.supplierId
            this.form.animalCertNo = item.animalCertNo
            this.form.animalType = item.animalType
          }
        } else {
          this.form.supplierName = null
          this.form.supplierId = null
          this.form.animalCertNo = null
          this.form.animalType = null
        }
      },
      deep: true
    },
    "form.animalType": {
      handler(newVal, oldVal) {
        this.getPro()
      },
      deep: true,
    }
  },
  computed: {
    ...mapState({
      animalList: state => state.user.animalList
    }),
    animalName() {
      return (value) => {
        if (value === null) return '未知'
        const animal = this.animalList.find(item =>
          String(item.typeValue) === String(value)
        )
        return animal ? animal.typeName : '未知'
      }
    }
  },
  created() {
    this.loading = false
    this.getInspection()
    this.getUser()
    this.getBatch();
    this.getPro()
    this.getList();
  },
  methods: {
    changeDate(cellValue) {
       if (cellValue == null || cellValue == "") return "";
      var date = new Date(cellValue)
      var year = date.getFullYear()
      var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
      var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
      return year + '-' + month + '-' + day
    },
    // 根据选择项目选择是选项还是input
    changeRowName(e, i) {
      this.inspectionList.forEach(item => {
        if(e === item.projectName) {
          this.form.examineItemsArr[i].checkType = item.checkType
        }
      })
      console.log(e, i)
    },
    /** 根据提供的值 返回数组 **/
    getResultList(val) {
      let arr = null
      this.inspectionList.forEach(item => {
        if(val === item.projectName) {
          arr = item.resultList
        }
      })
      return arr
    },
    // 检测项目
    getInspection() {
      getInspectionList({}).then(res => {
        res.data.forEach(item => {
          item.resultList = item.result ? JSON.parse(item.result) : []
        })
        this.inspectionList = res.data
      })
    },
    //获取批次的生产计划
    getProducePlan(){
      let params = {
        entranceBatchId: this.form.entranceBatchId
      }
      getProducePlanDetail(params).then(res => {
        if(res.data && res.data.planStartTime){
          this.form.keepTime = res.data.planStartTime
        }
      })
    },
    addItem(i) {
      let examineItemsArr = this.form.examineItemsArr
      examineItemsArr.push({
        name: null,
        checkType: 0,
        value: null,
      });
      this.$set(this.form,"examineItemsArr",examineItemsArr)
      console.log(this.form.examineItemsArr)
    },
    removeItem(i) {
      this.form.examineItemsArr.splice(i, 1);
    },
    /** getUser **/
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.form.userName = response.data.nickName
      });
    },
    /** 入场批次 **/
    getBatch() {
      let params = {
        entranceTime: changeDate(new Date().getTime() - 1000*60 * 60 * 24 * 2) + ' 23:59:59'
      }
      getPartItem(params).then(res => {

        this.batchList = res.data.data
      })
    },
    /** 产品列表 **/
    getPro() {
      if (this.isFromDetail) return;
      if(!this.form.animalType) return;
      let params = {
        animalType: this.form.animalType
      }
      listProductCategoryAll(params).then(res => {
        this.proList = res.rows
        if(res.rows && res.rows.length > 0) {
          if(!this.form.produceName) {
            this.form.produceName = res.rows[0].productName
          }
        } else {
          this.form.produceName = null
        }
      })
    },
    /** 查询检验项目列表 */
    getList() {
      getSamplePage(this.queryParams).then(res => {
        this.disposalList = res.data.records;
        this.total = res.data.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        timeRange: null,
        sampleNum: null,
        startTime: null,
        endTime: null
      }
      // this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isView = false;
      this.title = "添加样品留存登记";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      getSampleDetail(params).then(res => {
        this.isFromDetail = true
        this.form = res.data;
        let examineItemsArr = this.form.examineItems ? JSON.parse(this.form.examineItems) : [{name: '水份检测', value: null}]
        this.$set(this.form,"examineItemsArr",examineItemsArr)
        this.open = true;
        this.isView = false;
        this.title = "修改样品留存登记";
        this.$nextTick(() => {
          this.isFromDetail = false
        })
      })
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      getSampleDetail(params).then(res => {
        this.form = res.data;
        let examineItemsArr = this.form.examineItems ? JSON.parse(this.form.examineItems) : [{name: '水份检测', value: null}]
        this.$set(this.form,"examineItemsArr",examineItemsArr);
        this.open = true;
        this.isView = true;
        this.title = "查看样品留存登记";
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.showFuJian = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        animalCertNo: null,
        animalType: null,
        dealTime:  moment(new Date().getTime() + 1000 * 60 * 60 * 24 * 30 * 3).format('YYYY-MM-DD HH:mm:ss'),
        entranceBatchId: null,
        keepTime:  moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
        produceName: null,
        sampleDeal: '无害化处理',
        sampleNum: null,
        supplierId: null,
        supplierName: null,
        userName: this.user.nickName,
        examineItem: null,
        moisture: null,
        clearDate: moment(new Date().getTime() + 1000 * 60 * 60 * 24 * 30 * 3).format('YYYY-MM-DD'),
        clearPerson: this.user.nickName,
        examineItemsArr: [{
          name: this.inspectionList.length > 0 ? this.inspectionList[0].projectName : null,
          checkType: this.inspectionList.length > 0 ? this.inspectionList[0].checkType : 0,
          value: null
        }],
        examineItems:null,
        recheckTime: null,
        recheckItemsArr: [],
        recheckItem: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.examineItems = JSON.stringify(this.form.examineItemsArr)
          this.form.clearDate = moment(this.form.clearDate).format('YYYY-MM-DD HH:mm:ss')
          if (this.form.id != null) {
            // 编辑
            editSamplePage(this.form).then(res => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            })
          } else {
            // 新增
            addSamplePage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      let params = {
        ids: ids
      }
      delSamplePage(params).then(res => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      })
    },
    /** 删除按钮操作 */
    handleDeleteAll() {
      const ids = this.ids;
      this.$modal.confirm('是否确认删除所选数据项？').then(() => {
        let params = {
          ids: ids.join(',')
        }
        delSamplePage(params).then(res => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
          this.$refs.multipleTable.clearSelection();
        })
      })
    },
    openModal(item) {
      this.selectList = item ? JSON.parse(item) : []
      console.log(this.selectList)
      this.show = true
    },
    resetShow() {
      this.show = false
      this.selectList = []
    },
    handleFujian(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      getSampleDetail(params).then(res => {
        this.form = res.data;
        let recheckItemsArr = this.form.examineItems ? JSON.parse(this.form.examineItems) : [{name: '水份检测', value: null}]
        this.$set(this.form,"recheckItemsArr",recheckItemsArr);
        this.showFuJian = true
      })
    },
    submitFujian() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.recheckItem = JSON.stringify(this.form.recheckItemsArr)
          if (this.form.id != null) {
            // 编辑
            editSamplePage(this.form).then(res => {
              this.$modal.msgSuccess("修改成功");
              this.cancel()
              this.getList();
            })
          }
        }
      })
    },
  }
}
</script>

<style scoped lang="scss">
  .text-blue {
    color: #1853C5;
    cursor: pointer;
  }
</style>
