<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">工位号：</span>
        <el-select v-model="stationNumberValue" placeholder="请选择工位号" size="small" style="width: 200px">
          <el-option
            v-for="item in stationNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            size="mini"
          />
        </el-select>
        <span style="margin-left: 10px">图号：</span>
        <el-select v-model="engineTypeValue" placeholder="请选择产品型号" size="small" style="width: 250px">
          <el-option
            v-for="item in engineType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            size="mini"
          />
        </el-select>
        <el-button type="primary" plain size="small" icon="el-icon-order" @click="searchTable()">查询</el-button>
        <el-button type="distribution" icon="el-icon-circle-plus-outline" size="small" @click="addTo">新增</el-button>
        <!--        <el-button type="success" size="small" plain icon="el-icon-document-copy" @click="copyOrder('form4')">复制工步</el-button>-->
        <!--<el-button icon="el-icon-upload2" plain size="small" type="info" @click="importOrder('form')">检查项导入</el-button>-->
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        height="600px"
        class="main"
        tooltip-effect="dark"
        style="width: 80%"
        border
        size="mini"
      >
        <el-table-column label="工步号" align="center" width="80px" >
          <template slot-scope="scope">
            <div style="white-space: pre-line !important;">{{ scope.row.工步号 }}</div>
          </template>
        </el-table-column>
        <el-table-column label="质检项描述">
          <template slot-scope="scope">
            <div style="white-space: pre-line !important;">{{ scope.row.操作内容 }}</div>
          </template>
        </el-table-column>
        <el-table-column label="符合标准及条例" width="200">
          <template slot-scope="scope">
            <div style="white-space: pre-line !important;">{{ scope.row.技术要求 }}</div>
          </template>
        </el-table-column>
        <!--        <el-table-column align="center" label="检验方法" width="80">-->
        <!--          <template slot-scope="scope">-->
        <!--            <div style="white-space: pre-line !important;">{{ scope.row.检验方法 }}</div>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column align="center" label="结果类型" width="80">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.结果类型 === '定量'" type="success" size="mini">定量</el-tag>
            <el-tag v-if="scope.row.结果类型 === '定性'" type="warning" size="mini">定性</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="结果上限" width="80">
          <template slot-scope="scope">
            <div style="white-space: pre-line !important;">{{ scope.row.结果上限 }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="结果下限" width="80">
          <template slot-scope="scope">
            <div style="white-space: pre-line !important;">{{ scope.row.结果下限 }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="单位" width="80">
          <template slot-scope="scope">
            <div style="white-space: pre-line !important;">{{ scope.row.结果单位 }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" size="mini" @click="editInformation(scope.row)">编辑</el-button>
            <el-button type="text" icon="el-icon-delete" size="mini" style="color:#ff0000;" @click="deleteInformation(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 新增弹窗 -->
    <el-dialog :visible.sync="dialogFormVisible" title="新增检查项目" center style="min-height: 200px;" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-position="right" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="工位号" prop="stationNumber" style="display: inline-block">
              <el-select v-model="form.stationNumber" placeholder="请选择工位号" size="small" style="width: 250px">
                <el-option
                  v-for="item in stationNumber"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品型号" prop="moduleDescription" style="display: inline-block">
              <el-select v-model="form.moduleDescription" placeholder="请选择产品型号" size="small" style="width: 250px">
                <el-option
                  v-for="item in engineType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="序号" prop="number" style="display: inline-block">
              <el-input-number v-model="form.number" :min="1" :step="1" style="width:250px;" placeholder="请输入序号" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结果类型" prop="checkResultType" style="display: inline-block">
              <el-select v-model="form.checkResultType" placeholder="请选择结果类型" size="small" style="width: 250px">
                <el-option
                  v-for="item in checkResultTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="质检项描述" prop="checkDescription" style="display: inline-block">
              <el-input
                v-model="form.checkDescription"
                :rows="2"
                type="textarea"
                style="width: 250px;"
                placeholder="请输入质检项描述"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标准及条例" prop="checkRequireType" style="display: inline-block">
              <el-input
                v-model="form.checkRequireType"
                :rows="2"
                type="textarea"
                style="width: 250px;"
                placeholder="请输入符合标准及条例"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.checkResultType === '定量'">
          <el-col :span="8">
            <el-form-item label="结果上限" prop="checkResultUpper" style="display: inline-block">
              <el-input-number v-model="form.checkResultUpper" :min="form.checkResultLower" size="small" style="width:150px;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结果下限" prop="checkResultLower" style="display: inline-block">
              <el-input-number v-model="form.checkResultLower" :max="form.checkResultUpper" size="small" style="width:150px;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="checkResultUnit" style="display: inline-block">
              <el-input v-model="form.checkResultUnit" style="width:150px;" placeholder="请输入单位" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff('form')">取消</el-button>
        <el-button v-if="title === '添加'" type="primary" size="small" @click="submitAdd('form')">确定</el-button>
      </div>
    </el-dialog>
    <!-- 编辑弹窗 -->
    <el-dialog :visible.sync="dialogFormVisible1" title="编辑检查项目" center style="min-height: 200px;" width="800px">
      <el-form ref="form1" :model="form1" :rules="rules1" label-position="right" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="工位号" prop="stationNumber" style="display: inline-block">
              <el-select v-model="form1.stationNumber" :disabled="true" placeholder="请选择工位号" size="small" style="width: 250px">
                <el-option
                  v-for="item in stationNumber"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品型号" prop="engineTypeValue" style="display: inline-block">
              <el-select v-model="form1.engineTypeValue" :disabled="true" placeholder="请选择产品型号" size="small" style="width: 250px">
                <el-option
                  v-for="item in engineType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="序号" prop="number" style="display: inline-block">
              <el-input-number v-model="form1.number" :min="1" :step="1" style="width:250px;" placeholder="请输入序号" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结果类型" prop="checkResultType" style="display: inline-block">
              <el-select v-model="form1.checkResultType" placeholder="请选择结果类型" size="small" style="width: 250px">
                <el-option
                  v-for="item in checkResultTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="质检项描述" prop="checkDescription" style="display: inline-block">
              <el-input
                v-model="form1.checkDescription"
                :rows="2"
                type="textarea"
                style="width: 250px;"
                placeholder="请输入质检项描述"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标准及条例" prop="checkRequireType" style="display: inline-block">
              <el-input
                v-model="form1.checkRequireType"
                :rows="2"
                type="textarea"
                style="width: 250px;"
                placeholder="请输入符合标准及条例"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form1.checkResultType === '定量'">
          <el-col :span="8">
            <el-form-item label="结果上限" prop="checkResultUpper" style="display: inline-block">
              <el-input-number v-model="form1.checkResultUpper" :min="form1.checkResultLower" size="small" style="width:150px;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结果下限" prop="checkResultLower" style="display: inline-block">
              <el-input-number v-model="form1.checkResultLower" :max="form1.checkResultUpper" size="small" style="width:150px;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="checkResultUnit" style="display: inline-block">
              <el-input v-model="form1.checkResultUnit" style="width:150px;" placeholder="请输入单位" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff1()">取消</el-button>
        <el-button type="primary" size="small" @click="submitUpdate('form1')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible4" title="数据复制" center style="min-height: 200px" width="400px">
      <el-form ref="form1" :model="form4" :rules="rules4" label-position="right" label-width="110px">
        <el-form-item label="工位号" prop="engineTypeValue" style="display: inline-block">
          <el-select v-model="form4.stationNumberValue" placeholder="请选择工位号" size="small">
            <el-option
              v-for="item in stationNumber"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              size="mini"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="产品型号" prop="engineTypeValue" style="display: inline-block">
          <el-select v-model="form4.engineTypeValue" placeholder="请选择产品型号" size="small">
            <el-option
              v-for="item in engineType"
              :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="callOff4()">取消</el-button>
        <el-button type="primary" size="small" @click="submitAdd4()">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible3" center style="min-height: 200px" title="检查项导入" width="900px">
      <div class="app-container">
        <upload-excel-component style="margin-left: 15%" @getSheetName="getSheetName" @on-selected-file="selected"/>
        <div style="margin-left: 395px">
          <span v-show="worksheet.length > 1" style="cursor: pointer;width: 50px;" @click="removeAll"><i
            class="el-icon-close"
          /></span>
          <el-upload :file-list="itemFile" :sheet-names="sheetNames" :on-remove="handleRemove" action="" style="width: 220px"/>
        </div>
        <div v-if="worksheet.length !== 0" style="margin: 3px 0 0 395px">
          <el-button icon="el-icon-upload2" size="small" type="primary" @click="basicPartsToSQL">导入到数据库
          </el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { sleep } from '../../../utils/tool'
import UploadExcelComponent from './UploadExcel.vue'

export default {
  name: 'UploadExcel',
  components: { UploadExcelComponent },
  data() {
    return {
      worksheet: [],
      itemFile: [],
      sheetNames: [],
      tableData: [], // 总数据数组
      stationNumber: [],
      stationNumberValue: '',
      stationName: '',
      moduleDescription: [],
      moduleDescriptionValue: '',
      engineTypeValue: '',
      engineTypeValue1: '',
      engineTypeName: '',
      engineType: [],
      labelText: '',
      labelNumber: '',
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible4: false,
      dialogFormVisible3: false, // 导入
      title: '',
      checkResultTypes: [
        { label: '定性', value: '定性' },
        { label: '定量', value: '定量' }
      ],
      form: {
        engineTypeValue: '', // 产品型号代码
        stationNumber: '', // 工位号
        number: '', // 工序号
        checkDescription: '', // 质检项描述
        checkRequireType: '', // 符合标准及条例
        checkMethod: '', // 检验方法
        checkResultType: '', // 结果类型
        checkResultUpper: 0, // 结果上限
        checkResultLower: 0, // 结果下限
        checkResultUnit: '' // 单位
      },
      rules: {
        stationNumber: [{ required: true, message: '请选择工位号', trigger: 'change' }],
        engineTypeValue: [{ required: true, message: '请选择图号', trigger: 'change' }],
        number: [{ required: true, message: '请输入序号', trigger: 'blur' }],
        checkDescription: [{ required: true, message: '请输入质检项描述', trigger: 'blur' }],
        checkRequireType: [{ required: true, message: '请输入符合标准及条例', trigger: 'blur' }],
        checkMethod: [{ required: true, message: '请选择检验方法', trigger: 'change' }],
        checkResultType: [{ required: true, message: '请选择结果类型', trigger: 'change' }],
        checkResultUpper: [{ required: true, message: '请输入结果上限', trigger: 'blur' }],
        checkResultLower: [{ required: true, message: '请输入结果下限', trigger: 'blur' }]
      },
      form1: {
        ID: '',
        engineTypeValue: '', // 产品型号代码
        stationNumber: '', // 工位号
        number: '', // 工序号
        checkDescription: '', // 质检项描述
        checkRequireType: '', // 符合标准及条例
        checkMethod: '', // 检验方法
        checkResultType: '', // 结果类型
        checkResultUpper: 0, // 结果上限
        checkResultLower: 0, // 结果下限
        checkResultUnit: '' // 单位
      },
      rules1: {
        stationNumber: [{ required: true, message: '请选择工位号', trigger: 'change' }],
        engineTypeValue: [{ required: true, message: '请选择图号', trigger: 'change' }],
        number: [{ required: true, message: '请输入序号', trigger: 'blur' }],
        checkDescription: [{ required: true, message: '请输入质检项描述', trigger: 'blur' }],
        checkRequireType: [{ required: true, message: '请输入符合标准及条例', trigger: 'blur' }],
        checkMethod: [{ required: true, message: '请选择检验方法', trigger: 'change' }],
        checkResultType: [{ required: true, message: '请选择结果类型', trigger: 'change' }],
        checkResultUpper: [{ required: true, message: '请输入结果上限', trigger: 'blur' }],
        checkResultLower: [{ required: true, message: '请输入结果下限', trigger: 'blur' }]
      },
      form4: {
        engineTypeValue: '',
        stationNumberValue: ''
      },
      rules4: { // 订单下发验证
        engineTypeValue: [{ required: true, message: '请选择机型', trigger: 'blur' }],
        stationNumberValue: [{ required: true, message: '请选择工位号', trigger: 'blur' }]
      }
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token',
      'departmentName'
    ])
  },
  watch: {
  },
  created() {
    this.getStationNumber()
    this.getEndStation()
  },
  mounted() {
    setTimeout(() => {
      this.searchTable()
    }, 300)
    setInterval(() => {
    }, 1000 * 2)
  },
  methods: {
    // 获取工位号
    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].工位号
        for (let i = 0; i < response.data.length; i++) {
          this.stationNumber.push({
            label: `【${response.data[i].工位号}】${response.data[i].工位名称}`,
            value: response.data[i].工位号
          })
        }
      })
    },
    // 初始化获取产品型号
    getEndStation() {
      this.engineType = []
      var param = []
      var Data = this.CreateData('11', 'MES_基本变量_机型代码_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length) this.engineTypeValue = response.data[0].发动机机型标志
        for (let i = 0; i < response.data.length; i++) {
          this.engineType.push({
            label: response.data[i].发动机型号 + '-' + response.data[i].标识字符,
            value: response.data[i].发动机机型标志
          })
        }
      })
    },
    // 查询
    searchTable() {
      this.tableData = []
      var param = []
      param[0] = ['产品型号代码', this.engineTypeValue]
      param[1] = ['工位号', this.stationNumberValue]
      var Data = this.CreateData('11', '电子看板_工序内容_查询', param)
      this.ExecDatabase(Data).then(response => {
        console.log(response, 66)
        if (response.data.length !== 0) {
          this.tableData = response.data
        }
      })
    },
    // 新增
    addTo() {
      this.dialogFormVisible = true
    },
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['工位号', this.form.stationNumber]
          param[1] = ['产品型号代码', this.form.moduleDescription]
          param[2] = ['工步号', this.form.number]
          param[3] = ['操作内容', this.form.checkDescription]
          param[4] = ['技术要求', this.form.checkRequireType]
          param[5] = ['检验方法', this.form.checkMethod]
          param[6] = ['结果类型', this.form.checkResultType]
          param[7] = ['结果上限', this.form.checkResultUpper]
          param[8] = ['结果下限', this.form.checkResultLower]
          param[9] = ['结果单位', this.form.checkResultUnit]
          console.log(param)
          var Data = this.CreateData('12', '电子看板_工序内容_增加', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '增加成功',
                type: 'success'
              })
              this.dialogFormVisible = false
              this.searchTable()
            } else {
              this.$message.error('增加失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    callOff() {
      this.dialogFormVisible = false
      this.$refs['form'].resetFields()
    },
    // 编辑
    editInformation(row) {
      this.form1.ID = row.ID
      this.form1.engineTypeValue = row.产品型号代码
      this.form1.stationNumber = row.工位号
      this.form1.number = row.工步号
      this.form1.checkDescription = row.操作内容
      this.form1.checkRequireType = row.技术要求
      this.form1.checkMethod = row.检验方法
      this.form1.checkResultType = row.结果类型
      this.form1.checkResultUpper = row.结果类型 === '定量' ? Number(row.结果上限) : 0
      this.form1.checkResultLower = row.结果类型 === '定量' ? Number(row.结果下限) : 0
      this.form1.checkResultUnit = row.结果单位
      this.dialogFormVisible1 = true
    },
    submitUpdate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['ID', this.form1.ID]
          param[1] = ['工步号', this.form1.number]
          param[2] = ['操作内容', this.form1.checkDescription]
          param[3] = ['技术要求', this.form1.checkRequireType]
          param[4] = ['检验方法', this.form1.checkMethod]
          param[5] = ['结果类型', this.form1.checkResultType]
          param[6] = ['结果上限', this.form1.checkResultUpper]
          param[7] = ['结果下限', this.form1.checkResultLower]
          param[8] = ['结果单位', this.form1.checkResultUnit]
          var Data = this.CreateData('12', '电子看板_工序内容_修改', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.dialogFormVisible1 = false
              this.searchTable()
            } else {
              this.$message.error('修改失败！')
            }
          })
        } else {
          return false
        }
      })
    },
    callOff1() {
      this.dialogFormVisible1 = false
      this.$refs['form1'].resetFields()
    },
    // 删除
    deleteInformation(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.searchTable()
          } else {
            this.$message.error('检查项删除失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // *****************************导入/复制**********************
    getSheetName(val) {
      this.sheetNames = val
    },
    copyOrder(formName) {
      if (this.tableData.length) {
        if (this.$refs[formName] !== undefined) {
          this.$refs[formName].resetFields()
        }
        this.dialogFormVisible4 = true
      } else {
        this.$message({
          message: '暂无可复制的数据！',
          type: 'error'
        })
      }
    },
    // 导入订单
    importOrder() {
      this.dialogFormVisible3 = true
    },
    removeAll() {
      this.worksheet = []
      this.itemFile = []
    },
    async selected(data) { // 选择需要导入的文件
      console.log(data, 1111)
      this.worksheet = data.worksheet // 获取每个多选文件的表格坐标及值
      this.itemFile = data.itemFile
    },
    handleRemove(file) { // 移除文件
      for (let i = 0; i < this.itemFile.length; i++) {
        if (this.itemFile[i].name === file.name) {
          this.worksheet.splice(i, 1)
          this.itemFile.splice(i, 1)
        }
      }
    },
    async basicPartsToSQL() {
      try {
        this.loading = true
        this.err = 0
        console.log(this.worksheet.length, 'this.worksheet.length', this.itemFile)
        for (let j = this.worksheet.length - 1; j >= 0; j--) {
          let workCode,
            workName,
            workType,
            workNumber,
            workIndex,
            workDetail,
            workStandard,
            workFun,
            resType,
            resMax,
            resMin,
            resUnit
          const sheetName = this.itemFile[j]['name']
          console.log(sheetName, 'sheetName')
          const OpName = sheetName.split('-')[0]
          const EngineType = sheetName.split('-')[1]
          await this.importBeforeDispose(OpName, EngineType)
          for (let i = 0; i < 500; i++) {
            const attr = i + 2
            workCode = this.worksheet[j][`A${attr}`] ? this.worksheet[j][`A${attr}`].v : ''
            workName = this.worksheet[j][`B${attr}`] ? this.worksheet[j][`B${attr}`].v : ''
            workType = this.worksheet[0][`C${attr}`] ? this.worksheet[0][`C${attr}`].v : ''
            workNumber = this.worksheet[0][`D${attr}`] ? this.worksheet[0][`D${attr}`].v : ''
            workIndex = this.worksheet[0][`E${attr}`] ? this.worksheet[0][`E${attr}`].v : ''
            workDetail = this.worksheet[0][`F${attr}`] ? this.worksheet[0][`F${attr}`].v : ''
            workStandard = this.worksheet[0][`G${attr}`] ? this.worksheet[0][`G${attr}`].v : ''
            workFun = this.worksheet[0][`H${attr}`] ? this.worksheet[0][`H${attr}`].v : ''
            resType = this.worksheet[0][`I${attr}`] ? this.worksheet[0][`I${attr}`].v : ''
            resMax = this.worksheet[0][`J${attr}`] ? this.worksheet[0][`J${attr}`].v : ''
            resMin = this.worksheet[0][`K${attr}`] ? this.worksheet[0][`K${attr}`].v : ''
            resUnit = this.worksheet[0][`L${attr}`] ? this.worksheet[0][`L${attr}`].v : ''
            if (workCode !== '' && workName !== '' && workType !== '' && workNumber !== '' && workDetail !== '' && resType !== '') {
              await sleep(50)
              console.log(workCode,
                workName,
                workType,
                workNumber,
                workIndex,
                workDetail,
                workStandard,
                workFun,
                resType,
                resMax,
                resMin,
                resUnit, OpName, EngineType)
              await this.insertToSQL(workCode,
                workName,
                workType,
                workNumber,
                workIndex,
                workDetail,
                workStandard,
                workFun,
                resType,
                resMax,
                resMin,
                resUnit, OpName, EngineType)
            }
          }
          this.itemFile.splice(j, 1)
          this.worksheet.splice(j, 1)
          this.err === 0 ? this.$message.success(`导入完成`) : this.$message.error(`导入失败零件个数为${this.err}，请检查文件是否正确`)
        }
        this.loading = false
        this.searchTable()
      } catch (e) {
        this.err++
        this.loading = false
        this.$notify.error(`导入数据错误,请检查导入文件是否正确`)
        console.log(`导入数据错误${e}`)
      }
    },
    async insertToSQL(workCode, workName, workType, workNumber, workIndex, workDetail, workStandard, workFun, resType, resMax, resMin, resUnit, OpName, EngineType) {
      try {
        var param = []
        param[0] = ['装配编号', workCode]
        param[1] = ['装配名称', workName]
        param[2] = ['质检项分类', workType]
        param[3] = ['质检项编号', workNumber]
        param[4] = ['质检项序号', workIndex]
        param[5] = ['质检项描述', workDetail]
        param[6] = ['符合标准及条例', workStandard]
        param[7] = ['检验方法', workFun]
        param[8] = ['结果类型', resType]
        param[9] = ['结果上限', resMax]
        param[10] = ['结果下限', resMin]
        param[11] = ['结果单位', resUnit]
        param[12] = ['工位号', OpName]
        param[13] = ['基本机型', EngineType]
        var Data = this.CreateData('12', '检查项_导入', param)
        const response = await this.ExecDatabase(Data)
        const res = response.data
        if (Object.prototype.hasOwnProperty.call(res, 'output') === false) {
          if (res[0].result === '0') {
            // eslint-disable-next-line no-sequences
            this.$notify.error(`${OpName, workDetail}导入失败`)
          }
        } else {
          if (res.result[0].result === '0') {
            // eslint-disable-next-line no-sequences
            this.$notify.error(`${OpName, workDetail}导入失败`)
          }
          if (res.output[0].导入类型 === '2') {
            // eslint-disable-next-line no-sequences
            this.$notify.warning(`${OpName, workDetail}存在重复数据`)
          }
        }
      } catch (e) {
        this.err++
        this.$message.error(`导入数据错误`)
        console.log(`导入数据错误${e}`)
      }
    },
    async importBeforeDispose(OpName, EngineType) {
      var param = []
      param[0] = ['工位号', OpName]
      param[1] = ['基本机型', EngineType]
      console.log(param)
      var Data = this.CreateData('12', '检查项_导入前处理', param)
      return new Promise((resolve, reject) => {
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            resolve(1)
          } else {
            reject(2)
          }
        })
      })
    },
    async submitAdd4() {
      let number, text
      for (let i = 0; i < this.tableData.length; i++) {
        number = this.tableData[i].工步号
        text = this.tableData[i].操作内容
        await this.submitAdd5(number, text)
      }
      this.$message({
        message: '增加成功',
        type: 'success'
      })
      this.dialogFormVisible4 = false
      this.engineTypeValue = this.form4.engineTypeValue
      this.stationNumberValue = this.form4.stationNumberValue
      this.searchTable()
    },
    async submitAdd5(number, text) {
      var param = []
      param[0] = ['工位号', this.form4.stationNumberValue]
      param[1] = ['产品型号代码', this.form4.engineTypeValue]
      param[2] = ['工步号', number]
      param[3] = ['操作内容', text]
      param[4] = ['发动机型号', this.form4.engineTypeValue]
      console.log(param)
      var Data = this.CreateData('12', '电子看板_工序内容_增加', param)
      return new Promise((resolve, reject) => {
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            console.log('1')
            resolve(1)
          } else {
            console.log('0')
            reject(2)
          }
        })
      })
    },
    callOff4() {
      this.dialogFormVisible4 = false
    }
  }
}
</script>

<style scoped>
  .topCard{
    margin: 5px;
  }
  .topDiv{
    margin-bottom: 10px;
  }
  .el-select{
    width:200px
  }
  .el-input{
    width:200px
  }
  .text {
    font-size: 14px;
  }

  .item {
    padding: 18px 0;
  }

  .box-card {
    position: absolute;
    right: 6px;
    top: 80px;
    width: 300px;
  }
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  ::v-deep.el-input.is-disabled .el-input__inner{
    color: #606266!important;
  }

  ::v-deep textarea{
    height: 100px;
  }

  /** deep/.el-upload-list{
    display: none;
  }**/
</style>

