<template>
  <div class="app-container">
    <el-card>
      <span>项目名称</span>
      <el-select v-model="projectValue" placeholder="请选择项目名称" filterable size="small" @change="searchMachine">
        <el-option
          v-for="item in project"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>

      <span>机床图号</span>
      <el-select v-model="machineValue" placeholder="请选择机床图号" filterable size="small">
        <el-option
          v-for="item in machine"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>

      <!--<span>签订日期:</span>-->
      <!--<el-date-picker-->
      <!--v-model="startTime"-->
      <!--value-format="yyyy-MM-dd"-->
      <!--size="small"-->
      <!--style="width: 160px"-->
      <!--type="date"-->
      <!--placeholder="选择日期"/>-->
      <!--<span class="demonstration">~</span>-->
      <!--<el-date-picker-->
      <!--v-model="endTime"-->
      <!--value-format="yyyy-MM-dd"-->
      <!--size="small"-->
      <!--style="width: 160px"-->
      <!--type="date"-->
      <!--placeholder="选择日期"/>-->

      <!--<span>交货期:</span>-->
      <!--<el-date-picker-->
      <!--v-model="startTime1"-->
      <!--value-format="yyyy-MM-dd"-->
      <!--size="small"-->
      <!--style="width: 160px"-->
      <!--type="date"-->
      <!--placeholder="选择日期"/>-->
      <!--<span class="demonstration">~</span>-->
      <!--<el-date-picker-->
      <!--v-model="endTime1"-->
      <!--value-format="yyyy-MM-dd"-->
      <!--size="small"-->
      <!--style="width: 160px"-->
      <!--type="date"-->
      <!--placeholder="选择日期"/>-->

      <el-button icon="el-icon-search" type="success" size="small" style="margin-left: 20px" @click="searchTable()">查询</el-button>
      <el-table v-loading="loading" :data="tableData" size="mini" highlight-current-row style="width: 100%; margin-top: 30px" border element-loading-text="拼命加载中">
        <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">
          <template slot-scope="scope">
            {{ scope.row.工期 }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-card>
      <div class="word">设计</div>
      <el-table v-loading="loading1" :data="tableData1" size="mini" highlight-current-row style="width: 100%;" border element-loading-text="拼命加载中">
        <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>
    </el-card>
    <el-card>
      <div class="word">采购</div>
      <el-table v-loading="loading1" :data="tableData2" size="mini" highlight-current-row style="width: 100%;" border element-loading-text="拼命加载中">
        <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>
    </el-card>
    <el-card>
      <div class="word">备料</div>
      <el-table v-loading="loading1" :data="tableData3" size="mini" highlight-current-row style="width: 100%;" border element-loading-text="拼命加载中">
        <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>
    </el-card>
    <el-card>
      <div class="word">制造</div>
      <el-table v-loading="loading1" :data="tableData4" size="mini" highlight-current-row style="width: 100%;" border element-loading-text="拼命加载中">
        <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>
    </el-card>
    <el-card>
      <div class="word">装配调试</div>
      <el-table v-loading="loading1" :data="tableData5" size="mini" highlight-current-row style="width: 100%;" border element-loading-text="拼命加载中">
        <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>
    </el-card>
  </div>
</template>

<script>import { initProject, initMachine, searchtable, searchtable2 } from '@/api/ManufacturingCenter/ProjectPlanningQuery'

export default {
  data() {
    return {
      projectValue: '',
      project: [],
      machineValue: '',
      machine: [],
      loading: false,
      loading1: false,
      tableData: [], // 表格数据
      tableData1: [], // 表格数据
      tableData2: [], // 表格数据
      tableData3: [], // 表格数据
      tableData4: [], // 表格数据
      tableData5: [] // 表格数据
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.getSelect(initProject, ['项目名称', '项目流水号'], 'project')
    },
    searchMachine() {
      this.machine = []
      initMachine(this.projectValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machine.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    // 查询表格数据
    searchTable() {
      this.loading = true
      this.tableData = []
      this.tableData1 = []
      this.tableData2 = []
      this.tableData3 = []
      this.tableData4 = []
      this.tableData5 = []
      if (this.projectValue !== '') {
        if (this.machineValue !== '') {
          searchtable(this.projectValue, this.machineValue).then(response => {
            this.loading = false
            this.tableData = response.data
          }).then(() => {
            searchtable2(this.machineValue, 1).then(response => {
              this.loading1 = false
              console.log(response.data, 2)
              this.tableData1 = response.data
            })
            searchtable2(this.machineValue, 2).then(response => {
              this.loading1 = false
              console.log(response.data, 3)
              this.tableData2 = response.data
            })
            searchtable2(this.machineValue, 3).then(response => {
              this.loading1 = false
              console.log(response.data, 4)
              this.tableData3 = response.data
            })
            searchtable2(this.machineValue, 4).then(response => {
              this.loading1 = false
              console.log(response.data, 5)
              this.tableData4 = response.data
            })
            searchtable2(this.machineValue, 5).then(response => {
              this.loading1 = false
              console.log(response.data, 6)
              this.tableData5 = response.data
            })
          })
        } else {
          this.$message.warning('请选择机床')
        }
      } else {
        this.$message.warning('请选择项目')
      }
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 10px;
  }
  .word{
    font-size: 20px;
    margin-bottom: 20px;
    margin-left: 20px;
  }
  span{
    margin: 10px 0 10px 10px;
  }
</style>

