<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :bodyStyle="bodyStyle"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    :footer="null">

      <a-card :bordered="false">
        <!-- table区域-begin -->
        <div>

          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange">


             <span slot="action" slot-scope="text, record">
              <a @click="viewInvoice(record)" v-has="'companyBusiness:incoice'">发票</a>
             </span>
          </a-table>
        </div>

       <hlw-picture-modal ref="hwViewPictureForm" @ok="modalFormOk"></hlw-picture-modal>
      </a-card>

  </a-modal>
</template>
<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  import HlwPictureModal from './modules/HlwPictureModal'

  export default {
    name: 'HlwCompanyBusinessInvoiceDetailsList',
    mixins: [JeecgListMixin],
    components: {
      HlwPictureModal
    },
    data() {
      return {
        description: '发票明细页面',
        headers: {},
        fileList: [],
        form: this.$form.createForm(this),
        title: '操作',
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.66) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '80%',
          style: { top: '20px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        invoiceId: 0,
        idList: "",
        accept: '.pdf',
        confirmLoading: false,
        validatorRules: {},
        // 表头
        columns: [
          {
            title: '发票号',
            align: 'center',
            dataIndex: 'invoiceNumber',
          },
          {
            title: '开票金额',
            align: 'center',
            dataIndex: 'amount'
          },
          {
            title: '开票时间',
            align: 'center',
            dataIndex: 'uploadTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          },

        ],
        url: {
          list: '/wisdom/hlwInvoice/companyBusinessInvoiceDetailList',
          imgerver: window._CONFIG['imgDomainOssURL']
        },
        dictOptions: {}
      }
    },
    computed: {},
    methods: {
      close() {
        this.visible = false
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record);
        this.visible = true
        this.loadData1(this.model)
      },
      handleOk() {
        this.close()
        this.visible = false
      },
      handleCancel() {
        this.close()
      },

      loadData1(record) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        var params= Object.assign({pageNo:this.ipagination.current,pageSize:this.ipagination.pageSize},record)
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },




      handleTableChange(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        this.ipagination = pagination;
        this.loadData1(this.model)
      },


      viewInvoice(record){
        var invoice=record.invoice;
        var idcard = [];
        if(invoice){

          var arr=invoice.split(",")
          for (let i = 0; i <arr.length ; i++) {
            if( arr[i].indexOf("http")!=-1){
              idcard.push(arr[i])
            }else{
              idcard.push(this.url.imgerver  +arr[i])
            }
          }
          this.$refs.hwViewPictureForm.edit(idcard);
          this.$refs.hwViewPictureForm.title = '打款凭证'
          this.$refs.hwViewPictureForm.disableSubmit = false
        }else{
          this.$message.warning('未上传')
        }
      },



    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
<style lang="scss" scoped>

</style>