<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <el-select v-model="machineNumberValue" filterable placeholder="机床图号" size="small" style="margin-left: 10px;width: 180px;margin-top: 5px" clearable @change="machineChange()">
          <el-option
            v-for="item in machineNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value">
            <div style="float: left">{{ item.label }}</div>
            <div style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</div>
          </el-option>
        </el-select>
        <el-select v-model="groupNumberValue" filterable placeholder="组号" size="small" style="margin-left: 10px;width:100px" clearable>
          <el-option
            v-for="item in groupNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-input v-model="SpareParts" filterable placeholder="零件图号或零件名称" style="width: 150px;margin-left: 10px" size="small" clearable/>
        <el-select v-model="QualityTypeValue" filterable placeholder="质检类型" style="margin-left: 10px;width:150px" size="small" clearable>
          <el-option
            v-for="item in QualityTypeNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <!--<span class="demonstration">时间区间:</span>-->
        <el-date-picker
          v-model="startTime"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 160px;margin-left: 10px"
          type="date"
          placeholder="选择开始日期"/>
        <span class="demonstration">~</span>
        <el-date-picker
          v-model="endTime"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 160px"
          type="date"
          placeholder="选择结束日期"/>
        <!--<span>质检情况:</span>-->
        <el-select v-model="qualityInspectionValue" filterable placeholder="质检情况" size="small" style="width: 100px;margin-left: 10px" clearable>
          <el-option
            v-for="item in qualityInspection"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <!--<span>质检人员:</span>-->
        <el-select v-model="personNum" filterable placeholder="质检人员" size="small" style="width: 130px;margin-left: 10px" clearable>
          <el-option
            v-for="item in person"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-button type="primary" size="small" icon="el-icon-search" style="margin-left: 15px;margin-top: 5px" plain @click="pageSize=10; pageCurrent= 1;selecttable()">查询</el-button>
        <el-tooltip :open-delay="1000" effect="dark" content="导出查询数据" placement="top">
          <el-button type="warning" size="small" icon="el-icon-download" plain style="margin-left:10px" @click="exportExcel()">导出</el-button>
        </el-tooltip>
        <el-button type="distribution" size="small" icon="el-icon-circle-plus-outline" plain style="margin-left:10px" @click="AddTableData()">新增</el-button>
      </el-row>
    </el-card>
    <el-card>
      <el-table v-loading="loading" :data="tableData1" element-loading-text="质检数据较多，请耐心等候..." border size="mini" highlight-current-row style="width: 100%" stripe height="475px">
        <el-table-column align="center" label="禁用情况" width="80px">
          <template slot-scope="scope">
            <el-tag v-if="parseInt(scope.row.是否禁用)===0||scope.row.是否禁用===''" type="success" size="small" @click="approvalPass(scope.row)">未禁用</el-tag>
            <el-tag v-if="parseInt(scope.row.是否禁用)===1" type="error" size="small">已禁用</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center" width="90px">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="机床名称" align="center" min-width="180px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.机床名称 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center" width="60px">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" align="center" min-width="130px" show-overflow-tooltip>
          <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-column label="规格或材料" align="center" width="120px" show-overflow-tooltip>
          <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-column label="质检人员" align="center">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="检测数量" align="center" width="120px">
          <template slot-scope="scope">
            <template v-if="scope.row.edit">
              <el-input-number v-model="scope.row.数量" :min="0" :max="scope.row.零件数量" :step="1" style="width: 90%" size="mini"/>
            </template>
            <template v-else>
              {{ scope.row.数量 }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="检测结果" align="center" width="120px">
          <template slot-scope="scope">
            <template v-if="scope.row.edit">
              <el-select v-model="scope.row.是否合格" placeholder="请选择" filterable size="mini" style="width: 100%">
                <el-option
                  v-for="item in qualityInspection"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </template>
            <template v-else>
              {{ scope.row.是否合格 ===1 ? '合格' : '不合格' }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="不合格数" align="center" width="120px">
          <template slot-scope="scope">
            <template v-if="scope.row.edit && scope.row.是否合格 === 2">
              <el-input-number v-model="scope.row.不合格数量" :min="0" :max="scope.row.数量" :step="1" style="width: 90%" size="mini"/>
            </template>
            <template v-else-if="scope.row.是否合格 === 1">
              {{ scope.row.不合格数量 = '' }}
            </template>
            <template v-else>
              {{ scope.row.不合格数量 }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="不合格原因" align="center" width="140px">
          <template slot-scope="scope">
            <template v-if="scope.row.edit && scope.row.是否合格 === 2">
              <el-select v-model="scope.row.不合格原因" placeholder="请选择" filterable size="mini" style="width: 100%">
                <el-option
                  v-for="item in reasonsForNonconformity"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </template>
            <template v-else-if="scope.row.是否合格 === 1">
              {{ scope.row.不合格原因 = null }}
            </template>
            <template v-else>
              {{ scope.row.不合格原因文本 }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="处理结果" align="center" width="140px" show-overflow-tooltip>
          <template slot-scope="scope">
            <template v-if="scope.row.edit && scope.row.是否合格 === 2">
              <el-select v-model="scope.row.处理结果" placeholder="请选择" filterable size="mini" style="width: 100%">
                <el-option
                  v-for="item in disqualificationTreatment"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </template>
            <template v-else-if="scope.row.是否合格 === 1">
              {{ scope.row.处理结果 = null }}
            </template>
            <template v-else>
              {{ scope.row.不合格处理文本 }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="质检时间" align="center" width="100px">
          <template slot-scope="scope">
            {{ scope.row.操作时间 ? scope.row.操作时间.split(' ')[0] : '' }}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" width="140px" show-overflow-tooltip>
          <template slot-scope="scope">
            <template v-if="scope.row.edit">
              <el-input v-model="scope.row.备注" size="mini" style="width: 100%"/>
            </template>
            <template v-else>
              {{ scope.row.备注 }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="编辑人" align="center" width="90px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.编辑人 }}
          </template>
        </el-table-column>
        <el-table-column label="编辑时间" align="center" width="90px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.编辑时间 ? scope.row.编辑时间.split(' ')[0] : scope.row.编辑时间 }}
          </template>
        </el-table-column>
        <el-table-column label="形位" align="center" width="70">
          <template slot-scope="scope">
            <el-popover placement="right" width="500" trigger="click">
              <el-table :data="gridData" class="subTableHeader" highlight-current-row size="mini">
                <el-table-column width="50" align="center" type="index" label="序号"/>
                <el-table-column min-width="150" align="center" label="类别">
                  <template slot-scope="scope">
                    {{ scope.row.类别 }}
                  </template>
                </el-table-column>
                <el-table-column min-width="100" align="center" label="数值">
                  <template slot-scope="scope">
                    {{ scope.row.数值 }}
                  </template>
                </el-table-column>
                <el-table-column min-width="100" align="center" label="零件数量">
                  <template slot-scope="scope">
                    {{ scope.row.零件数量 }}
                  </template>
                </el-table-column>
              </el-table>
              <el-button slot="reference" type="text" plain size="mini" icon="el-icon-search" @click="searchTableDetail(1, scope.row.质检流水号)">形位</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="尺寸" align="center" width="70">
          <template slot-scope="scope">
            <el-popover placement="right" width="500" trigger="click">
              <el-table :data="gridData" class="subTableHeader" highlight-current-row size="mini">
                <el-table-column width="50" align="center" type="index" label="序号"/>
                <el-table-column min-width="150" align="center" label="类别">
                  <template slot-scope="scope">
                    {{ scope.row.类别 }}
                  </template>
                </el-table-column>
                <el-table-column min-width="100" align="center" label="数值">
                  <template slot-scope="scope">
                    {{ scope.row.数值 }}
                  </template>
                </el-table-column>
                <el-table-column min-width="100" align="center" label="零件数量">
                  <template slot-scope="scope">
                    {{ scope.row.零件数量 }}
                  </template>
                </el-table-column>
              </el-table>
              <el-button slot="reference" type="text" plain size="mini" icon="el-icon-search" @click="searchTableDetail(2, scope.row.质检流水号)">尺寸</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="外观" align="center" width="70">
          <template slot-scope="scope">
            <el-popover placement="right" width="500" trigger="click">
              <el-table :data="gridData" class="subTableHeader" highlight-current-row size="mini">
                <el-table-column width="50" align="center" type="index" label="序号"/>
                <el-table-column min-width="150" align="center" label="类别">
                  <template slot-scope="scope">
                    {{ scope.row.类别 }}
                  </template>
                </el-table-column>
                <el-table-column min-width="100" align="center" label="数值">
                  <template slot-scope="scope">
                    {{ scope.row.数值 }}
                  </template>
                </el-table-column>
                <el-table-column min-width="100" align="center" label="零件数量">
                  <template slot-scope="scope">
                    {{ scope.row.零件数量 }}
                  </template>
                </el-table-column>
              </el-table>
              <el-button slot="reference" type="text" plain size="mini" icon="el-icon-search" @click="searchTableDetail(3, scope.row.质检流水号)">外观</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="查看图片" align="center" width="100px">
          <template slot-scope="scope">
            <el-button
              v-if="!scope.row.edit"
              size="mini"
              type="text"
              plain
              icon="el-icon-search"
              @click="viewPicture(scope.row)">查看图片</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" min-width="100">
          <template slot-scope="scope">
            <el-tooltip :open-delay="1200" effect="dark" content="编辑" placement="top">
              <div style="display: inline-block;margin-right: 10px">
                <el-button v-if="!scope.row.edit" :disabled="scope.row.考核状态 >= 7" type="text" size="mini" icon="el-icon-edit" @click="scope.row.edit=!scope.row.edit"/>
                <el-button v-if="scope.row.edit" type="text" plain size="small" @click="confirmEdit(scope.row)">确定</el-button>
                <el-button v-if="scope.row.edit" type="text" plain size="small" @click="cancel(scope.row)">取消</el-button>
              </div>
            </el-tooltip>
            <el-tooltip :open-delay="1200" effect="dark" content="删除" placement="top">
              <div style="display: inline-block">
                <el-button v-if="!scope.row.edit" :disabled="scope.row.考核状态 >= 7" type="text" size="mini" icon="el-icon-delete" @click="deleterow(scope.row)"/>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40, 100]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
    <el-card>
      <span style="margin-left: 45%;font-size: 20px;">正在加工零件列表</span>
      <el-table :data="tableData10" border size="mini" highlight-current-row style="width: 100%" stripe height="475px">
        <el-table-column label="机床图号" prop="机床图号" align="center" width="110px">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="机床名称" prop="机床名称" align="center" min-width="200px">
          <template slot-scope="scope">
            {{ scope.row.机床名称 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" prop="组号" align="center">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" prop="零件图号" align="center" min-width="110px">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" prop="零件名称" 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="工序名称" prop="工艺名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.工艺名称 }}
          </template>
        </el-table-column>
        <el-table-column label="工位" prop="终端编号" align="center" width="100px">
          <template slot-scope="scope">
            {{ scope.row.终端编号 }}
          </template>
        </el-table-column>
        <el-table-column label="操作工" prop="姓名" align="center">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="120">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              plain
              icon="el-icon-search"
              @click="viewProcedures(scope.row)">查看工序</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--      <div class="block">-->
      <!--        <el-pagination-->
      <!--          :current-page="pageCurrent1"-->
      <!--          :page-sizes="[10, 20, 30, 40, 100]"-->
      <!--          :page-size="pageSize1"-->
      <!--          :total="total1"-->
      <!--          layout="total, sizes, prev, pager, next, jumper"-->
      <!--          @size-change="handleSizeChange1"-->
      <!--          @current-change="handleCurrentChange1"/>-->
      <!--      </div>-->
    </el-card>
    <el-card>
      <span style="margin-left: 45%;font-size: 20px">待加工零件列表</span>
      <el-table :data="tableData20" border size="mini" highlight-current-row style="width: 100%" stripe height="475px">
        <el-table-column label="机床图号" prop="机床图号" align="center" width="110px">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="机床名称" prop="机床名称" align="center" min-width="200px">
          <template slot-scope="scope">
            {{ scope.row.机床名称 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" prop="组号" align="center" width="70px">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" prop="零件图号" align="center" width="140px">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" prop="零件名称" align="center" min-width="120px">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件数量" align="center" width="70px">
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <el-table-column label="工序名称" prop="工艺名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.工艺名称 }}
          </template>
        </el-table-column>
        <el-table-column label="工位" prop="MES终端编号" align="center" width="80px">
          <template slot-scope="scope">
            {{ scope.row.MES终端编号 }}
          </template>
        </el-table-column>
        <el-table-column label="操作工" prop="姓名" align="center">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="120">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              plain
              icon="el-icon-search"
              @click="viewProcedures(scope.row)">查看工序</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--      <div class="block">-->
      <!--        <el-pagination-->
      <!--          :current-page="pageCurrent2"-->
      <!--          :page-sizes="[10, 20, 30, 40, 100]"-->
      <!--          :page-size="pageSize2"-->
      <!--          :total="total2"-->
      <!--          layout="total, sizes, prev, pager, next, jumper"-->
      <!--          @size-change="handleSizeChange2"-->
      <!--          @current-change="handleCurrentChange2"/>-->
      <!--      </div>-->
    </el-card>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible4" title="工序完成情况" center style="min-height: 300px">
      <el-row>
        <span>零件图号:</span>
        <el-input v-model="SparePartsNumber" style="width: 200px" size="small"/>
        <span>零件名称:</span>
        <el-input v-model="SparePartsName" style="width: 200px" size="small"/>
      </el-row>
      <el-table
        :data="tableData5"
        style="width: 100%;margin-top: 20px"
        size="mini"
        height="300"
        stripe
        highlight-current-row
        border>
        <el-table-column align="center" label="工序顺序" width="70">
          <template slot-scope="scope">
            {{ scope.row.工序顺序 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="工艺名称" width="120">
          <template slot-scope="scope">
            {{ scope.row.工艺名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="工艺要求">
          <template slot-scope="scope">
            {{ scope.row.工艺要求 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作工">
          <template slot-scope="scope">
            {{ scope.row.操作员 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="完成数量" width="120">
          <template slot-scope="scope">
            {{ scope.row.完成数量 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="工艺是否完成" width="120">
          <template slot-scope="scope">
            <el-tag v-if="parseInt(scope.row.工序状态)===4" type="success" size="small">已完成</el-tag>
            <el-tag v-if="parseInt(scope.row.工序状态)===5" type="warning" size="small">报废</el-tag>
            <el-tag v-if="parseInt(scope.row.工序状态)!==4 && parseInt(scope.row.工序状态)!==5" type="primary" size="small">未完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="质检数量" width="120">
          <template slot-scope="scope">
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="不合格数" width="120">
          <template slot-scope="scope">
            {{ scope.row.不合格数量 }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" title="图片" center style="" width="800px">
      <viewer>
        <img v-for="url in urls" :key="url" :src="url" lazy style="width: 700px;height: 700px">
      </viewer>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible10" :title="dialogmethod ? '编辑质检数据' : '新增质检数据'" center style="min-height: 300px" width="700px">
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="right" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="质检类型" prop="质检类型">
              <el-select v-model="form2.质检类型" disabled filterable placeholder="选择质检类型" style="width:150px" size="small" clearable>
                <el-option
                  v-for="item in QualityTypeNumber"
                  :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="机床图号">
              <el-select v-model="form2.机床图号" :disabled="dialogmethod" filterable placeholder="选择机床图号" size="small" style="width: 150px" clearable @change="machineChange1()">
                <el-option
                  v-for="item in machineNumber"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                  <div style="float: left">{{ item.label }}</div>
                  <div style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="组号" prop="组号">
              <el-select v-model="form2.组号" :disabled="dialogmethod" filterable placeholder="选择组号" size="small" style="width:150px" clearable @change="groupChange()">
                <el-option
                  v-for="item in groupNumber1"
                  :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="零件图号">
              <el-select v-model="form2.零件图号" :disabled="dialogmethod" filterable placeholder="选择零件图号" style="width:150px" size="small" clearable @change="partChange">
                <el-option
                  v-for="item in partNum"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工序" prop="工序">
              <el-select v-model="form2.工序" :disabled="dialogmethod" filterable placeholder="选择工序" style="width:150px" size="small" clearable @change="procedureChange">
                <el-option
                  v-for="item in procedureNum"
                  :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="操作工">
              <el-select v-model="form2.操作工" filterable placeholder="选择操作工" style="width:150px" size="small" clearable>
                <el-option
                  v-for="item in operators"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="质检情况" prop="质检情况">
              <el-select v-model="form2.质检情况" filterable placeholder="选择质检情况" style="width:150px" size="small" clearable>
                <el-option
                  v-for="item in qualityInspection"
                  :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="检测数">
              <el-input-number v-model="form2.检测数" :min="0" :max="proceductnummax" :step="1" placeholder="检测数" style="width:150px" size="small" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="不合格数量" prop="不合格数量">
              <el-input-number v-model="form2.不合格数量" :disabled="form2.质检情况===1" :min="0" :max="Number(form2.检测数)" :step="1" placeholder="不合格数量" style="width:150px" size="small" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不合格原因" prop="不合格原因">
              <el-select v-model="form2.不合格原因" :disabled="form2.质检情况===1" placeholder="请选择" filterable size="small" style="width: 150px">
                <el-option
                  v-for="item in reasonsForNonconformity"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="不合格处理" prop="不合格处理">
              <el-select v-model="form2.不合格处理" :disabled="form2.质检情况===1" placeholder="请选择" filterable size="small" style="width: 150px">
                <el-option
                  v-for="item in disqualificationTreatment"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input v-model="form2.备注" style="width:150px" size="small" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="AddTableData_disable" type="primary" size="small" icon="el-icon-check" @click="submitTable">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { initProject, searchgroup, selecttable, QualityType, searchPic, searchTableDetail, searchData, searchData1, processingStatus, initPerson, Prohibit, initDisqualificationTreatment, initReasonsForNonconformity, searchparts, searchprocedure, searchoperators, submitTable, confirmEdit, searchproceductnum, deleterow } from '@/api/Assembly/QualityInspectionInformationInquiry'
import { readFile } from '@/utils/request'
import { mapGetters } from 'vuex'
// import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      machineNumberValue: '',
      machineNumber: [],
      startTime: '',
      endTime: '',
      form2: {
        机床图号: '',
        组号: '',
        零件图号: '',
        工序: '',
        质检类型: 10,
        质检情况: 1,
        检测数: '',
        不合格数量: '',
        不合格原因: '',
        不合格处理: '',
        备注: '',
        操作工: ''
      },
      rules2: {
        操作工: [{ required: true, message: '请选择操作工' }],
        工序: [{ required: true, message: '请选择工序' }],
        质检情况: [{ required: true, message: '请选择质检情况' }]
      },
      urls: [],
      URL: '',
      number: '',
      reasonsForNonconformity: [],
      disqualificationTreatment: [],
      operators: [],
      groupNumberValue: '',
      groupNumber: [],
      groupNumber1: [],
      partNum: [],
      procedureNum: [],
      gridData: [],
      QualityTypeNumber: [],
      QualityTypeValue: '',
      qualityInspectionValue: '',
      qualityInspection: [
        {
          value: 1,
          label: '合格'
        }, {
          value: 2,
          label: '不合格'
        }
      ],
      tableData1: [],
      tableData10: [],
      tableData20: [],
      tableData5: [],
      SpareParts: '',
      SparePartsNumber: '',
      SparePartsName: '',
      personNum: '',
      person: [],
      dialogFormVisible: false,
      dialogFormVisible4: false,
      dialogFormVisible10: false,
      AddTableData_disable: false,
      loading: false,
      total: 0, // 总条数
      pageSize: 10, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      dialogmethod: false, // false新增  true 编辑
      proceductnummax: 0
      // total1: 0, // 总条数
      // pageSize1: 10, // 每页显示条数
      // pageCurrent1: 1, // 后台获取页
      // total2: 0, // 总条数
      // pageSize2: 10, // 每页显示条数
      // pageCurrent2: 1 // 后台获取页
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
  },
  mounted() {
    this.initProject()
    this.QualityType()
    this.fetchData()
    this.fetchData1()
  },
  methods: {
    // 表内编辑取消
    cancel(row) {
      row.edit = !row.edit
      console.log(row, 8888)
      row.备注 = row.备注_原
      row.不合格数量 = row.不合格数量_原
      row.是否合格 = row.是否合格_原
      row.数量 = row.数量_原
      row.不合格原因文本 = row.不合格原因文本_原
      row.不合格处理文本 = row.不合格处理文本_原
    },
    // 表内编辑确定
    confirmEdit(row) {
      console.log(this.$store.state.user.id, 787878)
      confirmEdit(row.质检流水号, row.质检类型代码, row.零部件流水号, row.是否合格, row.数量, row.不合格数量, row.不合格原因, row.处理结果, row.备注, this.$store.state.user.id).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('编辑成功')
          this.selecttable()
        } else {
          this.$message.error('编辑失败')
        }
      })
      row.edit = false
    },
    // 删除质检
    deleterow(row) {
      // this.plan = row.计划流水号
      console.log(row, 4545)
      this.$confirm('是否删除该质检记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleterow(row.质检流水号, row.质检类型代码, row.零部件流水号, row.数量).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.selecttable()
          } else {
            this.$message.error('编辑失败')
          }
        })
      })
    },
    initProject() {
      initProject().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber.push({
            label: response.data[i].机床图号,
            name: response.data[i].项目名称,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    QualityType() {
      QualityType().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.QualityTypeNumber.push({
            label: response.data[i].质检类型,
            value: response.data[i].质检类型代码
          })
        }
      })
      initPerson().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.person.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
      initDisqualificationTreatment().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.disqualificationTreatment.push({
            label: response.data[i].不合格处理文本,
            value: response.data[i].不合格处理
          })
        }
      })
      initReasonsForNonconformity().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.reasonsForNonconformity.push({
            label: response.data[i].不合格原因文本,
            value: response.data[i].不合格原因
          })
        }
      })
    },
    approvalPass(row) {
      this.$confirm('是否禁用?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        Prohibit(row.质检流水号, row.质检类型代码).then(res => {
          if (res.data[0].result === '1') {
            this.$message.success('操作成功')
            this.selecttable()
          } else {
            this.$message.error('操作失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    // 删除
    handleEdit(row) {
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
      console.log(row, 8989)
      this.partNum = []
      this.groupNumber = []
      this.procedureNum = []
      this.operators = []
      this.AddTableData_disable = false
      this.dialogmethod = true // 编辑置为true
      this.dialogFormVisible10 = true
    },
    // 新增
    AddTableData() {
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
      this.partNum = []
      this.groupNumber = []
      this.procedureNum = []
      this.operators = []
      this.AddTableData_disable = false
      this.dialogmethod = false // 新增置为false
      this.dialogFormVisible10 = true
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        return v[j]
      }))
    },
    exportExcel() {
      if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check1 = 1 } else { this.check1 = 0 }
      if (this.groupNumberValue !== '' && this.groupNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
      if (this.SpareParts !== '' && this.SpareParts !== null) { this.check3 = 1 } else { this.check3 = 0 }
      if (this.QualityTypeValue !== '' && this.QualityTypeValue !== null) { this.check4 = 1 } else { this.check4 = 0 }
      if (this.startTime !== '' && this.startTime !== null) { this.check5 = 1 } else { this.check5 = 0 }
      if (this.endTime !== '' && this.endTime !== null) { this.check6 = 1 } else { this.check6 = 0 }
      if (this.qualityInspectionValue !== '' && this.qualityInspectionValue !== null) { this.check7 = 1 } else { this.check7 = 0 }
      if (this.personNum !== '' && this.personNum !== null) { this.check8 = 1 } else { this.check8 = 0 }
      var param = []
      param[0] = ['机床流水号_check', this.check1]
      param[1] = ['机床流水号', this.machineNumberValue]
      param[2] = ['组件流水号_check', this.check2]
      param[3] = ['组件流水号', this.groupNumberValue]
      param[4] = ['零件名称_check', this.check3]
      param[5] = ['零件名称', this.SpareParts]
      param[6] = ['质检类型代码_check', this.check4]
      param[7] = ['质检类型代码', this.QualityTypeValue]
      param[8] = ['开始时间_check', this.check5]
      param[9] = ['开始时间', this.startTime]
      param[10] = ['结束时间_check', this.check6]
      param[11] = ['结束时间', this.endTime]
      param[12] = ['质检情况_check', this.check7]
      param[13] = ['质检情况', this.qualityInspectionValue]
      param[14] = ['人员编号_check', this.check8]
      param[15] = ['人员编号', this.personNum]
      var Data = this.CreateData('2001', '报表_质检管理_质量情况_查询数据', param)
      this.exportExcel_NPOI(Data)
    },
    // exportExcel1() {
    //   if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check1 = 1 } else { this.check1 = 0 }
    //   if (this.groupNumberValue !== '' && this.groupNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
    //   if (this.SpareParts !== '' && this.SpareParts !== null) { this.check3 = 1 } else { this.check3 = 0 }
    //   if (this.QualityTypeValue !== '' && this.QualityTypeValue !== null) { this.check4 = 1 } else { this.check4 = 0 }
    //   if (this.startTime !== '' && this.startTime !== null) { this.check5 = 1 } else { this.check5 = 0 }
    //   if (this.endTime !== '' && this.endTime !== null) { this.check6 = 1 } else { this.check6 = 0 }
    //   if (this.qualityInspectionValue !== '' && this.qualityInspectionValue !== null) { this.check7 = 1 } else { this.check7 = 0 }
    //   if (this.personNum !== '' && this.personNum !== null) { this.check8 = 1 } else { this.check8 = 0 }
    //   selecttable22(this.check1, this.machineNumberValue, this.check2, this.groupNumberValue, this.check3, this.SpareParts, this.check4, this.QualityTypeValue, this.check5, this.startTime, this.check6, this.endTime, this.check7, this.qualityInspectionValue, this.check8, this.personNum).then(response => {
    //     import('@/vendor/Export2Excel').then(excel => {
    //       const tHeader = ['是否禁用', '机床图号', '机床名称', '组号', '零件图号', '零件名称', '零件数量', '规格或材料', '工序名称', '质检类型', '检验数量', '不合格数量', '不合格原因', '处理结果', '质检时间', '备注']
    //       const filterVal = ['禁用情况', '机床图号', '机床名称', '组号', '零件图号', '零件名称', '零件数量', '规格或材料', '工艺名称', '质检类型', '数量', '不合格数量', '不合格原因文本', '不合格处理文本', '操作时间', '备注']
    //       const list = response.data
    //       const data = this.formatJson(filterVal, list)
    //       excel.export_json_to_excel({
    //         header: tHeader,
    //         data,
    //         filename: '质检情况表',
    //         autoWidth: true,
    //         bookType: 'xlsx'
    //       })
    //     })
    //   })
    // },
    fetchData() {
      searchData().then(response => {
        this.tableData10 = response.data
        this.total1 = response.data.total
      })
    },
    fetchData1() {
      searchData1().then(response => {
        console.log(response)
        this.tableData20 = response.data
        this.total2 = response.data.total
      })
    },
    machineChange() {
      this.groupNumberValue = ''
      this.groupNumber = []
      searchgroup(this.machineNumberValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.groupNumber.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    machineChange1() {
      this.form2.组号 = ''
      this.groupNumber1 = []
      searchgroup(this.form2.机床图号).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.groupNumber1.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    groupChange() {
      this.form2.零件图号 = ''
      this.partNum = []
      searchparts(this.form2.组号).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.partNum.push({
            label: response.data[i].零件图号,
            value: response.data[i].工艺计划流水号
          })
        }
      })
    },
    partChange() {
      this.form2.工序 = ''
      this.procedureNum = []
      searchproceductnum(this.form2.零件图号).then(response => {
        this.proceductnummax = response.data[0].批次数量
      })
      searchprocedure(this.form2.零件图号).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.procedureNum.push({
            label: response.data[i].工艺名称,
            value: response.data[i].工序流水号
          })
        }
      })
    },
    procedureChange() {
      searchoperators(this.form2.工序).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.operators.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
    },
    submitTable() {
      this.$refs['form2'].validate((valid) => {
        if (valid) {
          this.AddTableData_disable = true

          submitTable(this.form2.工序, this.form2.质检类型, this.form2.检测数, this.form2.质检情况, this.id, this.form2.不合格数量, this.form2.不合格原因, this.form2.不合格处理, this.form2.备注, this.form2.操作工, this.$store.state.user.id).then(response => {
            if (response.data[0].result === '1') {
              this.dialogFormVisible10 = false
              this.$message.success('新增成功')
              this.selecttable()
            } else {
              this.$message.error('新增失败')
            }
          })
        } else {
          return false
        }
      })
    },
    searchTableDetail(type, num) {
      searchTableDetail(type, num).then(response => {
        this.gridData = response.data
      })
      console.log(type)
    },
    selecttable() {
      this.loading = true
      this.tableData1 = []
      if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check1 = 1 } else { this.check1 = 0 }
      if (this.groupNumberValue !== '' && this.groupNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
      if (this.SpareParts !== '' && this.SpareParts !== null) { this.check3 = 1 } else { this.check3 = 0 }
      if (this.QualityTypeValue !== '' && this.QualityTypeValue !== null) { this.check4 = 1 } else { this.check4 = 0 }
      if (this.startTime !== '' && this.startTime !== null) { this.check5 = 1 } else { this.check5 = 0 }
      if (this.endTime !== '' && this.endTime !== null) { this.check6 = 1 } else { this.check6 = 0 }
      if (this.qualityInspectionValue !== '' && this.qualityInspectionValue !== null) { this.check7 = 1 } else { this.check7 = 0 }
      if (this.personNum !== '' && this.personNum !== null) { this.check8 = 1 } else { this.check8 = 0 }
      selecttable(this.check1, this.machineNumberValue, this.check2, this.groupNumberValue, this.check3, this.SpareParts, this.check4, this.QualityTypeValue, this.check5, this.startTime, this.check6, this.endTime, this.check7, this.qualityInspectionValue, this.check8, this.personNum, this.pageCurrent, this.pageSize).then(response => {
        this.tableData1 = response.data.result
        this.tableData1.map(v => {
          this.$set(v, 'edit', false)
          this.$set(v, '备注_原', v.备注)
          this.$set(v, '不合格数量_原', v.不合格数量)
          this.$set(v, '是否合格_原', v.是否合格)
          this.$set(v, '数量_原', v.数量)
          this.$set(v, '不合格原因文本_原', v.不合格原因文本)
          this.$set(v, '不合格处理文本_原', v.不合格处理文本)
        })
        console.log(this.tableData1, 8979)
        this.loading = false
        this.total = parseInt(response.data.output[0].ItemCount)
      })
    },
    viewPicture(row) {
      this.dialogFormVisible = true
      console.log(row)
      searchPic(row.质检流水号).then(response => {
        console.log(response.data, 222)
        this.urls = []
        // this.URL = readFile + response.data[0].文件标识 + '.' + response.data[0].文件后缀
        for (let i = 0; i < response.data.length; i++) {
          this.urls.push(readFile + response.data[i].文件标识 + '.' + response.data[i].文件后缀)
        }
      })
    },
    viewProcedures(row) {
      this.dialogFormVisible4 = true
      this.SparePartsNumber = row.零件图号
      this.SparePartsName = row.零件名称
      processingStatus(row.工艺计划流水号).then(response => {
        this.tableData5 = response.data
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.selecttable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.selecttable()
    }
    // handleSizeChange1(val) {
    //   this.pageCurrent1 = 1
    //   this.pageSize1 = val
    //   this.fetchData()
    // },
    // handleCurrentChange1(val) {
    //   this.pageCurrent1 = val
    //   this.fetchData()
    // },
    // handleSizeChange2(val) {
    //   this.pageCurrent2 = 1
    //   this.pageSize2 = val
    //   this.fetchData1()
    // },
    // handleCurrentChange2(val) {
    //   this.pageCurrent2 = val
    //   this.fetchData1()
    // }
  }
}

</script>

<style scoped>
h3{
  margin: 5px !important;
}
</style>
