<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <el-select v-model="supplierValue" placeholder="选择供应商" filterable style="width: 220px;margin-left: 5px" size="small" clearable>
          <el-option
            v-for="item in supplierValues"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span>申请时间:</span>
        <el-date-picker v-model="date1" size="small" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择开始日期"/>&nbsp;~
        <el-date-picker v-model="date2" size="small" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择结束日期"/>
        <el-button type="success" size="small" icon="el-icon-search" style="margin-left:10px" @click="total1=0;pageCurrent1=1;pageSize1=100000;searchTable1()">查询</el-button>
      </div>
      <!--      <h4 style="margin: 0">发票结算申请单</h4>-->
      <el-table id="expandTable" :data="tableData1" border highlight-current-row height="250px" style="width: 100%;height: 330px;overflow:auto" size="mini">
        <!--        <el-table-column type="expand">-->
        <!--          <template slot-scope="scope">-->
        <!--            <el-form label-position="left" inline class="demo-table-expand">-->
        <!--              <el-row>-->
        <!--                <el-col :lg="10" :sm="12">-->
        <!--                  <viewer>-->
        <!--                    <img :src="scope.row.scanSrc" alt="发票扫描件" height="120px">-->
        <!--                  </viewer>-->
        <!--                </el-col>-->
        <!--                <el-col :span="6">-->
        <!--                  <el-form-item label="已付款项">-->
        <!--                    <span>{{ scope.row.已付款项 }}</span>-->
        <!--                  </el-form-item><br>-->
        <!--                  <el-form-item label="尚欠金额">-->
        <!--                    <span>{{ scope.row.尚欠金额 }}</span>-->
        <!--                  </el-form-item><br>-->
        <!--                  <el-form-item label="备注">-->
        <!--                    <span>{{ scope.row.备注 }}</span>-->
        <!--                  </el-form-item><br>-->
        <!--                </el-col>-->
        <!--                <el-col :span="6">-->
        <!--                  <el-form-item label="是否费用类发票">-->
        <!--                    <span>{{ scope.row.是否费用类 }}</span>-->
        <!--                  </el-form-item><br>-->
        <!--                  <el-form-item label="税额">-->
        <!--                    <span>{{ scope.row.税额 }}</span>-->
        <!--                  </el-form-item>-->
        <!--                </el-col>-->
        <!--              </el-row>-->
        <!--            </el-form>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column label="供应商" align="center" width="180" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.供应商名称 }}
          </template>
        </el-table-column>
        <el-table-column label="到票号" align="center" min-width="90">
          <template slot-scope="scope">
            {{ scope.row.发票号 }}
          </template>
        </el-table-column>
        <el-table-column label="到票金额(元)" align="center" width="110">
          <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.申请人姓名 ? scope.row.申请人姓名 : '未提交' }}
          </template>
        </el-table-column>
        <el-table-column label="申请时间" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.申请时间 ? scope.row.申请时间.split(' ')[0] : '—' }}
          </template>
        </el-table-column>
        <el-table-column label="采购审批" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.审批人1姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="审批时间" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.审批1时间 ? scope.row.审批1时间.split(' ')[0] : '—' }}
          </template>
        </el-table-column>
        <el-table-column label="未过原因" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.审批1未过原因 }}
          </template>
        </el-table-column>
        <el-table-column label="总经理审批" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.审批人4姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="审批时间" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.审批4时间 ? scope.row.审批4时间.split(' ')[0] : '—' }}
          </template>
        </el-table-column>
        <el-table-column label="未过原因" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.审批4未过原因 }}
          </template>
        </el-table-column>
        <el-table-column label="财务审批" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.审批人3姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="审批时间" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.审批3时间 ? scope.row.审批3时间.split(' ')[0] : '—' }}
          </template>
        </el-table-column>
        <el-table-column label="未过原因" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.审批2未过原因 }}
          </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 { searchTable1, searchSupplier } from '@/api/PurchasingCenter/InvoiceSettlementApproveSearch'
import { mapGetters } from 'vuex'
import { readFile } from '@/utils/request'
import request from '@/utils/request'
export default {
  name: '', // 发票结算审批
  data() {
    return {
      date1: '',
      date2: '',
      tableData1: [],
      total1: 0,
      pageCurrent1: 1,
      pageSize1: 10,
      invoiceNumber: '',
      tableData2: [],
      tableData3: [],
      supplierValues: [],
      supplierValue: ''
    }
  },
  computed: {
    ...mapGetters([
      'token',
      'sidebar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.fetchData()
    this.searchTable1()
    this.searchSupplier()
  },
  methods: {
    fetchData() {
      // console.log(this.token)
    },
    searchSupplier() { // 查询创立日期和注册资本大于符合条件的数据
      this.supplierName ? this.supplierCheck1 = 1 : (this.supplierCheck1 = 0, this.supplierName = '')
      this.enterpriseNature ? this.supplierCheck2 = 1 : (this.supplierCheck2 = 0, this.enterpriseNature = '')
      this.createDate ? this.supplierCheck3 = 1 : (this.supplierCheck3 = 0, this.createDate = '')
      this.registeredCapital ? this.supplierCheck4 = 1 : (this.supplierCheck4 = 0, this.registeredCapital = '')
      this.taxNum ? this.supplierCheck5 = 1 : (this.supplierCheck5 = 0, this.taxNum = '')
      this.EMail ? this.supplierCheck6 = 1 : (this.supplierCheck6 = 0, this.EMail = '')
      this.address ? this.supplierCheck7 = 1 : (this.supplierCheck7 = 0, this.address = '')
      this.account ? this.supplierCheck8 = 1 : (this.supplierCheck8 = 0, this.account = '')
      this.openingBank ? this.supplierCheck9 = 1 : (this.supplierCheck9 = 0, this.openingBank = '')
      this.phone ? this.supplierCheck10 = 1 : (this.supplierCheck10 = 0, this.phone = '')
      this.fax ? this.supplierCheck11 = 1 : (this.supplierCheck11 = 0, this.fax = '')
      this.goodTime ? this.supplierCheck12 = 1 : (this.supplierCheck12 = 0, this.goodTime = '')
      searchSupplier(this.supplierCheck1, this.supplierName, this.supplierCheck2, this.enterpriseNature, this.supplierCheck3, this.createDate, this.supplierCheck4, this.registeredCapital, this.supplierCheck5, this.taxNum, this.supplierCheck6, this.EMail, this.supplierCheck7, this.address, this.supplierCheck8, this.account, this.supplierCheck9, this.openingBank, this.supplierCheck10, this.phone, this.supplierCheck11, this.fax, this.supplierCheck12, this.goodTime).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].创立日期 !== '' && response.data[i].创立日期 !== null) {
            response.data[i].创立日期 = response.data[i].创立日期.split(' ')[0]
          }
        }
        for (let i = 0; i < response.data.length; i++) {
          this.supplierValues.push({
            label: response.data[i].供应商名称,
            value: response.data[i].供应商流水号
          })
        }
      })
    },
    searchTable1() {
      let check
      this.date1 && this.date2 ? this.check1 = 1 : (this.check1 = 0, this.date1 = '', this.date2 = '')
      this.supplierValue ? check = 1 : check = 0
      searchTable1(this.check1, this.date1, this.date2, this.pageCurrent1, this.pageSize1, this.token, check, this.supplierValue).then(response => {
        this.tableData1 = response.data.rows
        this.tableData1.map(v => {
          this.$set(v, 'scanSrc', '')
          return v
        })
        for (let i = 0; i < response.data.rows.length; i++) {
          this.tableData1[i].scanSrc = this.searchPic(response.data.rows[i], i)
        }
        this.total1 = response.data.total
      })
    },
    async searchPic(row, i) {
      const { data } = await request({
        url: '',
        method: 'post',
        data: {
          type: '3',
          name: `select * from 采购管理_采购发票_附件 where 是否启用 = 1 and 发票交接流水号 = ${row.发票结算申请单流水号}`
        }
      })
      this.tableData1[i].scanSrc = readFile + data[0].文件标识 + '.' + data[0].文件后缀
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      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;
  }
  #expandTable .el-form-item{
    margin: 0;
  }
  .el-card{
    margin: 0px;
  }
</style>
