<template>
  <div class="app-container">
    <el-card style="width: 72%">
      <div style="margin-top: 7px; margin-bottom: 7px">
        <span>供应商</span>
        <el-select v-model="supplierNameValue" style="width:200px" placeholder="供应商" size="small" filterable clearable>
          <el-option
            v-for="item in supplierNames"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span>零件图号</span>
        <el-input v-model="partNumber" size="small" placeholder="零件图号" style="width: 160px" clearable/>
        <span>备料状态</span>
        <el-select v-model="MaterialsValue" placeholder="请选择备料状态" filterable size="small" style="width: 100px" clearable>
          <el-option
            v-for="item in Materials"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-button icon="el-icon-search" type="success" size="small" @click="pageCurrent = 1;pageSize = 100;getTableData()">查询</el-button>
      </div>
    </el-card>
    <el-card style="width: 72%">
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        stripe
        size="mini"
        style="width: 100%"
        height="760">
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50"/>
        <el-table-column
          label="备料状态"
          align="center"
          width="80px">
          <template slot-scope="scope">
            <el-tag v-if="Number(scope.row.是否到货)===0" type="warning" size="mini">未到</el-tag>
            <el-tag v-if="Number(scope.row.是否到货)===1" type="primary" size="mini">已到</el-tag>
            <el-tag v-if="Number(scope.row.是否到货)===2" type="success" size="mini">已结</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="供应商"
          align="center"
          min-width="210px">
          <template slot-scope="scope">{{ scope.row.供应商名称 }}</template>
        </el-table-column>
        <el-table-column
          label="物料编码"
          align="center"
          min-width="180px">
          <template slot-scope="scope">{{ scope.row.物料编码 }}</template>
        </el-table-column>
        <el-table-column
          label="物料名称"
          align="center"
          width="120px">
          <template slot-scope="scope">{{ scope.row.零件名称 }}</template>
        </el-table-column>
        <el-table-column
          label="材料"
          width="100"
          align="center">
          <template slot-scope="scope">{{ scope.row.材料 }}</template>
        </el-table-column>
        <el-table-column label="备料件数" align="center" width="70">
          <template slot-scope="scope">
            {{ scope.row.采购数量 }}
          </template>
        </el-table-column>
        <el-table-column label="备料时间" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.下单日期 ? scope.row.下单日期.split(' ')[0] : '' }}
          </template>
        </el-table-column>
        <el-table-column
          label="到货件数"
          align="center"
          width="70">
          <template slot-scope="scope">{{ scope.row.到货数量 }}</template>
        </el-table-column>
        <el-table-column
          label="到货时间"
          align="center"
          width="100">
          <template slot-scope="scope">{{ scope.row.日期 ? scope.row.日期.split(' ')[0] : '' }}</template>
        </el-table-column>
        <el-table-column
          label="结算时间"
          align="center"
          width="100">
          <template slot-scope="scope">{{ scope.row.开票时间 ? scope.row.开票时间.split(' ')[0] : '' }}</template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40, 100]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChanges"
          @current-change="handleCurrentChanges"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchSupplier, searchTable } from '@/api/WorkshopProcurement/OutsourcingMaterialsSearch'
export default {
  name: 'Index',
  data() {
    return {
      supplierNameValue: '',
      supplierNames: [],
      partNumber: '',
      MaterialsValue: '',
      Materials: [{
        value: 0,
        label: '未到'
      }, {
        value: 1,
        label: '已到'
      }, {
        value: 2,
        label: '已结'
      }],
      loading: false,
      total: 0,
      tableData: [],
      pageCurrent: 1,
      pageSize: 100
    }
  },
  created() {
    this.fetchData()
    this.getTableData()
  },
  methods: {
    fetchData() {
      searchSupplier(0, '', 0, '', 0, '', 0, '', 0, '', 0, '', 0, '', 0, '', 0, '', 0, '', 0, '', 0, '').then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.supplierNames.push({
            label: response.data[i].供应商名称,
            value: response.data[i].供应商流水号
          })
        }
      })
    },
    getTableData() {
      this.loading = true
      let check, check1, check2
      this.supplierNameValue ? check = 1 : check = 0
      this.partNumber ? check1 = 1 : check1 = 0
      if (this.MaterialsValue !== '' && this.MaterialsValue !== null) {
        check2 = 1
      } else {
        check2 = 0
      }
      console.log(this.MaterialsValue, check2, 123)
      searchTable(check, this.supplierNameValue, check1, this.partNumber, check2, this.MaterialsValue, this.pageSize, this.pageCurrent).then(response => {
        this.tableData = response.data.rows
        this.total = response.data.total
        this.loading = false
      })
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.getTableData()
    },
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.getTableData()
    }
  }
}
</script>

<style scoped>
  span{
    margin: 0px;
  }
  .wrapper{
    width: 225px;
    height: 50px;
    overflow: hidden;
    border: 1px solid #b8c7d9;
    float: left;
    margin: 0px;
  }
  .content{
    position: relative;
    padding: 8px 8px 0 8px;
  }
  .action{
    position: absolute;
    top: 4px;
    right: 8px;
  }
  .delete{
    padding: 0 5px;
    border-radius: 3px;
    color: #0f84b0;
    font-size: 12px;
  }
  .delete:hover{
    background: -webkit-linear-gradient(top,#0ba9e3,#0099d3);
    color: #fff;
  }
  a{
    text-decoration: none;
  }
  .icon{
    width: 30px;
    height: 30px;
    display: inline-block;
    margin-right: 7px;
    margin-top: 2px;
    font-size: 26px;
  }
  .info{
    position: absolute;
    left: 44px;
    line-height: 30px;
    display: inline-block;
    color: #999;
  }
  .el-card {
    padding: 0px !important;
    margin: 0px !important;
  }
</style>
