<template>
  <div class="app-container">

    <el-card>
      <span>零件号:</span>
      <el-input v-model="partNum" placeholder="零件号" size="small" clearable style="width:200px"/>
      <span>厂家:</span>
      <el-select v-model="ManufacturerNameValue" placeholder="选择外协厂家" filterable clearable size="small" style="width:190px;margin:10px;">
        <el-option
          v-for="item in ManufacturerName"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 10px;" @click="PageCurrent=1;PageSize=10;searchTable()">查询</el-button>
      <el-table v-loading="loading0" :data="tableData" height="550" size="mini" stripe style="width: 100%;" border element-loading-text="拼命加载中">
        <el-table-column label="序号" type="index" align="center" fixed="left" width="50"/>
        <el-table-column label="付款" prop="实际付款时间" width="65" align="center" fixed="left">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.实际付款时间!==''" type="success" size="small">已付</el-tag>
            <el-tag v-else type="info" size="small">未付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="到货" prop="单据状态" width="65" align="center" fixed="left">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.单据状态==='3'" type="success" size="small">已到</el-tag>
            <el-tag v-else type="info" size="small">未到</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="单据号" prop="表单号" align="center" width="180px" fixed="left">
          <template slot-scope="scope">
            {{ scope.row.表单号 }}
          </template>
        </el-table-column>
        <el-table-column label="外协厂家" prop="外协厂家名称" align="center" min-width="190px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.外协厂家名称 }}
          </template>
        </el-table-column>
        <el-table-column label="总价" align="center" min-width="70px">
          <template slot-scope="scope">
            {{ scope.row.总价 }}
          </template>
        </el-table-column>
        <el-table-column label="质量扣款" align="center" min-width="70px">
          <template slot-scope="scope">
            {{ scope.row.扣款_质量 }}
          </template>
        </el-table-column>
        <el-table-column label="计划扣款" align="center" min-width="70px">
          <template slot-scope="scope">
            {{ scope.row.扣款_计划 }}
          </template>
        </el-table-column>
        <el-table-column label="其他扣款" align="center" min-width="70px">
          <template slot-scope="scope">
            {{ scope.row.扣款_其他 }}
          </template>
        </el-table-column>
        <el-table-column label="应付金额" align="center" min-width="70px">
          <template slot-scope="scope">
            {{ scope.row.应付总额 }}
          </template>
        </el-table-column>
        <el-table-column label="任务下达日期" prop="任务下达日期" align="center" min-width="125px">
          <template slot-scope="scope">
            {{ scope.row.任务下达日期 }}
          </template>
        </el-table-column>
        <el-table-column label="外协员" prop="外协员姓名" align="center" width="90px">
          <template slot-scope="scope">
            {{ scope.row.外协员姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="扣款说明" align="center" min-width="120px">
          <template slot-scope="scope">
            {{ scope.row.扣款说明 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!loading0"
          :current-page="PageCurrent"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchOutHelpState } from '@/api/Outsourcing/OutsourcingStatus'
export default {
  data() {
    return {
      loading0: false,
      partNum: '', // 零件图号
      check: '',
      tableData: [],
      active: [],
      PageCurrent: 1,
      PageSize: 10,
      total: 0
    }
  },
  methods: {
    searchTable() {
      this.loading0 = true
      this.total = 0
      this.tableData = []
      this.active = []
      if (this.partNum !== '') {
        this.check = 1
      } else { this.check = 0 }
      searchOutHelpState(this.PageCurrent, this.PageSize, this.check, this.partNum).then(response => {
        if (response.data.rows.length !== 0) {
          this.total = response.data.total
          this.tableData = response.data.rows
          for (let i = 0; i < response.data.rows.length; i++) {
            this.active.push(parseInt(response.data.rows[i].外协零件状态) + 1)
          }
        } else {
          this.loading0 = false
        }
      }).then(() => {
        this.loading0 = false
      })
    },
    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;
  }
</style>
