<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <span>合同号:</span>
        <el-select v-model="contractNumValue" placeholder="合同号" size="small" filterable clearable>
          <el-option
            v-for="item in contractNum"
            :key="item.value"
            :label="item.label"
            :value="item.value">
            <div style="float: left">{{ item.label }}</div>
            <div style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</div>
          </el-option>
        </el-select>
        <span>供应商:</span>
        <el-input v-model="supplierName" placeholder="供应商" size="small" clearable/>
        <el-button
          type="success"
          size="small"
          icon="el-icon-search"
          style="margin-left:10px"
          @click="total1=0;pageCurrent1=1;pageSize1=10;searchTable1()">查询</el-button>
      </div>
      <el-table v-loading="" :data="tableData1" stripe border style="width: 100%" height="800px" size="mini">
        <el-table-column type="expand" label="详情" align="center">
          <template slot-scope="scope">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-row>
                <el-form-item label="交货日期">
                  {{ scope.row.交货日期 }}
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="支付日期">
                  {{ scope.row.支付日期 }}
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="支付方式">
                  {{ scope.row.支付方式 }}
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="开票信息">
                  {{ scope.row.开票信息 }}
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="其他说明">
                  {{ scope.row.其他说明 }}
                </el-form-item>
              </el-row>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="采购合同号" prop="采购合同编号" 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="供应商" prop="供应商名称" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.供应商名称 }}
          </template>
        </el-table-column>
        <el-table-column label="采购员" prop="姓名" align="center" min-width="60">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="合同总额" prop="合同金额" align="center" min-width="70" fixed="right">
          <template slot-scope="scope">
            {{ scope.row.合同总额 }}
          </template>
        </el-table-column>
        <el-table-column label="欠款金额" prop="已付金额" align="center" min-width="70" fixed="right">
          <template slot-scope="scope">
            {{ (Number(scope.row.合同总额)-Number(scope.row.已付金额)).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="已付金额" prop="已付金额" align="center" min-width="70" fixed="right">
          <template slot-scope="scope">
            {{ Number(scope.row.已付金额).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="付款进度" prop="付款进度" align="center" min-width="150" fixed="right">
          <template slot-scope="scope">
            <el-progress
              :text-inside="true"
              :stroke-width="18"
              :percentage="scope.row.付款进度 = (100*(Number(scope.row.已付金额))/scope.row.合同总额) > 100 ? 100 : Number((100*(Number(scope.row.已付金额))/scope.row.合同总额).toFixed(2))"
              status="success"/>
          </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 { initPayState, searchPayState } from '@/api/PurchasingCenter/PayStateSearch'
import { mapGetters } from 'vuex'

export default {
  name: '', // 付款情况查询
  data() {
    return {
      check1: 0,
      check2: 0,
      contractNumValue: '',
      contractNum: [],
      supplierName: '',
      tableData1: [],
      pageSize1: 10,
      pageCurrent1: 1,
      total1: 0,
      dialogVisible1: false
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.fetchData()
    this.searchTable1()
  },
  methods: {
    fetchData() {
      initPayState().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.contractNum.push({
            label: response.data[i].采购合同编号,
            name: response.data[i].采购合同名称,
            value: response.data[i].采购合同流水号
          })
        }
      })
    },
    searchTable1() {
      this.tableData1 = []
      this.contractNumValue ? this.check1 = 1 : this.check1 = 0
      this.supplierName ? this.check2 = 1 : this.check2 = 0
      searchPayState(this.pageCurrent1, this.pageSize1, this.check1, this.contractNumValue, this.check2, this.supplierName).then(response => {
        // this.tableData1 = response.data.rows
        response.data.rows.map(v => {
          this.tableData1.push({
            交货日期: v.交货日期,
            支付日期: v.支付日期,
            支付方式: v.支付方式,
            开票信息: v.开票信息,
            其他说明: v.其他说明,
            采购合同编号: v.采购合同编号,
            采购合同名称: v.采购合同名称,
            供应商名称: v.供应商名称,
            姓名: v.姓名,
            合同总额: v.合同总额,
            欠款金额: v.欠款金额,
            已付金额: v.已付金额
          })
        })
        console.log(response.data.rows)
        this.total1 = response.data.total
      })
    },
    handleSizeChange1(val) {
      this.pageSize1 = val
      this.pageCurrent1 = 1
      this.searchTable1()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchTable1()
    }
  }
}
</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
  }
  .el-form-item {
    margin: 0;
  }
</style>
