<template>
  <div style="width: 99%; height: 98%; margin-left: 4px;background-color: #d5dce4">
    <div style="width: 100%; height: 100%; margin-left: 10px; margin-top: 10px">
      <el-row style="width: 99%; height: 90%;">
        <el-col style="width: 44%; height: 100%;">
          <el-table
            :data="DeviceManagement_table1"
            :header-cell-style="{background:'#F5F5F5'}"
            style="border: 1px solid black; font-weight: lighter"
            width="100%"
            height="100%"
            border
            stripe
            tooltip-effect="dark"
          >
            <el-table-column type="index" align="center" label="序号" width="60px" />
            <el-table-column align="center" label="设备名称" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.设备名称 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="保养内容" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.保养内容 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="保养属性" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.保养属性 }}
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col style="width: 55%; height: 100%; border: 1px solid black;margin-left: 5px;">
          <img :src="'data:image/jpeg;base64,'+Image" style="width: 100%; height: 100%">
        </el-col>
      </el-row>
      <div style="width: 80%; height: 8%; float: left; margin-top: 25px">
        <el-input v-model="内容" style="width:100%; border: 1px solid black;" clearable placeholder="备注" />
      </div>
      <div style="width: 12%; height: 8%; float: left; margin-top: 22px;margin-left: 98px">
        <div id="111" style="width: 100%; height: 70%; border: 1px solid black; margin-left: 0px; text-align: center; line-height: 35px" @click="baoY()">
          <span style="font-size: x-large;line-height: 50px">设备保养</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      DeviceManagement_table1: [],
      内容: '',
      Image: '',
      filePath: '',
      count: 1
    }
  },
  created() {
    this.getTable()
    this.getImage()
  },
  methods: {
    getTable() {
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationNumber]
      param[1] = ['保养类型代码', '2']
      const Data = this.CreateData('11', '设备管理_设备维护内容_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.DeviceManagement_table1.push({
            序号: response.data[i].序号,
            设备名称: response.data[i].机床名称,
            保养内容: response.data[i].设备维护内容,
            保养属性: response.data[i].保养类型代码
          })
        }
      })
    },
    getImage() {
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationNumber]
      param[1] = ['保养类型代码', '2']
      const Data = this.CreateData('11', '设备管理_设备维护图片_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.Image = response.data[0].保养图片
      })
    },
    baoY() {
      if (this.count === 1) {
        document.getElementById(111).style.backgroundColor = 'cornflowerblue'
        const param = []
        param[0] = ['工位号', this.$store.state.station.stationNumber]
        param[1] = ['备注', this.内容]
        const Data = this.CreateData('12', '设备管理_设备维护记录表_增加', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '设备保存成功',
              type: 'success'
            })
          } else {
            this.$message.error('设备保存失败')
          }
        })
        this.count = 2
      } else if (this.count === 2) {
        document.getElementById(111).style.backgroundColor = 'white'
        this.count = 1
      }
    }
  }

}
</script>
<style scoped>
</style>
