<template>
  <div class="app-container">
    <el-card style="margin-top: 5px">
      <el-row>
        <el-col :span="7">
          <span>原材料名称:</span>
          <el-input v-model="RawMaterialName" placeholder="原材料名称" size="mini" clearable style="width: 120px"/>
          <el-button type="success" icon="el-icon-search" size="mini" style="margin-left: 10px" @click="pageCurrent=1;searchTableData()">查询</el-button>
          <el-table :data="tableData" style="margin-top: 15px;width: 100%" height="500" size="mini" border @selection-change="handleSelectionChange">
            <el-table-column type="selection" align="center" width="55"/>
            <el-table-column align="center" label="原材料名称">
              <template slot-scope="scope">
                {{ scope.row.原材料名称 }}
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col :span="16" style="margin-left: 20px">
          <span>原材料名称:</span>
          <el-input v-model="RawMaterialName" placeholder="原材料名称" size="mini" clearable style="width: 120px"/>
          <el-button type="success" icon="el-icon-search" size="mini" style="margin-left: 10px" @click="pageCurrent=1;searchTableData()">查询</el-button>
          <el-button type="primary" icon="el-icon-circle-plus-outline" size="mini" @click="handleAdd()">增加</el-button>
          <el-table :data="tableData" style="margin-top: 15px;width: 100%" height="500" size="mini" highlight-current-row border>
            <el-table-column align="center" label="原材料名称">
              <template slot-scope="scope">
                {{ scope.row.原材料名称 }}
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="margin: 10px;">
            <el-pagination
              :current-page="pageCurrent"
              :page-sizes="[10, 20, 30, 40, 50]"
              :page-size="pageSize"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"/>
          </div>
        </el-col>
      </el-row>
      <el-row style="margin-top: 10px">
        <el-table :data="tableData" style="width: 100%" height="500" size="mini" highlight-current-row border>
          <el-table-column align="center" label="原材料名称">
            <template slot-scope="scope">
              {{ scope.row.原材料名称 }}
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin: 10px;">
          <el-pagination
            :current-page="pageCurrent"
            :page-sizes="[10, 20, 30, 40, 50]"
            :page-size="pageSize"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import { searchTableData } from '@/api/ManufacturingCenter/SparePartsPurchase'

export default {
  data() {
    return {
      RawMaterialNumber: '',
      RawMaterialName: '',
      param: 0,
      tableData: [],
      pageCurrent: 1,
      pageSize: 10,
      total: null,
      dialogFormVisible: false,
      title: '',
      form: {
        RawMaterialName: ''
      },
      rules: {
        RawMaterialName: [{ required: true, message: '请输入物料名称', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.searchTableData()
  },
  methods: {
    // 获取原材料
    searchTableData() {
      searchTableData(this.RawMaterialName, this.pageCurrent, this.pageSize).then(response => {
        this.tableData = response.data.rows
        this.total = parseInt(response.data.total)
      })
    },
    // tabledata分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTableData()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTableData()
    },
    // 多选
    handleSelectionChange(val) {
      this.materielGroup = []
      for (let i = 0; i < val.length; i++) {
        this.materielGroup.push(val[i].物料流水号)
      }
    }
  }
}
</script>

<style scoped>
  span {
    margin: 10px 0px 10px 10px;
  }
  .el-select{
    width:190px
  }
  .el-input{
    width:190px
  }
</style>
