<template>
  <div class="page-header-index-wide">
  <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.generateTimeRange"
                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.companyName"></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>
            </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.sumAccount}}元</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.sumServiceFee}}元</a></div>-->

      <div style="display: flex;flex-direction: column"><i class="anticon anticon-info-circle ant-alert-icon"></i> 开票金额合计 <a style="font-weight: 600">{{ this.sumMoney}}元</a></div>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <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="'hlgAccountDetailIn:export'">导出</a-button>
      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
        <!--<a-button type="primary" icon="import">导入</a-button>-->
      <!--</a-upload>-->
      <!--<a-dropdown v-if="selectedRowKeys.length > 0">-->
        <!--<a-menu slot="overlay">-->
          <!--<a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
        <!--</a-menu>-->
        <!--<a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--</a-dropdown>-->
    </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="'hlgAccountDetailIn:serviceContract'">合同</a>
        </span>

        <span slot="action1" slot-scope="text, record">
           <a style="color:#000c17">{{record.dutyParagraph}}
             <a-icon type="picture" :style="{color:'#8e8e8e'}" title="营业执照" @click="viewDutyParagraph(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>
  </div>
</template>

<script>

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

  export default {
    name: "HwPlatformCompanyAccountDetailZSList",
    mixins:[JeecgListMixin,Arithmetic],
    components: {
      HwPictureModal,
      JDate,
      HlgViewContractModal
    },
    data () {
      return {
        queryParam: {
          generateTimeRange:[moment(new Date(new Date().getTime()-3600*24*1000*30), 'YYYY/MM/DD'), moment(new Date(), 'YYYY/MM/DD')],
          generateTimeRange_begin:new Date(new Date().getTime()-3600*24*1000*30).toLocaleDateString()+" 00:00:00",
          generateTimeRange_end:new Date().toLocaleDateString() +" 23:59:59"
        },
        sumAccount:0,
        sumServiceFee:0,
        sumMoney:0,
        description: '入账统计',
        allowClear:false,
        // 表头
        columns: [
          {
            title:'付款方',
            align:"left",
            dataIndex: 'companyName'
          },

          {
            title:'税号',
            align:"left",
            dataIndex: 'dutyParagraph',
            scopedSlots: { customRender: 'action1' }
          },
          {
            title:'服务商',
            align:"left",
            dataIndex: 'subcontractorName',
          },
          {
            title:'开票金额',
            align:"left",
            dataIndex: 'sumMoney',
            customRender: (text,record)=> {
              return this.numAdd(record.amount,record.serviceFee)
            }
          },

          {
            title:'入账日期',
            align:"left",
            dataIndex: 'generateTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"left",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/hlgaccount/hlgAccountDetail/inList",
          exportXlsUrl: "/hlgaccount/hlgAccountDetail/exportXls",
          exportXls:'/online/cgform/api/exportXls/',
          imgerver: window._CONFIG['imgDomainOssURL'],
          hpWorkImgerver:window._CONFIG['imgHpworkDomainOssURL']
        },
        dictOptions:{
        } 
      }
    },
    created(){
      console.log(this.queryParam.generateTimeRange_end)
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      moment,
      initDictConfig(){
      },

      getQueryParams(){
        console.log(this.queryParam.generateTimeRange)
        var param = Object.assign({}, this.queryParam,this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        delete param.generateTimeRange; // 时间参数不传递后台
        return filterObj(param);
      },
      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.generateTimeRange_begin=dateString[0]+" 00:00:00";
        this.queryParam.generateTimeRange_end=dateString[1] +" 23:59:59";
      },
      onDateOk(value) {
        console.log(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对象
          }
        })
      },

      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.sumMoney=this.returnFloat(res.result.records[0].sumMoney)
            }else{
              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;
        }
      },
      //查看合同
      viewServiceContract(record){
        if(record.serviceContract==null || record.serviceContract === ''){
          this.$message.warning('该合同为线下合同,不支持预览')
          return
        }
        this.$refs.hlgViewContractForm.edit(record.serviceContract,record.systemType);
        this.$refs.hlgViewContractForm.title = '查看合同'
        this.$refs.hlgViewContractForm.disableSubmit = false
        this.$refs.hlgViewContractForm.contractName = '服务合同';
      },
      viewDutyParagraph(record){
        var idcard = [];
        var BusinessLicense=record.businessLicense;
        if(BusinessLicense){
          if( BusinessLicense.indexOf("http")!=-1){
            idcard.push(BusinessLicense)
          }else{
            //  systemType 1:来自慧灵工 2：来自开心灵工
            if(record.systemType==1){
              idcard.push(this.url.imgerver +BusinessLicense)
            }else{
              idcard.push(this.url.hpWorkImgerver +BusinessLicense)
            }
          }
          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>