<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="1400px"
      append-to-body
      height="500px"
      @close="close"
      @keyup.enter.native="getWorkInvoice"
	  v-model="visibleChoose">
      <div style="height: calc(100%);">
		<el-form size="large" :inline="true" class="query-form m-b-10" ref="searchForm" :model="searchForm" @submit.native.prevent>
          <!-- 搜索框-->
          <el-form-item label="发票申请编号" prop="no">
            <el-input size="large" v-model="searchForm.no" placeholder="发票申请编号" clearable></el-input>
          </el-form-item>
          <el-form-item label="发票号" prop="number">
            <el-input size="large" v-model="searchForm.number" placeholder="发票号" clearable></el-input>
          </el-form-item>
          <el-form-item label="开票内容" prop="billingContent">
            <el-select v-model="searchForm.billingContent" placeholder="请选择" style="width:100%" clearable>
              <el-option
                v-for="item in $dictUtils.getDictList('invoice_billing_content')"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>


          <el-form-item>
            <el-button type="primary" @click="list()" size="large" icon="el-icon-search">查询</el-button>
            <el-button @click="resetSearch()" size="large" icon="el-icon-refresh-right">重置</el-button>
          </el-form-item>
        </el-form>

        <vxe-table
          border="inner"
          height="480px"
          :loading="loading"
          size="small"
          ref="invoiceTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          :print-config="{}"
          :sort-config="{remote:true}"
          :data="dataList"
          :row-config="{isCurrent: true}"
          :tree-config="{transform: true, rowField: 'id', parentField: 'oneUpCompany'}"
          :radio-config="{trigger: 'row'}">
          <vxe-column type="seq" width="40"></vxe-column>
          <vxe-column type="radio" width="60px"></vxe-column>
          <vxe-column width="230px" title="发票申请编号" align="center" field="no"></vxe-column>
          <vxe-column width="200px" title="发票号" align="center" field="number"></vxe-column>
          <vxe-column width="200px" title="开票内容" align="center" field="billingContent">
            <template #default="scope">
              {{$dictUtils.getDictLabel('invoice_billing_content', scope.row.billingContent, '-')}}
            </template>
          </vxe-column>
			<vxe-column width="200px" title="项目名称" align="center" field="programName"></vxe-column>
			<vxe-column width="200px" title="经办人" align="center" field="operator"></vxe-column>
          <vxe-column width="200px" title="开票总金额" align="center" field="account"></vxe-column>
        </vxe-table>
		  <vxe-pager
			  background
			  :current-page="tablePage.currentPage"
			  :page-size="tablePage.pageSize"
			  :total="tablePage.total"
			  :page-sizes="[10, 20, 100, 1000, {label: '全量数据', value: 1000000}]"
			  :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
			  @page-change="currentChangeHandle">
		  </vxe-pager>
      </div>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			<el-button type="primary" v-if="method != 'view'" @click="getWorkInvoice()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
		</template>
    </el-dialog>
  </div>
</template>

<script>
  import FinanceInvoiceService from '@/api/finance/invoice/FinanceInvoiceService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visibleChoose: false,
        loading: false,
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        dataList: [],
        searchForm: {
          number: '',
          no: '',
		  billingContent: ''
        }
      }
    },
	  financeInvoiceService: null,
    created () {
		this.financeInvoiceService = new FinanceInvoiceService()
    },
    components: {
    },
    methods: {
      init () {
        this.title = '发票选择'
        this.visibleChoose = true
        this.list()
      },
      // 表单提交
		getWorkInvoice () {
        let row = this.$refs.invoiceTable.getRadioRecord()
        if (this.commonJS.isEmpty(row)) {
          this.$message.error('请至少选择一条数据')
        } else {
          this.close()
          this.$emit('getWorkInvoiceRadioChoose', row)
        }
      },
      list () {
        this.dataList = []
        this.loading = true
        this.searchForm.isTrue = '1'
		  this.financeInvoiceService.redList({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm
        }).then((data) => {
          this.dataList = data.records
          this.tablePage.total = data.total
          this.loading = false
        })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.list()
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.list()
      },
      close () {
        this.$refs.searchForm.resetFields()
        this.visibleChoose = false
      }
    }
  }
</script>
<style scoped>
  /deep/ .el-dialog__body {
    padding-top: 0;
  }
  /deep/ .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
    margin-bottom: 0px;
  }
</style>
