<template>
  <div class="app-container">
    <el-tabs v-model="activeName" type="border-card">
      <el-tab-pane label="质检方案" name="first">
        <el-card style="">
          <el-row>
            <span>方案名称</span>
            <el-input v-model="schemeName" clearable size="small" placeholder="方案名称" style="width: 200px"/>
            <span style="margin-left: 10px">产品型号:</span>
            <el-select v-model="engineTypeValue" placeholder="产品型号" clearable size="small" style="width:120px" @change="fetchData">
              <el-option
                v-for="item in engineType"
                :key="item.label"
                :label="item.label"
                :value="item.label"/>
            </el-select>
            <el-button type="success" icon="el-icon-search" size="small" style="margin-left: 10px;margin-top: 15px" @click="fetchData">查询</el-button>
            <el-button type="warning" icon="el-icon-plus" size="small" style="margin-left: 10px;margin-top: 15px" @click="addCheckOrder()">新增</el-button>
            <el-button :disabled="currentRow === null" type="primary" icon="el-icon-s-flag" size="small" style="margin-left: 10px;margin-top: 15px" @click="addCheckOrderPlus()">方案升版</el-button>
            <el-button :disabled="currentRow === null" type="primary" icon="el-icon-download" size="small" style="margin-left: 10px;margin-top: 15px" @click="makeCheckPlan()">下发计划</el-button>
          </el-row>
          <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: 62%"
            height= "590px"
            size="small"
          >
            <el-table-column width="40">
              <template slot-scope="scope">
                <el-radio
                  :label="scope.row"
                  v-model="currentRow"
                  class="radio"
                  @input="changeValue"
                >&emsp;&emsp;&emsp;</el-radio>
              </template>
            </el-table-column>
            <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="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 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 label="执行" align="center" width="60">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.当前执行" size="mini" @change="editCheckOrder_SetSure(scope.row)"/>
              </template>
            </el-table-column>
            <el-table-column label="编辑" width="100" align="center">
              <template slot-scope="scope">
                <el-button size="mini" type="text" title="修改" icon="el-icon-edit" @click="editCheckOrder(scope.row)" />
                <el-button 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="[15, 30, 40]"
              :page-size="10"
              :total="totalNum"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"/>
          </div>
        </el-card>
      </el-tab-pane>
      <el-tab-pane label="检查工具/方法" name="third">
        <index-tool-method/>
      </el-tab-pane>
      <el-tab-pane label="规则设定" name="forth">
        <index-down-load-rules v-if="activeName === 'forth'"/>
      </el-tab-pane>
    </el-tabs>
    <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="请输入方案名称"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="产品型号" prop="engineTypeValue" style="display: inline-block">
          <el-select v-model="form_addCheckOrder.engineTypeValue" placeholder="产品型号" size="small" style="width:200px">
            <el-option
              v-for="item in engineType"
              :key="item.label"
              :label="item.label"
              :value="item.label"/>
          </el-select>
        </el-form-item>
        <el-form-item label="版本" prop="version" style="display: inline-block">
          <el-input
            v-model="form_addCheckOrder.version"
            clearable
            size="small"
            placeholder="请输入版本号"
            style="width: 200px"/>
        </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="engineTypeValue" style="display: inline-block">
          <el-select v-model="form_editCheckOrder.engineTypeValue" placeholder="产品型号" size="small" style="width:200px">
            <el-option
              v-for="item in engineType"
              :key="item.label"
              :label="item.label"
              :value="item.label"/>
          </el-select>
        </el-form-item>
        <el-form-item label="版本号" prop="version" style="display: inline-block">
          <el-input
            v-model="form_editCheckOrder.version"
            clearable
            size="small"
            placeholder="请输入版本号"
            style="width: 200px"/>
        </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_addCheckOrderPlus" title="检验方案升版" center style="min-height: 200px;" width="400px">
      <el-form ref="form_addCheckOrderPlus" :model="form_addCheckOrderPlus" :rules="rules_addCheckOrderPlus" label-position="right" label-width="110px">
        <el-form-item label="原始方案" prop="checkOrderNameOrigin" style="display: inline-block">
          <el-input
            v-model="form_addCheckOrderPlus.checkOrderNameOrigin"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="方案名称" prop="checkOrderName" style="display: inline-block">
          <el-input
            v-model="form_addCheckOrderPlus.checkOrderName"
            clearable
            size="small"
            placeholder="请输入方案名称"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="产品型号" prop="engineTypeValue" style="display: inline-block">
          <el-select v-model="form_addCheckOrderPlus.engineTypeValue" placeholder="产品型号" size="small" style="width:200px">
            <el-option
              v-for="item in engineType"
              :key="item.label"
              :label="item.label"
              :value="item.label"/>
          </el-select>
        </el-form-item>
        <el-form-item label="版本" prop="version" style="display: inline-block">
          <el-input
            v-model="form_addCheckOrderPlus.version"
            clearable
            size="small"
            placeholder="请输入版本号"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
          <div style="width: 200px">
            <el-input
              v-model="form_addCheckOrderPlus.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_addCheckOrderPlus')">取消</el-button>
        <el-button type="primary" size="small" @click="addCheckOrderPlus_sure('form_addCheckOrderPlus')">确定</el-button>
      </div>
    </el-dialog>
    <!--    方案项目详情-->
    <el-dialog :visible.sync="dialogFormVisible_addCheckOrder_content_show" :title="title" center style="min-height: 200px;" width="1200px" @close="fetchData">
      <el-row>
        <el-button size="mini" title="增加检查项目" type="warning" icon="el-icon-plus" @click="addCheckOrder_content()">增加项目</el-button>
        <span style="margin-left: 10px">筛选：</span>
        <el-radio-group v-model="rulerTypeFilter" @input="changeRulesValue">
          <el-radio :label="9999">全部</el-radio>
          <el-radio :label="1">按台下发</el-radio>
          <el-radio :label="2">定时下发</el-radio>
        </el-radio-group>
      </el-row>
      <el-table
        :data="tableData_content"
        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%"
        max-height= "490px"
        size="small"
      >
        <el-table-column label="序号" type="index" align="center"/>
        <el-table-column label="启用" width="60" align="center">
          <template slot-scope="scope">
            <el-checkbox v-model="scope.row.是否启用" @change="changeIsUsed(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column label="下发规则" width="130" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.规则类型 === 1" type="success" size="mini">【按台】 {{ scope.row.规则频次 }}台/次</el-tag>
            <el-tag v-else-if="scope.row.规则类型 === 2" type="primary" size="mini">【定时】 {{ scope.row.规则频次 }}时/次</el-tag>
            <el-tag v-else type="warning">未设定</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="质检项目" width="150" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查项目 }}
          </template>
        </el-table-column>
        <el-table-column label="质检内容" min-width="100" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查内容 }}
          </template>
        </el-table-column>
        <el-table-column label="类型" width="70" 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 label="检测数" width="70" 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-link type="primary" @click="showFileListInfo(scope.row)">{{ scope.row.图片数量 }}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="检查工具" width="180" align="center">
          <template slot-scope="scope">
            {{ scope.row.检查工具名称 }}{{ 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 label="上限" width="70" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.项目类型==='定量'">{{ scope.row.上限 }}</span>
            <span v-else />
          </template>
        </el-table-column>
        <el-table-column label="下限" width="70" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.项目类型==='定量'">{{ scope.row.下限 }}</span>
            <span v-else />
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="编辑" width="100" align="center">
          <template slot-scope="scope">
            <el-button size="mini" title="编辑检查项目" type="text" icon="el-icon-edit" @click="editCheckOrder_content(scope.row)" />
            <el-button size="mini" title="删除检查项目" type="text" icon="el-icon-delete" style="color: #ff0000" @click="deleteCheckOrder_content(scope.row)"/>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible2" title="上传附件" center style="min-height: 200px;" width="400px"/>
    <el-dialog :visible.sync="showTableData_content_exchange" title="指导图片预览" center style="min-height: 200px" width="600px">
      <div style="height: 300px">
        <el-col :span="12">
          <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>
                &nbsp;&nbsp;
                <el-button type="text" size="mini" icon="el-icon-delete" style="color: #ff0000;float: right;padding: 0;margin-left: 5px" @click="deletePic(item)"/>
                <a class="el-icon-download" style="float: right" @click="downLoadFile(item)"/>
                <div style="height: 1px;background-color: #bebebe;margin-top: 2px" />
              </el-row>
              <el-row v-else>
                <span class="tmp">
                  {{ index + 1 }}.{{ item.附件名称 }}.{{ item.附件类型 }}
                </span>
                &nbsp;&nbsp;
                <el-button type="text" size="mini" icon="el-icon-delete" style="color: #ff0000;float: right;padding: 0;margin-left: 5px" @click="deletePic(item)"/>
                <a class="el-icon-download" style="float: right" @click="downLoadFile(item)"/>
                <div style="height: 1px;background-color: #bebebe;margin-top: 2px" />
              </el-row>
            </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_exchange=false">关闭</el-button>
            <el-button type="primary" size="small" @click="solveNcSubmit1('formEdit1')">上传</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_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="80px">
        <el-row>
          <el-col :span="9">
            <el-form-item label="名称" prop="checkOrderName" style="display: inline-block">
              <el-input
                v-model="form_addCheckOrder_content.checkOrderName"
                size="small"
                style="width: 200px"
                placeholder="检查项目名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="类型" prop="checkOrderType" style="display: inline-block">
              <el-radio-group v-model="form_addCheckOrder_content.checkOrderType" size="mini">
                <el-radio-button :label="'定性'">定性</el-radio-button>
                <el-radio-button :label="'定量'">定量</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数量" prop="checkOrderNum" style="display: inline-block">
              <el-input-number
                v-model="form_addCheckOrder_content.checkOrderNum"
                :min="1"
                size="small"
                style="width: 110px"
                placeholder="请输入最大值"/>
            </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" style="width:610px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="频次类型" prop="rulerType" style="display: inline-block">
              <el-radio-group v-model="form_addCheckOrder_content.rulerType">
                <el-radio :label="1">按台下发</el-radio>
                <el-radio :label="2">定时下发</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="频次" prop="rulerRate" style="display: inline-block">
              <el-input-number
                v-model="form_addCheckOrder_content.rulerRate"
                :min="1"
                size="small"
                style="width: 200px"
                placeholder="请输入频次"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查工具" prop="toolNameId" style="display: inline-block">
              <el-select v-model="form_addCheckOrder_content.toolNameId" placeholder="择检查工具" size="small" style="width:200px">
                <el-option
                  v-for="item in CheckToolBase"
                  :key="item.ID"
                  :label= "`${item.检查工具名称}【${item.检查工具编号}】`"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查方法" prop="methodNameId" style="display: inline-block">
              <el-select v-model="form_addCheckOrder_content.methodNameId" placeholder="择检查工具" size="small" 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 v-if="form_addCheckOrder_content.checkOrderType === '定量'">
          <el-col :span="12">
            <el-form-item label="最大值" prop="maximumValue" style="display: inline-block">
              <el-input-number
                v-model="form_addCheckOrder_content.maximumValue"
                :min="form_addCheckOrder_content.minimumValue"
                size="small"
                style="width: 200px"
                placeholder="请输入最大值"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最小值" prop="minimumValue" style="display: inline-block">
              <el-input-number
                v-model="form_addCheckOrder_content.minimumValue"
                :max="form_addCheckOrder_content.maximumValue"
                size="small"
                style="width: 235px"
                placeholder="请输入最小值"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
            <el-input
              v-model="form_addCheckOrder_content.checkOrderRemarks"
              :rows="2"
              type="textarea"
              size="small"
              style="width: 610px"
              placeholder="请输入备注"/>
          </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="80px">
        <el-row>
          <el-col :span="9">
            <el-form-item label="名称" prop="checkOrderName" style="display: inline-block">
              <el-input
                v-model="form_editCheckOrder_content.checkOrderName"
                size="small"
                style="width: 200px"
                placeholder="项目名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="类型" prop="checkOrderType" style="display: inline-block">
              <el-radio-group v-model="form_editCheckOrder_content.checkOrderType" size="mini">
                <el-radio-button :label="'定性'">定性</el-radio-button>
                <el-radio-button :label="'定量'">定量</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数量" prop="checkOrderNum" style="display: inline-block">
              <el-input-number
                v-model="form_editCheckOrder_content.checkOrderNum"
                :min="1"
                size="small"
                style="width: 110px"
                placeholder="请输入最大值"/>
            </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" style="width:610px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="频次类型" prop="rulerType" style="display: inline-block">
              <el-radio-group v-model="form_editCheckOrder_content.rulerType">
                <el-radio :label="1">按台下发</el-radio>
                <el-radio :label="2">定时下发</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="频次" prop="rulerRate" style="display: inline-block">
              <el-input-number
                v-model="form_editCheckOrder_content.rulerRate"
                :min="1"
                size="small"
                style="width: 200px"
                placeholder="请输入频次"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查工具" prop="toolNameId" style="display: inline-block">
              <el-select v-model="form_editCheckOrder_content.toolNameId" placeholder="择检查工具" size="small" style="width:200px">
                <el-option
                  v-for="item in CheckToolBase"
                  :key="item.ID"
                  :label= "`${item.检查工具名称}【${item.检查工具编号}】`"
                  :value="item.ID"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查方法" prop="methodNameId" style="display: inline-block">
              <el-select v-model="form_editCheckOrder_content.methodNameId" placeholder="择检查工具" size="small" 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 v-if="form_editCheckOrder_content.checkOrderType === '定量'">
          <el-col :span="12">
            <el-form-item label="最大值" prop="maximumValue" style="display: inline-block">
              <el-input-number
                v-model="form_editCheckOrder_content.maximumValue"
                :min="form_editCheckOrder_content.minimumValue"
                size="small"
                style="width: 200px"
                placeholder="请输入最大值"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最小值" prop="minimumValue" style="display: inline-block">
              <el-input-number
                v-model="form_editCheckOrder_content.minimumValue"
                :max="form_editCheckOrder_content.maximumValue"
                size="small"
                style="width: 235px"
                placeholder="请输入最小值"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="备注" prop="checkOrderRemarks" style="display: inline-block">
            <el-input
              v-model="form_editCheckOrder_content.checkOrderRemarks"
              :rows="2"
              type="textarea"
              size="small"
              style="width: 610px"
              placeholder="请输入备注"/>
          </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_makeCheckPlan" title="下发计划" center style="min-height: 200px;" width="400px">
      <el-form ref="form_makeCheckPlan" :model="form_makeCheckPlan" :rules="rules_makeCheckPlan" label-position="right" label-width="110px">
        <el-form-item label="方案名称" prop="checkSchemeName" style="display: inline-block">
          <el-input
            v-model="form_makeCheckPlan.checkSchemeName"
            readonly
            style="width:200px"
            size="small"/>
        </el-form-item>
        <el-form-item label="计划名称" prop="checkPlanName" style="display: inline-block">
          <el-input
            v-model="form_makeCheckPlan.checkPlanName"
            clearable
            size="small"
            style="width:200px"
            placeholder="请输入计划名称"/>
        </el-form-item>
        <el-form-item label="计划日期" prop="checkDate" style="display: inline-block">
          <el-date-picker v-model="form_makeCheckPlan.checkDate" size="small" type="date" value-format="yyyy-MM-dd" style="width:200px" placeholder="检查日期"/>
        </el-form-item>
        <el-form-item label="部门" prop="checkPlanDepartmentId" style="display: inline-block">
          <el-select v-model="form_makeCheckPlan.checkPlanDepartmentId" placeholder="择检查部门" size="small" style="width:200px">
            <el-option
              v-for="item in departmentList"
              :key="item.value"
              :label= "item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="checkPlanRemarks" style="display: inline-block">
          <el-input
            v-model="form_makeCheckPlan.checkPlanRemarks"
            :rows="2"
            type="textarea"
            size="small"
            style="width:200px"
            placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="makeCheckPlan_cancel('form_makeCheckPlan')">取消</el-button>
        <el-button type="primary" size="small" @click="makeCheckPlan_sure('form_makeCheckPlan')">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible_addCheckContentBase" title="增加检查项" center style="min-height: 200px;" width="400px">
      <el-form ref="form_addCheckContentBase" :model="form_addCheckContentBase" :rules="rules_addCheckContentBase" label-position="right" label-width="110px">
        <el-form-item label="工位号" prop="stationNumberValue" style="display: inline-block">
          <el-select v-model="form_addCheckContentBase.stationNumberValue" size="small" placeholder="请选择工位号">
            <el-option
              v-for="item in stationNumber"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="检查项" prop="checkItem" style="display: inline-block">
          <el-input
            v-model="form_addCheckContentBase.checkItem"
            clearable
            size="small"
            placeholder="请输入检查项"/>
        </el-form-item>
        <el-form-item label="检查内容" prop="checkItemContent" style="display: inline-block">
          <el-input
            v-model="form_addCheckContentBase.checkItemContent"
            clearable
            size="small"
            placeholder="请输入检查内容"/>
        </el-form-item>
        <el-form-item label="标准值" prop="standardValue" style="display: inline-block">
          <el-input
            v-model="form_addCheckContentBase.standardValue"
            clearable
            size="small"
            placeholder="请输入标准值"/>
        </el-form-item>
        <el-form-item label="最大值" prop="maximumValue" style="display: inline-block">
          <el-input
            v-model="form_addCheckContentBase.maximumValue"
            clearable
            size="small"
            placeholder="请输入最大值"/>
        </el-form-item>
        <el-form-item label="最小值" prop="minimumValue" style="display: inline-block">
          <el-input
            v-model="form_addCheckContentBase.minimumValue"
            clearable
            size="small"
            placeholder="请输入最小值"/>
        </el-form-item>
        <el-form-item label="单位" prop="unit" style="display: inline-block">
          <el-input
            v-model="form_addCheckContentBase.unit"
            clearable
            size="small"
            placeholder="单位"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="addCheckContentBase_cancel('form_addCheckContentBase')">取消</el-button>
        <el-button type="primary" size="small" @click="addCheckContentBase_sure('form_addCheckContentBase')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible_editCheckContentBase" title="编辑检查项" center style="min-height: 200px;" width="400px">
      <el-form ref="form_editCheckContentBase" :model="form_editCheckContentBase" :rules="rules_editCheckContentBase" label-position="right" label-width="110px">
        <el-form-item label="工位号" prop="stationNumberValue" style="display: inline-block">
          <el-select v-model="form_editCheckContentBase.stationNumberValue" disabled="" size="small" placeholder="请选择工位号">
            <el-option
              v-for="item in stationNumber"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="检查项" prop="checkItem" style="display: inline-block">
          <el-input
            v-model="form_editCheckContentBase.checkItem"
            clearable
            size="small"
            placeholder="请输入检查项"/>
        </el-form-item>
        <el-form-item label="检查内容" prop="checkItemContent" style="display: inline-block">
          <el-input
            v-model="form_editCheckContentBase.checkItemContent"
            clearable
            size="small"
            placeholder="请输入检查内容"/>
        </el-form-item>
        <el-form-item label="标准值" prop="standardValue" style="display: inline-block">
          <el-input
            v-model="form_editCheckContentBase.standardValue"
            clearable
            size="small"
            placeholder="请输入标准值"/>
        </el-form-item>
        <el-form-item label="最大值" prop="maximumValue" style="display: inline-block">
          <el-input
            v-model="form_editCheckContentBase.maximumValue"
            clearable
            size="small"
            placeholder="请输入最大值"/>
        </el-form-item>
        <el-form-item label="最小值" prop="minimumValue" style="display: inline-block">
          <el-input
            v-model="form_editCheckContentBase.minimumValue"
            clearable
            size="small"
            placeholder="请输入最小值"/>
        </el-form-item>
        <el-form-item label="单位" prop="unit" style="display: inline-block">
          <el-input
            v-model="form_editCheckContentBase.unit"
            clearable
            size="small"
            placeholder="单位"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="editCheckContentBase_cancel('form_editCheckContentBase')">取消</el-button>
        <el-button type="primary" size="small" @click="editCheckContentBase_sure('form_editCheckContentBase')">确定</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>

  </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 indexToolMethod from './indexToolMethod..vue'
import indexDownLoadRules from './indexDownLoadRules.vue'
import { url } from '../../../utils/request'
import elImageViewer from 'element-ui/packages/image/src/image-viewer'
export default {
  components: { indexToolMethod, elImageViewer, indexDownLoadRules },
  data() {
    return {
      engineType: [],
      engineTypeValue: '',
      currentPage: 1,
      pageSize: 15,
      pageCurrent: 1,
      totalNum: null,
      activeName: 'first',
      schemeName: '',
      tableData: [],
      currentRow: null,
      listLoading: false,
      dialogFormVisible_addCheckOrder: false,
      dialogFormVisible_addCheckOrderRulers: false,

      form_addCheckOrder: {
        checkOrderName: '',
        engineTypeValue: '',
        checkOrderRemarks: '',
        version: ''
      },
      rules_addCheckOrder: {
        engineTypeValue: [{ required: true, message: '请选择产品型号', trigger: 'change' }],
        checkOrderName: [{ required: true, message: '请输入方案名称', trigger: 'blur' }],
        version: [{ required: true, message: '请输入版本号', trigger: 'blur' }]
      },
      dialogFormVisible_addCheckOrderPlus: false,

      form_addCheckOrderPlus: {
        checkOrderNameOrigin: '',
        checkOrderNameId: '',
        checkOrderName: '',
        engineTypeValue: '',
        checkOrderRemarks: '',
        version: ''
      },
      rules_addCheckOrderPlus: {
        engineTypeValue: [{ required: true, message: '请选择产品型号', trigger: 'change' }],
        checkOrderName: [{ required: true, message: '请输入方案名称', trigger: 'blur' }],
        version: [{ required: true, message: '请输入版本号', trigger: 'blur' }]
      },
      dialogFormVisible_editCheckOrder: false,
      form_editCheckOrder: {
        checkOrderName: '',
        engineTypeValue: '',
        checkOrderRemarks: '',
        version: '',
        id: ''
      },
      rules_editCheckOrder: {
        engineTypeValue: [{ required: true, message: '请选择产品型号', trigger: 'change' }],
        checkOrderName: [{ required: true, message: '请输入方案名称', trigger: 'blur' }],
        version: [{ required: true, message: '请输入版本号', trigger: 'blur' }]
      },

      department: '', // 部门
      departmentList: [], // 部门表
      staffName: '', // 员工姓名
      roleName: null, // 角色名称
      tableData_people: [],
      List1: [],
      data2_tree: [],
      roleNames: [],
      personNumber: '',
      personName: '',
      stationNumber: [],
      stationNumberValue: '0',
      statusNumber: [],
      statusNumberValue: 0,

      dateTime: [],
      dialogFormVisible_selectPeople: false,
      tableData_contentOrigin: [],
      tableData_content: [],

      currentSelectCheckOrder: {},
      title: '',
      dialogFormVisible_addCheckOrder_content_show: false,
      showTableData_content_exchange: false,
      RepairManagementDataTableOrigin: [],
      imageType: ['bmp', 'jpg', 'png', 'gif'],
      RepairManagementReplaceForm: {
        ID: 0
      },
      pdfType: ['pdf'],
      dialogFormVisible2: false,
      formEdit1: {
        id: 0
      },
      limit: 1,
      DataPDF: {},
      uploadPDF: url,
      imgViewerVisible: false,
      imgViewerList: [],
      dialogFormVisible_addCheckOrder_content: false,
      rulerTypeFilter: 9999,
      form_addCheckOrder_content: {
        checkSchemeId: 0,
        checkOrderName: '',
        checkOrderContent: '',
        checkOrderType: '定性',
        checkOrderNum: 1,
        rulerTyperulerType: 1,
        rulerRate: 1,
        checkOrderRemarks: '',
        standardValue: '',
        maximumValue: 0,
        minimumValue: 0,
        unit: '',
        toolNameId: '',
        methodNameId: ''
      },
      rules_addCheckOrder_content: {
        checkOrderName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
        checkOrderContent: [{ required: true, message: '请输入项目内容', trigger: 'blur' }],
        checkOrderType: [{ required: true, message: '请选择类型', trigger: 'change' }],
        rulerType: [{ required: true, message: '请选择频次类型', trigger: 'change' }],
        rulerRate: [{ required: true, message: '请输入频次', trigger: 'blur' }],
        checkOrderNum: [{ required: true, message: '请输入数量', trigger: 'blur' }],
        maximumValue: [{ required: true, message: '请输入最大值', trigger: 'blur' }],
        minimumValue: [{ required: true, message: '请输入最小值', trigger: 'blur' }],
        toolNameId: [{ required: true, message: '请输入检查工具', trigger: 'blur' }],
        methodNameId: [{ required: true, message: '请输入检查方法', trigger: 'blur' }]
      },
      dialogFormVisible_makeCheckPlan: false,
      form_makeCheckPlan: {
        checkSchemeId: 0,
        checkSchemeName: '',
        checkPlanName: '',
        checkPlanDepartmentId: '',
        checkPlanDepartmentName: '',
        checkDate: '',
        checkPlanRemarks: ''
      },
      rules_makeCheckPlan: {
        checkPlanName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
        checkPlanDepartmentId: [{ required: true, message: '请选择部门', trigger: 'blur' }],
        checkDate: [{ required: true, message: '请选择日期', trigger: 'change' }]
      },
      dialogFormVisible_editCheckOrder_content: false,
      form_editCheckOrder_content: {
        ID: '',
        checkSchemeId: 0,
        checkOrderName: '',
        checkOrderContent: '',
        checkOrderType: '定性',
        checkOrderNum: 1,
        checkOrderRemarks: '',
        standardValue: '',
        rulerType: 1,
        rulerRate: 1,
        maximumValue: 0,
        minimumValue: 0,
        unit: '',
        toolNameId: '',
        methodNameId: ''
      },
      rules_editCheckOrder_content: {
        checkOrderName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
        checkOrderContent: [{ required: true, message: '请输入项目内容', trigger: 'blur' }],
        checkOrderType: [{ required: true, message: '请选择类型', trigger: 'change' }],
        checkOrderNum: [{ required: true, message: '请输入数量', trigger: 'blur' }],
        maximumValue: [{ required: true, message: '请输入最大值', trigger: 'blur' }],
        rulerType: [{ required: true, message: '请选择频次类型', trigger: 'change' }],
        rulerRate: [{ required: true, message: '请输入频次', trigger: 'blur' }],
        minimumValue: [{ required: true, message: '请输入最小值', trigger: 'blur' }],
        toolNameId: [{ required: true, message: '请输入检查工具', trigger: 'blur' }],
        methodNameId: [{ required: true, message: '请输入检查方法', trigger: 'blur' }]
      },

      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' }]
      },
      listLoading1: false,
      listLoading2: false,
      listLoading3: false,
      listLoading4: false,
      listLoading5: false,

      downloadLoading: '',
      tableData_excel: [],
      colorchart: []
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'id'
    ])
  },
  created() {
    this.dateTime = [getBeforeOrAfterTime(-7), getNowTime2()]
    this.getEndStation()
    this.getDepartment()
    this.fetchData()
    this.fetchData_getPeople()
    this.getStationNumber()
    this.searchCheckToolBase()
    this.searchCheckMethodBase()
  },
  methods: {
    // 初始化获取产品型号
    getEndStation() {
      this.engineType = []
      var param = []
      var Data = this.CreateData('11', 'CATL_基础信息_机型信息_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.engineType.push({
            label: response.data[i].机型号,
            value: response.data[i].机型ID
          })
        }
      })
    },
    getDepartment() {
      this.departmentList = []
      var param = []
      var Data = this.CreateData('11', '质检_工单_新增_查询部门', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.departmentList.push({
            label: response.data[i].子部门名称,
            value: response.data[i].子节点
          })
        }
      })
    },
    solveNcSubmit1() {
      if (this.$refs.uploadPDF.uploadFiles.length > 0) {
        this.reportPicUpload(this.RepairManagementReplaceForm.ID)
      } else {
        this.$message.warning('请选择附件')
      }
    },
    reportPicUpload(OCC_ID) {
      // 如果文件列表为空，则不需要调用上传
      var param = []
      param[0] = ['检查项id', OCC_ID]
      param[1] = ['文件名称', '']
      param[2] = ['文件后缀', '']
      param[3] = ['文件内容', null]
      var Data1 = this.CreateData('15', '质检_基础_检查项_图片_增加', param)
      this.DataPDF.param = Data1
      this.$refs.uploadPDF.submit()
    },
    // 取消
    callOff(formName) {
      this.dialogFormVisible2 = false
      this.$refs[formName].resetFields()
    },
    // 给样式的
    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(res) {
      this.dialogFormVisible2 = false
      this.$refs.uploadPDF.clearFiles()
      // 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'
      //   }
      // }
      this.fetchData_content(this.currentSelectCheckOrder)
      this.showFileListInfo({
        ID: this.RepairManagementReplaceForm.ID
      })
      this.$message.success('文件上传成功!')
    },
    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('一次仅可上传一张图片')
    },
    changeIsUsed(row) {
      var param = []
      param[0] = ['ID', row.ID]
      param[1] = ['是否启用', row.是否启用]
      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('设置失败！')
        }
      })
    },
    showFileListInfo(item) {
      const param = []
      this.RepairManagementReplaceForm.ID = item.ID
      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
        } else {
          this.RepairManagementDataTableOrigin = []
        }
        this.showTableData_content_exchange = true
      })
    },
    showPic(item) {
      this.imgViewerList = [item.url]
      this.imgViewerVisible = true
    },
    downLoadFile(item) {
      const url = item.url
      const fileName = item.附件名称 + '.' + item.附件类型
      const xhr = new XMLHttpRequest()
      xhr.open('GET', url)
      xhr.responseType = 'blob'
      xhr.onload = function() {
        const blob = xhr.response
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = fileName
        link.target = '_blank' // 可选，如果希望在新窗口中下载文件，请取消注释此行
        link.click()
      }
      xhr.send()
    },
    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.人员编号
    },
    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].工位名称
          })
        }
      })
    },

    // region 质检方案维护
    fetchData() {
      this.listLoading = true
      var param = []
      param[0] = ['方案名称', this.schemeName]
      param[1] = ['产品型号', this.engineTypeValue]
      param[2] = ['PageCurrent', this.pageCurrent]
      param[3] = ['PageSize', this.pageSize]
      param[4] = ['PageCount', 1000, 'int', '1']
      param[5] = ['ItemCount', 1000, 'int', '1']
      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
        this.currentRow = null
      }).catch(er => {
        this.listLoading = false
        this.$message.error('错误')
      })
    },
    addCheckOrder() {
      this.form_addCheckOrder.checkOrderName = ''
      this.form_addCheckOrder.checkOrderRemarks = ''
      this.form_addCheckOrder.engineTypeValue = ''
      this.form_addCheckOrder.version = ''
      this.dialogFormVisible_addCheckOrder = true
    },
    addCheckOrder_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['方案名称', this.form_addCheckOrder.checkOrderName]
          param[1] = ['版本', this.form_addCheckOrder.version]
          param[2] = ['产品型号', this.form_addCheckOrder.engineTypeValue]
          param[3] = ['当前执行', 0]
          param[4] = ['备注', this.form_addCheckOrder.checkOrderRemarks]
          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()
    },
    changeValue(value) {
      this.currentRow = value
    },
    changeRulesValue(value) {
      if (value === 9999) {
        this.tableData_content = this.tableData_contentOrigin
      } else {
        this.tableData_content = this.tableData_contentOrigin.filter(res => res.规则类型 === value)
      }
    },

    makeCheckPlan() {
      this.dialogFormVisible_makeCheckPlan = true
      this.form_makeCheckPlan.checkSchemeName = this.currentRow['方案名称']
      this.form_makeCheckPlan.checkSchemeId = this.currentRow['ID']
    },
    makeCheckPlan_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['质检单名称', this.form_makeCheckPlan.checkPlanName]
          param[1] = ['检验方案id', this.form_makeCheckPlan.checkSchemeId]
          param[2] = ['部门id', this.form_makeCheckPlan.checkPlanDepartmentId]
          param[3] = ['方案类型', 2]
          param[4] = ['检查备注', this.form_makeCheckPlan.checkPlanRemarks]
          var Data = this.CreateData('12', '质检_工单_新增', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '下发成功！',
                type: 'success'
              })
              this.dialogFormVisible_makeCheckPlan = false
            } else {
              this.$message.error('下发失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    makeCheckPlan_cancel(formName) {
      this.dialogFormVisible_makeCheckPlan = false
      this.$refs[formName].resetFields()
    },
    addCheckOrderPlus() {
      this.form_addCheckOrderPlus.checkOrderNameOrigin = this.currentRow.方案名称
      this.form_addCheckOrderPlus.checkOrderNameId = this.currentRow.ID
      this.form_addCheckOrderPlus.checkOrderName = ''
      this.form_addCheckOrderPlus.checkOrderRemarks = ''
      this.form_addCheckOrderPlus.engineTypeValue = ''
      this.form_addCheckOrderPlus.version = ''
      this.dialogFormVisible_addCheckOrderPlus = true
    },
    addCheckOrderPlus_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['方案名称', this.form_addCheckOrderPlus.checkOrderName]
          param[1] = ['版本', this.form_addCheckOrderPlus.version]
          param[2] = ['产品型号', this.form_addCheckOrderPlus.engineTypeValue]
          param[3] = ['当前执行', 0]
          param[4] = ['备注', this.form_addCheckOrderPlus.checkOrderRemarks]
          param[5] = ['方案ID', this.form_addCheckOrderPlus.checkOrderNameId]
          var Data = this.CreateData('12', '质检_基础_检验方案_增加_升版', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '增加成功',
                type: 'success'
              })
              this.dialogFormVisible_addCheckOrderPlus = false
              this.fetchData()
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    editCheckOrder(row) {
      this.form_editCheckOrder.checkOrderName = row.方案名称
      this.form_editCheckOrder.engineTypeValue = row.产品型号
      this.form_editCheckOrder.checkOrderRemarks = row.备注
      this.form_editCheckOrder.version = row.版本
      this.form_editCheckOrder.ID = row.ID
      this.dialogFormVisible_editCheckOrder = true
    },
    editCheckOrder_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['方案名称', this.form_editCheckOrder.checkOrderName]
          param[1] = ['版本', this.form_editCheckOrder.version]
          param[2] = ['产品型号', this.form_editCheckOrder.engineTypeValue]
          param[3] = ['当前执行', 1]
          param[4] = ['备注', this.form_editCheckOrder.checkOrderRemarks]
          param[5] = ['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_editCheckOrder = false
      this.$refs[formName].resetFields()
    },
    editCheckOrder_SetSure(row) {
      var param = []
      param[0] = ['产品型号', row.产品型号]
      param[1] = ['当前执行', row.当前执行]
      param[2] = ['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.dialogFormVisible_editCheckOrder = false
          this.fetchData()
        } else {
          this.$message.error('设置失败！')
        }
      })
    },
    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: '已取消删除'
        })
      })
    },
    CheckOrder_rowClick(row) {
      this.rulerTypeFilter = 9999
      this.currentSelectCheckOrder = row
      this.title = `【${row.方案名称}】项目详情`
      this.fetchData_content(row)
    },
    // endregion
    // region 质检工单详细信息维护
    fetchData_content(row) {
      var param = []
      param[0] = ['方案id', row.ID]
      var Data = this.CreateData('11', '质检_基础_检查项_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData_contentOrigin = response.data
        this.changeRulesValue(this.rulerTypeFilter)
        this.dialogFormVisible_addCheckOrder_content_show = true
      }).catch(er => {
        this.$message.error('错误')
      })
    },
    addCheckOrder_content() {
      this.form_addCheckOrder_content = {
        checkSchemeId: this.currentSelectCheckOrder.ID,
        checkOrderName: '',
        checkOrderContent: '',
        checkOrderType: '定性',
        rulerType: 1,
        rulerRate: 1,
        checkOrderNum: 1,
        standardValue: '',
        maximumValue: 0,
        minimumValue: 0,
        unit: '',
        toolNameId: '',
        methodNameId: ''
      }
      this.dialogFormVisible_addCheckOrder_content = true
    },
    addCheckOrder_content_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['检查项目', this.form_addCheckOrder_content.checkOrderName]
          param[1] = ['检查内容', this.form_addCheckOrder_content.checkOrderContent]
          param[2] = ['检查数量', this.form_addCheckOrder_content.checkOrderNum]
          param[3] = ['方案id', this.form_addCheckOrder_content.checkSchemeId]
          param[4] = ['项目类型', this.form_addCheckOrder_content.checkOrderType]
          param[5] = ['标准值', this.form_addCheckOrder_content.standardValue]
          param[6] = ['下限', this.form_addCheckOrder_content.minimumValue]
          param[7] = ['上限', this.form_addCheckOrder_content.maximumValue]
          param[8] = ['单位', this.form_addCheckOrder_content.unit]
          param[9] = ['检查工具id', this.form_addCheckOrder_content.toolNameId]
          param[10] = ['检查方法id', this.form_addCheckOrder_content.methodNameId]
          param[11] = ['规则类型', this.form_addCheckOrder_content.rulerType]
          param[12] = ['规则频次', this.form_addCheckOrder_content.rulerRate]
          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)
              this.dialogFormVisible_addCheckOrder_content = false
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    addCheckOrder_content_cancel(formName) {
      this.dialogFormVisible_addCheckOrder_content = false
      this.$refs[formName].resetFields()
    },
    editCheckOrder_content(row) {
      console.log(row)
      this.dialogFormVisible_editCheckOrder_content = true
      this.form_editCheckOrder_content.checkSchemeId = row.方案id
      this.form_editCheckOrder_content.checkOrderName = row.检查项目
      this.form_editCheckOrder_content.checkOrderContent = row.检查内容
      this.form_editCheckOrder_content.checkOrderType = row.项目类型
      this.form_editCheckOrder_content.checkOrderNum = row.检查数量
      this.form_editCheckOrder_content.checkOrderRemarks = row.原始备注
      this.form_editCheckOrder_content.standardValue = row.标准值
      this.form_editCheckOrder_content.maximumValue = row.上限 === '' ? 0 : Number(row.上限)
      this.form_editCheckOrder_content.minimumValue = row.下限 === '' ? 0 : Number(row.下限)
      this.form_editCheckOrder_content.unit = row.单位
      this.form_editCheckOrder_content.toolNameId = row.检查工具id
      this.form_editCheckOrder_content.methodNameId = row.检查方法id
      this.form_editCheckOrder_content.rulerType = row.规则类型
      this.form_editCheckOrder_content.rulerRate = row.规则频次
      this.form_editCheckOrder_content.ID = row.ID
    },
    editCheckOrder_content_sure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['检查项目', this.form_editCheckOrder_content.checkOrderName]
          param[1] = ['检查内容', this.form_editCheckOrder_content.checkOrderContent]
          param[2] = ['检查数量', this.form_editCheckOrder_content.checkOrderNum]
          param[3] = ['ID', this.form_editCheckOrder_content.ID]
          param[4] = ['项目类型', this.form_editCheckOrder_content.checkOrderType]
          param[5] = ['标准值', this.form_editCheckOrder_content.standardValue]
          param[6] = ['下限', this.form_editCheckOrder_content.minimumValue]
          param[7] = ['上限', this.form_editCheckOrder_content.maximumValue]
          param[8] = ['单位', this.form_editCheckOrder_content.unit]
          param[9] = ['检查工具id', this.form_editCheckOrder_content.toolNameId]
          param[10] = ['检查方法id', this.form_editCheckOrder_content.methodNameId]
          param[11] = ['规则类型', this.form_editCheckOrder_content.rulerType]
          param[12] = ['规则频次', this.form_editCheckOrder_content.rulerRate]
          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_content = false
              this.fetchData_content(this.currentSelectCheckOrder)
            } else {
              this.$message.error('编辑失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    editCheckOrder_content_cancel(formName) {
      this.dialogFormVisible_editCheckOrder_content = false
      this.$refs[formName].resetFields()
    },
    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.showFileListInfo({
            ID: this.RepairManagementReplaceForm.ID
          })
        } else {
          this.$message.error('删除失败!')
        }
      })
    },
    deleteCheckOrder_content(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_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_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()
    },
    // endregion
    searchCheckToolBase() {
      this.CheckToolBase = []
      var param = []
      var Data = this.CreateData('11', '质检_基础_检查工具_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.CheckToolBase = response.data
      }).catch(er => {
        this.$message.error('错误')
      })
    },
    searchCheckMethodBase() {
      this.CheckMethodBase = []
      var param = []
      var Data = this.CreateData('11', '质检_基础_检查方法_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.CheckMethodBase = response.data
      }).catch(er => {
        this.$message.error('错误')
      })
    },
    // 分页功能改变显示数量
    handleSizeChange(val) {
      this.pageSize = val
      this.fetchData()
    },
    // 分页功能改变当前页
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.fetchData()
    }
  }
}
</script>

<style scoped>
  span{
    /*margin: 10px 0px 10px 10px;*/
  }
  .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>

