<template>
  <div>
    <el-popover
      placement="bottom"
      width="100%"
      v-model="visible">
      <div>
        <div class="flex-align-center flex-between" style="margin-bottom:10px">
          <el-input style="width:200px" suffix-icon="el-icon-search" size="small" v-model="params.content.where.condition" placeholder="输入凭证信息" @keyup.enter.native="queryEnterpriseArchives(params.content.pageNumber = 1)" @clear="queryEnterpriseArchives(params.content.pageNumber = 1)" clearable></el-input>
        </div>
        <el-table
          :data="ENlist"
          size="small"
          stripe
          style="width: 100%"
          height="300"
          border>
          <el-table-column
            prop="billno"
            label="凭证单号"
            width="180">
          </el-table-column>
          <el-table-column
            prop="checkdate"
            label="审核时间"
            width="180">
          </el-table-column>
          <el-table-column
            prop="amount"
            label="金额">
            <template slot-scope="scope">
              {{tool.formatAmount(scope.row.amount,2)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="class"
            label="分类">
          </el-table-column>
          <el-table-column>
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="rowClick(scope.row)">选 择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="margin-top:16px;text-align:right">
          <el-pagination
            background
            small
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-size="params.content.pageSize"
            layout="total, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
      <el-input :validate-event="false" :disabled="!sys_enterpriseid || !sa_accountclassid" slot="reference" v-model="form.billno" @focus="queryEnterpriseArchives"  placeholder="请选择支出或收入凭证"></el-input>
    </el-popover>
  </div>
</template>

<script>
import { log } from '@antv/g2plot/lib/utils'
export default {
  props:['sys_enterpriseid','sa_accountclassid'],
  components:{
  },
  data () {
    return {
      ENlist:[],
      total:0,
      currentPage:0,
      form:{
        billno:''
      },
      params:{
        "id": 20221124090704,
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "sys_enterpriseid":1,
            "sa_accountclassid":9,
            "where": {
                "condition": ""
            }
        }
      },
      visible:false
    }
  },
  watch: {
    sa_accountclassid (val) {
      if( this.form.sa_accountclassid != this.sa_accountclassid && this.sys_enterpriseid) {
        this.queryEnterpriseArchives()
      }
    }
  },
  methods:{
    async queryEnterpriseArchives () {
      if (!this.sa_accountclassid || !this.sys_enterpriseid) return
      if(this.params.content.sa_accountclassid == this.sa_accountclassid && this.params.content.sys_enterpriseid == this.sys_enterpriseid) return
      this.params.content.sa_accountclassid = this.sa_accountclassid
      this.params.content.sys_enterpriseid = this.sys_enterpriseid
      const res = await this.$api.requested(this.params)
      this.ENlist = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      this.params.content.pageSize = val
      this.queryEnterpriseArchives()
    },
    handleCurrentChange(val) {
      this.params.content.pageNumber = val
      this.queryEnterpriseArchives()
    },
    rowClick (row) {
      this.visible = false
      this.form.billno = row.billno
      this.$emit('rowClick',row)
    },
    onSuccess () {
      this.queryEnterpriseArchives()
      this.form.billno = this.ENlist[0].billno
      this.$emit('rowClick',this.ENlist[0])
    }
  },
  mounted () {
    // this.queryEnterpriseArchives()
  }
}

</script>
<style>
</style>