<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>
          <template v-if="toggleSearchStatus">
            <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">
              <a-form-item label="状态">
                <j-dict-select-tag v-model="queryParam.dutyStatus" placeholder="请选择"
                                   dictCode="duty_status"></j-dict-select-tag>
              </a-form-item>
            </a-col>
          </template>
          <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="handleDuty" type="primary" icon="plus" v-has="'dutyApply:duty'">完税</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 @click="handleEdit(record)">人员明细</a>
        </span>

      </a-table>
    </div>

    <hlwDutyApply-modal ref="modalForm" @ok="modalFormOk"></hlwDutyApply-modal>
    <HlwDutyTaxModal ref="taxModal" @ok="modalFormOk"></HlwDutyTaxModal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlwDutyApplyModal from './modules/HlwDutyApplyModal'
  import HlwDutyTaxModal from './modules/HlwDutyTaxModal'
  import { httpAction,getAction } from '@/api/manage'

  export default {
    name: "HlwDutyApplyList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HlwDutyApplyModal,
      HlwDutyTaxModal
    },
    data () {
      return {
        description: 'hlw_duty_apply管理页面',
        // 表头
        columns: [
          {
            title:'付款平台',
            align:"left",
            dataIndex: 'applicationName'
          },
          {
            title:'付款单号',
            align:"left",
            dataIndex: 'paymentCode'
          },
          {
            title:'付款企业',
            align:"left",
            dataIndex: 'companyName'
          },
          {
            title:'通过平台',
            align:"left",
            dataIndex: 'isThroughPlatform_dictText'
          },
          {
            title:'服务商',
            align:"left",
            dataIndex: 'subcontractorName'
          },
          {
            title:'完税金额',
            align:"left",
            dataIndex: 'amount'
          },
          {
            title:'状态',
            align:"left",
            dataIndex: 'dutyStatus',
            customRender:function (text,record) {
              return record.dutyPaidId ? '已完税':'未完税'
            }
          },
          {
            title:'创建时间',
            align:"left",
            dataIndex: 'applyTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"left",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/wisdom/hlwDutyApply/list",
          delete: "/wisdom/hlwDutyApply/delete",
          deleteBatch: "/wisdom/hlwDutyApply/deleteBatch",
          exportXlsUrl: "/wisdom/hlwDutyApply/exportXls",
          importExcelUrl: "wisdom/hlwDutyApply/importExcel",
          checkList: "/wisdom/hlwDutyApply/checkList"
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleDuty(record){
        const that = this;
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return false;
        }
        const modal = that.$confirm({
          title: '完税证明',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '本次完税证明选中'+ that.selectedRowKeys.length +'条',
          okText: '继续',
          cancelText: '取消',
          onOk: function() {
            that.confirmLoading = true;
            var ids = that.selectedRowKeys.join(",");
            console.log("ddf",that.selectedRowKeys,ids)
            //提交后台，查看选中的是否为同一企业、同一服务商的数据
            getAction(that.url.checkList,{ids:ids}).then((res)=>{
              if(res.success){
                that.$refs.taxModal.add(res.result, ids)
                that.$refs.taxModal.title = '完税证明'
                that.$refs.taxModal.disableSubmit = false
              }else{
                that.$message.error(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          },
          onCancel(e) {
            modal.destroy()
          }
        })
      },
      handleEdit(record){
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '人员明细'
        this.$refs.modalForm.disableSubmit = false
      },
      getCheckboxProps(record) {
        return {
          props: {
            disabled: record.dutyPaidId != null
          }
        }
      },
      modalFormOk(){
        this.loadData(1);
        this.onClearSelected();
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>