<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="付款单号">
              <a-input placeholder="请输入付款单号" v-model="queryParam.paymentCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="付款企业">
              <a-input placeholder="请输入付款企业"  v-model="queryParam.companyName"></a-input>
            </a-form-item>
          </a-col>


          <a-col :md="6" :sm="8">
            <a-form-item  label="状态">
              <j-dict-select-tag v-model="queryParam.invoiceStatus" placeholder="请选择状态" dictCode="invoiceStatus"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--{{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--<a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--</a>-->
            </span>
          </a-col>


        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
          <a-button @click="invoicePayment()" type="primary" icon="plus" v-has="'invoice:payment'">开票</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps:getCheckboxProps}"
        class="j-table-force-nowrap"
        @change="handleTableChange">



        <span slot="action" slot-scope="text, record">

        </span>

      </a-table>
    </div>

    <hlw-invoice-modal ref="modalForm" @ok="modalFormOk"></hlw-invoice-modal>
  </a-card>
</template>

<script>

  import { httpAction ,getAction,putAction} from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlwInvoiceModal from './modules/HlwInvoiceModal'
  const invoicePayment = (params) => putAction('/wisdom/hlwSubcontractorAccountFlow/invoicePayment', params)

  export default {
    name: "HlwInvoiceList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HlwInvoiceModal,
    },
    data () {
      return {
        queryParam: {},
        selectedRowKeys: [],
        selectedRows: [],
        description: '开票申请',
        // 表头
        columns: [
          {
            title:'付款平台',
            align:"center",
            dataIndex: 'applicationName'
          },
          {
            title:'付款单号',
            align:"center",
            dataIndex: 'paymentCode'
          },
          {
            title:'付款企业',
            align:"center",
            dataIndex: 'companyName',
            customRender:function (text) {
              return text
            }
          },
          {
            title:'通过平台',
            align:"center",
            dataIndex: 'isThroughPlatform_dictText'
          },
          {
            title:'服务商',
            align:"center",
            dataIndex: 'subcontractorName'
          },
          {
            title:'开票金额',
            align:"center",
            dataIndex: 'totalPayment'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'invoiceId',
            customRender:function (text,record) {
              return record.invoiceId!=null?"已开票":"未开票";
            }
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
        ],
        url: {
          list: "/wisdom/hlwSubcontractorAccountFlow/invoicePaymentApplyList",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //监听checkbox属性
      getCheckboxProps(record) {
        var b=false;
        if(record.invoiceId !=null){
          b=true;
        }
        return {
          props: {
            disabled: b,
          }
        }
      },

      onSelectChange (selectedRowKeys,selectedRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectedRows = selectedRows;
      },
      invoicePayment(){
        if(this.selectedRowKeys.length==0){
          this.$message.warning('请先选择付款数据')
          return
        }
        var list=[]
        for(var i=0;i<this.selectedRowKeys.length;i++){
          list.push(this.selectedRowKeys[i])
        }
        let that = this
        const modal = that.$confirm({
          title: '开票',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '确定将当前选中的项开票吗',
          okText: '确定',
          cancelText: '取消',
          onOk: function() {
            that.loading = true;
            invoicePayment(
              {idsList:list}
            ).then((res) => {
              if (res.success) {
                that.selectedRowKeys = [];
                that.selectedRows = [];
                that.loading = false
                that.$refs.modalForm.edit(res.result)
                that.$refs.modalForm.title = '开票'
                that.$refs.modalForm.disableSubmit = false
              } else {
                that.$error({
                  title: '错误提示',
                  content: res.message,
                  okText: '确定',
                  centered:true,
                  onOk: () => {
                    that.loading = false;
                  }
                })
              }
            })
          },
          onCancel() {
            modal.destroy()
          }
        })
      }

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