<template>
  <div class="app-container">
    <el-card style="">
      <el-row>
        <span>日期:</span>
        <el-date-picker
          v-model="dateTime"
          :clearable="false"
          size="small"
          type="daterange"
          align="center"
          style="width: 240px;"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="～"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <!--        <span>状态:</span>-->
        <!--        <el-select v-model="statusNumberValue" placeholder="状态" size="small" style="width:200px" @change="fetchData">-->
        <!--          <el-option-->
        <!--            v-for="item in statusNumber"-->
        <!--            :key="item.value"-->
        <!--            :label="item.label"-->
        <!--            :value="item.value"/>-->
        <!--        </el-select>-->
        <el-button type="success" icon="el-icon-search" size="small" style="margin-left: 20px;margin-top: 15px" @click="fetchData">查询</el-button>
        <!--        <el-button type="warning" icon="el-icon-plus" size="small" style="margin-left: 20px;margin-top: 15px" @click="addCheckOrder()">新增质检单</el-button>-->
      </el-row>
      <el-col :span="24">
        <el-table
          :data="tableData"
          border
          element-loading-text="数据加载中"
          highlight-current-row
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          style="width: 80%"
          height= "640px"
          size="small"
        >
          <el-table-column label="序号" type="index" align="center"/>
          <el-table-column label="质检单名称" min-width="100" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.质检单名称 }}
            </template>
          </el-table-column>
          <el-table-column label="质检日期" width="90" align="center">
            <template slot-scope="scope">
              {{ scope.row.质检日期 }}
            </template>
          </el-table-column>
          <el-table-column label="检验部门" width="100" align="center">
            <template slot-scope="scope">
              {{ scope.row.部门名称 }}
            </template>
          </el-table-column>
          <el-table-column label="状态" width="80" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.状态 === 1" size="small" type="danger">未下发</el-tag>
              <el-tag v-if="scope.row.状态 === 2" size="small" type="warning">未执行</el-tag>
              <el-tag v-if="scope.row.状态 === 3" size="small" type="primary">质检中</el-tag>
              <el-tag v-if="scope.row.状态 === 4" size="small" type="success">已完成</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="检验数量" width="80" align="center">
            <template slot-scope="scope">
              <el-link type="primary" @click="CheckOrder_rowClick(scope.row)">{{ scope.row.质检数量 }}</el-link>
            </template>
          </el-table-column>
          <el-table-column label="检验备注" min-width="100" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.检查备注 }}
            </template>
          </el-table-column>
          <el-table-column v-if="tokenCode1 !== 3" label="编辑" width="100" align="center">
            <template slot-scope="scope">
              <el-button v-if="scope.row['状态'] === 1" size="mini" type="text" title="下发" icon="el-icon-bottom" @click="deleteCheckChangeStatus(scope.row, 2)" />
              <el-button v-if="scope.row['状态'] === 2" size="mini" type="text" title="取消下发" icon="el-icon-top" @click="deleteCheckChangeStatus(scope.row, 1)" />
              <!--              <el-button v-if="scope.row['状态'] === 1" size="mini" type="text" title="修改" icon="el-icon-edit" @click="editCheckOrder(scope.row)" />-->
              <el-button v-if="scope.row['状态'] === 1" size="mini" type="text" title="删除" icon="el-icon-delete" style="color: #ff0000" @click="deleteCheckOrder(scope.row)"/>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            :total="totalNum"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </el-col>
    </el-card>
    <el-dialog :visible.sync="dialogFormVisible_addCheckOrder" title="增加检查工单" center style="min-height: 200px;" width="400px">
      <el-form ref="form_addCheckOrder" :model="form_addCheckOrder" :rules="rules_addCheckOrder" label-position="right" label-width="110px">
        <el-form-item label="检查单名称" prop="checkOrderName" style="display: inline-block">
          <el-input
            v-model="form_addCheckOrder.checkOrderName"
            clearable
            size="small"
            placeholder="请输入检查单名称"/>
        </el-form-item>
        <el-form-item label="产品编号" prop="productCode" style="display: inline-block">
          <el-input
            v-model="form_addCheckOrder.productCode"
            clearable
            size="small"
            placeholder="请输入产品编号"/>
        </el-form-item>
        <el-form-item label="检查人" prop="usedPersonId" style="display: inline-block">
          <el-input v-model="form_addCheckOrder.usedPersonName" placeholder="请双击选择" size="small" readonly style="width:200px" @dblclick.native="dialogFormVisible_selectPeople = true"/>
        </el-form-item>
        <el-form-item label="检查时间" prop="checkOrderDate" style="display: inline-block">
          <el-date-picker
            v-model="form_addCheckOrder.checkOrderDate"
            :clearable="false"
            size="small"
            type="date"
            style="width: 200px;"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"/>
        </el-form-item>
        <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
          <div style="width: 200px">
            <el-input
              v-model="form_addCheckOrder.checkOrderRemarks"
              :rows="2"
              type="textarea"
              size="small"
              placeholder="请输入备注"/>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="addCheckOrder_cancel('form_addCheckOrder')">取消</el-button>
        <el-button type="primary" size="small" @click="addCheckOrder_sure('form_addCheckOrder')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible_editCheckOrder" title="编辑检查工单" center style="min-height: 200px;" width="400px">
      <el-form ref="form_editCheckOrder" :model="form_editCheckOrder" :rules="rules_editCheckOrder" label-position="right" label-width="110px">
        <el-form-item label="检查单名称" prop="checkOrderName" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrder.checkOrderName"
            clearable
            size="small"
            placeholder="请输入检查单名称"/>
        </el-form-item>
        <el-form-item label="产品编号" prop="productCode" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrder.productCode"
            clearable
            size="small"
            placeholder="请输入产品编号"/>
        </el-form-item>
        <el-form-item label="检查人" prop="usedPersonId" style="display: inline-block">
          <el-input v-model="form_editCheckOrder.usedPersonName" placeholder="请双击选择" size="small" readonly style="width:200px" @dblclick.native="dialogFormVisible_selectPeople = true"/>
        </el-form-item>
        <el-form-item label="检查时间" prop="checkOrderDate" style="display: inline-block">
          <el-date-picker
            v-model="form_editCheckOrder.checkOrderDate"
            :clearable="false"
            size="small"
            type="date"
            style="width: 200px;"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"/>
        </el-form-item>
        <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
          <div style="width: 200px">
            <el-input
              v-model="form_editCheckOrder.checkOrderRemarks"
              :rows="2"
              type="textarea"
              size="small"
              placeholder="请输入备注"/>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="editCheckOrder_cancel('form_editCheckOrder')">取消</el-button>
        <el-button type="primary" size="small" @click="editCheckOrder_sure('form_editCheckOrder')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible_selectPeople" title="人员信息" center width="750px">
      <div style="height: 420px">
        <div style="float: left;margin-top: 10px;margin-left: 20px;overflow-y: scroll;height: 400px;border: 1px solid #cfcfcf">
          <el-tree
            :data="data2_tree"
            node-key="id"
            style="width: 150px;float: left"
            height="400"
            accordion
            @node-click="handleNodeClick"
          />
        </div>
        <el-table :data="List1" highlight-current-row height="400" style="width: 400px;float: left;margin-left: 30px" @row-click="peopleRowClick">
          <el-table-column label="考勤编号" align="center" >
            <template slot-scope="scope">
              {{ scope.row.考勤编号 }}
            </template>
          </el-table-column>
          <el-table-column label="姓名" align="center" >
            <template slot-scope="scope">
              {{ scope.row.姓名 }}
            </template>
          </el-table-column>
          <el-table-column label="性别" align="center">
            <template slot-scope="scope">
              {{ scope.row.性别 }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-button style="margin-left: 260px" @click="dialogFormVisible = false">取消</el-button>
      <el-button type="primary" style="margin-top: 20px" @click="getName">确认</el-button>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible_addCheckOrder_content" title="增加检查项目" center style="min-height: 200px;" width="800px">
      <el-form ref="form_addCheckOrder_content" :model="form_addCheckOrder_content" :rules="rules_addCheckOrder_content" label-position="right" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查单名称" prop="checkOrderName" style="display: inline-block">
              <el-input
                v-model="form_addCheckOrder_content.checkOrderName"
                readonly
                size="small"
                style="width: 200px"
                placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查单号" prop="checkOrderCode" style="display: inline-block">
              <el-input
                v-model="form_addCheckOrder_content.checkOrderCode"
                readonly
                style="width: 200px"
                size="small"
                placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工位号" prop="stationNumberValue" style="display: inline-block">
              <el-select v-model="form_addCheckOrder_content.stationNumberValue" size="small" placeholder="请选择工位号" style="width: 200px" @change="searchCheckContentBase(form_addCheckOrder_content.stationNumberValue)">
                <el-option
                  v-for="item in stationNumber"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查项目" prop="checkOrderContentId" style="display: inline-block">
              <el-select v-model="form_addCheckOrder_content.checkOrderContentId" size="small" placeholder="请选择检查项目" style="width: 200px">
                <el-option
                  v-for="item in CheckContentBase"
                  :key="item.ID"
                  :label="item.检查项目"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="检查内容" prop="checkOrderContent" style="display: inline-block">
            <el-input v-model="form_addCheckOrder_content.checkOrderContent" :rows="2" type="textarea" placeholder="检查内容" size="small" readonly style="width:575px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查工具" prop="checkOrderToolId" style="display: inline-block">
              <el-select v-model="form_addCheckOrder_content.checkOrderToolId" size="small" placeholder="请选择检查工具" style="width: 200px">
                <el-option
                  v-for="item in CheckToolBase"
                  :key="item.ID"
                  :label="item.检查工具名称"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查方法" prop="checkOrderMethodId" style="display: inline-block">
              <el-select v-model="form_addCheckOrder_content.checkOrderMethodId" size="small" placeholder="请选择检查方法" style="width: 200px">
                <el-option
                  v-for="item in CheckMethodBase"
                  :key="item.ID"
                  :label="item.检查方法名称"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
            <div style="width: 575px">
              <el-input
                v-model="form_addCheckOrder_content.checkOrderRemarks"
                :rows="2"
                type="textarea"
                size="small"
                placeholder="请输入备注"/>
            </div>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="addCheckOrder_content_cancel('form_addCheckOrder_content')">取消</el-button>
        <el-button type="primary" size="small" @click="addCheckOrder_content_sure('form_addCheckOrder_content')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible_editCheckOrder_content" title="编辑检查工单" center style="min-height: 200px;" width="800px">
      <el-form ref="form_editCheckOrder_content" :model="form_editCheckOrder_content" :rules="rules_editCheckOrder_content" label-position="right" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查单名称" prop="checkOrderName" style="display: inline-block">
              <el-input
                v-model="form_editCheckOrder_content.checkOrderName"
                readonly
                size="small"
                style="width: 200px"
                placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查单号" prop="checkOrderCode" style="display: inline-block">
              <el-input
                v-model="form_editCheckOrder_content.checkOrderCode"
                readonly
                style="width: 200px"
                size="small"
                placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工位号" prop="stationNumberValue" style="display: inline-block">
              <el-select v-model="form_editCheckOrder_content.stationNumberValue" size="small" placeholder="请选择工位号" style="width: 200px" @change="searchCheckContentBase(form_editCheckOrder_content.stationNumberValue)">
                <el-option
                  v-for="item in stationNumber"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查项目" prop="checkOrderContentId" style="display: inline-block">
              <el-select v-model="form_editCheckOrder_content.checkOrderContentId" size="small" placeholder="请选择检查项目" style="width: 200px">
                <el-option
                  v-for="item in CheckContentBase"
                  :key="item.ID"
                  :label="item.检查项目"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="检查内容" prop="checkOrderContent" style="display: inline-block">
            <el-input v-model="form_editCheckOrder_content.checkOrderContent" :rows="2" type="textarea" placeholder="检查内容" size="small" readonly style="width:575px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查工具" prop="checkOrderToolId" style="display: inline-block">
              <el-select v-model="form_editCheckOrder_content.checkOrderToolId" size="small" placeholder="请选择检查工具" style="width: 200px">
                <el-option
                  v-for="item in CheckToolBase"
                  :key="item.ID"
                  :label="item.检查工具名称"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查方法" prop="checkOrderMethodId" style="display: inline-block">
              <el-select v-model="form_editCheckOrder_content.checkOrderMethodId" size="small" placeholder="请选择检查方法" style="width: 200px">
                <el-option
                  v-for="item in CheckMethodBase"
                  :key="item.ID"
                  :label="item.检查方法名称"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
            <div style="width: 575px">
              <el-input
                v-model="form_editCheckOrder_content.checkOrderRemarks"
                :rows="2"
                type="textarea"
                size="small"
                placeholder="请输入备注"/>
            </div>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="editCheckOrder_content_cancel('form_editCheckOrder_content')">取消</el-button>
        <el-button type="primary" size="small" @click="editCheckOrder_content_sure('form_editCheckOrder_content')">确定</el-button>
      </div>
    </el-dialog>
    <!--    方案项目详情-->
    <el-dialog :visible.sync="dialogFormVisible_addCheckOrder_content_show" title="检验计划详情" center style="min-height: 200px;" width="1200px">
      <el-table
        :data="tableData_content"
        :expand-row-keys="expandsDetail"
        :row-key="getRowKeys"
        border
        element-loading-text="数据加载中"
        highlight-current-row
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
        style="width: 100%"
        height="500px"
        size="small"
        @expand-change="selectPlan"
      >
        <el-table-column v-if="currentSelectCheckOrder.状态 !== 1" key="tableData_content_1" align="center" type="expand" label="" width="35">
          <template slot-scope="scope" >
            <div style="margin: 5px 10px;width: 1000px;z-index: 99;">
              <el-col :span="16">
                <el-table
                  :data="tableDataPrintDetail"
                  :header-cell-style="{ background: '#e5e7f8', color: '#606266' }"
                  element-loading-text="数据加载中"
                  element-loading-spinner="el-icon-loading"
                  element-loading-background="rgba(0, 0, 0, 0.2)"
                  class="main"
                  tooltip-effect="dark"
                  style="width: 100%;z-index: 99;"
                  height="230px"
                  border
                  size="mini">
                  <el-table-column align="center" label="序号" width="80px">
                    <template slot-scope="scope1">
                      {{ scope1.$index + 1 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="产品编号" width="250px">
                    <template slot-scope="scope1">
                      <div style="display: flex;align-items: center;justify-content: center">
                        <span v-if="scope.row.项目类型==='定量'" style="color: #ff0000;margin-right: 5px">*</span>
                        <el-input v-model="scope1.row.产品编号" size="mini" placeholder="产品编号" @change="judgeValueProductCode(scope.row, scope1.row)" />
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column v-if="scope.row.项目类型==='定量'" align="center" label="测量值">
                    <template slot-scope="scope1">
                      <div style="display: flex;align-items: center;justify-content: center">
                        <span style="color: #ff0000;margin-right: 5px">*</span>
                        <el-input-number v-model="scope1.row.测量值" size="mini" @change="judgeValueIsOK(scope.row, scope1.row)" />
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column v-if="scope.row.项目类型==='定量'" align="center" label="是否合格" width="150px">
                    <template slot-scope="scope1">
                      <div style="pointer-events: none;">
                        <el-tag v-if="scope1.row.是否合格 === 1" type="success" size="mini" style="width: 50px">OK</el-tag>
                        <el-tag v-else-if="scope1.row.是否合格 === 2" type="danger" size="mini" style="width: 50px">NOK</el-tag>
                        <el-tag v-else type="info" size="mini" style="width: 50px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</el-tag>
                        <!--                        <el-radio-group v-model="scope1.row.是否合格">-->
                        <!--                          <el-radio :label="1"><span style="color: #00893d">OK</span></el-radio>-->
                        <!--                          <el-radio :label="2"><span style="color: #ff0000">NOK</span></el-radio>-->
                        <!--                        </el-radio-group>-->
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column v-if="scope.row.项目类型==='定性'" align="center" label="是否合格">
                    <template slot-scope="scope1">
                      <el-radio-group v-model="scope1.row.是否合格" @input="changeIsOk(scope.row, scope1.row)">
                        <el-radio :label="1"><span style="color: #00893d">OK</span></el-radio>
                        <el-radio :label="2"><span style="color: #ff0000">NOK</span></el-radio>
                      </el-radio-group>
                    </template>
                  </el-table-column>
                  <!--                <el-table-column align="center" label="状态" width="100px">-->
                  <!--                  <template slot-scope="scope">-->
                  <!--                    <el-tag v-if="scope.row.状态 === 1" type="success" size="mini">已完成</el-tag>-->
                  <!--                    <el-tag v-else type="info" size="mini">未检测</el-tag>-->
                  <!--                  </template>-->
                  <!--                </el-table-column>-->
                </el-table>
              </el-col>
              <el-col :span="8">
                <div style="">
                  <!--                  <div style="margin: 10px;">-->
                  <!--                    <span style="font-size: 16px">产品编号：</span>-->
                  <!--                    <el-input v-model="scope.row.产品编号" size="mini" style="width: 200px" />-->
                  <!--                  </div>-->
                  <div style="margin: 10px;">
                    <span style="font-size: 16px">过程备注：</span>
                    <el-input v-model="scope.row.备注" :rows="2" type="textarea" style="width: 200px" />
                  </div>
                  <div style="margin: 10px;">
                    <el-button :disabled="currentSelectCheckOrder['状态'] === 4" type="success" size="small" @click="editCheckOrder_content_sure(scope.row)">确认结果</el-button>
                    <el-button :disabled="currentSelectCheckOrder['状态'] === 4" icon="el-icon-upload2" type="primary" size="small" @click="getGuidePic1(scope.row)">上传图片</el-button>
                    <!--                    <span style="font-size: 16px">检验图片：</span>-->
                    <!--                    <span style="font-size: 16px">{{ scope.row.上传图片数量 }}</span>-->
                  </div>
                </div>
              </el-col>
            </div>
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_2" label="状态" width="120" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row['状态'] === 0" type="warning" size="mini">未检【{{ scope.row.检查数量 }}】项</el-tag>
            <el-tag v-else-if="scope.row['状态'] === 1 && scope.row['是否合格'] === 2" type="danger" size="mini">NOK 【{{ scope.row.检查数量 }}】项</el-tag>
            <el-tag v-else type="success" size="mini">OK 【{{ scope.row.检查数量 }}】项</el-tag>
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_3" label="类型" width="80" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.项目类型==='定性'" style="color: #4bbdff">{{ scope.row.项目类型 }}</span>
            <span v-if="scope.row.项目类型==='定量'" style="color: #00893d">{{ scope.row.项目类型 }}</span>
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_4" label="检验项目" width="150" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查项目 }}
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_6" label="检验内容" min-width="100" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查内容 }}
          </template>
        </el-table-column>
        <!--        <el-table-column label="项目数量" width="80" align="center">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.检查数量 }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column key="tableData_content_7" label="指导图片" width="80" align="center">
          <template slot-scope="scope">
            <el-link v-if="scope.row.指导图片数量 > 0" type="primary" @click="showFileListInfo(scope.row)">{{ scope.row.指导图片数量 }}</el-link>
            <span v-else>{{ scope.row.指导图片数量 }}</span>
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_8" label="检验工具" width="180" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查工具编号1 }}{{ scope.row.检查工具名称 }}
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_9" label="检验方法" width="100" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查方法名称 }}
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_10" label="上限" width="80" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.项目类型==='定量'">{{ scope.row.上限 }}</span>
            <span v-else />
          </template>
        </el-table-column>
        <el-table-column key="tableData_content_11" label="下限" width="80" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.项目类型==='定量'">{{ scope.row.下限 }}</span>
            <span v-else />
          </template>
        </el-table-column>
        <el-table-column v-if="currentSelectCheckOrder.状态 === 1 && tokenCode1 !== 3" key="tableData_content_12" label="编辑" width="70" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-delete" title="删除" style="color: #ff0000" @click="deleteCheckOrder_content(scope.row)"/>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible_addCheckOrder_content_show = false">关闭</el-button>
        <el-button v-if="currentSelectCheckOrder.状态 !== 1" type="primary" size="small" @click="editCheckOrder_Finish()">结束工单({{ tableData_contentFinish }}/{{ tableData_contentAll }} )</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="showTableData_content_exchange" title="指导图片查看" center style="min-height: 200px" width="400px">
      <el-row style="height: 300px;overflow: auto;border: 1px solid #bebebe">
        <div v-for="(item, index) in RepairManagementDataTableOrigin" :key="index" style="margin: 10px 0">
          <el-row v-if="/(jpg|jpeg|png|GIF|JPG|PNG)$/i.test(item.附件类型)">
            <el-link type="primary" @click="showPic(item)">
              <span class="tmp">
                {{ index + 1 }}.{{ item.附件名称 }}.{{ item.附件类型 }}
              </span>
            </el-link>
            <div style="height: 1px;background-color: #bebebe;margin-top: 2px" />
          </el-row>
          <el-row v-else>
            <span class="tmp">
              {{ index + 1 }}.{{ item.附件名称 }}.{{ item.附件类型 }}
            </span>
            <div style="height: 1px;background-color: #bebebe;margin-top: 2px" />
          </el-row>
        </div>
      </el-row>
      <el-image-viewer
        v-if="imgViewerVisible"
        :url-list="imgViewerList"
        :on-close="()=>{imgViewerVisible=false}"
        style="z-index: 98965"
      />
    </el-dialog>
    <el-dialog :visible.sync="showTableData_content_exchange2" title="过程图片上传" center style="min-height: 200px" width="600px">
      <div style="height: 300px">
        <el-col :span="15">
          <el-row style="height: 300px;overflow: auto;border: 1px solid #bebebe">
            <div v-for="(item, index) in RepairManagementDataTableOrigin" :key="index" style="margin: 10px 0">
              <el-row v-if="/(jpg|jpeg|png|GIF|JPG|PNG)$/i.test(item.附件类型)">
                <el-link type="primary" @click="showPic(item)">
                  <span class="tmp">
                    {{ index + 1 }}.{{ item.附件名称 }}.{{ item.附件类型 }}
                  </span>
                </el-link>
                <el-button type="text" size="mini" icon="el-icon-delete" style="color: #ff0000;float: right;padding: 0" @click="deletePic(item)"/>
              </el-row>
              <el-row v-else>
                <span class="tmp">
                  {{ index + 1 }}.{{ item.附件名称 }}.{{ item.附件类型 }}
                </span>
                <el-button type="text" size="mini" icon="el-icon-delete" style="color: #ff0000;float: right;padding: 0" @click="deletePic(item)"/>
              </el-row>
              <div style="height: 1px;background-color: #bebebe;margin-top: 2px" />
            </div>
          </el-row>
        </el-col>
        <el-col :span="8" style="margin-left: 5px">
          <div style="height: 268px">
            <el-upload
              id="invoiceScan"
              ref="uploadPDF"
              :multiple="true"
              :auto-upload="false"
              :on-success="uploadSuccessPDF"
              :before-upload="beforeUploadPdf"
              :on-exceed="warningExceedPdf"
              :limit="limit"
              :data="DataPDF"
              :action="uploadPDF"
              accept="image/png, image/jpeg"
              class="custom-upload"
              drag>
              <i class="el-icon-upload"/>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
              <div slot="tip">单次上传一张图，不超过5mb</div>
            </el-upload>
          </div>
          <div>
            <el-button size="small" @click="showTableData_content_exchange2=false">关闭</el-button>
            <el-button size="small" type="primary" @click="reportPicUpload()">上传图片</el-button>
          </div>
        </el-col>
      </div>
      <el-image-viewer
        v-if="imgViewerVisible"
        :url-list="imgViewerList"
        :on-close="()=>{imgViewerVisible=false}"
        style="z-index: 98965"
      />
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible_editCheckOrderFinish" title="检验工单完成确认" center style="min-height: 200px;" width="400px">
      <el-form ref="form_editCheckOrderFinish" :model="form_editCheckOrderFinish" :rules="form_editCheckOrderFinish_rules" label-position="right" label-width="110px">
        <el-form-item label="检查单名称" prop="checkOrderCode" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrderFinish.checkOrderCode"
            style="width: 200px"
            readonly
            size="small"/>
        </el-form-item>
        <!--        <el-form-item label="检查单号" prop="checkOrderName" style="display: inline-block">-->
        <!--          <el-input-->
        <!--            v-model="form_editCheckOrderFinish.checkOrderName"-->
        <!--            style="width: 200px"-->
        <!--            size="small"-->
        <!--            readonly/>-->
        <!--        </el-form-item>-->
        <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrderFinish.checkOrderRemarks"
            :rows="2"
            type="textarea"
            size="small"
            style="width: 200px"
            placeholder="请输入备注"/>
        </el-form-item>
        <el-form-item v-if="form_editCheckOrderFinish.checkOrderType === 2" label="授权账号" prop="checkOrderUserName" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrderFinish.checkOrderUserName"
            style="width: 200px"
            size="small"
            placeholder="请输入授权账号"
          />
        </el-form-item>
        <el-form-item v-if="form_editCheckOrderFinish.checkOrderType === 2" label="*授权密码" prop="checkOrderPassword" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrderFinish.checkOrderPassword"
            style="width: 200px"
            size="small"
            placeholder="请输入授权密码"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="editCheckOrder_Finish_cancel('form_editCheckOrderFinish')">取消</el-button>
        <el-button type="primary" size="small" @click="editCheckOrder_Finish_sure('form_editCheckOrderFinish')">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { fn } from '@/api/BasicData/WorkshopPersonnelRoleMana'
import { getNowTime2 } from '@/utils/tool'
import { mapGetters } from 'vuex'
import { base64ImgtoFile, getBeforeOrAfterTime } from '../../../utils/tool'
import elImageViewer from 'element-ui/packages/image/src/image-viewer'
import { url } from '../../../utils/request'
export default {
  components: { elImageViewer },
  data() {
    return {
      department: '', // 部门
      staffName: '', // 员工姓名
      roleName: null, // 角色名称
      tableData_people: [],
      imgViewerList: [],
      imgViewerVisible: false,
      List1: [],
      data2_tree: [],
      roleNames: [],
      personNumber: '',
      personName: '',
      stationNumber: [],
      stationNumberValue: '0',
      statusNumber: [
        {
          value: 0,
          label: '全部'
        },
        {
          value: 1,
          label: '未下发'
        },
        {
          value: 2,
          label: '已下发'
        }
      ],
      statusNumberValue: 0,
      dialogFormVisible_addCheckOrder_content_show: false,
      showTableData_content_exchange: false,
      showTableData_content_exchange2: false,
      RepairManagementDataTableOrigin: [],
      imageType: ['bmp', 'jpg', 'png', 'gif'],
      pdfType: ['pdf'],
      limit: 1,
      DataPDF: {},
      uploadPDF: url,
      dialogFormVisible2: false,
      activeName: 'first',
      dateTime: [],
      tokenCode1: 3,
      dialogFormVisible_selectPeople: false,
      tableData: [],
      tableData_content: [],
      expandsDetail: [],
      tableDataPrintDetail: [],
      dialogFormVisible_addCheckOrder: false,
      form_addCheckOrder: {
        checkOrderName: '',
        checkOrderRemarks: '',
        makePersonId: '',
        makePersonName: '',
        usedPersonId: '',
        usedPersonName: '',
        productCode: '',
        checkOrderDate: ''
      },
      rules_addCheckOrder: {
        usedPersonId: [{ required: true, message: '请选择检查人员' }],
        checkOrderName: [{ required: true, message: '请输入检查工单名称', trigger: 'blur' }],
        productCode: [{ required: true, message: '请选择产品编号', trigger: 'blur' }]
      },
      tableData_contentAll: 0,
      tableData_contentFinish: 0,
      dialogFormVisible_editCheckOrderFinish: false,
      form_editCheckOrderFinish: {
        checkOrderType: 1,
        checkOrderPassword: '',
        checkOrderUserName: '',
        checkOrderCode: '',
        checkOrderName: '',
        checkOrderRemarks: '',
        ID: ''
      },
      form_editCheckOrderFinish_rules: {
        checkOrderPassword: [{ required: true, message: '请输入授权账号', trigger: 'blur' }],
        checkOrderUserName: [{ required: true, message: '请输入授权密码', trigger: 'blur' }]
      },
      dialogFormVisible_editCheckOrder: false,
      form_editCheckOrder: {
        checkOrderName: '',
        checkOrderRemarks: '',
        makePersonId: '',
        makePersonName: '',
        usedPersonId: '',
        usedPersonName: '',
        productCode: '',
        checkOrderDate: ''
      },
      rules_editCheckOrder: {
        usedPersonId: [{ required: true, message: '请选择检查人员' }],
        checkOrderName: [{ required: true, message: '请输入检查工单名称', trigger: 'blur' }],
        productCode: [{ required: true, message: '请选择产品编号', trigger: 'blur' }]
      },
      RepairManagementReplaceForm: {
        ID: ''
      },
      currentSelectCheckOrder: {},
      dialogFormVisible_addCheckOrder_content: false,
      form_addCheckOrder_content: {
        checkOrderRemarks: '',
        checkOrderName: '',
        checkOrderCode: '',
        stationNumberValue: '',
        checkOrderContentId: '',
        checkOrderContent: '',
        checkOrderToolId: '',
        checkOrderMethodId: ''
      },
      rules_addCheckOrder_content: {
        checkOrderContentId: [{ required: true, message: '请选择检查项', trigger: 'change' }],
        checkOrderToolId: [{ required: true, message: '请选择检查工具', trigger: 'change' }],
        checkOrderMethodId: [{ required: true, message: '请选择检查方法', trigger: 'change' }]
      },
      dialogFormVisible_editCheckOrder_content: false,
      form_editCheckOrder_content: {
        ID: '',
        checkOrderRemarks: '',
        checkOrderName: '',
        checkOrderCode: '',
        stationNumberValue: '',
        checkOrderContentId: '',
        checkOrderContent: '',
        checkOrderToolId: '',
        checkOrderMethodId: ''
      },
      rules_editCheckOrder_content: {
        checkOrderContentId: [{ required: true, message: '请选择检查项', trigger: 'change' }],
        checkOrderToolId: [{ required: true, message: '请选择检查工具', trigger: 'change' }],
        checkOrderMethodId: [{ required: true, message: '请选择检查方法', trigger: 'change' }]
      },

      CheckContentBase: [],
      tableDataCheckContentBase: [],
      dialogFormVisible_addCheckContentBase: false,
      form_addCheckContentBase: {
        stationNumberValue: '',
        checkItem: '',
        checkItemContent: '',
        standardValue: '',
        maximumValue: '',
        minimumValue: '',
        unit: ''
      },
      rules_addCheckContentBase: {
        stationNumberValue: [{ required: true, message: '请选择工位号', trigger: 'change' }],
        checkItem: [{ required: true, message: '请输入检查项', trigger: 'blur' }],
        checkItemContent: [{ required: true, message: '请输入检查项内容', trigger: 'blur' }]
      },
      dialogFormVisible_editCheckContentBase: false,
      form_editCheckContentBase: {
        ID: '',
        stationNumberValue: '',
        checkItem: '',
        checkItemContent: '',
        standardValue: '',
        maximumValue: '',
        minimumValue: '',
        unit: ''
      },
      rules_editCheckContentBase: {
        stationNumberValue: [{ required: true, message: '请选择工位号', trigger: 'change' }],
        checkItem: [{ required: true, message: '请输入检查项', trigger: 'blur' }],
        checkItemContent: [{ required: true, message: '请输入检查项内容', trigger: 'blur' }]
      },

      tableDataCheckToolBase: [],
      CheckToolBase: [],
      dialogFormVisible_addCheckToolBase: false,
      form_addCheckToolBase: {
        toolName: ''
      },
      rules_addCheckToolBase: {
        toolName: [{ required: true, message: '请输入工具名称', trigger: 'blur' }]
      },
      dialogFormVisible_editCheckToolBase: false,
      form_editCheckToolBase: {
        ID: '',
        toolName: ''
      },
      rules_editCheckToolBase: {
        toolName: [{ required: true, message: '请输入工具名称', trigger: 'blur' }]
      },
      CheckMethodBase: [],
      tableDataCheckMethodBase: [],
      dialogFormVisible_addCheckMethodBase: false,
      form_addCheckMethodBase: {
        methodName: ''
      },
      rules_addCheckMethodBase: {
        methodName: [{ required: true, message: '请输入检查方法名称', trigger: 'blur' }]
      },
      dialogFormVisible_editCheckMethodBase: false,
      form_editCheckMethodBase: {
        ID: '',
        methodName: ''
      },
      rules_editCheckMethodBase: {
        methodName: [{ required: true, message: '请输入检查方法名称', trigger: 'blur' }]
      },
      listLoading: false,
      listLoading1: false,
      listLoading2: false,
      listLoading3: false,
      listLoading4: false,
      listLoading5: false,
      currentPage: 1,
      pageSize: 15,
      pageCurrent: 1,
      totalNum: null,
      downloadLoading: '',
      tableData_excel: [],
      colorchart: []
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'tokenCode',
      'departmentId',
      'id'
    ])
  },
  created() {
    this.tokenCode1 = parseInt(this.tokenCode)
    this.dateTime = [getBeforeOrAfterTime(-7), getNowTime2()]
    this.fetchData()
    this.fetchData_getPeople()
    this.getStationNumber()
    // this.searchCheckToolBase()
    // this.searchCheckMethodBase()
    // this.searchTableCheckToolBase()
    // this.searchTableCheckMethodBase()
  },
  methods: {
    fetchData_getPeople() {
      var param = []
      param[0] = ['子节点', 0]
      var Data = this.CreateData('11', '人事档案管理_部门关系_查询节点', param)
      this.ExecDatabase(Data).then(response => {
        const data = response.data
        this.data2_tree = fn(data, 0)
      })
      var param1 = []
      var Data1 = this.CreateData('11', '菜单系统模块_项目角色_查询数据_new', param1)
      this.ExecDatabase(Data1).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.roleNames.push({
            label: response.data[i].角色功能,
            value: response.data[i].角色编号
          })
        }
      })
      this.searchData_getPeople()
    },
    searchData_getPeople() {
      if (this.staffName !== '' && this.staffName !== null) {
        this.check1 = 1
      } else {
        this.check1 = 0
      }
      if (this.roleName !== '' && this.roleName !== null) {
        this.check2 = 1
      } else {
        this.check2 = 0
      }
      var param = []
      param[0] = ['姓名_check', this.check1]
      param[1] = ['姓名', this.staffName]
      param[2] = ['角色编号_check', this.check2]
      param[3] = ['角色编号', this.roleName]
      var Data = this.CreateData('11', '菜单系统模块_项目角色员工综合_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData_people = response.data
      })
    },
    handleNodeClick(data) { // 树节点点击
      this.department = data.label
      var param = []
      param[0] = ['考核部门编号', data.id]
      var Data = this.CreateData('11', '人事档案管理_人员_部门与人员_查询数据_根据部门编号', param)
      this.ExecDatabase(Data).then(response => {
        this.List1 = response.data
      })
    },
    getName() { // 提交人员
      this.dialogFormVisible_selectPeople = false
      this.form_addCheckOrder.usedPersonId = this.personNumber
      this.form_addCheckOrder.usedPersonName = this.personName
      this.form_editCheckOrder.usedPersonId = this.personNumber
      this.form_editCheckOrder.usedPersonName = this.personName
    },
    peopleRowClick(row) { // 获取当前行人员信息
      this.personName = row.姓名
      this.personNumber = row.人员编号
    },
    // 获取展开列的工单号
    getRowKeys(row) {
      return row.ID
    },
    // 控制展开列
    selectPlan(row, expandedRows) {
      if (expandedRows.length) {
        this.expandsDetail = []
        if (row) {
          this.tableDataPrintDetail = []
          var param = []
          param[0] = ['检查项id', row.ID]
          var Data = this.CreateData('11', '质检_工单检查内容_测量值_查询', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data.length !== 0) {
              this.tableDataPrintDetail = response.data
            }
            this.expandsDetail.push(row.ID)
          })
        }
      } else {
        this.expandsDetail = []
      }
    },
    getStationNumber() {
      this.stationNumber = []
      var param = []
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length) {
          this.stationNumberValue = response.data[0].工位号
          this.stationName = response.data[0].工序名称
        }
        for (let i = 0; i < response.data.length; i++) {
          this.stationNumber.push({
            label: `【${response.data[i].工位号}】${response.data[i].工位名称}`,
            value: response.data[i].工位号,
            labelName: response.data[i].工位名称
          })
        }
      })
    },
    showPic(item) {
      this.imgViewerList = [item.url]
      this.imgViewerVisible = true
    },
    showFileListInfo(item) {
      const param = []
      param[0] = ['检查项id', item.基础项目id]
      const Data = this.CreateData('11', '质检_基础_检查项_图片_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          for (let i = 0; i < response.data.length; i++) {
            if (this.imageType.indexOf(response.data[i]['附件类型'].toLowerCase()) !== -1) {
              response.data[i]['url'] = window.URL.createObjectURL(base64ImgtoFile(response.data[i]['附件内容'], response.data[i]['附件名称'], response.data[i]['附件类型']))
            } else {
              response.data[i]['url'] = window.URL.createObjectURL(base64ImgtoFile(response.data[i]['附件内容'], response.data[i]['附件名称'], response.data[i]['附件类型']))
            }
          }
          this.RepairManagementDataTableOrigin = response.data
          this.showTableData_content_exchange = true
        } else {
          this.RepairManagementDataTableOrigin = []
        }
      })
    },
    // region 质检工单维护
    fetchData() {
      this.listLoading = true
      // const statusNumber = this.statusNumberValue === 0 ? 0 : 1
      var param = []
      param[0] = ['开始日期', this.dateTime[0]]
      param[1] = ['结束日期', this.dateTime[1]]
      param[2] = ['状态', this.statusNumberValue]
      param[3] = ['状态_ischeck', false]
      param[4] = ['PageCurrent', this.pageCurrent]
      param[5] = ['PageSize', this.pageSize]
      param[6] = ['PageCount', 1000, 'int', '1']
      param[7] = ['ItemCount', 1000, 'int', '1']
      param[8] = ['日期_ischeck', 1]
      param[9] = ['部门id', this.departmentId]
      param[10] = ['部门id_ischeck', 0]
      var Data = this.CreateData('11', '质检_工单_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData = response.data.result
        this.totalNum = parseInt(response.data.output[0].ItemCount)
        this.listLoading = false
      }).catch(er => {
        this.listLoading = false
        this.$message.error('错误')
      })
    },
    addCheckOrder() {
      this.dialogFormVisible_addCheckOrder = true
      this.form_addCheckOrder.checkOrderName = ''
      this.form_addCheckOrder.checkOrderRemarks = ''
      this.form_addCheckOrder.makePersonId = this.id
      this.form_addCheckOrder.makePersonName = ''
      this.form_addCheckOrder.usedPersonId = ''
      this.form_addCheckOrder.usedPersonName = ''
      this.form_addCheckOrder.productCode = ''
      this.form_addCheckOrder.checkOrderDate = getNowTime2()
    },
    addCheckOrder_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['质检单名称', this.form_addCheckOrder.checkOrderName]
          param[1] = ['检查备注', this.form_addCheckOrder.checkOrderRemarks]
          param[2] = ['下发人id', this.form_addCheckOrder.makePersonId]
          param[3] = ['检验员id', this.form_addCheckOrder.usedPersonId]
          param[4] = ['产品编号', this.form_addCheckOrder.productCode]
          param[5] = ['质检日期', this.form_addCheckOrder.checkOrderDate]
          var Data = this.CreateData('12', '质检_工单_新增', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '增加成功',
                type: 'success'
              })
              this.dialogFormVisible_addCheckOrder = false
              this.fetchData()
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    addCheckOrder_cancel(formName) {
      this.dialogFormVisible_addCheckOrder = false
      this.$refs[formName].resetFields()
    },
    editCheckOrder(row) {
      this.dialogFormVisible_editCheckOrder = true
      this.form_editCheckOrder.checkOrderName = row.质检单名称
      this.form_editCheckOrder.checkOrderRemarks = row.检查备注
      this.form_editCheckOrder.makePersonId = row.下发人id
      this.form_editCheckOrder.makePersonName = row.下发人姓名
      this.form_editCheckOrder.usedPersonId = row.检验员id
      this.form_editCheckOrder.usedPersonName = row.质检员姓名
      this.form_editCheckOrder.productCode = row.产品编号
      this.form_editCheckOrder.checkOrderDate = row.质检日期
      this.form_editCheckOrder.ID = row.ID
    },
    editCheckOrder_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['质检单名称', this.form_editCheckOrder.checkOrderName]
          param[1] = ['检查备注', this.form_editCheckOrder.checkOrderRemarks]
          param[2] = ['下发人id', this.form_editCheckOrder.makePersonId]
          param[3] = ['检验员id', this.form_editCheckOrder.usedPersonId]
          param[4] = ['产品编号', this.form_editCheckOrder.productCode]
          param[5] = ['质检日期', this.form_editCheckOrder.checkOrderDate]
          param[6] = ['ID', this.form_editCheckOrder.ID]
          var Data = this.CreateData('12', '质检_工单_编辑', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '编辑成功！',
                type: 'success'
              })
              this.dialogFormVisible_editCheckOrder = false
              this.fetchData()
            } else {
              this.$message.error('编辑失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    editCheckOrder_cancel(formName) {
      this.dialogFormVisible_editCheckContentBase = false
      this.$refs[formName].resetFields()
    },
    deleteCheckOrder(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['ID', row.ID]
        var Data = this.CreateData('12', '质检_工单_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '质检工单删除成功',
              type: 'success'
            })
            this.fetchData()
          } else {
            this.$message.error('质检工单删除失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    deleteCheckChangeStatus(row, status) {
      var param = []
      param[0] = ['质检单号', row.质检单号]
      param[1] = ['状态', status]
      var message = [
        '',
        '取消下发',
        '下发'
      ]
      var Data = this.CreateData('12', '质检_工单_状态更改', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            message: message[status] + '成功',
            type: 'success'
          })
          this.fetchData()
        } else {
          this.$message.error(message[status] + '失败！')
        }
      })
    },
    CheckOrder_rowClick(row) {
      this.currentSelectCheckOrder = row
      this.fetchData_content(row)
    },
    searchCheckContentBase(stationNumberValue) {
      this.CheckContentBase = []
      var param = []
      param[0] = ['工位号', stationNumberValue]
      var Data = this.CreateData('11', '质检_基础_检查项_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.CheckContentBase = response.data
        if (this.CheckContentBase.length > 0) {
          this.form_addCheckOrder_content.checkOrderContentId = response.data[0]['ID']
          this.form_editCheckOrder_content.checkOrderContentId = response.data[0]['ID']
          this.form_addCheckOrder_content.checkOrderContent = response.data[0]['检查内容']
          this.form_editCheckOrder_content.checkOrderContent = response.data[0]['检查内容']
        } else {
          this.form_addCheckOrder_content.checkOrderContentId = ''
          this.form_editCheckOrder_content.checkOrderContentId = ''
          this.form_addCheckOrder_content.checkOrderContent = ''
          this.form_editCheckOrder_content.checkOrderContent = ''
        }
      }).catch(er => {
        this.$message.error('错误')
      })
    },
    searchCheckToolBase() {
      this.CheckToolBase = []
      var param = []
      var Data = this.CreateData('11', '质检_基础_检查工具_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.CheckToolBase = response.data
        if (this.CheckToolBase.length > 0) {
          this.form_addCheckOrder_content.checkOrderToolId = response.data[0]['ID']
        } else {
          this.form_addCheckOrder_content.checkOrderToolId = ''
        }
      }).catch(er => {
        this.listLoading2 = false
        this.$message.error('错误')
      })
    },
    searchCheckMethodBase() {
      this.CheckMethodBase = []
      var param = []
      var Data = this.CreateData('11', '质检_基础_检查方法_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.CheckMethodBase = response.data
        if (this.CheckMethodBase.length > 0) {
          this.form_addCheckOrder_content.checkOrderMethodId = response.data[0]['ID']
        } else {
          this.form_addCheckOrder_content.checkOrderMethodId = ''
        }
      }).catch(er => {
        this.$message.error('错误')
      })
    },
    // endregion
    // region 质检工单详细信息维护
    fetchData_content(row) {
      var param = []
      param[0] = ['质检单号', row.质检单号]
      var Data = this.CreateData('11', '质检_工单检查内容_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData_content = []
        const tableData_content1 = {}
        this.tableData_contentFinish = 0
        this.tableData_contentAll = 0
        for (let i = 0; i < response.data.length; i++) {
          if (Object.hasOwn(tableData_content1, response.data[i]['ID'])) {
            tableData_content1[response.data[i]['ID']]['children1'].push({
              ID: response.data[i]['测量值id'],
              测量值: response.data[i]['测量值'],
              是否合格: response.data[i]['是否合格1'],
              产品编号: response.data[i]['产品编号1'],
              状态: response.data[i]['测量值状态']
            })
          } else {
            tableData_content1[response.data[i]['ID']] = { ...{ children1: [{
              ID: response.data[i]['测量值id'],
              测量值: response.data[i]['测量值'],
              是否合格: response.data[i]['是否合格1'],
              产品编号: response.data[i]['产品编号1'],
              状态: response.data[i]['测量值状态']
            }] }, ...response.data[i] }
          }
        }
        for (const item of Object.entries(tableData_content1)) {
          const value = item[1]
          this.tableData_content.push(value)
          if (value.状态 === 1) this.tableData_contentFinish++
        }
        this.tableData_contentAll = this.tableData_content.length
        this.dialogFormVisible_addCheckOrder_content_show = true
      }).catch(er => {
        this.$message.error('错误')
      })
    },
    addCheckOrder_content() {
      this.dialogFormVisible_addCheckOrder_content = true
      this.form_addCheckOrder_content.checkOrderName = this.currentSelectCheckOrder['质检单名称']
      this.form_addCheckOrder_content.checkOrderCode = this.currentSelectCheckOrder['质检单号']
    },
    addCheckOrder_content_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['质检单号', this.form_addCheckOrder_content.checkOrderCode]
          param[1] = ['原始备注', this.form_addCheckOrder_content.checkOrderRemarks]
          param[2] = ['检查项id', this.form_addCheckOrder_content.checkOrderContentId]
          param[3] = ['检查工具id', this.form_addCheckOrder_content.checkOrderToolId]
          param[4] = ['检查方法id', this.form_addCheckOrder_content.checkOrderMethodId]
          var Data = this.CreateData('12', '质检_工单检查内容_新增', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '增加成功',
                type: 'success'
              })
              this.dialogFormVisible_addCheckOrder_content = false
              this.fetchData_content(this.currentSelectCheckOrder)
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    addCheckOrder_content_cancel(formName) {
      this.dialogFormVisible_addCheckOrder_content = false
      this.$refs[formName].resetFields()
    },
    editCheckOrder_content(row) {
      this.dialogFormVisible_editCheckOrder_content = true
      this.searchCheckContentBase(row.工位号)
      this.form_editCheckOrder_content.checkOrderRemarks = row.原始备注
      this.form_editCheckOrder_content.checkOrderName = this.currentSelectCheckOrder['质检单名称']
      this.form_editCheckOrder_content.checkOrderCode = this.currentSelectCheckOrder['质检单号']
      this.form_editCheckOrder_content.stationNumberValue = row.工位号
      this.form_editCheckOrder_content.checkOrderContentId = row.检查项id
      this.form_editCheckOrder_content.checkOrderContent = row.检查内容
      this.form_editCheckOrder_content.checkOrderToolId = row.检查工具id
      this.form_editCheckOrder_content.checkOrderMethodId = row.检查方法id
      this.form_editCheckOrder_content.ID = row.ID
    },
    editCheckOrder_content_sure(item) {
      let isOk = true
      for (let i = 0; i < item.children1.length; i++) {
        // if (item.children1[i].状态 !== 1) {
        //   isOk = false
        // }
        if (item.children1[i].测量值 === '' && item.项目类型 === '定量') {
          isOk = false
        }
        if (item.children1[i].产品编号 === '' && item.项目类型 === '定量') {
          isOk = false
        }
        if (item.children1[i].是否合格 === 0) {
          isOk = false
        }
      }
      if (!isOk) {
        this.$confirm('存在未检查项目，是否提交?', '检验提交', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.editCheckOrder_content_sure_submit_before(item)
        }).catch(() => {
        })
      } else {
        this.editCheckOrder_content_sure_submit_before(item)
      }
    },
    async editCheckOrder_content_sure_submit_before(item) {
      console.log(item)
      const 检查后备注 = item.备注
      const 检查项ID = item.ID
      const 质检单号 = item.质检单号
      for (let i = 0; i < item.children1.length; i++) {
        const 是否合格 = item.children1[i].是否合格
        const 检验值 = item.children1[i].测量值
        const ID = item.children1[i].ID
        const 产品编号 = item.children1[i].产品编号
        await this.editCheckOrder_content_sure_submit({
          ID: ID,
          检查项ID: 检查项ID,
          质检单号: 质检单号,
          是否合格: 是否合格,
          检验值: 检验值,
          产品编号: 产品编号,
          检查后备注: 检查后备注
        })
      }
      this.$message.success('提交成功！')
      this.fetchData_content(this.currentSelectCheckOrder)
      this.fetchData()
    },
    editCheckOrder_content_sure_submit(item) {
      return new Promise((resolve, reject) => {
        var param = []
        param[0] = ['检验值', item.检验值]
        param[1] = ['检查后备注', item.检查后备注]
        param[2] = ['是否合格', item.是否合格]
        param[3] = ['ID', item.ID]
        param[4] = ['检查项ID', item.检查项ID]
        param[5] = ['质检单号', item.质检单号]
        param[6] = ['产品编号', item.产品编号]
        param[7] = ['记录人', this.name]
        var Data = this.CreateData('12', '质检_工单检查内容_录入编辑', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            resolve(true)
          } else {
            reject(false)
          }
        })
      })
    },
    getGuidePic1(item) {
      console.log(item)
      this.RepairManagementReplaceForm.ID = item.ID
      const param = []
      param[0] = ['检查项id', item.ID]
      const Data = this.CreateData('11', '质检_质检单_详细内容_图片_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          for (let i = 0; i < response.data.length; i++) {
            if (this.imageType.indexOf(response.data[i]['附件类型'].toLowerCase()) !== -1) {
              response.data[i]['url'] = window.URL.createObjectURL(base64ImgtoFile(response.data[i]['附件内容'], response.data[i]['附件名称'], response.data[i]['附件类型']))
            } else {
              response.data[i]['url'] = window.URL.createObjectURL(base64ImgtoFile(response.data[i]['附件内容'], response.data[i]['附件名称'], response.data[i]['附件类型']))
            }
          }
          this.RepairManagementDataTableOrigin = response.data
          this.showTableData_content_exchange2 = true
        } else {
          this.showTableData_content_exchange2 = true
          this.RepairManagementDataTableOrigin = []
        }
      })
    },
    deletePic(row) {
      var param = []
      param[0] = ['ID', row.ID]
      var Data = this.CreateData('12', '质检_质检单_详细内容_图片_删除', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('删除成功！')
          this.getGuidePic1({
            ID: this.RepairManagementReplaceForm.ID
          })
        } else {
          this.$message.error('删除失败!')
        }
      })
    },
    reportPicUpload() {
      var param = []
      param[0] = ['检查项id', this.RepairManagementReplaceForm.ID]
      param[1] = ['文件名称', '']
      param[2] = ['文件后缀', '']
      param[3] = ['文件内容', null]
      var Data1 = this.CreateData('15', '质检_质检单_详细内容_图片_增加', param)
      this.DataPDF.param = Data1
      this.$refs.uploadPDF.submit()
    },
    judgeValueIsOK(item, item1) {
      for (let i = 0; i < item.children1.length; i++) {
        if (item.children1[i].ID === item1.ID) {
          try {
            const up = Number(item.上限)
            const down = Number(item.下限)
            const value = Number(item1['测量值'])
            if (value >= down && value <= up) {
              item1['是否合格'] = 1
            } else {
              item1['是否合格'] = 2
            }
          } catch (e) {
            item1['是否合格'] = 2
          }
          item.children1[i] = item1
        }
      }
    },
    judgeValueProductCode(item, item1) {
      for (let i = 0; i < item.children1.length; i++) {
        if (item.children1[i].ID === item1.ID) {
          item.children1[i] = item1
        }
      }
    },
    changeIsOk(item, item1) {
      console.log(item, item1)
      for (let i = 0; i < item.children1.length; i++) {
        if (item.children1[i].ID === item1.ID) {
          item.children1[i] = item1
        }
      }
    },
    editCheckOrder_Finish() {
      let isOk = true
      for (let i = 0; i < this.tableData_content.length; i++) {
        if (this.tableData_content[i].状态 === 0) {
          isOk = false
        }
        const item = this.tableData_content[i]
        for (let i = 0; i < item.children1.length; i++) {
          if (item.children1[i].状态 !== 1) {
            isOk = false
          }
          if (item.children1[i].测量值 === '' && item.项目类型 === '定量') {
            isOk = false
          }
          if (item.children1[i].产品编号 === '' && item.项目类型 === '定量') {
            isOk = false
          }
          if (item.children1[i].是否合格 === 0) {
            isOk = false
          }
        }
      }
      if (isOk) {
        this.form_editCheckOrderFinish.checkOrderType = 1
        this.form_editCheckOrderFinish.checkOrderUserName = '1'
        this.form_editCheckOrderFinish.checkOrderPassword = '1'
      } else {
        this.form_editCheckOrderFinish.checkOrderType = 2
        this.form_editCheckOrderFinish.checkOrderUserName = ''
        this.form_editCheckOrderFinish.checkOrderPassword = ''
      }
      this.dialogFormVisible_editCheckOrderFinish = true
      this.form_editCheckOrderFinish.checkOrderCode = this.currentSelectCheckOrder['质检单号']
      this.form_editCheckOrderFinish.checkOrderName = this.currentSelectCheckOrder['质检单名称']
      this.form_editCheckOrderFinish.checkOrderRemarks = ''
      this.form_editCheckOrderFinish.ID = this.currentSelectCheckOrder.ID
    },
    editCheckOrder_Finish_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['备注', this.form_editCheckOrderFinish.checkOrderRemarks]
          param[1] = ['ID', this.form_editCheckOrderFinish.ID]
          param[2] = ['账号', this.form_editCheckOrderFinish.checkOrderUserName]
          param[3] = ['密码', this.form_editCheckOrderFinish.checkOrderPassword]
          param[4] = ['提交类型', this.form_editCheckOrderFinish.checkOrderType]
          var Data = this.CreateData('11', '质检_工单_结束工单', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === 1) {
              this.$message.success('提交成功！')
              this.fetchData()
              this.dialogFormVisible_editCheckOrderFinish = false
              this.dialogFormVisible_addCheckOrder_content_show = false
              // this.dialogFormVisible_editCheckOrder_content = false
            } else {
              this.$message.error(response.data[0]['msg'])
            }
          }).catch(er => {})
        }
      })
    },
    editCheckOrder_Finish_cancel(formName) {
      this.dialogFormVisible_editCheckOrderFinish = false
      this.$refs[formName].resetFields()
    },
    editCheckOrder_content_cancel(formName) {
      this.dialogFormVisible_addCheckOrder_content_show = false
      this.$refs[formName].resetFields()
    },
    deleteCheckOrder_content(row) {
      console.log(row)
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['ID', row.ID]
        var Data = this.CreateData('12', '质检_工单检查内容_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '质检单检查项删除成功',
              type: 'success'
            })
            this.fetchData_content(this.currentSelectCheckOrder)
          } else {
            this.$message.error('质检单检查项删除失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // endregion
    // region 质检项维护
    searchTableCheckContentBase() {
      this.listLoading1 = true
      this.tableDataCheckContentBase = []
      var param = []
      param[0] = ['工位号', this.stationNumberValue]
      var Data = this.CreateData('11', '质检_基础_检查项_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableDataCheckContentBase = response.data
        this.listLoading1 = false
      }).catch(er => {
        this.listLoading1 = false
        this.$message.error('错误')
      })
    },
    addCheckContentBase() {
      this.dialogFormVisible_addCheckContentBase = true
      this.form_addCheckContentBase.stationNumberValue = ''
      this.form_addCheckContentBase.checkItem = ''
      this.form_addCheckContentBase.checkItemContent = ''
      this.form_addCheckContentBase.standardValue = ''
      this.form_addCheckContentBase.maximumValue = ''
      this.form_addCheckContentBase.minimumValue = ''
      this.form_addCheckContentBase.unit = ''
    },
    addCheckContentBase_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['工位号', this.form_addCheckContentBase.stationNumberValue]
          param[1] = ['检查项目', this.form_addCheckContentBase.checkItem]
          param[2] = ['检查内容', this.form_addCheckContentBase.checkItemContent]
          param[3] = ['标准值', this.form_addCheckContentBase.standardValue]
          param[4] = ['上限', this.form_addCheckContentBase.maximumValue]
          param[5] = ['下限', this.form_addCheckContentBase.minimumValue]
          param[6] = ['单位', this.form_addCheckContentBase.unit]
          var Data = this.CreateData('12', '质检_基础_检查项_增加', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '增加成功',
                type: 'success'
              })
              this.dialogFormVisible_addCheckContentBase = false
              this.searchTableCheckContentBase()
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    addCheckContentBase_cancel(formName) {
      this.dialogFormVisible_addCheckContentBase = false
      this.$refs[formName].resetFields()
    },
    editCheckContentBase(row) {
      this.dialogFormVisible_editCheckContentBase = true
      this.form_editCheckContentBase.stationNumberValue = row.工位号
      this.form_editCheckContentBase.checkItem = row.检查项目
      this.form_editCheckContentBase.checkItemContent = row.检查内容
      this.form_editCheckContentBase.standardValue = row.标准值
      this.form_editCheckContentBase.maximumValue = row.上限
      this.form_editCheckContentBase.minimumValue = row.下限
      this.form_editCheckContentBase.unit = row.单位
      this.form_editCheckContentBase.ID = row.ID
    },
    editCheckContentBase_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['工位号', this.form_editCheckContentBase.stationNumberValue]
          param[1] = ['检查项目', this.form_editCheckContentBase.checkItem]
          param[2] = ['检查内容', this.form_editCheckContentBase.checkItemContent]
          param[3] = ['标准值', this.form_editCheckContentBase.standardValue]
          param[4] = ['上限', this.form_editCheckContentBase.maximumValue]
          param[5] = ['下限', this.form_editCheckContentBase.minimumValue]
          param[6] = ['单位', this.form_editCheckContentBase.unit]
          param[7] = ['ID', this.form_editCheckContentBase.ID]
          var Data = this.CreateData('12', '质检_基础_检查项_编辑', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '编辑成功！',
                type: 'success'
              })
              this.dialogFormVisible_editCheckContentBase = false
              this.searchTableCheckContentBase()
            } else {
              this.$message.error('编辑失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    editCheckContentBase_cancel(formName) {
      this.dialogFormVisible_editCheckContentBase = false
      this.$refs[formName].resetFields()
    },
    deleteCheckContentBase(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['ID', row.ID]
        var Data = this.CreateData('12', '质检_基础_检查项_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '检查项删除成功',
              type: 'success'
            })
            this.searchTableCheckContentBase()
          } else {
            this.$message.error('检查项删除失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // endregion
    // 分页功能改变显示数量
    handleSizeChange(val) {
      this.pageSize = val
      this.fetchData()
    },
    // 分页功能改变当前页
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.fetchData()
    },
    // 给样式的
    handelLimitStyle() {
      var obj = document.getElementsByClassName('el-upload--picture-card')
      if (obj[0].style.display === 'none') {
        for (var i = 0; i < obj.length; i++) {
          obj[i].style.display = 'block'
        }
      }
    },
    handelLimit() {
      var obj = document.getElementsByClassName('el-upload--picture-card')
      if (obj[0].style.display === '') {
        for (var i = 0; i < obj.length; i++) {
          obj[i].style.display = 'none'
        }
      }
    },
    // 上传成功回调
    uploadSuccessPDF() {
      this.$refs.uploadPDF.clearFiles()
      this.fetchData_content(this.currentSelectCheckOrder)
      this.$message.success('文件上传成功!')
      this.getGuidePic1({
        ID: this.RepairManagementReplaceForm.ID
      })
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisiblePictureCard = true
    },
    // 上传前检测
    beforeUploadPdf(file) {
      const isLt2M = file.size / 1024 / 1024 <= 5
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 5MB!')
        return false
      }
      return true
    },
    warningExceedPdf() {
      this.$message.error('一次仅可上传一张图片')
    }
  }
}
</script>

<style scoped>
  .el-table .warning-row{

  }
  .el-table .warning-row {
       background: #a94442;
     }
  .el-table .sucess-row {
    background: #f0f9eb;
  }
  .el-table td, .is-leaf{
    background-color: rgb(255, 91, 103);
    color: black;
    font-weight:400
  }
  .custom-upload ::v-deep.el-upload-dragger{
    width: 210px;
  }
  .custom-upload {
    width: 220px;  /* 设置上传框的宽度 */
    height: 150px; /* 设置上传框的高度 */
  }

  .custom-upload ::v-deep .el-upload {
    width: 100%;
    height: 100%;
  }

  .custom-upload .el-icon-plus {
    font-size: 28px; /* 图标大小 */
    line-height: 150px; /* 垂直居中对齐 */
  }
</style>

