<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">产品编号：</span>
        <el-input v-model="barcode" style="width:200px;" clearable placeholder="" size="small"/>
        <el-button type="primary" plain size="small" icon="el-icon-search" style="margin-left: 10px" @click="getTable2()">查询</el-button>
        <el-button type="warning" plain size="small" icon="el-icon-plus" style="margin-left: 10px" @click="creatOrder">增加</el-button>
      </div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        element-loading-text="数据加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
        class="main"
        tooltip-effect="dark"
        height="650px"
        style="width: 70%"
        border
        size="mini">
        <el-table-column type="index" width="60" label="序号" align="center"/>
        <el-table-column align="center" label="产品编号">
          <template slot-scope="scope">
            {{ scope.row.产品编号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="产品名称" width="100">
          <template slot-scope="scope">
            {{ scope.row.产品名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目状态" width="100">
          <template slot-scope="scope">
            {{ scope.row.项目状态 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="检查时间" width="100">
          <template slot-scope="scope">
            {{ scope.row.检查时间 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="检查人员" width="100">
          <template slot-scope="scope">
            {{ scope.row.检查人员 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="审核" width="100">
          <template slot-scope="scope">
            {{ scope.row.审核 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目数量" width="80">
          <template slot-scope="scope">
            <el-link type="primary" @click="showFileList(scope.row)">{{ scope.row.项目数量 }}</el-link>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="100">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="solveNc(scope.row)"/>
            </el-tooltip>
            <el-button type="text" style="color: #ff0000" @click="deleteInformation(scope.row)"><i class="el-icon-delete"/></el-button>
            <el-tooltip class="item" effect="dark" content="预览" placement="bottom">
              <el-button
                v-if="scope.row.项目数量 > 0"
                size="mini"
                type="text"
                icon="el-icon-printer"
                style="color: #ffcc00"
                @click="showPrintContentView(scope.row, true)"/>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-sizes="[15, 30, 40]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
    <el-dialog :visible.sync="dialogFormVisible" title="增加出厂报告" center style="min-height: 200px;" width="400px">
      <el-form ref="formAdd" :model="formAdd" :rules="rulesAdd" label-position="right" label-width="110px">
        <el-form-item label="产品编号" prop="productCode" style="display: inline-block">
          <el-input
            v-model="formAdd.productCode"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="方案" prop="productScheme" style="display: inline-block">
          <el-select v-model="formAdd.productScheme" placeholder="请选择方案" size="small" style="width: 200px">
            <el-option
              v-for="item in productScheme"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              size="mini"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff('formAdd')">取消</el-button>
        <el-button type="primary" size="small" @click="submitAdd('formAdd')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible1" title="编辑" center style="min-height: 200px;" width="400px">
      <el-form ref="formEdit" :model="formEdit" :rules="rulesEdit" label-position="right" label-width="110px">
        <el-form-item label="产品编号" prop="productCode" style="display: inline-block">
          <el-input
            v-model="formEdit.productCode"
            size="small"
            readonly
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName" style="display: inline-block">
          <el-input
            v-model="formEdit.productName"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="项目状态" prop="productStatus" style="display: inline-block">
          <el-input
            v-model="formEdit.productStatus"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="检查时间" prop="checkTime" style="display: inline-block">
          <el-date-picker v-model="formEdit.checkTime" :clearable="false" type="date" size="small" format="yyyyMMdd" value-format="yyyyMMdd" style="width:200px"/>
        </el-form-item>
        <el-form-item label="检查人员" prop="checkPerson" style="display: inline-block">
          <el-input
            v-model="formEdit.checkPerson"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="审核人员" prop="reviewPerson" style="display: inline-block">
          <el-input
            v-model="formEdit.reviewPerson"
            size="small"
            style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff('formEdit')">取消</el-button>
        <el-button type="primary" size="small" @click="solveNcSubmit('formEdit')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible2" :title="title" :show-close="false" center style="min-height: 200px;" width="1000px">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item title="出厂报告项目" name="1">
          <el-table
            ref="multipleTable3"
            :data="tableData1"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}"
            max-height="300px"
            class="main"
            tooltip-effect="dark"
            style="width: 100%"
            border
            size="mini">
            <el-table-column align="center" label="序号" width="100">
              <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="100">
              <template slot-scope="scope">
                {{ scope.row.测试方法 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="检测标准" width="150">
              <template slot-scope="scope">
                {{ scope.row.检测要求 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="实测值" width="100">
              <template slot-scope="scope">
                {{ scope.row.实测值 }}
              </template>
            </el-table-column>
            <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="70">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="editContent(scope)"/>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="过站数据信息" name="2">
          <el-table
            :data="tableDataPassStation"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}"
            max-height="300px"
            class="main"
            tooltip-effect="dark"
            style="width: 100%"
            border
            size="mini">
            <el-table-column type="index" width="60" label="序号" align="center"/>
            <el-table-column align="center" label="工位号" width="80">
              <template slot-scope="scope">
                {{ scope.row.工位号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="到达时间" width="150">
              <template slot-scope="scope">
                {{ scope.row.到达时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="离开时间" width="150">
              <template slot-scope="scope">
                {{ scope.row.离开时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="节拍(m)" width="120">
              <template slot-scope="scope">
                {{ scope.row.在线时间 }}
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="质量数据信息" name="3">
          <el-table
            ref="multipleTable"
            :data="tableDataQuality"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}"
            max-height="300px"
            class="main"
            tooltip-effect="dark"
            style="width: 100%"
            border
            size="mini">
            <el-table-column type="index" width="60" label="序号" align="center"/>
            <el-table-column align="center" width="100px" 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="150px">
              <template slot-scope="scope">
                {{ scope.row.测量值 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="测量单位" width="80px">
              <template slot-scope="scope">
                {{ scope.row.测量单位 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="值上限" width="80px">
              <template slot-scope="scope">
                {{ scope.row.上限值 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="值下限" width="80px">
              <template slot-scope="scope">
                {{ scope.row.下限值 }}
              </template>
            </el-table-column>
            <el-table-column align="center" width="150px" label="生产日期">
              <template slot-scope="scope">
                {{ scope.row.生产日期 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="合格标志" width="80px">
              <template slot-scope="scope">
                {{ scope.row.合格标志 }}
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="margin-top: 10px;">
            <el-pagination
              :current-page="pageCurrent1"
              :page-sizes="[15, 30, 40]"
              :page-size="pageSize1"
              :total="total1"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange1"
              @current-change="handleCurrentChange1"/>
          </div>
        </el-collapse-item>
      </el-collapse>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOffProjectContent()">关闭</el-button>
        <el-button type="warning" size="small" icon="el-icon-printer" @click="openPrintView()">打印预览</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible3" title="编辑" center style="min-height: 200px;" width="400px">
      <el-form ref="formEdit3" :model="formEdit3" :rules="rulesEdit3" label-position="right" label-width="110px">
        <el-form-item label="序号" prop="序号" style="display: inline-block">
          <el-input-number
            v-model="formEdit3.序号"
            :step="1"
            :min="1"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="类别" prop="类别" style="display: inline-block">
          <el-input
            v-model="formEdit3.类别"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="测试方法" prop="测试方法" style="display: inline-block">
          <el-input
            v-model="formEdit3.测试方法"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="检测标准" prop="检测标准" style="display: inline-block">
          <el-input
            v-model="formEdit3.检测标准"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="实测值" prop="实测值" style="display: inline-block">
          <el-input
            v-model="formEdit3.实测值"
            size="small"
            style="width: 200px"/>
        </el-form-item>
        <el-form-item label="判定" prop="判定" style="display: inline-block">
          <el-input
            v-model="formEdit3.判定"
            size="small"
            style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff('formEdit3')">取消</el-button>
        <el-button type="primary" size="small" @click="editContentSure('formEdit3')">确定</el-button>
      </div>
    </el-dialog>
    <!--    合格证打印 -->
    <el-dialog :visible.sync="factoryReportDialogVisible" :append-to-body="true" title="合格证打印预览" center width="1150px">
      <factory-report
        ref="factoryReportRef"
        :from-text-obj="fromTextObj"
        :close-print-view="closePrintView"
        :loading-documents-table-data="loadingDocumentsTableData"
        style="height: 500px;overflow: auto"
      />
    </el-dialog>
  </div>
</template>

<script>
import { url } from '../../../utils/request'
import { getBeforeOrAfterTime, getNowTime2 } from '../../../utils/tool'
import { mapGetters } from 'vuex'
import factoryReport from './ReportPrint.vue'

export default {
  name: 'RepairManagement',
  components: { factoryReport },
  data() {
    return {
      productScheme: [],
      imageType: ['bmp', 'jpg', 'png', 'gif'],
      pdfType: ['pdf'],
      imgViewerVisible: false,
      imgViewerList: [],
      solveTypeList: [{ label: '合格放行', value: '合格放行' }, { label: '偏差放行', value: '偏差放行' }, { label: '返工放行', value: '返工放行' }],
      stationNumber: [],
      tableData: [],
      formAdd: {
        productCode: '',
        productScheme: ''
      },
      rulesAdd: {
        productScheme: [{ required: true, message: '请选择方案！', trigger: 'blur' }],
        productCode: [{ required: true, message: '请输入/扫描产品编号！', trigger: 'blur' }]
      },
      formEdit: {
        productCode: '',
        productName: '',
        productStatus: '',
        checkTime: '',
        result: '',
        checkPerson: '',
        reviewPerson: ''
      },
      rulesEdit: {
        productName: [{ required: true, message: '请输入产品名称！', trigger: 'blur' }],
        productStatus: [{ required: true, message: '请输入项目状态！', trigger: 'blur' }],
        checkTime: [{ required: true, message: '请输入检查时间！', trigger: 'blur' }],
        checkPerson: [{ required: true, message: '请输入检查人！', trigger: 'blur' }],
        reviewPerson: [{ required: true, message: '请输入审核人！', trigger: 'blur' }]
      },
      formEdit1: {
        productCode: ''
      },
      activeName: '1',
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      formEdit3: {
        index: 0,
        ID: 0,
        序号: 0,
        类别: '',
        测试方法: '',
        检测标准: '',
        实测值: '',
        判定: ''
      },
      rulesEdit3: {
        序号: [{ required: true, message: '请输入序号！', trigger: 'blur' }],
        类别: [{ required: true, message: '请输入类别！', trigger: 'blur' }],
        测试方法: [{ required: true, message: '请输入测试方法！', trigger: 'blur' }],
        检测标准: [{ required: true, message: '请输入检测标准！', trigger: 'blur' }],
        实测值: [{ required: true, message: '请输入实测值！', trigger: 'blur' }],
        判定: [{ required: true, message: '请输入判定！', trigger: 'blur' }]
      },
      title: '',
      tableDataBase: [], // 总数据数组
      tableDataSelect: [], // 总数据数组
      tableData1: [], // 总数据数组
      tableDataPassStation: [], // 总数据数组
      tableDataQuality: [], // 总数据数组
      loadingDocumentsTableData: [], // 总数据数组
      tableData1Select: [], // 总数据数组
      stationNumberValue: '',
      disabledIn: true,
      disabledOut: true,
      factoryReportDialogVisible: false,
      fromTextObj: {
        productName: '',
        productStatus: '',
        productCode: '',
        checkPerson: '',
        reviewPerson: '',
        checkTime: '',
        conclusion: ''
      },
      dataType: 0,
      stationName: '',
      solveStatus: 9999,
      solveStatusList: [
        {
          label: '全部',
          value: 9999
        },
        {
          label: '未处理',
          value: 0
        },
        {
          label: '已处理',
          value: 1
        }
      ],
      limit: 1,
      DataPDF: {},
      uploadPDF: url,
      total: 0, // 总条数
      pageList: 30, // 每页显示条数
      pageSize: 30, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      total1: 0, // 总条数
      pageList1: 30, // 每页显示条数
      pageSize1: 30, // 每页显示条数
      pageCurrent1: 1, // 后台获取页
      loading: false,
      problemList: [],
      dateTime: [],
      barcode: '',
      barcodeMaterial: '',
      loading_checkOrder: false,
      showImages: false,
      imageList: [],
      RepairManagementDataTable: [],
      userInfo: '',
      showTableData_content: false,
      loading_checkOrder_content: false,
      RepairManagementMaterialDataTable: [],
      showTableData_content_exchange1: false,
      uploader: [],
      Data: {},
      resultSelect: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NOK',
          value: 'NOK'
        },
        {
          label: '空白',
          value: '空白'
        }
      ],
      RepairManagementReplaceForm: {
        ID: 0,
        productCode: '',
        solveType: '',
        solvePeople: ''
      },
      showTableData_content_exchange: false,
      loading_checkOrder_content_exchange: false,
      RepairType: 1,
      currentSelectRow: {},
      RepairManagementReplaceDialogVisible: false,
      RepairManagementDestroyAllDialogVisible: false,
      RepairManagementReplaceRules: {
        materialBarCodeNew: [{ required: true, message: '请输入/扫描新物料码！', trigger: 'blur' }]
      },
      RepairManagementType: '1',
      partCode: '',
      opCode: '',
      opCodeS: [],
      stationArr: [],
      RepairManagementDataLogTable: [],
      RepairManagementDataTableOrigin: [],
      engineValue: {
        OpName: null,
        EngineID: null, // 产品编号
        EngineType: null, // 产品型号
        EngineTypeID: null, // 机型代码
        PalletCode: null,
        ProcessCode: null, // 程序号
        PartPalletCode: null, // 托盘号
        PalletInfo: null, // 托盘信息
        RepairPartStatusPLC: null,
        QualityMask: null,
        OrderForm: null, // 订单号
        EngineTypeString: null // 产品型号字符串北汽专用
      }
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'id',
      'token'
    ])
  },
  created() {
    this.dateTime = [getBeforeOrAfterTime(-7), getNowTime2()]
    this.searchTable()
    // this.userInfo = localStorage.getItem('userInfo') === '' ? {} : JSON.parse(localStorage.getItem('userInfo'))
  },
  mounted() {
    this.getStationNumber()
    this.getProductScheme()
    this.getTable2()
  },
  methods: {
    // 工位号
    getStationNumber() {
      this.stationNumber = []
      var param = []
      var Data = this.CreateData('11', '工位与名称_视图_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.stationNumber.push({
            label: response.data[i].工位号,
            value: response.data[i].工位号
          })
        }
      })
    },
    getProductScheme() {
      this.productScheme = []
      var param = []
      var Data = this.CreateData('11', 'CATL_出厂报告_方案_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.productScheme.push({
            label: `${response.data[i].方案名称}【${response.data[i].方案版本}】`,
            value: response.data[i].ID
          })
        }
      })
    },
    searchCheckContentBase(stationNumberValue) {
      this.problemList = []
      this.formAdd.problemId = ''
      var param = []
      param[0] = ['工位号', stationNumberValue]
      var Data = this.CreateData('11', 'CATL_基础_OCC_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          for (let i = 0; i < response.data.length; i++) {
            this.problemList.push({
              label: response.data[i].问题项目,
              value: response.data[i].ID
            })
          }
          this.formAdd.problemId = response.data[0].ID
        }
      })
    },

    // 查询NC
    getTable2() {
      this.tableData = []
      this.loading = true
      const param = []
      param[0] = ['产品编号', this.barcode]
      // param[1] = ['开始日期', this.dateTime[0]]
      // param[2] = ['结束日期', this.dateTime[1]]
      // param[3] = ['状态', this.solveStatus]
      param[1] = ['PageCurrent', this.pageCurrent]
      param[2] = ['PageSize', this.pageSize]
      param[3] = ['PageCount', '1111', 'int', '1']
      param[4] = ['ItemCount', '1111', 'int', '1']
      const Data = this.CreateData('11', 'CATL_出厂报告_查询_分页', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result && response.data.result.length > 0) {
          this.tableData = response.data.result
          this.total = parseInt(response.data.output[0].ItemCount)
          this.loading = false
        } else {
          this.tableData = []
          this.loading = false
        }
      })
    },
    // 新增NC
    creatOrder() {
      this.formAdd.productCode = ''
      this.dialogFormVisible = true
    },
    // 提交新增NC
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['产品编号', this.formAdd.productCode]
          param[1] = ['方案id', this.formAdd.productScheme]
          var Data = this.CreateData('12', 'CATL_出厂报告_增加', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0]['result'] === '1') {
              this.$message({
                message: '增加成功！',
                type: 'success'
              })
              this.dialogFormVisible = false
              this.getTable2()
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    // 取消新增NC
    callOff(formName) {
      this.dialogFormVisible = false
      this.dialogFormVisible1 = false
      this.dialogFormVisible2 = false
      this.$refs[formName].resetFields()
    },
    solveNc(row) {
      this.formEdit.productCode = row['产品编号']
      this.formEdit.productName = row['产品名称']
      this.formEdit.productStatus = row['项目状态']
      this.formEdit.checkTime = row['检查时间']
      this.formEdit.checkPerson = row['检查人员']
      this.formEdit.reviewPerson = row['审核']
      this.dialogFormVisible1 = true
    },
    solveNcSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['产品编号', this.formEdit.productCode]
          param[1] = ['产品名称', this.formEdit.productName]
          param[2] = ['项目状态', this.formEdit.productStatus]
          param[3] = ['检查时间', this.formEdit.checkTime]
          param[4] = ['结论', this.formEdit.result]
          param[5] = ['检查人员', this.formEdit.checkPerson]
          param[6] = ['审核', this.formEdit.reviewPerson]
          var Data = this.CreateData('12', 'CATL_出厂报告_编辑', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功!')
              this.dialogFormVisible1 = false
              this.getTable2()
            } else {
              this.$message.error('编辑失败!')
            }
          })
        }
      })
    },

    showPrintContent(row) {
      this.dialogFormVisible2 = true
      this.fromTextObj.productCode = row['产品编号']
      this.fromTextObj.productName = row['产品名称']
      this.fromTextObj.productStatus = row['项目状态']
      this.fromTextObj.checkTime = row['检查时间']
      this.fromTextObj.checkPerson = row['检查人员']
      this.fromTextObj.reviewPerson = row['审核']
    },
    showPrintContentView(row) {
      this.showFileList(row, true)
    },
    deleteInformation(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['产品编号', row.产品编号]
        var Data = this.CreateData('12', 'CATL_出厂报告_项目_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getTable2()
          } else {
            this.$message.error('删除失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    closePrintView() {
      this.factoryReportDialogVisible = false
    },
    openPrintView() {
      this.loadingDocumentsTableData = this.tableData1
      this.factoryReportDialogVisible = true
    },
    callOffProjectContent() {
      this.dialogFormVisible2 = false
      this.getTable2()
    },
    async saveProjectContent() {
      var param = []
      param[0] = ['产品编号', this.fromTextObj.productCode]
      var Data = this.CreateData('12', 'CATL_出厂报告_项目_增加_前处理', param)
      this.ExecDatabase(Data).then(async response => {
        for (let i = 0; i < this.tableData1.length; i++) {
          await this.saveProjectContentExec(this.tableData1[i])
        }
        this.$message.success('保存成功！')
      })
    },
    saveProjectContentExec(row) {
      return new Promise((resolve, reject) => {
        var param = []
        param[0] = ['产品编号', this.fromTextObj.productCode]
        param[1] = ['类别', row.类别]
        param[2] = ['测试方法', row.测试方法]
        param[3] = ['检测标准', row.检测要求]
        param[4] = ['实测值', row.实测值]
        param[5] = ['判定', row.判定]
        var Data = this.CreateData('12', 'CATL_出厂报告_项目_增加', param)
        this.ExecDatabase(Data).then(response => {
          resolve(true)
        })
      })
    },
    // 查询信息
    searchTable() {
      this.tableDataBase = []
      var param = []
      param[0] = ['工位号', this.stationNumberValue]
      param[1] = ['查询类型', this.dataType]
      param[2] = ['产品编号', this.fromTextObj.productCode]
      var Data = this.CreateData('11', 'CATL_出厂报告_基础项目_综合_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.tableDataBase = response.data
        }
      })
    },
    showFileList(row, isShowPrint = false) {
      this.activeName = '1'
      this.fromTextObj.productCode = row['产品编号']
      this.fromTextObj.productName = row['产品名称']
      this.fromTextObj.productStatus = row['项目状态']
      this.fromTextObj.checkTime = row['检查时间']
      this.fromTextObj.checkPerson = row['检查人员']
      this.fromTextObj.reviewPerson = row['审核']
      this.tableData1 = []
      this.tableDataPassStation = []
      this.pageList1 = 30
      this.pageSize1 = 30
      this.pageCurrent1 = 1
      var param = []
      param[0] = ['产品编号', this.fromTextObj.productCode]
      var Data = this.CreateData('11', 'CATL_出厂报告_项目_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.tableData1 = response.data
          this.loadingDocumentsTableData = this.tableData1
          if (isShowPrint) {
            this.factoryReportDialogVisible = true
          }
        }
        if (!isShowPrint) this.dialogFormVisible2 = true
      })
      this.title = `出厂报告项目管理【${row.产品编号}】`

      var param1 = []
      param1[0] = ['产品编号', this.fromTextObj.productCode]
      var Data1 = this.CreateData('11', 'CATL_出厂报告_项目_过站信息_查询', param1)
      this.ExecDatabase(Data1).then(response => {
        if (response.data.length !== 0) {
          this.tableDataPassStation = response.data
        }
      })
      this.getQualityData()
    },
    getQualityData() {
      var param2 = []
      param2[0] = ['产品编号', this.fromTextObj.productCode]
      param2[1] = ['PageCurrent', this.pageCurrent1]
      param2[2] = ['PageSize', this.pageSize1]
      param2[3] = ['PageCount', '1111', 'int', '1']
      param2[4] = ['ItemCount', '1111', 'int', '1']
      var Data2 = this.CreateData('11', 'CATL_出厂报告_项目_质量信息_查询', param2)
      this.ExecDatabase(Data2).then(response => {
        if (response.data.result.length !== 0) {
          this.tableDataQuality = response.data.result
        }
        this.total1 = parseInt(response.data.output[0].ItemCount)
      })
    },
    editContent(scope) {
      const row = scope.row
      this.formEdit3.index = scope.$index
      this.formEdit3.ID = row['ID']
      this.formEdit3.序号 = row['序号']
      this.formEdit3.类别 = row['类别']
      this.formEdit3.测试方法 = row['测试方法']
      this.formEdit3.检测标准 = row['检测标准']
      this.formEdit3.实测值 = row['实测值']
      this.formEdit3.判定 = row['判定']
      this.dialogFormVisible3 = true
    },
    editContentSure() {
      var param = []
      param[0] = ['ID', this.formEdit3.ID]
      param[1] = ['类别', this.formEdit3.类别]
      param[2] = ['测试方法', this.formEdit3.测试方法]
      param[3] = ['检测标准', this.formEdit3.检测标准]
      param[4] = ['实测值', this.formEdit3.实测值]
      param[5] = ['判定', this.formEdit3.判定]
      param[6] = ['序号', this.formEdit3.序号]
      var Data = this.CreateData('12', 'CATL_出厂报告_项目_编辑', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('编辑成功!')
          this.tableData1[this.formEdit3.index]['类别'] = this.formEdit3.类别
          this.tableData1[this.formEdit3.index]['测试方法'] = this.formEdit3.测试方法
          this.tableData1[this.formEdit3.index]['检测要求'] = this.formEdit3.检测标准
          this.tableData1[this.formEdit3.index]['实测值'] = this.formEdit3.实测值
          this.tableData1[this.formEdit3.index]['判定'] = this.formEdit3.判定
          this.dialogFormVisible3 = false
        } else {
          this.$message.error('编辑失败!')
        }
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.getTable2()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.getTable2()
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.getQualityData()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.getQualityData()
    },
    handleSelectionChange(val) {
      this.tableDataSelect = val
    },
    handleSelectionChange1(val) {
      this.tableData1Select = val
    },
    selectable(row) {
      // for (let i = 0; i < this.tableData1.length; i++) {
      //   if (this.tableData1[i].idd === row['idd']) {
      //     isOK = false
      //   }
      // }
      return true
    },
    selectContent() {
      if (this.tableData1.length === 0) {
        this.tableData1 = this.tableDataSelect
      } else {
        for (let i = 0; i < this.tableDataSelect.length; i++) {
          this.tableData1.push(this.tableDataSelect[i])
          // let isOk = true
          // for (let j = 0; j < this.tableData1.length; j++) {
          //   if (this.tableDataSelect[i]['idd'] === this.tableData1[j]['idd']) {
          //     isOk = false
          //   }
          // }
          // if (isOk) {
          //   this.tableData1.push(this.tableDataSelect[i])
          // }
        }
      }
      this.$nextTick(() => {
        if (this.$refs.multipleTable1) this.$refs.multipleTable1.clearSelection()
        if (this.$refs.multipleTable2) this.$refs.multipleTable2.clearSelection()
        this.tableDataSelect = []
      })
    },
    unselectContent() {
      this.tableData1 = this.resArr(this.tableData1, this.tableData1Select)
    },
    resArr(arr1, arr2) {
      return arr1.filter((v) => arr2.every((val) => val.idd !== v.idd))
    },
    // 表格颜色变化
    tableRowClassName({ row }) {
      // for (let i = 0; i < this.tableData1.length; i++) {
      //   if (this.tableData1[i].idd === 'type' + this.dataType + '_' + row['ID']) {
      //     classStr = 'warning_Alarm'
      //   }
      // }
      return ''
    },
    // 给样式的
    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.dialogFormVisible1 = false
      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.getTable2()
      this.$message.success('文件上传成功!')
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisiblePictureCard = true
    },
    // 上传前检测
    beforeUploadPdf(file) {
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 10MB!')
        return false
      }
      return true
    },
    warningExceedPdf() {
      this.$message.error('一次仅可上传一份文件')
    }
  }
}
</script>

<style scoped>
.tmp {
  white-space:nowrap;/*强制单行显示*/
  text-overflow:ellipsis;/*超出部分省略号表示*/
  overflow:hidden;/*超出部分隐藏*/
  width: 300px;/*设置显示的最大宽度*/
  display:inline-block;
  font-size: 16px;
}
.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; /* 垂直居中对齐 */
}
::v-deep.el-table .warning_Alarm {
  background: #ffad1b !important;
  color: #000 !important;
}
</style>
