<template>
  <div class="app-container">
    <el-card>
      <!--      <el-input v-model="billNames" clearable filterable size="small" placeholder="供应商或合同编号" style="width: 200px;margin: 5px"/>-->
      <el-select v-model="supplierValue" placeholder="供应商" filterable size="small" style="margin-left: 5px" clearable @change="totalSum=0;totalPay=0;totalDebt=0;">
        <el-option
          v-for="item in supplier"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-select v-model="personValue" placeholder="采购员" size="small" style="width: 120px" clearable>
        <el-option
          v-for="item in person"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span style="margin-left: 0">审批时间:</span>
      <el-date-picker
        v-model="dateRange"
        size="small"
        type="daterange"
        align="center"
        style="width: 300px"
        value-format="yyyy-MM-dd"
        format="yyyy-MM-dd"
        range-separator="～"
        start-placeholder="开始日期"
        end-placeholder="结束日期"/>
      <el-button type="primary" plain size="small" icon="el-icon-search" style="margin-left: 10px" @click="total1=0;pageCurrent1=1;pageSize1=50;searchTable1()">查询</el-button>
      <el-radio v-model="radio" label="1" style="margin: 0 0 0 10px">全部</el-radio>
      <el-radio v-model="radio" label="2" style="margin: 0 0 0 10px">通过</el-radio>
      <el-radio v-model="radio" label="3" style="margin: 0 0 0 10px">未过</el-radio>
      <el-button type="success" size="small" icon="el-icon-download" style="margin-left:10px;margin-top: 3px;margin-right: 20px;float: right" plain @click="exportTable('')">导出</el-button>
    </el-card>
    <el-card style="margin-top: 5px">
      <el-table v-loading="loading1" :data="tableData1" size="mini" border stripe style="width: 100%" height="600px" highlight-current-row>
        <el-table-column label="供应商" align="center" min-width="150" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.供应商名称 }}
          </template>
        </el-table-column>
        <el-table-column label="请款人" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="请款金额(元)" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.请款金额 }}
          </template>
        </el-table-column>
        <el-table-column label="请款时间" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.请款时间 ? scope.row.请款时间.split(' ')[0] : '' }}
          </template>
        </el-table-column>
        <!--<el-table-column label="审核时间" align="center" min-width="60">-->
        <!--<template slot-scope="scope">-->
        <!--{{ scope.row.审核时间 ? scope.row.审核时间.split(' ')[0] : '' }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="审核人" align="center" min-width="60">-->
        <!--<template slot-scope="scope">-->
        <!--{{ scope.row.审核人姓名 }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="审核结果" align="center" min-width="60">-->
        <!--<template slot-scope="scope">-->
        <!--{{ scope.row.审核情况内容 }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column label="审批人" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.审批人 }}
          </template>
        </el-table-column>
        <el-table-column label="审批时间" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.审批时间 ? scope.row.审批时间.split(' ')[0] : '' }}
          </template>
        </el-table-column>
        <el-table-column label="审批结果" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.审批情况内容 }}
          </template>
        </el-table-column>
        <el-table-column label="未过原因" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.未通过审批原因 === '通过' ? '' : scope.row.未通过审批原因 }}
          </template>
        </el-table-column>
        <el-table-column label="付款人" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.付款人 }}
          </template>
        </el-table-column>
        <el-table-column label="付款时间" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.付款时间 ? scope.row.付款时间.split(' ')[0] : '' }}
          </template>
        </el-table-column>
        <el-table-column label="付款情况" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.付款情况内容 }}
          </template>
        </el-table-column>
        <el-table-column label="未过原因" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.未付款原因 === '通过' ? '' : scope.row.未付款原因 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="90px" fixed="right">
          <template slot-scope="scope">
            <el-tooltip :open-delay="1000" effect="dark" content="查看详情" placement="top">
              <div style="display: inline-block">
                <el-button type="text" size="mini" @click="searchTable2(scope.row)">详情</el-button>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent1"
          :page-sizes="[50, 100, 150, 200]"
          :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>

    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" title="请款信息明细" center width="800px">
      <el-table :data="gridData" highlight-current-row size="mini" show-summary>
        <el-table-column width="50" align="center" type="index" label="序号"/>
        <el-table-column min-width="120" align="center" label="采购合同编号">
          <template slot-scope="scope">
            {{ scope.row.采购合同编号 }}
          </template>
        </el-table-column>
        <el-table-column min-width="120" align="center" label="已付金额(元)" prop="已付金额">
          <template slot-scope="scope">
            {{ scope.row.已付金额.toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column min-width="120" align="center" label="请款金额(元)" prop="请款金额">
          <template slot-scope="scope">
            {{ scope.row.请款金额.toFixed(2) }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { initBuyer, searchTable1, searchSupplier } from '@/api/WorkshopProcurement/RequestApprovalQuery2'
import { searchRequsetFundDetail } from '@/api/WorkshopProcurement/PurchaseContractRequestFund1'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      radio: '1',
      billNames: '',
      supplier: [],
      supplierValue: '',
      person: [],
      personValue: '',
      dateRange: '',
      total1: 0,
      pageCurrent1: 1,
      pageSize1: 50,
      tableData1: [],
      loading1: false,
      dialogFormVisible: false,
      gridData: []
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.fetchData()
    this.searchTable1()
    this.searchSupplier()
  },
  methods: {
    searchSupplier() {
      this.supplier = []
      searchSupplier().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.supplier.push({
            label: response.data[i].供应商名称,
            value: response.data[i].供应商流水号
          })
        }
      })
    },
    fetchData() {
      this.person = []
      initBuyer().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.person.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
    },
    searchTable1() {
      this.loading1 = true
      var check1, check2
      this.supplierValue ? check1 = 1 : check1 = 0
      this.dateRange ? check2 = 1 : (check2 = 0, this.dateRange = '')
      searchTable1(this.radio, check1, this.supplierValue, check2, this.dateRange[0], this.dateRange[1], this.pageCurrent1, this.pageSize1).then(response => {
        console.log(response.data, 123)
        this.loading1 = false
        this.tableData1 = response.data.rows
        this.total1 = response.data.total
      })
    },
    searchTable2(row) { // 查看详情（请款信息包含的合同）
      this.gridData = []
      this.dialogFormVisible = true
      searchRequsetFundDetail(row.采购合同请款流水号).then(response => {
        this.gridData = response.data
      })
    },
    exportTable() {
      var check1, check2
      this.supplierValue ? check1 = 1 : check1 = 0
      this.dateRange ? check2 = 1 : (check2 = 0, this.dateRange = '')
      var param = []
      param[0] = ['查询全部', this.radio]
      param[1] = ['供应商名称_check', check1]
      param[2] = ['供应商名称', this.supplierValue]
      param[3] = ['时间段_check', check2]
      if (check2 === 0) {
        param[4] = ['开始时间', '']
        param[5] = ['结束时间', '']
      } else {
        param[4] = ['开始时间', this.dateRange[0]]
        param[5] = ['结束时间', this.dateRange[1]]
      }
      var Data = this.CreateData('2001', '报表_车间采购管理_采购合同_请款审批_查询数据', param)
      this.exportExcel_NPOI(Data)
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchTable1()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchTable1()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 0px;
  }
  .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>
