<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.subcontractorName"></a-input>
            </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 v-has="'hcwinvoice:invoicePayment'" @click="invoicePayment()" type="primary" icon="plus" >申请开票</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">
            <a v-has="'hcwinvoice:paymentDetail'" @click="paymentDetail(record)" >创客付款单</a>
        </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/hlwInvoice/invoicePayment', params)

  export default {
    name: "HlwInvoiceList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HlwInvoiceModal,
    },
    data () {
      return {
        queryParam: {},
        selectedRowKeys: [],
        selectedRows: [],
        description: '未开票申请',
        // 表头
        columns: [
          {
            title:'批次单号',
            align:"center",
            dataIndex: 'paymentCode'
          },
          {
            title:'任务名称',
            align:"center",
            dataIndex: 'requirementName',
          },
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'companyName',
            customRender:function (text) {
              return text
            }
          },
          {
            title:'服务商',
            align:"center",
            dataIndex: 'subcontractorName'
          },
          {
            title:'付款人数',
            align:"center",
            dataIndex: 'paymentNumber'
          },
          {
            title:'创客佣金',
            align:"center",
            dataIndex: 'amount',
            customRender:function (text,record) {
              return record.isThroughPlatform==1?record.cpAmount: record.amount;
            }
          },
          {
            title:'服务费',
            align:"center",
            dataIndex: 'serviceFee',
            customRender:function (text,record) {
              return record.isThroughPlatform==1?record.cpServiceFee: record.serviceFee;
            }
          },
          {
            title:'付款总金额',
            align:"center",
            dataIndex: 'totalPayment',
            customRender:function (text,record) {
              return record.isThroughPlatform==1?record.serviceAmount: record.totalPayment;
            }
          },
          {
            title:'任务单号',
            align:"center",
            dataIndex: 'requirementCode'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/wisdom/hlwInvoice/list",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //监听checkbox属性
      getCheckboxProps(record) {
        var b=false;
        if(record.invoiceId !=null || record.applyTime!=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
                res.result.totalNum=list.length
                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()
          }
        })
      },


      paymentDetail(record){
        this.$router.push({ path: '/wisdom/hlwInvoice/add',query:{record:JSON.stringify(record) }})
      }

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