<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="8" :sm="8">
            <a-form-item label="时间">
              <a-range-picker
                style="width: 100%"
                v-model="queryParam.paymentTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onDateChange"
                @ok="onDateOk"
                :allowClear="allowClear"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="收款方">
              <a-input placeholder="请输入收款方" v-model="queryParam.userName"></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.idcardNumber"></a-input>
              </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="ant-alert ant-alert-info" style="margin-bottom: 16px;display: flex;flex-direction: row">
      <div style="display: flex;flex-direction: column"><i class="anticon anticon-info-circle ant-alert-icon"></i> 实发合计 <a style="font-weight: 600">{{ this.sumPayment}}元</a></div>

      <div style="display: flex;flex-direction: column;margin-left: 30%;"><i class="anticon anticon-info-circle ant-alert-icon"></i> 税费合计 <a style="font-weight: 600">{{ this.sumTaxFee}}元</a></div>

      <div style="display: flex;flex-direction: column;margin-left: 30%;"><i class="anticon anticon-info-circle ant-alert-icon"></i> 总计 <a style="font-weight: 600">{{ this.sumMoney}}元</a></div>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <i style="float: left;font-family:'STHeiti';font-size: 18px;color: rgba(0, 0, 0, 0.85);font-weight:bold">出账明细</i>
      <a-button type="primary" style="float: right;margin-right: 10px;margin-bottom: 5px;z-index: 1" icon="download" @click="handleExportXls1('出账统计')" v-has="'hlgPaymentDetailOut:export'">导出</a-button>
    </div>

    <!-- 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="viewServiceContract(record)" v-has="'hlgPaymentDetailOut:serviceContract'">合同</a>
        </span>

        <span slot="action1" slot-scope="text, record">
           <a style="color:#000c17">{{record.idcardNumber}}
             <a-icon type="picture" :style="{color:'#8e8e8e'}" title="身份证照片" @click="viewIdcardPicture(record)" style="margin-left: 12px" />
           </a>
        </span>

      </a-table>
    </div>

    <hw-picture-modal ref="hwViewPictureForm" @ok="modalFormOk"></hw-picture-modal>
    <HlgViewContractModal ref="hlgViewContractForm"></HlgViewContractModal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JDate from '@/components/jeecg/JDate'
  import { filterObj } from '@/utils/util';
  import moment from "moment"
  import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
  import { getAction,postAction,deleteAction,downFile } from '@/api/manage'
  import { Arithmetic } from '@/mixins/Arithmetic'
  import HwPictureModal from '../tools/HwPictureModal'
  import HlgViewContractModal from './modules/HlgViewContractModal'

  export default {
    name: "HlgPaymentOutDetailList",
    mixins:[JeecgListMixin,Arithmetic],
    components: {
      HwPictureModal,
      JDate,
      HlgViewContractModal
    },
    data () {
      return {
        queryParam: {
          paymentTimeRange:[moment(new Date(new Date().getTime()-3600*24*1000*30), 'YYYY/MM/DD'), moment(new Date(), 'YYYY/MM/DD')],
          paymentTime_begin:new Date(new Date().getTime()-3600*24*1000*30).toLocaleDateString()+" 00:00:00",
          paymentTime_end:new Date().toLocaleDateString() +" 23:59:59",
        },
        sumPayment:0,
        sumTaxFee:0,
        sumMoney:0,
        allowClear:false,
        description: '出账管理页面',
        // 表头
        columns: [
          {
            title:'服务商',
            align:"left",
            dataIndex: 'subcontractorName'
          },
          {
            title:'收款方',
            align:"left",
            dataIndex: 'userName'
          },
          {
            title:'身份证号',
            align:"left",
            dataIndex: 'idcardNumber',
            scopedSlots: { customRender: 'action1' }
          },
          {
            title:'银行卡号',
            align:"left",
            dataIndex: 'cardNumber'
          },
          {
            title:'不含税金额',
            align:"left",
            dataIndex: 'payment'
          },
          {
            title:'税费',
            align:"left",
            dataIndex: 'taxFee'
          },
          {
            title:'含税金额',
            align:"left",
            dataIndex: 'taxRate',
            customRender: (text,record)=> {
              return this.numAdd(record.taxFee,record.payment)
            }
          },
          {
            title:'付款时间',
            align:"left",
            dataIndex: 'paymentTime',

          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"left",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/hlgpayment/hlgPaymentDetail/outList",
          delete: "/hlgpayment/hlgPaymentDetail/delete",
          deleteBatch: "/hlgpayment/hlgPaymentDetail/deleteBatch",
          exportXlsUrl: "/hlgpayment/hlgPaymentDetail/exportXls",
          importExcelUrl: "hlgpayment/hlgPaymentDetail/importExcel",
          imgerver: window._CONFIG['imgDomainOssURL'],
          hpWorkImgerver:window._CONFIG['imgHpworkDomainOssURL']
        },
        dictOptions:{
        } 
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      getQueryParams(){
        console.log(this.queryParam.paymentBy)
        var param = Object.assign({}, this.queryParam,this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        delete param.paymentTimeRange; // 时间参数不传递后台
        return filterObj(param);
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        if(arg){
          this.ipagination.current=arg
        }
        var params = this.getQueryParams()//查询条件
        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.result.records.length>0){
              this.sumPayment=this.returnFloat(res.result.records[0].sumPayment)
              this.sumTaxFee=this.returnFloat(res.result.records[0].sumTaxFee)
              this.sumMoney= this.numAdd(this.sumTaxFee,this.sumPayment)
            }else{
              this.sumPayment=this.returnFloat(0)
              this.sumTaxFee=this.returnFloat(0)
              this.sumMoney=this.returnFloat(0)
            }

          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      returnFloat(value){
        var value=Math.round(parseFloat(value)*100)/100;
        var s=value.toString().split(".");
        if(s.length==1){
          value=value.toString()+".00";
          return value;
        }
        if(s.length>1){
          if(s[1].length<2){
            value=value.toString()+"0";
          }
          return value;
        }
      },

      handleExportXls1(){
        let param = this.getQueryParams()//查询条件
        downFile(this.url.exportXlsUrl,param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data]), this.description+'.xls')
          }else{
            let url = window.URL.createObjectURL(new Blob([data]))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', this.description+'.xls')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.paymentTime_begin=dateString[0]+" 00:00:00";
        this.queryParam.paymentTime_end=dateString[1] +" 23:59:59";
      },
      onDateOk(value) {
        console.log(value);
      },
      //查看合同
      viewServiceContract(record){
        if(record.workContract === null || record.workContract === ''){
          this.$message.warning('该合同为线下合同,不支持预览')
          return
        }
        this.$refs.hlgViewContractForm.edit(record.workContract,record.systemType,record.isImportWorkContract);
        this.$refs.hlgViewContractForm.title = '查看合同'
        this.$refs.hlgViewContractForm.disableSubmit = false
        this.$refs.hlgViewContractForm.contractName = '承揽合同';
      },
      viewIdcardPicture(record){
        var idcard = [];
        var idcardPicture=record.idcardPicture;
        //判断字符串为，时排除掉（A-B-C idcardPicture是在sql里拼接的参数会有只有，的情况）
        if(idcardPicture && idcardPicture.length!=1){
          var ss=idcardPicture.split(",")
          for (let i = 0; i <ss.length ; i++) {
            var idpic=ss[i]
            if(idpic!=''){
              if( idpic.indexOf("http")!=-1){
                idcard.push(idpic)
              }else{
                if(record.systemType==1){
                  if(record.isImport==1){
                    idcard.push(this.url.hpWorkImgerver +idpic)
                  }else{
                    idcard.push(this.url.imgerver +idpic)
                  }
                }else{
                  idcard.push(this.url.hpWorkImgerver +idpic)
                }
              }
            }
          }
          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>