<template>
  <div class="app-container">
    <el-card class="topCard">
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        size="mini"
        height="440"
        center
        style="width: 50%">
        <el-table-column width="60" label="序号" type="index" align="center"/>
        <el-table-column label="操作工号" align="center" width="120">
          <template slot-scope="scope">
            {{ scope.row.工位号 }}
          </template>
        </el-table-column>
        <el-table-column label="工位名称" align="left">
          <template slot-scope="scope">
            {{ scope.row.工位名称 }}
          </template>
        </el-table-column>
        <el-table-column label="线体类型" align="center" width="100">
          <template slot-scope="scope">
            <!--{{ scope.row.线体类型 }}-->
            <el-tag v-if="scope.row.线体类型 == 1" effect="plain" style="width: 70px"
            >装配线
            </el-tag>
            <el-tag v-else-if="scope.row.线体类型 == 2" effect="plain" style="width: 70px"
                    type="success">测试线
            </el-tag>
            <el-tag v-else effect="plain" style="width: 70px"
                    type="info">线外工位
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleEdit(scope.row)">修改名称
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </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: {
        tagID: '',
        stationNo: '',
        measurementItems: '',
        valueName: ''
      },
      rules: { // 表单验证规则
      },
      total: 0, // 总条数
      pageList: 50, // 每页显示条数
      pageSize: 50, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {
    this.searchTable()
  },
  methods: {
    // 初始化获取日志类型
    getDataType() {
      this.dataType = []
      var param = []
      var Data = this.CreateData('11', '_日志_描述表_查询模块类型', param)
      this.ExecDatabase(Data).then(response => {
        for (const item of response.data) {
          this.dataType.push({
            lable: item.操作模块,
            value: item.操作模块
          })
        }
      })
    }, // 初始化日志描述
    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.描述
          })
        }
      })
    },
    // 修改工位名称
    handleEdit(row) {
      this.$prompt('请输入修改后' + row.工位号 + '工位名称', '工位名称修改', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValue: row.工位名称
      }).then(({value}) => {
        const param = []
        param[0] = ['工位号', row.工位号]
        param[1] = ['工位名称', value]
        const Data = this.CreateData('12', 'MES_计划BOM_工位与名称_工位名称修改', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('修改工位名称成功！')
            this.searchTable()
          } else {
            this.$message.success('修改工位名称失败！')
          }
        })
      })
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        console.log(response, 66)
        if (response.data.length !== 0) {
          this.tableData = response.data
        }
        this.loading = false
      })
    },
    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>
