<template>
  <div class="app-container">
    <el-card>
      <div>
        <el-row>
          <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" style="margin:0px 10px;width:150px" clearable @change="machineChange">
            <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-select v-model="groupNumberValue" placeholder="组号" style="margin:0px 10px;width:100px" size="small" clearable>
            <el-option
              v-for="item in groupNumber"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-input v-model="PrNum" size="small" placeholder="零件号" clearable style="width: 250px; margin:0px 10px;width:150px"/>
          <el-select v-model="personValue" placeholder="工艺员" size="small" style="margin:0px 10px;width:150px" clearable >
            <el-option
              v-for="item in person"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-button type="success" size="small" style="margin: 0px 10px" icon="el-icon-search" @click="pageCurrent=1;pageSize=300;total=0;searchData()">查询</el-button>
          <el-tooltip effect="dark" content="将零件打回，重新编制工艺定额" placement="top">
            <el-button v-show="true" type="danger" plain style="margin-left: 0px;margin-top: 3px" icon="el-icon-edit" size="small" @click="returnEdit">零件工艺调整</el-button>
          </el-tooltip>
        </el-row>
      </div>
    </el-card>
    <el-row>
      <el-col style="width: 670px">
        <el-card>
          <el-table
            v-loading="loading"
            :data="tableData"
            size="mini"
            height="740"
            style="width: 650px"
            border
            stripe
            highlight-current-row
            @selection-change="handleSelectionChange"
            @row-click="click">
            <el-table-column
              type="selection"
              align="center"
              width="55"/>
            <el-table-column label="机床号" prop="机床图号" align="center" width="120px">
              <template slot-scope="scope">
                {{ scope.row.机床图号 }}
              </template>
            </el-table-column>
            <el-table-column label="组号" prop="组号" align="center" width="70px">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column label="零件图号" prop="零件图号" show-overflow-tooltip align="center" min-width="140px">
              <template slot-scope="scope">
                {{ scope.row.零件图号 }}
              </template>
            </el-table-column>
            <el-table-column label="零件名称" prop="零件名称" show-overflow-tooltip align="center" width="100px">
              <template slot-scope="scope">
                {{ scope.row.零件名称 }}
              </template>
            </el-table-column>
            <el-table-column label="数量" align="center" width="50px">
              <template slot-scope="scope">
                {{ scope.row.批次数量 }}
              </template>
            </el-table-column>
            <el-table-column label="工艺员" prop="工艺员" align="center" width="75px">
              <template slot-scope="scope">
                {{ scope.row.工艺员 }}
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="margin-top: 10px;">
            <el-pagination
              :current-page="pageCurrent"
              :page-sizes="[5, 10, 20, 300]"
              :page-size="pageSize"
              :pager-count="5"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"/>
          </div>
        </el-card>
      </el-col>
      <el-col style="width: 1000px">
        <el-card v-if="tableData2.length">
          <table class="tg">
            <tr>
              <td class="tg-x61c" colspan="4" rowspan="2">江苏高精</td>
              <td class="tg-c3ow" colspan="2" rowspan="2">零件条码</td>
              <td class="tg-c3ow" colspan="3">零件图号</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].零件图号 : '' }}</td>
              <td class="tg-c3ow">数量</td>
            </tr>
            <tr>
              <td class="tg-c3ow" colspan="3">零件名称</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].零件名称 : '' }}</td>
              <td class="tg-c3ow" rowspan="3">{{ tableData2[0] ? tableData2[0].投产数量 : '' }}</td>
            </tr>
            <tr>
              <td class="tg-c3ow" colspan="2">项目名称</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].项目名称 : '' }}</td>
              <td class="tg-c3ow" colspan="2" rowspan="2">{{ tableData2[0] ? 'P' + tableData2[0].工艺计划流水号 : '' }}</td>
              <td class="tg-c3ow" colspan="3">机床</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].机床图号 : '' }}</td>
            </tr>
            <tr>
              <td class="tg-c3ow">材质</td>
              <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].材料 : '' }}</td>
              <td class="tg-c3ow">规格</td>
              <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].原材料规格 : '' }}</td>
              <td class="tg-c3ow" colspan="3">组号</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].组号 : '' }}</td>
            </tr>
            <tr>
              <td class="tg-c3ow">序次</td>
              <td class="tg-c3ow">工艺名称</td>
              <td class="tg-c3ow" colspan="3">工艺要求</td>
              <td class="tg-c3ow">难度系数</td>
              <td class="tg-c3ow">工作者</td>
              <td class="tg-c3ow">单件</td>
              <td class="tg-c3ow">准结</td>
              <td class="tg-c3ow">检查结果</td>
              <td class="tg-c3ow">计划完成日期</td>
              <td class="tg-c3ow">工序条码</td>
            </tr>
            <tr v-for="(value,key) in tableData2" :id="key" :key="key">
              <td class="tg-c3ow">{{ key + 1 }}</td>
              <td class="tg-c3ow">{{ value.工艺名称 }}</td>
              <td class="tg-c3ow" colspan="3">{{ value.工艺要求 }}</td>
              <td class="tg-c3ow">{{ value.工艺难度等级 }}</td>
              <td class="tg-c3ow"/>
              <td class="tg-c3ow">{{ value.单件定额工时 }}</td>
              <td class="tg-c3ow">{{ value.准结定额工时 }}</td>
              <td class="tg-c3ow"/>
              <td class="tg-c3ow">{{ value.计划日期 }}</td>
              <td class="tg-c3ow">{{ value.工序流水号 }}</td>
            </tr>
            <tr>
              <td class="tg-c3ow">工艺员</td>
              <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].工艺员 : '' }}</td>
              <td class="tg-c3ow">定额员</td>
              <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].定额员 : '' }}</td>
              <td class="tg-c3ow">工艺完成</td>
              <td class="tg-c3ow">{{ tableData2[0].工艺实际完成时间 ? tableData2[0].工艺实际完成时间.split(' ')[0] : '' }}</td>
              <td class="tg-c3ow">加工开始</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].机加工开始时间 : '' }}</td>
              <td class="tg-c3ow">加工结束</td>
              <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].机加工结束时间 : '' }}</td>
            </tr>
          </table>
        </el-card>
      </el-col>
    </el-row>
    <!--    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisiblePeople" :title="title" center>-->
    <!--      <div v-if="tableData2.length">-->
    <!--        <table class="tg">-->
    <!--          <tr>-->
    <!--            <td class="tg-x61c" colspan="4" rowspan="2">江苏高精</td>-->
    <!--            <td class="tg-c3ow" colspan="2" rowspan="2">零件条码</td>-->
    <!--            <td class="tg-c3ow" colspan="3">零件图号</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].零件图号 : '' }}</td>-->
    <!--            <td class="tg-c3ow">数量</td>-->
    <!--          </tr>-->
    <!--          <tr>-->
    <!--            <td class="tg-c3ow" colspan="3">零件名称</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].零件名称 : '' }}</td>-->
    <!--            <td class="tg-c3ow" rowspan="3">{{ tableData2[0] ? tableData2[0].投产数量 : '' }}</td>-->
    <!--          </tr>-->
    <!--          <tr>-->
    <!--            <td class="tg-c3ow" colspan="2">项目名称</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].项目名称 : '' }}</td>-->
    <!--            <td class="tg-c3ow" colspan="2" rowspan="2">{{ tableData2[0] ? 'P' + tableData2[0].工艺计划流水号 : '' }}</td>-->
    <!--            <td class="tg-c3ow" colspan="3">机床</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].机床图号 : '' }}</td>-->
    <!--          </tr>-->
    <!--          <tr>-->
    <!--            <td class="tg-c3ow">材质</td>-->
    <!--            <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].材料 : '' }}</td>-->
    <!--            <td class="tg-c3ow">规格</td>-->
    <!--            <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].原材料规格 : '' }}</td>-->
    <!--            <td class="tg-c3ow" colspan="3">组号</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].组号 : '' }}</td>-->
    <!--          </tr>-->
    <!--          <tr>-->
    <!--            <td class="tg-c3ow">序次</td>-->
    <!--            <td class="tg-c3ow">工艺名称</td>-->
    <!--            <td class="tg-c3ow" colspan="3">工艺要求</td>-->
    <!--            <td class="tg-c3ow">难度系数</td>-->
    <!--            <td class="tg-c3ow">工作者</td>-->
    <!--            <td class="tg-c3ow">单件</td>-->
    <!--            <td class="tg-c3ow">准结</td>-->
    <!--            <td class="tg-c3ow">检查结果</td>-->
    <!--            <td class="tg-c3ow">计划完成日期</td>-->
    <!--            <td class="tg-c3ow">工序条码</td>-->
    <!--          </tr>-->
    <!--          <tr v-for="(value,key) in tableData2" :id="key" :key="key">-->
    <!--            <td class="tg-c3ow">{{ key + 1 }}</td>-->
    <!--            <td class="tg-c3ow">{{ value.工艺名称 }}</td>-->
    <!--            <td class="tg-c3ow" colspan="3">{{ value.工艺要求 }}</td>-->
    <!--            <td class="tg-c3ow">{{ value.工艺难度等级 }}</td>-->
    <!--            <td class="tg-c3ow"/>-->
    <!--            <td class="tg-c3ow">{{ value.单件定额工时 }}</td>-->
    <!--            <td class="tg-c3ow">{{ value.准结定额工时 }}</td>-->
    <!--            <td class="tg-c3ow"/>-->
    <!--            <td class="tg-c3ow">{{ value.计划日期 }}</td>-->
    <!--            <td class="tg-c3ow">{{ value.工序流水号 }}</td>-->
    <!--          </tr>-->
    <!--          <tr>-->
    <!--            <td class="tg-c3ow">工艺员</td>-->
    <!--            <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].工艺员 : '' }}</td>-->
    <!--            <td class="tg-c3ow">定额员</td>-->
    <!--            <td class="tg-c3ow">{{ tableData2[0] ? tableData2[0].定额员 : '' }}</td>-->
    <!--            <td class="tg-c3ow">工艺完成</td>-->
    <!--            <td class="tg-c3ow">{{ tableData2[0].工艺实际完成时间 ? tableData2[0].工艺实际完成时间.split(' ')[0] : '' }}</td>-->
    <!--            <td class="tg-c3ow">加工开始</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].机加工开始时间 : '' }}</td>-->
    <!--            <td class="tg-c3ow">加工结束</td>-->
    <!--            <td class="tg-c3ow" colspan="2">{{ tableData2[0] ? tableData2[0].机加工结束时间 : '' }}</td>-->
    <!--          </tr>-->
    <!--        </table>-->
    <!--      </div>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import { initMachineProject, searchgroup, initPerson, search, searchtable1,
  returnEdit } from '@/api/ManufacturingCenter/PartWorkCraftSelect_rdlc'

export default {
  data() {
    return {
      partNumValue: [],
      machineNumberValue: '',
      machineNumber: [],
      groupNumberValue: '',
      groupNumber: [],
      personValue: '',
      person: [],
      pageCurrent: 1,
      pageSize: 300,
      total: 0,
      tableData: [],
      loading: false,
      PrNum: '',
      tableData2: [],
      tableData3: [],
      dialogFormVisiblePeople: false,
      title: '',
      机床号: '',
      组号: '',
      零件图号: '',
      零件名称: '',
      投产数量: '',
      材料: '',
      原材料规格: '',
      工艺员: '',
      定额员: '',
      日期: ''
    }
  },
  created() {
    this.fetchData()
    this.searchData()
  },
  methods: {
    returnEdit() { // 在制零件工艺修改
      if (this.partNumValue.length === 0) {
        this.$message.error('请选择零件')
      } else {
        this.$confirm(`此操作会将零件打回至未编制状态, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          returnEdit(this.partNumValue).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('打回成功')
              this.partNumValue = []
              this.searchData()
              this.tableData2 = []
            } else {
              this.$message.error('打回失败')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          })
        })
      }
    },
    fetchData() {
      initMachineProject().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].机床流水号
          })
        }
      })
      initPerson().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.person.push({
            label: 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].组件流水号
          })
        }
      })
    },
    searchData() {
      this.loading = true
      let check1, check2, check3, check4
      this.machineNumberValue ? check1 = 1 : check1 = 0
      this.groupNumberValue ? check2 = 1 : check2 = 0
      this.PrNum ? check3 = 1 : check3 = 0
      this.personValue ? check4 = 1 : check4 = 0
      search(this.pageCurrent, this.pageSize, check1, this.machineNumberValue, check2, this.groupNumberValue, check3, this.PrNum, check4, this.personValue).then(response => {
        this.tableData = response.data.rows
        this.total = response.data.total
        this.loading = false
      })
    },
    click(row) {
      this.零件图号 = row.零件图号
      searchtable1(row.工艺计划流水号).then(response => {
        this.tableData2 = response.data
        this.dialogFormVisiblePeople = true
        this.title = row.零件名称 + '工艺流程单'
      })
    },
    handleSelectionChange(val) {
      this.partNumValue = []
      for (let i = 0; i < val.length; i++) {
        this.partNumValue.push(val[i].工艺计划流水号)
      }
    },
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchData()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchData()
    }
  }
}
</script>
<style>
  td{
    width: 100px;
    height: 30px;
    text-align:center;
  }
  .tg  {border-collapse:collapse;border-spacing:0;margin: 0 auto}
  .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
  .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
  .tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}
  .tg .tg-x61c{font-weight:bold;font-size:28px;border-color:inherit;text-align:center;vertical-align:top}
</style>
<style scoped>
</style>
