<template>
  <div class="app-container bold-font">
    <el-card>
      <el-row>
        <el-select v-model="projectValue" filterable clearable size="small" style="margin-top:10px;width: 200px" placeholder="项目名称" @change="typeChange()">
          <el-option
            v-for="item in project"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="toolNumValue" clearable filterable size="small" style="margin-bottom:10px;width: 200px" placeholder="机床名称">
          <el-option
            v-for="item in toolNum"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-input v-model="CustomerNameValue" placeholder="客户名称" size="small" clearable style="width:200px"/>
        <h3 style="display: inline-block;margin: 0 0 0 10px">签订日期:</h3>
        <el-date-picker
          v-model="Sign"
          size="small"
          type="daterange"
          align="center"
          style="width: 240px;margin: 3px 0"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="～"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <h3 style="display: inline-block;margin: 0 0 0 10px">交货期:</h3>
        <el-date-picker
          v-model="delivery"
          size="small"
          type="daterange"
          align="center"
          style="width: 240px;margin: 3px 0"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="～"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <el-button size="small" icon="el-icon-search" type="primary" plain style="margin-left: 10px" @click="pageSize=10; pageCurrent=1;searchTable()">查询</el-button>
      </el-row>
    </el-card>

    <el-card style="overflow: auto">
      <el-col style="width: 1400px;">
        <el-table v-loading="loading" :data="tableData" height="330" highlight-current-row style="margin-top: 5px;width: 100%;" border element-loading-text="拼命加载中" @row-click="rowClick">
          <el-table-column label="项目编号" align="center" width="140px" fixed="left">
            <template slot-scope="scope">
              <template v-if="scope.row.edit">
                <el-input v-model="scope.row.项目编号" size="mini"/>
              </template>
              <template v-else>
                {{ scope.row.项目编号 }}
              </template>
            </template>
          </el-table-column>
          <el-table-column label="项目名称" align="center" min-width="120px" fixed="left">
            <template slot-scope="scope">
              {{ scope.row.项目名称 }}
            </template>
          </el-table-column>
          <el-table-column label="机床图号" align="center" width="140px" fixed="left">
            <template slot-scope="scope">
              {{ scope.row.机床图号 }}
            </template>
          </el-table-column>
          <el-table-column label="机床名称" align="center" width="280px" fixed="left">
            <template slot-scope="scope">
              {{ scope.row.机床名称 }}
            </template>
          </el-table-column>
          <el-table-column label="机床数量" align="center" width="100px">
            <template slot-scope="scope">
              {{ scope.row.机床数量 }}
            </template>
          </el-table-column>
          <el-table-column label="签订日期" align="center" width="125px">
            <template slot-scope="scope">
              {{ scope.row.合同签订日期 !== '1900-01-01' ? scope.row.合同签订日期 : '' }}
            </template>
          </el-table-column>
          <el-table-column label="交货期" align="center" width="125px">
            <template slot-scope="scope">
              {{ scope.row.发货节点 !== '1900-01-01' ? scope.row.发货节点 : '' }}
            </template>
          </el-table-column>
          <el-table-column label="设备预验节点" align="center" width="125px">
            <template slot-scope="scope">
              {{ scope.row.设备预验收节点 !== '1900/1/1' ? scope.row.设备预验收节点 : '' }}
            </template>
          </el-table-column>
          <el-table-column label="安装调试节点" align="center" width="125px">
            <template slot-scope="scope">
              {{ scope.row.安装调试节点 !== '1900/1/1' ? scope.row.安装调试节点 : '' }}
            </template>
          </el-table-column>
          <el-table-column v-if="false" label="操作" width="150px" align="center">
            <template slot-scope="scope">
              <el-button v-if="scope.row.edit" type="success" size="small" @click="confirmEdit(scope.row)">确定</el-button>
              <el-button v-else type="primary" size="small" @click="scope.row.edit=!scope.row.edit">编辑</el-button>
              <el-button v-if="scope.row.edit" type="primary" size="small" @click="scope.row.edit=!scope.row.edit">取消</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 15px;">
          <el-pagination
            v-if="!loading"
            :current-page="pageCurrent"
            :page-sizes="[10, 20, 30, 40, 100]"
            :page-size="pageSize"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </el-col>
      <el-col style="width: 240px;">
        <div style="width: 80px;font-size: 18px;float: left;text-align: center;">进程</div>
        <div style="width: 80px;font-size: 18px;float: left;text-align: center;">计划时间</div>
        <div style="width: 80px;font-size: 18px;float: left;text-align: center;">实际时间</div>
        <el-form label-position="right" label-width="85px" class="demo-ruleForm1">
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="审图开始">
                <el-col style="width: 80px;">
                  {{ 审图开始 }}
                </el-col>
                <el-col style="width: 80px;">
                  -
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="审图结束">
                <el-col style="width: 80px;">
                  {{ 审图结束 }}
                </el-col>
                <el-col style="width: 80px;">
                  {{ 审图实际完成时间 }}
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="发图完成">
                <el-col style="width: 80px;">
                  {{ 发图完成 }}
                </el-col>
                <el-col style="width: 80px;">
                  {{ 机床设计实际完成时间 }}
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="采购完成">
                <el-col style="width: 80px;">
                  {{ 采购完成 }}
                </el-col>
                <el-col style="width: 80px;">
                  {{ 采购实际完成时间 }}
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="备料完成">
                <el-col style="width: 80px;">
                  {{ 备料完成 }}
                </el-col>
                <el-col style="width: 80px;">
                  {{ 备料实际完成时间 }}
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="制造完成">
                <el-col style="width: 80px;">
                  {{ 制造完成 }}
                </el-col>
                <el-col style="width: 80px;">
                  {{ 机床生产实际完成时间 }}
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="width: 270px">
              <el-form-item label="装配完成">
                <el-col style="width: 80px;">
                  {{ 装配完成 }}
                </el-col>
                <el-col style="width: 80px;">
                  {{ 机床装配实际完成时间 }}
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-col>
    </el-card>

    <el-card>
      <el-table v-loading="loading2" :data="tableData2" :row-class-name="tableRowClassName" style="margin-top: 10px;width: 100%;" border element-loading-text="拼命加载中">
        <el-table-column width="100px" label="计划名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.计划类型名称 }}
          </template>
        </el-table-column>
        <el-table-column width="150px" label="组号" align="center">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column width="300px" label="任务名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.任务名称 }}
          </template>
        </el-table-column>
        <el-table-column width="120px" label="负责人" align="center">
          <template slot-scope="scope">
            {{ scope.row.负责人 }}
          </template>
        </el-table-column>
        <el-table-column label="任务开始时间" align="center" width="150px">
          <template slot-scope="scope">
            {{ scope.row.任务开始时间 ? scope.row.任务开始时间.split(' ')[0] : '-' }}
          </template>
        </el-table-column>
        <el-table-column label="计划完成" align="center" width="150px">
          <template slot-scope="scope">
            {{ scope.row.计划完成时间 ? scope.row.计划完成时间.split(' ')[0] : '-' }}
          </template>
        </el-table-column>
        <el-table-column width="140px" label="计划工期(天)" align="center">
          <template slot-scope="scope">
            {{ scope.row.货期 }}
          </template>
        </el-table-column>
        <el-table-column label="实际完成时间" align="center" width="150px">
          <template slot-scope="scope">
            {{ scope.row.实际完成时间 ? scope.row.实际完成时间.split(' ')[0] : '-' }}
          </template>
        </el-table-column>
        <el-table-column width="140px" label="实际工期(天)" align="center">
          <template slot-scope="scope">
            {{ scope.row.实际完成时间 ? scope.row.实际工期 : '-' }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getProject, getCustomerName, searchgroupName, getToolNum, searchtable, searchTable2 } from '@/api/ManufacturingCenter/ProjectPlanningManagementQuery'
export default {
  data() {
    return {
      Sign: '',
      delivery: '',
      项目流水号: '',
      机床流水号: '',
      项目编号: '',
      设计者: '',
      审图开始: '',
      审图结束: '',
      发图完成: '',
      采购完成: '',
      备料完成: '',
      制造完成: '',
      装配完成: '',
      更新时间: '',
      // /////////////
      审图实际完成时间: '',
      机床设计实际完成时间: '',
      采购实际完成时间: '',
      备料实际完成时间: '',
      机床生产实际完成时间: '',
      机床装配实际完成时间: '',
      machineNum: '',
      jichuang: '',
      title: '',
      tableData2: [],
      loading2: false,
      code: '',
      time_SignStart: '', // 签订开始
      time_SignFinish: '', // 签订结束
      time_deliveryStart: '', // 交货开始
      time_deliveryFinish: '', // 交货结束
      projectValue: '',
      project: [], // 项目名称
      CustomerNameValue: '',
      CustomerName: [], // 客户名称
      toolNumValue: '',
      toolNum: [], // 机床
      groupNum: [],
      loading: false,
      tableData: [], // 表格数据
      total: null, // 总条数
      pageSize: 10, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {
    this.fetchData()
    this.getCustomerName()
    this.searchTable()
  },
  methods: {
    fetchData() {
      this.projectValue = ''
      this.project = []
      getProject().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.project.push({
            label: response.data[i].项目名称,
            value: response.data[i].项目流水号
          })
        }
      })
    },
    typeChange() {
      this.toolNumValue = ''
      this.toolNum = []
      getToolNum(1, this.projectValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.toolNum.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    groupChange(row, index) {
      if (row.组件流水号 !== '') {
        searchgroupName(row.组件流水号).then(response => {
          this.tableData2[index].任务名称 = response.data[0].组件名称
        })
      }
    },
    getCustomerName() {
      this.CustomerNameValue = ''
      this.CustomerName = []
      getCustomerName().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.CustomerName.push({
            label: response.data[i].客户名称,
            value: response.data[i].客户流水号
          })
        }
      })
    },
    // 查询表格数据
    searchTable() {
      this.loading = true
      this.tableData = []
      this.tableData2 = []
      this.radio = ''
      this.项目流水号 = ''
      this.机床流水号 = ''
      this.项目编号 = ''
      this.设计者 = ''
      this.审图开始 = ''
      this.审图结束 = ''
      this.发图完成 = ''
      this.采购完成 = ''
      this.备料完成 = ''
      this.制造完成 = ''
      this.装配完成 = ''
      this.更新时间 = ''
      this.jichuang = ''
      this.code = ''
      if (this.projectValue !== '' && this.projectValue !== null) { this.projectValuecheck = 1 } else { this.projectValuecheck = 0 }
      if (this.CustomerNameValue !== '' && this.CustomerNameValue !== null) { this.CustomerNameValuecheck = 1 } else { this.CustomerNameValuecheck = 0 }
      if (this.toolNumValue !== '' && this.toolNumValue !== null) { this.toolNumValuecheck = 1 } else { this.toolNumValuecheck = 0 }
      this.Sign ? this.time_Signcheck = 1 : (this.time_Signcheck = 0, this.Sign = '')
      this.delivery ? this.time_deliverycheck = 1 : (this.time_deliverycheck = 0, this.delivery = '')
      searchtable(this.projectValuecheck, this.projectValue, this.toolNumValuecheck, this.toolNumValue, this.CustomerNameValuecheck, this.CustomerNameValue, this.time_Signcheck, this.Sign[0], this.Sign[1], this.time_deliverycheck, this.delivery[0], this.delivery[1], this.pageCurrent, this.pageSize).then(response => {
        if (response.data.total === 0) {
          this.loading = false
        } else {
          this.tableData = response.data.rows
          this.total = response.data.total
        }
      }).then(() => {
        this.loading = false
      })
    },
    rowClick(row) {
      this.设计者 = row.机床设计者 ? row.机床设计者.split(' ')[0] : '-'
      this.审图开始 = row.审图计划开始时间 ? row.审图计划开始时间.split(' ')[0] : '-'
      this.审图结束 = row.审图计划完成时间 ? row.审图计划完成时间.split(' ')[0] : '-'
      this.发图完成 = row.机床设计完成时间 ? row.机床设计完成时间.split(' ')[0] : '-'
      this.采购完成 = row.采购完成时间 ? row.采购完成时间.split(' ')[0] : '-'
      this.备料完成 = row.备料完成时间 ? row.备料完成时间.split(' ')[0] : '-'
      this.制造完成 = row.机床生产完成时间 ? row.机床生产完成时间.split(' ')[0] : '-'
      this.装配完成 = row.机床装配完成时间 ? row.机床装配完成时间.split(' ')[0] : '-'
      this.更新时间 = row.更新 ? row.更新.split(' ')[0] : '-'
      // ////////////////////////////
      this.审图实际完成时间 = row.审图实际完成时间 ? row.审图实际完成时间.split(' ')[0] : '-'
      this.机床设计实际完成时间 = row.机床设计实际完成时间 ? row.机床设计实际完成时间.split(' ')[0] : '-'
      this.采购实际完成时间 = row.采购实际完成时间 ? row.采购实际完成时间.split(' ')[0] : '-'
      this.备料实际完成时间 = row.备料实际完成时间 ? row.备料实际完成时间.split(' ')[0] : '-'
      this.机床生产实际完成时间 = row.机床生产实际完成时间 ? row.机床生产实际完成时间.split(' ')[0] : '-'
      this.机床装配实际完成时间 = row.机床装配实际完成时间 ? row.机床装配实际完成时间.split(' ')[0] : '-'
      this.openDialog(row)
    },
    // 查询表格2数据
    openDialog(row) {
      this.loading2 = true
      this.tableData2 = []
      searchTable2(row.机床流水号).then(response => {
        if (response.data.length !== 0) {
          this.tableData2 = response.data
        }
      }).then(() => {
        this.loading2 = false
      })
    },
    // 考核状态变色
    tableRowClassName({ row, rowIndex }) {
      if (row.计划类型名称 === '设计') {
        return 'PPMQHairDrawing'
      } else if (row.计划类型名称 === '采购') {
        return 'PPMQPurchase'
      } else if (row.计划类型名称 === '备料') {
        return 'PPMQSpareParts'
      } else if (row.计划类型名称 === '制造') {
        return 'PPMQManufacture'
      } else if (row.计划类型名称 === '装配') {
        return 'PPMQassembling'
      }
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}
</script>
<style scoped>
  span{
    margin: 10px 0 10px 10px;
  }
  .el-pagination{
    background-color: white;
  }
</style>
<style>
  .PPMQHairDrawing{
    background: rgb(189,215,238) !important;
  }
  .PPMQPurchase{
    background: rgb(248,203,173) !important;
  }
  .PPMQSpareParts{
    background: rgb(201,201,201) !important;
  }
  .PPMQManufacture{
    background: rgb(255,230,153) !important;
  }
  .PPMQassembling{
    background: rgb(169,208,142) !important;
  }
  .demo-ruleForm1 .el-form-item {
    margin-bottom: 0px
  }
  .bold-font .el-table{
    font: bold 20px arial!important;
    margin: 0 0 10px 0;
    /*color: white;*/
  }
  .bold-font{
    /*color: ghostwhite;*/
    font: bold 22px arial!important;
    padding: 5px;
  }
</style>
