<template>
  <div class="routineCheckDiv">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">工位号：</span>
        <el-select v-model="dataTypeValue" placeholder="请选择工位号" clearable size="small" style="width: 150px">
          <el-option
            v-for="item in dataType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            size="mini"/>
        </el-select>
        <span style="margin-left: 10px">处理状态：</span>
        <el-select v-model="valueTypeValue" placeholder="处理状态" clearable size="small" style="width:100px">
          <el-option
            key="1"
            label="已处理"
            value="1"/>
          <el-option
            key="0"
            label="未处理"
            value="0"/>
        </el-select>
        <!--<span style="margin-left: 10px">时间：</span>-->
        <!--<el-date-picker-->
        <!--  :clearable="false"-->
        <!--  v-model="dateTime"-->
        <!--  size="small"-->
        <!--  type="daterange"-->
        <!--  align="center"-->
        <!--  style="width: 240px;"-->
        <!--  value-format="yyyy-MM-dd"-->
        <!--  format="yyyy-MM-dd"-->
        <!--  range-separator="～"-->
        <!--  start-placeholder="开始日期"-->
        <!--  end-placeholder="结束日期"/>-->
        <el-button type="primary" plain size="small" icon="el-icon-search" style="margin-left: 5px"
                   @click="pageSize=50;pageCurrent=1;searchTable()">查询
        </el-button>
        <!--        <el-button type="success" plain icon="el-icon-document-copy" size="small" @click="copyData('form4')">复制</el-button>-->
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        size="mini"
        height="640"
        center
        style="width: 100%">
        <el-table-column width="60" label="序号" type="index" align="center"/>
        <el-table-column label="工位号" align="center">
          <template slot-scope="scope">
            {{ scope.row.工位号 }}
          </template>
        </el-table-column>
        <el-table-column label="点检周期" align="center">
          <template slot-scope="scope">
            {{ scope.row.点检周期 }}
          </template>
        </el-table-column>
        <el-table-column label="点检类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.点检类型 }}
          </template>
        </el-table-column>
        <el-table-column label="点检项目" align="center">
          <template slot-scope="scope">
            {{ scope.row.点检项目 }}
          </template>
        </el-table-column>
        <el-table-column label="处理状态" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.处理状态 == 0" size="small" type="danger">未处理</el-tag>
            <el-tag v-if="scope.row.处理状态 == 1" size="small" type="success">已处理</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="处理结果" align="center">
          <template slot-scope="scope">
            {{ scope.row.处理结果 }}
          </template>
        </el-table-column>
        <el-table-column label="操作工" align="center">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="点检时间" align="center" width="170">
          <template slot-scope="scope">
            {{ scope.row.操作时间 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="170">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              :disabled="scope.row.处理状态 == 1"
              @click="handleEdit(scope.row)">处理异常
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-sizes="[50, 100, 200]"
          :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="dialogFormVisible1" title="异常点检处理" center style="min-height: 200px" width="400px">
      <el-form label-position="right" label-width="110px">
        <el-form-item label="处理结果" prop="partCode" style="display: inline-block">
          <el-input v-model="form.text" type="textarea" size="small" placeholder="处理结果"/>
        </el-form-item>
        <el-form-item label="异常处理结果" prop="workOp" style="display: inline-block">
          <el-select v-model="form.isOk" size="small" placeholder="请选择异常处理结果">
            <el-option label="已处理" :value="1"/>
            <el-option label="未处理" :value="0"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible1 = false">取消</el-button>
        <el-button type="primary" size="small" @click="submitAdd1()">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      dataType: [], // 日志类型数组
      dataTypeValue: '', // 日志类型
      valueType: [],
      valueTypeValue: '',
      alarmType: [],
      alarmTypeValue: '',
      dateTime: '', // 时间
      dialogFormVisible: false,
      dialogFormVisible4: false,
      form4: {
        engineTypeValue: ''
      },
      rules4: { // 订单下发验证
        engineTypeValue: [{required: true, message: '请选择', trigger: 'blur'}]
      },
      title: '',
      form: {
        id: '',
        text: '',
        isOk: ''
      },
      rules: { // 表单验证规则
      },
      total: 0, // 总条数
      pageList: 50, // 每页显示条数
      pageSize: 50, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      dialogFormVisible1: false // 弹窗
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new Date() // 修改数据date
    year = new Date().getFullYear()
    month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
    day = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
    audiTime = year + '-' + month + '-' + day
    console.log(audiTime, 'audiTime')
    this.dateTime = [audiTime, audiTime]
    this.getDataType()
    // this.getValueType()
    this.searchTable()
  },
  methods: {
    // 初始化获取日志类型
    getDataType() {
      this.dataType = []
      var param = []
      param[0] = ['类型', '质量维护']
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        // if (response.data.length) {
        //   this.stationNumberValue = response.data[0].工位号
        //   this.stationName = response.data[0].工序名称
        // }
        for (let i = 0; i < response.data.length; i++) {
          this.dataType.push({
            label: response.data[i].工位号,
            value: response.data[i].工位号,
            labelName: response.data[i].工位名称
          })
        }
      })
    }, // 初始化日志描述
    getValueType() {
      this.valueType = []
      var param = []
      var Data = this.CreateData('11', '_日志_描述表_查询模块描述', param)
      this.ExecDatabase(Data).then(response => {
        for (const item of response.data) {
          this.valueType.push({
            lable: item.描述,
            value: item.描述
          })
        }
      })
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      let stationNumberValue_check, valueType_check
      // this.engineTypeValue ? engineTypeValue_check = 1 : (engineTypeValue_check = 0, this.engineTypeValue = '')
      this.dataTypeValue ? stationNumberValue_check = 1 : (stationNumberValue_check = 0, this.dataTypeValue = '')
      this.valueTypeValue ? valueType_check = 1 : (valueType_check = 0, this.valueTypeValue = '')
      var param = []
      param[0] = ['工位号_ischeck', stationNumberValue_check]
      param[1] = ['工位号', this.dataTypeValue]
      param[2] = ['处理状态_ischeck', valueType_check]
      param[3] = ['处理状态', this.valueTypeValue]
      param[4] = ['PageCurrent', this.pageCurrent]
      param[5] = ['PageSize', this.pageSize]
      param[6] = ['PageCount', '1111', 'int', '1']
      param[7] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', 'MES_不合格点检记录_视图_查询', param)
      this.ExecDatabase(Data).then(response => {
        console.log(response, 66)
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    // 修改订单
    handleEdit(row) {
      this.form.text = row.处理结果
      this.form.id = row.ID
      this.form.isOk = row.处理状态
      this.dialogFormVisible1 = true
    },
    submitAdd1() {
      var param = []
      param[0] = ['id', this.form.id]
      param[1] = ['处理结果', this.form.text]
      param[2] = ['处理状态', this.form.isOk]
      var Data = this.CreateData('12', 'MES_不合格点检记录_处理记录', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            message: '异常处理成功',
            type: 'success'
          })
          this.pageCurrent = 1
          this.pageSize = 15
          this.searchTable()
          this.dialogFormVisible1 = false
        } else {
          this.$message.error('异常处理失败！')
        }
      })
    },
    callOff() {
      this.dialogFormVisible = false
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}
</script>
<style scoped>
.topDiv {
  margin-bottom: 10px;
}
</style>

