<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <span>机床编号:</span>
        <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" clearable @change="searchTable1();searchTable2()">
          <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>
        <!--        <span>组号:</span>-->
        <!--        <el-select v-model="groupNumberValue" filterable placeholder="组号" size="small" clearable @change="searchTable2()">-->
        <!--          <el-option-->
        <!--            v-for="item in groupNumber"-->
        <!--            :key="item.value"-->
        <!--            :label="item.label"-->
        <!--            :value="item.value"/>-->
        <!--        </el-select>-->
        <!--        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="searchTable1();searchTable2()">查询</el-button>-->
      </el-row>
    </el-card>
    <el-card>
      <h3 style="text-align: center;">总装调试</h3>
      <el-table :data="tableData1" border size="mini" highlight-current-row style="width: 100%;margin-top: 15px" height="200px">
        <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" width="250px" fixed="right">
          <template slot-scope="scope">
            <el-button v-if="scope.row.装配状态===null || scope.row.装配状态===0" type="success" size="small" @click="handlestart_1(scope.row)">开始装配</el-button>
            <el-button v-else-if="scope.row.装配状态===1" type="danger" size="small" @click="handleend_1(scope.row)">结束装配</el-button>
            <el-button v-else type="info" size="small" >装配完成</el-button>
            <el-button v-if="scope.row.调试状态===null || scope.row.调试状态===0" type="success" size="small" @click="handlestart_2(scope.row)">开始调试</el-button>
            <el-button v-else-if="scope.row.调试状态==1" type="danger" size="small" @click="handleend_2(scope.row)">结束调试</el-button>
            <el-button v-else type="info" size="small" >调试完成</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card>
      <h3 style="text-align: center;">部装</h3>
      <el-table :data="tableData2" border size="mini" highlight-current-row style="width: 100%;margin-top: 15px" height="380px">
        <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">
            {{ 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="250px" fixed="right">
          <template slot-scope="scope">
            <el-button v-if="scope.row.组件是否完成===null || scope.row.组件是否完成===0" type="success" size="small" @click="handlestart_3(scope.row)">开始装配</el-button>
            <el-button v-else-if="scope.row.组件是否完成===1" type="danger" size="small" @click="handleend_3(scope.row)">结束装配</el-button>
            <el-button v-else type="info" size="small" >装配完成</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { initProject, searchgroup, searchTable1, searchTable2, MachineToolStateUpdate, DebugStatusUpdate, ComponentStateUpdate } from '@/api/Assembly/AssemblyExecution'
// 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].机床流水号
          })
        }
      })
    },
    machineChange() {
      this.groupNumberValue = ''
      this.groupNumber = []
      searchgroup(this.machineNumberValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.groupNumber.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    searchTable1() {
      this.tableData1 = []
      if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
      searchTable1(this.machineNumberValue, this.check2).then(response => {
        this.tableData1 = response.data
        console.log(response.data, 1111)
      })
    },
    searchTable2() {
      this.tableData2 = []
      if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
      if (this.groupNumberValue !== '' && this.groupNumberValue !== null) { this.check3 = 1 } else { this.check3 = 0 }
      searchTable2(this.machineNumberValue, this.check2).then(response => {
        console.log(response.data, 222)
        this.tableData2 = response.data
      })
    },
    // 总装开始装配
    handlestart_1(row) { // 弹出单据编辑
      console.log(row)
      MachineToolStateUpdate(row.机床流水号, 1).then(response => {
        console.log(response.data)
        this.searchTable1()
        this.searchTable2()
      })
    },
    // 总装结束装配
    handleend_1(row) { // 弹出单据编辑
      console.log(row)
      MachineToolStateUpdate(row.机床流水号, 2).then(response => {
        console.log(response.data)
        this.searchTable1()
        this.searchTable2()
      })
    },
    // 总装开始调试
    handlestart_2(row) { // 弹出单据编辑
      console.log(row)
      DebugStatusUpdate(row.机床流水号, 1).then(response => {
        console.log(response.data)
        this.searchTable1()
        this.searchTable2()
      })
    },
    // 总装结束调试
    handleend_2(row) { // 弹出单据编辑
      console.log(row)
      DebugStatusUpdate(row.机床流水号, 2).then(response => {
        console.log(response.data)
        this.searchTable1()
        this.searchTable2()
      })
    },
    // 部装开始装配
    handlestart_3(row) { // 弹出单据编辑
      console.log(row)
      ComponentStateUpdate(row.组件流水号, 1).then(response => {
        console.log(response.data)
        this.searchTable1()
        this.searchTable2()
      })
    },
    // 部装结束装配
    handleend_3(row) { // 弹出单据编辑
      console.log(row)
      ComponentStateUpdate(row.组件流水号, 2).then(response => {
        console.log(response.data)
        this.searchTable1()
        this.searchTable2()
      })
    }
  }
}

</script>

<style scoped>

</style>
