<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <span>机床编号:</span>
        <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" clearable @change="selecttable()">
          <el-option
            v-for="item in machineNumber"
            :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>
        <!--<el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="selecttable">查询</el-button>-->
      </el-row>
    </el-card>
    <el-card>
      <el-table :data="tableData1" border size="mini" highlight-current-row style="width: 100%;margin-top: 15px" height="600px">
        <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">
            <template v-if="scope.row.edit">
              <el-input v-model="scope.row.注意事项" style="width:100px;margin-right:3px" size="mini" width="120"/>
            </template>
            <span v-else>{{ scope.row.注意事项 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="250px" fixed="right">
          <template slot-scope="scope">
            <el-button v-if="!scope.row.edit && scope.row.发货状态===1" type="success" size="mini" icon="el-icon-circle-check-outline" @click="scope.row.edit=!scope.row.edit" >确认审批</el-button>
            <el-button v-else-if="!scope.row.edit && scope.row.发货状态===2" disabled="true" type="danger" size="mini" icon="el-icon-circle-check-outline" >已审批</el-button>
            <el-button v-if="scope.row.edit" class="cancel-btn" size="mini" type="primary" @click="confirmEdit(scope.row)">确认</el-button>
            <el-button v-if="scope.row.edit" class="cancel-btn" size="mini" type="danger" @click="cancelEdit(scope.row)">取消</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { initProject, selecttable, updatestate } from '@/api/Assembly/ShipmentApproval'
// import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      machineNumberValue: '',
      machineNumber: [],
      groupNumberValue: '',
      groupNumber: [],
      tableData1: [],
      tableData2: []
    }
  },
  created() {

  },
  mounted() {
    this.initProject()
  },
  methods: {
    initProject() {
      initProject().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber.push({
            label: response.data[i].机床图号,
            name: response.data[i].项目名称,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    selecttable() {
      this.tableData1 = []
      if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
      selecttable(this.check2, this.machineNumberValue).then(response => {
        response.data.map(v => {
          this.$set(v, 'edit', false)
          v.原注意事项 = v.注意事项
          return v
        })
        this.tableData1 = response.data
        this.edit = false
        console.log(response.data)
      })
    },
    cancelEdit(row) {
      row.注意事项 = row.原注意事项
      row.edit = false
      this.$message('取消修改')
    },
    confirmEdit(row) {
      updatestate(row.机床流水号, 2, row.注意事项).then(response => {
        this.selecttable()
      })
    }
  }
}

</script>

<style scoped>

</style>
