<template>
  <div class="app-container">
    <el-card>
      <el-table v-loading="" :data="tableData1" border style="width: 100%;height: 100%;" height="300px" size="mini">
        <el-table-column label="交换单编号" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.交换单编号 }}
          </template>
        </el-table-column>
        <el-table-column label="交换件名称" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.交换件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="被交换件名称" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.被交换件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="交换数量" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.交换数量 }}
          </template>
        </el-table-column>
        <el-table-column label="申请人" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="申请时间" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.申请时间 }}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.备注 }}
          </template>
        </el-table-column>
        <el-table-column label="审核" align="center" min-width="200">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-check" @click="yesApproval(scope.row)">通过</el-button>
            <el-button type="danger" size="mini" icon="el-icon-close" @click="noApproval(scope.row)">不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize1"
          :total="total1"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchExchangePart, approvalExchangepart, disappExchangepart } from '@/api/Inventory/ExchangeApproval'
import { mapGetters } from 'vuex'

export default {
  name: '', // 财务审核
  data() {
    return {
      tableData1: [],
      pageSize1: 10,
      pageCurrent1: 1,
      total1: 0,
      tableData2: [],
      pageSize2: 10,
      pageCurrent2: 1,
      total2: 0,
      gridData: []
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.searchTable1()
    },
    searchTable1() {
      searchExchangePart(this.pageCurrent1, this.pageSize1).then(response => {
        this.tableData1 = response.data.rows
        this.total1 = response.data.total
        console.log(response)
      })
    },
    handleSizeChange1(val) {
      this.pageSize1 = val
      this.pageCurrent1 = 1
      this.searchTable1()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchTable1()
    },
    handleSizeChange2(val) {
      this.pageSize2 = val
      this.pageCurrent2 = 1
      this.searchTable2()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.searchTable2()
    },
    // searchTable02(row) { // 查看详情（请款信息包含的合同）
    //   searchRequsetFundDetail(row.离线合同请款流水号).then(response => {
    //     this.gridData = response.data
    //   })
    // },
    yesApproval(row) { // 通过审核
      this.$confirm('确定审核通过?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        approvalExchangepart(row.交换单流水号, row.交换件物料流水号, row.被交换件物料流水号, row.交换件组件零件流水号, row.被交换件组件零件流水号, row.交换件采购合同明细流水号, row.货位流水号, row.被交换货位流水号, row.交换数量).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('执行成功')
            this.searchTable1()
          } else { this.$message.error('执行失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消操作'
        })
      })
    },
    noApproval(row) { // 不通过审核
      this.$prompt('请输入不通过原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        disappExchangepart(row.交换单流水号, value).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('执行成功')
            this.searchTable1()
          } else { this.$message.error('执行失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消操作'
        })
      })
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-select{
    width:200px
  }
  .el-input{
    width:200px
  }
  span{
    margin: 10px 0 10px 10px;
  }
  .searchForm .el-form-item{
    margin-bottom: 5px;
  }
  .el-tag{
    margin: 0
  }
</style>
