<template>
  <div class="app-container">
    <el-card>
      <el-table :data="tableData1" highlight-current-row height="550" style="width: 100%;" size="mini" border>
        <el-table-column label="序号" type="index" align="center" width="50"/>
        <el-table-column label="项目名称" align="center" width="200px">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="申请人" align="center" width="80px">
          <template slot-scope="scope">
            {{ scope.row.申请人姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="原物料" align="center">
          <el-table-column label="原物料名称" align="center" min-width="150px">
            <template slot-scope="scope">
              {{ scope.row.原物料名称 }}
            </template>
          </el-table-column>
          <el-table-column label="原物料规格" align="center" min-width="150px">
            <template slot-scope="scope">
              {{ scope.row.原物料规格 }}
            </template>
          </el-table-column>
          <el-table-column label="原物料型号" align="center" min-width="150px">
            <template slot-scope="scope">
              {{ scope.row.原物料型号 }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="新物料" align="center">
          <el-table-column label="新物料名称" align="center" min-width="150px">
            <template slot-scope="scope">
              {{ scope.row.新物料名称 }}
            </template>
          </el-table-column>
          <el-table-column label="新物料规格" align="center" min-width="150px">
            <template slot-scope="scope">
              {{ scope.row.新物料规格 }}
            </template>
          </el-table-column>
          <el-table-column label="新物料型号" align="center" min-width="150px">
            <template slot-scope="scope">
              {{ scope.row.新物料型号 }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="是否同意修改" width="200px" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              class="el-icon-edit"
              @click="handleEdit1(scope.$index, scope.row)">同意</el-button>
            <el-button
              size="mini"
              type="danger"
              class="el-icon-edit"
              @click="handleEdit2(scope.$index, scope.row)">不同意</el-button>
          </template>
        </el-table-column>

      </el-table>
      <div class="block">
        <el-pagination
          v-if="!loading1"
          :current-page="pageCurrent1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize1"
          :total="total1"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchTable, edit } from '@/api/PurchasingCenter/PurchaseMaterielModify'
import { mapGetters } from 'vuex'

export default {
  name: '', // 采购物料修改
  data() {
    return {
      loading1: false,
      tableData1: [], // 表格数据
      total1: null, // 总条数
      pageSize1: 10, // 每页显示条数
      pageCurrent1: 1
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.searchTable()
  },
  methods: {
    searchTable() {
      this.loading1 = true
      this.tableData1 = []
      searchTable(this.pageCurrent1, this.pageSize1).then(response => {
        console.log(response.data)
        if (response.data.total === 0) {
          this.loading1 = false
        } else {
          this.tableData1 = response.data.rows
          this.total1 = response.data.total
        }
      }).then(() => {
        this.loading1 = false
      })
    },
    handleEdit1(index, row) {
      edit(row.组件零件流水号, row.标准件和外购件流水号, row.物料变更记录流水号, 1, this.id, row.原物料流水号).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            type: 'success',
            message: '信息更新成功!'
          })
          this.searchTable()
        } else {
          this.$message.error('信息更新失败')
        }
      })
    },
    handleEdit2(index, row) {
      edit(row.组件零件流水号, row.标准件和外购件流水号, row.物料变更记录流水号, 2, this.id, row.原物料流水号).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            type: 'success',
            message: '信息更新成功!'
          })
          this.searchTable()
        } else {
          this.$message.error('信息更新失败')
        }
      })
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchTable()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchTable()
    }
  }
}
</script>

<style scoped>
  span{
    margin: 10px 0 10px 10px;
  }
  .el-card{
    margin-bottom: 15px;
  }
</style>
