<template>
  <div>
    <el-card>
      <div style="padding: 10px;background-color:#F5F5F5">
        <el-select v-model="machineShop" style="width:180px;margin-left: 10px" clearable class="select12" placeholder="请选择车间" @change="searchProductionLine()">
          <el-option
            v-for="item in machineShops1"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="productionLine" style="width:180px;margin-left: 20px" clearable class="select12" placeholder="请选择产线" @change="searchRegion()">
          <el-option
            v-for="item in productionLines1"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="region" style="width:180px;margin-left: 20px" clearable class="select12" placeholder="请选择工序" @change="searchEquipment()">
          <el-option
            v-for="item in regions1"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="equipment" style="width:180px;margin-left: 20px" clearable class="select12" placeholder="请选择设备" @change="searchDate();searchTable()">
          <el-option
            v-for="item in equipments"
            :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>
        <upload-excel-component style="margin-left: 35px;display: inline" @on-selected-file="selected"/>
        <el-button :disabled="worksheet.length === 0" class="button11" icon="el-icon-upload2" style="height: 48px" @click="basicPartsToSQL">导入到数据库</el-button>
        <el-button :disabled="!equipment" type="success" icon="el-icon-upload2" style="height: 48px;margin: 0px" @click="uploadManual()">上传点检手册</el-button>
        <el-button
          :disabled="!equipment"
          type="primary"
          icon="el-icon-download"
          style="height: 48px;margin: 0px"
          @click="exportExcel()">导出</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="tableHeaderColor"
        :cell-style="tableColor"
        element-loading-text="数据加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
        tooltip-effect="dark"
        style="width: 100%"
        height="720px">
        <el-table-column align="left" label="序号" width="70px" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.序号 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="部位" width="85">
          <template slot-scope="scope">
            <span>{{ scope.row.部位 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="部件" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.部件 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="检修项目" min-width="110">
          <template slot-scope="scope">
            <span>{{ scope.row.检修项目 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="方法/要领" width="85">
          <template slot-scope="scope">
            <span>{{ scope.row.方法要领 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="工具材料" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.工具材料 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="判定基准" min-width="150">
          <template slot-scope="scope">
            <span >{{ scope.row.判定基准 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="手顺书/要领书" width="95">
          <template slot-scope="scope">
            <span>{{ scope.row.要领书 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="周期" width="70">
          <template slot-scope="scope">
            <span>{{ scope.row.周期 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="实施部门" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.实施部门 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="设备状态" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.设备状态 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="点检" width="70">
          <template slot-scope="scope">
            <span>{{ scope.row.点检 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="给油" width="70">
          <template slot-scope="scope">
            <span>{{ scope.row.给油 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="更换" width="70">
          <template slot-scope="scope">
            <span>{{ scope.row.更换 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="清扫" width="70">
          <template slot-scope="scope">
            <span>{{ scope.row.清扫 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="工时/min" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.工时 }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="修订日期" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.修改日期 }}</span>
          </template>
        </el-table-column>
        <el-table-column min-width="110px" align="left" label="操作" >
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-plus" @click="addBenchmark(scope.row)"/>
            <el-button type="text" icon="el-icon-edit" @click="editBenchmark(scope.row)"/>
            <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"/>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog :title="title" :visible.sync="dialogFormVisible" width="40%" >
        <el-form ref="form" :model="form" :rules="rules" label-position="top" label-width="120px" label-padding-bottom="0px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="部位:" prop="position">
                <el-input v-model="form.position" class="input2" placeholder="请输入部位" style="width: 200px;margin-top: 0px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="部件:" prop="parts">
                <el-input v-model="form.parts" class="input2" placeholder="请输入部件" style="width: 200px;margin-top: 0px"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="项目:" prop="project">
                <el-input v-model="form.project" class="input2" placeholder="请输入项目" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="方法/要领:" prop="method">
                <el-input v-model="form.method" class="input2" placeholder="请输入方法要领" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="工具材料:" prop="tool">
                <el-input v-model="form.tool" class="input2" placeholder="请输入工具材料" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="判定基准:" prop="benchmark">
                <el-input v-model="form.benchmark" class="input2" placeholder="请输入判定基准" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="手顺书/要领书:" prop="Essentials">
                <el-input v-model="form.Essentials" class="input2" placeholder="请输入要领书" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="周期:" prop="cycle">
                <el-input v-model="form.cycle" class="input2" placeholder="请输入周期" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="实施部门:" prop="department">
                <el-input v-model="form.department" class="input2" placeholder="请输入实施部门" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备状态:" prop="state">
                <el-select v-model="form.state" class="input2" size="small" style="width: 200px;margin-left: 0px" clearable placeholder="请选择班组名称">
                  <el-option
                    v-for="item in states"
                    :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="工时min:" prop="workingHours">
                <el-input v-model="form.workingHours" class="input2" type="number" placeholder="请输入工时" style="width: 200px;margin-left: 0px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <div style="margin-top: 10px">
                <el-checkbox v-model="form.spotCheck">点检</el-checkbox>
                <el-checkbox v-model="form.oilSupply">给油</el-checkbox>
                <el-checkbox v-model="form.replace">更换</el-checkbox>
                <el-checkbox v-model="form.clean">清扫</el-checkbox>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item >
              <div style="float: right">
                <el-button style="margin-top: 20px" class="button12" @click="callOff('form')">取消</el-button>
                <el-button v-if="title==='增加基准'" class="button11" @click="submitAdd('form')">确 定</el-button>
                <el-button v-if="title==='编辑基准'" class="button11" @click="submitEdit('form')">确 定</el-button>
              </div>
            </el-form-item>
          </el-row>
        </el-form>
      </el-dialog>
      <el-dialog
        :visible.sync="dialogVisible"
        align="center"
        title="点检操作手册"
        width="20%">
        <div v-for="(file, key) in hadFile" :key="key">
          <div class="wrapper">
            <div class="content">
              <div class="action">
                <a class="delete" @click="deleteFileData(file.id)">删除</a>
              </div>
              <div v-if="file.suffix==='pdf'" class="icon"><svg-icon icon-class="pdf" /></div>
              <div v-else-if="file.suffix==='docx'||file.suffix === 'doc'" class="icon"><svg-icon icon-class="doc" /></div>
              <div v-else-if="file.suffix==='xlsx' || file.suffix === 'xls'" class="icon"><svg-icon icon-class="excel" /></div>
              <div v-else-if="file.suffix==='pptx' || file.suffix === 'ppt'" class="icon"><svg-icon icon-class="ppt" /></div>
              <div v-else-if="file.suffix==='jpg' || file.suffix === 'jpeg'|| file.suffix === 'png'" class="icon"><svg-icon icon-class="pic" /></div>
              <div v-else class="icon"><svg-icon icon-class="file" /></div>
              <a id="appUrl" :href="file.url" target="view_window"><div class="info">{{ file.name }}</div></a>
            </div>
          </div>
        </div>
        <el-row>
          <div style="margin-bottom: 20px">
            <el-upload
              :action="action"
              :on-success="uploadSuccess"
              :on-error="uploadFailure"
              :show-file-list="showFileList"
              :file-list="fileList"
              class="upload-demo"
              multiple>
              <el-button size="small" class="button11" @click="batchImportOfDrawings">点击上传</el-button>
            </el-upload>
          </div>
        </el-row>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { MESUploadFileSpotCheck, MESDownloadFile } from '@/utils/request'
import { ExecDatabase } from '@/main'
import UploadExcelComponent from '@/views/UploadExcel/index.vue'
import { mapGetters } from 'vuex'
export default {
  components: { UploadExcelComponent },
  data() {
    return {
      dialogVisible: false,
      showFileList: false,
      hadFile: [],
      fileList: [],
      action: '',
      benchmarkDate: '',
      testItems: '', // 检测项ID
      order: '', // 顺序
      states: [{ // 设备运行状态
        label: '运行',
        value: '运行'
      }, {
        label: '停止',
        value: '停止'
      }],
      worksheet: [],
      itemFile: [],
      equipments: [],
      equipment: '',
      equipmentLabel: '',
      positionGroup: '',
      partsGroup: '',
      projectGroup: '',
      methodGroup: '',
      toolGroup: '',
      benchmarkGroup: '',
      EssentialsGroup: '',
      cycleGroup: '',
      departmentGroup: '',
      stateGroup: '',
      spotCheckGroup: '',
      oilSupplyGroup: '',
      replaceGroup: '',
      cleanGroup: '',
      workingHoursGroup: '',
      keyword: '', // 关键词
      keyword_check: 0,
      loading: false,
      tableData: [],
      title: '',
      dialogFormVisible: false,
      machineShops: [], // 车间
      regions: [], // 工序
      productionLines: [], // 产线
      machineShops1: [], // 车间
      regions1: [], // 工序
      productionLines1: [], // 产线
      machineShop: '', // 车间
      region: '', // 工序
      productionLine: '', // 产线
      form: {
        position: '', // 部位
        parts: '', // 部件
        project: '', // 项目
        method: '', // 方法要领
        tool: '', // 工具材料
        benchmark: '', // 判定基准
        Essentials: '', // 要领书
        cycle: '', // 周期
        department: '', // 实施部门
        state: '', // 设备状态
        spotCheck: false, // 点检
        oilSupply: false, // 给油
        replace: false, // 更换
        clean: false, // 清扫
        workingHours: '' // 工时
      },
      rules: {
        position: [{ required: true, message: '请输入部位', trigger: 'blur' }],
        parts: [{ required: true, message: '请输入部件', trigger: 'blur' }],
        project: [{ required: true, message: '请输入项目', trigger: 'blur' }],
        method: [{ required: true, message: '请输入方法要领', trigger: 'blur' }],
        tool: [{ required: true, message: '请输入工具材料', trigger: 'blur' }],
        benchmark: [{ required: true, message: '请输入判定基准', trigger: 'blur' }],
        Essentials: [{ required: true, message: '请输入要领书', trigger: 'blur' }],
        cycle: [{ required: true, message: '请输入周期', trigger: 'blur' }],
        department: [{ required: true, message: '请输入实施部门', trigger: 'blur' }],
        state: [{ required: true, message: '请选择设备状态', trigger: 'blur' }],
        workingHours: [{ required: true, message: '请输入工时', trigger: 'blur' }]
      },
      form1: {
        benchmarkDate: ''
      },
      rules1: {
        benchmarkDate: [{ required: true, message: '请选择基准日期', trigger: 'blur' }]
      },
      aaa: -1,
      total: 0, // 总条数
      pageSize: 10, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id',
      'token',
      'cname'
    ])
  },
  watch: {
    equipment(val) {
      this.equipmentLabel = ''
      for (let i = 0; i < this.equipments.length; i++) {
        if (val === this.equipments[i].value) {
          this.equipmentLabel = this.equipments[i].label
        }
      }
    }
  },
  created() {
    this.searchMachineShop()
    this.searchTable()
  },
  methods: {
    exportExcel() {
      var param = []
      param[0] = ['设备代码', this.equipment]
      var Data = this.CreateData('2001', '基础数据_设备自主基准保全库_导出', param)
      this.exportExcel_NPOI(Data)
    },
    async selected(data) { // 选择需要导入的文件
      console.log(data, 1111)
      this.worksheet = data.worksheet // 获取每个多选文件的表格坐标及值
      this.itemFile = data.itemFile
    },
    basicPartsToSQL() {
      try {
        this.loading = true
        this.err = 0
        console.log(this.worksheet[0])
        for (let j = this.worksheet.length - 1; j >= 0; j--) {
          let equipmentNumber,
            position,
            parts,
            project,
            method,
            tool,
            benchmark,
            Essentials,
            cycle,
            department,
            state,
            spotCheck,
            oilSupply,
            replace,
            clean,
            workingHours
          this.positionGroup = ''
          this.partsGroup = ''
          this.projectGroup = ''
          this.methodGroup = ''
          this.toolGroup = ''
          this.benchmarkGroup = ''
          this.EssentialsGroup = ''
          this.cycleGroup = ''
          this.departmentGroup = ''
          this.stateGroup = ''
          this.spotCheckGroup = ''
          this.oilSupplyGroup = ''
          this.replaceGroup = ''
          this.cleanGroup = ''
          this.workingHoursGroup = ''
          this.worksheet[j].F3 ? equipmentNumber = this.worksheet[j].F3.v : equipmentNumber = ''
          console.log(this.equipmentLabel.trim(), equipmentNumber.toString().trim(), this.worksheet, 123)
          if (this.equipmentLabel.trim() === equipmentNumber.toString().trim()) {
            for (let i = 0; i < 999; i++) {
              const attr = i + 5
              if (attr === 5) {
                position = this.worksheet[j][`C${attr}`] ? this.worksheet[j][`C${attr}`].v : ''
                parts = this.worksheet[j][`D${attr}`] ? this.worksheet[j][`D${attr}`].v : ''
              } else {
                position = this.worksheet[j][`C${attr}`] ? this.worksheet[j][`C${attr}`].v : position
                parts = this.worksheet[j][`D${attr}`] ? this.worksheet[j][`D${attr}`].v : parts
              }
              project = this.worksheet[j][`E${attr}`] ? this.worksheet[j][`E${attr}`].v : ''
              method = this.worksheet[j][`F${attr}`] ? this.worksheet[j][`F${attr}`].v : ''
              tool = this.worksheet[j][`G${attr}`] ? this.worksheet[j][`G${attr}`].v : ''
              benchmark = this.worksheet[j][`H${attr}`] ? this.worksheet[j][`H${attr}`].v : ''
              Essentials = this.worksheet[j][`I${attr}`] ? this.worksheet[j][`I${attr}`].v : ''
              cycle = this.worksheet[j][`J${attr}`] ? this.worksheet[j][`J${attr}`].v : ''
              department = this.worksheet[j][`K${attr}`] ? this.worksheet[j][`K${attr}`].v : ''
              state = this.worksheet[j][`L${attr}`] ? this.worksheet[j][`L${attr}`].v : ''
              spotCheck = this.worksheet[j][`M${attr}`] ? (this.worksheet[j][`M${attr}`].v.replace(/\s*/g, '') ? 1 : 0) : 0
              oilSupply = this.worksheet[j][`N${attr}`] ? (this.worksheet[j][`N${attr}`].v.replace(/\s*/g, '') ? 1 : 0) : 0
              replace = this.worksheet[j][`O${attr}`] ? (this.worksheet[j][`O${attr}`].v.replace(/\s*/g, '') ? 1 : 0) : 0
              clean = this.worksheet[j][`P${attr}`] ? (this.worksheet[j][`P${attr}`].v.replace(/\s*/g, '') ? 1 : 0) : 0
              workingHours = this.worksheet[j][`Q${attr}`] ? this.worksheet[j][`Q${attr}`].v : ''
              if (!project && !method && !tool && !benchmark && !Essentials && !cycle && !department && !state && !spotCheck && !oilSupply && !replace && !clean && !workingHours) { // 当数据都为空时，循环终止，防止向数据库中插入多余且无用的数据
                this.positionGroup = this.positionGroup.substr(0, this.positionGroup.length - 1)
                this.partsGroup = this.partsGroup.substr(0, this.partsGroup.length - 1)
                this.projectGroup = this.projectGroup.substr(0, this.projectGroup.length - 1)
                this.methodGroup = this.methodGroup.substr(0, this.methodGroup.length - 1)
                this.toolGroup = this.toolGroup.substr(0, this.toolGroup.length - 1)
                this.benchmarkGroup = this.benchmarkGroup.substr(0, this.benchmarkGroup.length - 1)
                this.EssentialsGroup = this.EssentialsGroup.substr(0, this.EssentialsGroup.length - 1)
                this.cycleGroup = this.cycleGroup.substr(0, this.cycleGroup.length - 1)
                this.departmentGroup = this.departmentGroup.substr(0, this.departmentGroup.length - 1)
                this.stateGroup = this.stateGroup.substr(0, this.stateGroup.length - 1)
                this.spotCheckGroup = this.spotCheckGroup.substr(0, this.spotCheckGroup.length - 1)
                this.oilSupplyGroup = this.oilSupplyGroup.substr(0, this.oilSupplyGroup.length - 1)
                this.replaceGroup = this.replaceGroup.substr(0, this.replaceGroup.length - 1)
                this.cleanGroup = this.cleanGroup.substr(0, this.cleanGroup.length - 1)
                this.workingHoursGroup = this.workingHoursGroup.substr(0, this.workingHoursGroup.length - 1)
                break
              } else if (!project) { // 项目不能为空
                this.$notify.error(`项目不能为空`)
                break
              } else if (!cycle) { // 周期不能为空
                this.$notify.error(`周期不能为空`)
                break
              } else {
                this.positionGroup = this.positionGroup + position + '^'
                this.partsGroup = this.partsGroup + parts + '^'
                this.projectGroup = this.projectGroup + project + '^'
                this.methodGroup = this.methodGroup + method + '^'
                this.toolGroup = this.toolGroup + tool + '^'
                this.benchmarkGroup = this.benchmarkGroup + benchmark + '^'
                this.EssentialsGroup = this.EssentialsGroup + Essentials + '^'
                this.cycleGroup = this.cycleGroup + cycle + '^'
                this.departmentGroup = this.departmentGroup + department + '^'
                this.stateGroup = this.stateGroup + state + '^'
                this.spotCheckGroup = this.spotCheckGroup + spotCheck + '^'
                this.oilSupplyGroup = this.oilSupplyGroup + oilSupply + '^'
                this.replaceGroup = this.replaceGroup + replace + '^'
                this.cleanGroup = this.cleanGroup + clean + '^'
                this.workingHoursGroup = this.workingHoursGroup + workingHours + '^'
              }
            }
            var param = []
            param[0] = ['设备代码', this.equipment]
            param[1] = ['部位组', this.positionGroup]
            param[2] = ['部件组', this.partsGroup]
            param[3] = ['项目组', this.projectGroup]
            param[4] = ['方法要领组', this.methodGroup]
            param[5] = ['工具材料组', this.toolGroup]
            param[6] = ['判定基准组', this.benchmarkGroup]
            param[7] = ['要领书组', this.EssentialsGroup]
            param[8] = ['周期组', this.cycleGroup]
            param[9] = ['实施部门组', this.departmentGroup]
            param[10] = ['设备状态组', this.stateGroup]
            param[11] = ['点检组', this.spotCheckGroup]
            param[12] = ['给油组', this.oilSupplyGroup]
            param[13] = ['更换组', this.replaceGroup]
            param[14] = ['清扫组', this.cleanGroup]
            param[15] = ['工时组', this.workingHoursGroup]
            param[16] = ['人员编号', this.id]
            var Data = this.CreateData('12', '基础数据_设备自主基准保全库_导入', param)
            ExecDatabase(Data).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('导入成功')
                this.searchTable()
              } else {
                this.$message.error('导入失败')
              }
            })
          } else {
            this.$message.warning('导入文件与该设备不符')
          }
          this.itemFile.splice(j, 1)
          this.worksheet.splice(j, 1)
        }
        this.loading = false
      } catch (e) {
        this.err++
        this.loading = false
        this.$notify.error(`导入数据错误,请检查导入文件是否正确`)
        console.log(`导入数据错误${e}`)
      }
    },
    tableHeaderColor() {
      return 'background-color: rgb(250, 250, 250);' +
        'height:20px;' +
        'border-bottom: 4px rgb(170, 170, 170) solid;color: rgb(35, 35, 35);' +
        'font-weight: 5000;' +
        'padding: 5px 10px'
    },
    tableColor() {
      return 'border-color: #E8E8E8;padding: 6px 0px 4px 0px'
    },
    tableColor1() {
      return 'border-color: #E8E8E8;padding: 7px 0px 5px 0px'
    },
    tableColor2() {
      return 'border-color: #E8E8E8;padding: 10px 0px 8px 0px'
    },
    uploadManual() {
      this.hadFile = []
      var param = []
      param[0] = ['设备代码', this.equipment]
      var Data = this.CreateData('11', '基础数据_点检作业手册_查询数据', param)
      ExecDatabase(Data).then(res => {
        this.suffix = res.data
        if (res.data.length > 0) {
          const server = `${MESDownloadFile}`.split('/')
          res.data.map(item => {
            this.hadFile.push({
              url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
              name: `${item.name}.${item.suffix}`,
              suffix: item.suffix,
              id: item.num
            })
          })
        }
      })
      this.dialogVisible = true
    },
    deleteFileData(id) {
      var param = []
      param[0] = ['num', id]
      var Data = this.CreateData('12', '基础数据_点检作业手册_删除数据', param)
      ExecDatabase(Data).then(res => {
        if (res.data[0].result === '1') {
          this.$message.success('删除成功')
          this.hadFile = []
          var param = []
          param[0] = ['设备代码', this.equipment]
          var Data = this.CreateData('11', '基础数据_点检作业手册_查询数据', param)
          ExecDatabase(Data).then(res => {
            this.suffix = res.data
            if (res.data.length > 0) {
              const server = `${MESDownloadFile}`.split('/')
              res.data.map(item => {
                this.hadFile.push({
                  url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                  name: `${item.name}.${item.suffix}`,
                  suffix: item.suffix,
                  id: item.num
                })
              })
            }
          })
        } else {
          this.$message.success('删除失败')
        }
      })
    },
    batchImportOfDrawings() {
      this.action = `${MESUploadFileSpotCheck}?&num=1&tableName=基础数据_点检作业手册&type=1&UploaderName=${this.id}&equipment=${this.equipment}`
    },
    uploadSuccess(res, file, fileList) {
      if (res[0].result === '1') {
        const index = fileList.indexOf(file)
        fileList.splice(index, 1)
      } else {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      }
      if (fileList.length === 0) {
        this.uploadManual()
        this.$message.success('文件上传成功')
      }
    },
    uploadFailure(res, file, fileList) {
      fileList.map(file => {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      })
    },
    submitDate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['设备代码', this.equipment]
          param[1] = ['基准日期', this.form1.benchmarkDate]
          var Data = this.CreateData('12', '基础数据_设备专业基准保全库_基准日期_修改', param)
          ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '信息修改成功',
                type: 'success'
              })
              this.searchDate()
              this.dialogFormVisible1 = false
            } else {
              this.$message.error('信息修改失败')
            }
          })
        }
      })
    },
    callOff1(formName) {
      this.dialogFormVisible1 = false
      this.$refs[formName].resetFields()
    },
    // 获得车间
    searchMachineShop() {
      this.machineShops1 = []
      this.machineShop = ''
      var param = []
      var Data = this.CreateData('11', '设备管理_车间_查询', param)
      ExecDatabase(Data).then(response => {
        response.data.map(v => {
          this.machineShops1.push({
            label: v.车间,
            value: v.车间代码
          })
        })
      }).then(() => {
      })
    },
    // 获得产线
    searchProductionLine() {
      this.productionLines1 = []
      this.productionLine = ''
      var param = []
      param[0] = ['车间代码', this.machineShop]
      var Data = this.CreateData('11', '设备管理_产线_查询', param)
      ExecDatabase(Data).then(response => {
        response.data.map(v => {
          this.productionLines1.push({
            label: v.产线名称,
            value: v.产线代码
          })
        })
      }).then(() => {
      })
    },
    // 获得工序
    searchRegion() {
      this.regions1 = []
      this.region = ''
      var param = []
      param[0] = ['产线代码', this.productionLine]
      var Data = this.CreateData('11', '设备管理_工序_查询', param)
      ExecDatabase(Data).then(response => {
        response.data.map(v => {
          this.regions1.push({
            label: v.工序名称,
            value: v.工序代码
          })
        })
      }).then(() => {
      })
    },
    // 获得设备
    searchEquipment() {
      this.equipments = []
      this.equipment = ''
      var param = []
      param[0] = ['工序代码', this.region]
      var Data = this.CreateData('11', '基础数据_设备列表_查询', param)
      ExecDatabase(Data).then(response => {
        response.data.map(v => {
          this.equipments.push({
            name: v.设备名称,
            label: v.设备编号,
            value: v.设备代码
          })
        })
      }).then(() => {
      })
    },
    searchDate() {
      var param = []
      param[0] = ['设备代码', this.equipment]
      var Data = this.CreateData('11', '基础数据_设备专业基准保全库_基准日期_查询', param)
      ExecDatabase(Data).then(response => {
        this.benchmarkDate = response.data[0].基准日期
      })
    },
    // 查询
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      param[0] = ['设备代码', this.equipment]
      var Data = this.CreateData('11', '基础数据_设备自主保全库_查询', param)
      ExecDatabase(Data).then(response => {
        this.tableData = response.data
        this.loading = false
      })
    },
    /**
     * 确定增加基准
     */
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.form.spotCheck ? this.form.spotCheck = 1 : this.form.spotCheck = 0
          this.form.oilSupply ? this.form.oilSupply = 1 : this.form.oilSupply = 0
          this.form.replace ? this.form.replace = 1 : this.form.replace = 0
          this.form.clean ? this.form.clean = 1 : this.form.clean = 0
          var param = []
          param[0] = ['设备代码', this.equipment]
          param[1] = ['部位', this.form.position]
          param[2] = ['部件', this.form.parts]
          param[3] = ['项目', this.form.project]
          param[4] = ['方法要领', this.form.method]
          param[5] = ['工具材料', this.form.tool]
          param[6] = ['判定基准', this.form.benchmark]
          param[7] = ['要领书', this.form.Essentials]
          param[8] = ['周期', this.form.cycle]
          param[9] = ['实施部门', this.form.department]
          param[10] = ['设备状态', this.form.state]
          param[11] = ['点检', this.form.spotCheck]
          param[12] = ['给油', this.form.oilSupply]
          param[13] = ['更换', this.form.replace]
          param[14] = ['清扫', this.form.clean]
          param[15] = ['工时', this.form.workingHours]
          param[16] = ['顺序', this.order]
          param[17] = ['人员编号', this.id]
          var Data = this.CreateData('12', '基础数据_设备自主基准保全库_插入', param)
          ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '信息增加成功',
                type: 'success'
              })
              this.dialogFormVisible = false
              this.searchTable()
            } else {
              this.$message.error('信息增加失败')
            }
          })
        }
      })
    },
    /**
     * 增加基准取消
     */
    callOff(formName) {
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    /**
     * 点击增加基准
     */
    addBenchmark(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '增加基准'
      this.form.position = ''
      this.form.parts = ''
      this.form.project = ''
      this.form.method = ''
      this.form.tool = ''
      this.form.benchmark = ''
      this.form.Essentials = ''
      this.form.cycle = ''
      this.form.department = ''
      this.form.state = ''
      this.form.workingHours = ''
      this.form.spotCheck = false
      this.form.oilSupply = false
      this.form.replace = false
      this.form.clean = false
      this.dialogFormVisible = true
      this.order = row.序号
    },
    /**
     * 点击修改基准
     */
    editBenchmark(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '编辑基准'
      this.dialogFormVisible = true
      this.testItems = row.点检项ID
      this.form.position = row.部位
      this.form.parts = row.部件
      this.form.project = row.检修项目
      this.form.method = row.方法要领
      this.form.tool = row.工具材料
      this.form.benchmark = row.判定基准
      this.form.Essentials = row.要领书
      this.form.cycle = row.周期
      this.form.department = row.实施部门
      this.form.state = row.设备状态
      this.form.workingHours = row.工时
      row.点检 ? this.form.spotCheck = true : this.form.spotCheck = false
      row.给油 ? this.form.oilSupply = true : this.form.oilSupply = false
      row.更换 ? this.form.replace = true : this.form.replace = false
      row.清扫 ? this.form.clean = true : this.form.clean = false
    },
    /**
     * 确定修改基准
     */
    submitEdit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.form.spotCheck ? this.form.spotCheck = 1 : this.form.spotCheck = 0
          this.form.oilSupply ? this.form.oilSupply = 1 : this.form.oilSupply = 0
          this.form.replace ? this.form.replace = 1 : this.form.replace = 0
          this.form.clean ? this.form.clean = 1 : this.form.clean = 0
          var param = []
          param[0] = ['点检项ID', this.testItems]
          param[1] = ['部位', this.form.position]
          param[2] = ['部件', this.form.parts]
          param[3] = ['项目', this.form.project]
          param[4] = ['方法要领', this.form.method]
          param[5] = ['工具材料', this.form.tool]
          param[6] = ['判定基准', this.form.benchmark]
          param[7] = ['要领书', this.form.Essentials]
          param[8] = ['周期', this.form.cycle]
          param[9] = ['实施部门', this.form.department]
          param[10] = ['设备状态', this.form.state]
          param[11] = ['点检', this.form.spotCheck]
          param[12] = ['给油', this.form.oilSupply]
          param[13] = ['更换', this.form.replace]
          param[14] = ['清扫', this.form.clean]
          param[15] = ['工时', this.form.workingHours]
          param[16] = ['人员编号', this.id]
          var Data = this.CreateData('12', '基础数据_设备自主基准保全库_修改', param)
          ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '信息修改成功',
                type: 'success'
              })
              this.dialogFormVisible = false
              this.searchTable()
            } else {
              this.$message.error('信息修改失败')
            }
          })
        }
      })
    },
    /**
     * 删除基准
     */
    handleDelete(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['点检项ID', row.点检项ID]
        param[1] = ['顺序', row.序号]
        param[2] = ['设备代码', this.equipment]
        var Data = this.CreateData('12', '基础数据_设备自主基准保全库_删除', param)
        ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchTable()
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    handleSizeChange1(val) {
      this.sparePageCurrent = 1
      this.sparePageSize = val
      this.getSpare()
    },
    handleCurrentChange1(val) {
      this.sparePageCurrent = val
      this.getSpare()
    }
  }
}
</script>

<style scoped>
  .machine-divider {
    margin: 5px 0;
    width: 100%;
    border-bottom: 1px solid #ccc;
  }
  .div {
    width: 220px;
    height:45px;
    margin-top: 0px;
    border-bottom: rgb(220,220,220) solid 2px
  }
  >>>.el-form--label-top .el-form-item__label {
    padding: 0px;
  }
  >>>.el-dialog__body {
    padding: 0px 30px;
    color: #606266;
    font-size: 20px;
    word-break: break-all;
  }
  >>>.el-tabs__item {
    font-size: 16px;
    padding-top: 10px;
    padding-bottom: 50px;
  }
  /*搜索框*/
  .input1 >>> .el-input__inner{
    height: 50px;
    border-radius: 0px;
  }
  /*只有下边框*/
  .input2 >>> .el-input__inner{
    height: 40px;
    border-radius: 0px;
    border-top: 0px;
    border-left: 0px;
    border-right: 0px;
    background: #ffffff;
  }
  .el-form-item {
    margin-bottom: 18px;
  }
  .wrapper{
    width: 300px;
    height: 55px;
    overflow: hidden;
    border: 1px solid #b8c7d9;
    /*float: left;*/
    margin: 10px;
  }
  .content{
    position: relative;
    padding: 8px 8px 0 8px;
  }
  .action{
    position: absolute;
    top: 2px;
    right: 8px;
  }
  .delete{
    padding: 0 5px;
    border-radius: 3px;
    color: #0f84b0;
    font-size: 12px;
  }
  .delete:hover{
    background: -webkit-linear-gradient(top,#0ba9e3,#0099d3);
    color: #fff;
  }
  a{
    text-decoration: none;
  }
  .icon{
    width: 30px;
    height: 30px;
    display: inline-block;
    margin-right: 225px;
    margin-top: -2px;
    font-size: 26px;
  }
  .info{
    width: 160px;
    height: 50px;
    position: absolute;
    left: 67px;
    line-height: 30px;
    display: inline-block;
    color: #999;
  }
</style>

