<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="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <!--<a-button type="primary" icon="download" @click="handleExportXls('企业账户明细')">导出</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="'require:viewServiceContract'">企业合同</a>
          <a-divider type="vertical"/>
          <template v-if="record.isThroughPlatform==1">
            <a @click="subcontractorInfo(record)" v-has="'require:subcontractorInfo'">转包信息</a>
          </template>
            <template v-if="record.isThroughPlatform==0">
            <a @click="subcontractorInfo(record)" v-has="'require:subcontractorInfo'">出账信息</a>
          </template>
        </span>

      </a-table>
    </div>

    <hwPlatformCompanyAccountDetail-modal ref="modalForm" @ok="modalFormOk"></hwPlatformCompanyAccountDetail-modal>

    <hw-subcontractor-account-detail-list ref="hwSubcontractorAccountDetailList" @ok="modalFormOk"></hw-subcontractor-account-detail-list>

    <HwPaymentOutModal ref="hwPaymentOutModal" @ok="modalFormOk"></HwPaymentOutModal>
  </a-card>
  </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HwPlatformCompanyAccountDetailModal from './modules/HwPlatformCompanyAccountDetailModal'
  import qs from 'qs';
  import HwSubcontractorAccountDetailList from '../subcontratormanager/HwSubcontractorAccountDetailList'
  import JDate from '@/components/jeecg/JDate'
  import { filterObj } from '@/utils/util';
  import moment from "moment"
  import HwPaymentOutModal from '../subcontratormanager/modules/HwPaymentOutModal'
  export default {
    name: "HwPlatformCompanyAccountDetailList",
    mixins:[JeecgListMixin],
    components: {
      HwPaymentOutModal,
      HwSubcontractorAccountDetailList,
      HwPlatformCompanyAccountDetailModal,
      JDate
    },
    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",
        },
        description: '企业账户明细管理页面',
        allowClear:false,
        // 表头
        columns: [
          {
            title:'业务单号',
            align:"center",
            dataIndex: 'hwRequirement.code'
          },
          {
            title:'需求方',
            align:"center",
            dataIndex: 'hwRequirement.companyName'
          },
          {
            title:'平台/服务商',
            align:"center",
            dataIndex: 'paymentId',
            customRender:function (text,record) {
              if(record.isThroughPlatform==1){
                return "江苏开心工作科技有限公司"
              }else{
                return record.subName
              }
            }
          },
          {
            title:'项目金额',
            align:"center",
            dataIndex: 'amount',
            customRender:function (text) {
             if(text==null){
               return "补发"
             }else{
               return text;
             }
            }
          },
          {
            title:'服务费',
            align:"center",
            dataIndex: 'serviceFee',
            customRender:function (text) {
              if(text==null){
                return "补发"
              }else{
                return text;
              }
            }

          },
          {
            title:'时间',
            align:"center",
            dataIndex: 'businessTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/saasmanager/hwPlatformCompanyAccountDetail/list",
          delete: "/saasmanager/hwPlatformCompanyAccountDetail/delete",
          deleteBatch: "/saasmanager/hwPlatformCompanyAccountDetail/deleteBatch",
          exportXlsUrl: "/saasmanager/hwPlatformCompanyAccountDetail/exportXls",
          importExcelUrl: "saasmanager/hwPlatformCompanyAccountDetail/importExcel",
        },
        dictOptions:{
        } 
      }
    },
    created(){

    },
    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);
      },
      subcontractorInfo(record){
        if(record.isThroughPlatform==1){
          this.$refs.hwSubcontractorAccountDetailList.edit(qs.stringify(record))
          this.$refs.hwSubcontractorAccountDetailList.title = '转包信息'
          this.$refs.hwSubcontractorAccountDetailList.disableSubmit = false
        }else{
          this.$refs.hwPaymentOutModal.edit(record)
          this.$refs.hwPaymentOutModal.title = '出账信息'
          this.$refs.hwPaymentOutModal.disableSubmit = false
        }
      },
      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);
      },
      viewServiceContract(record){
        if(record.hwRequirement.serviceContract==null){
          this.$message.warning('该合同为线下合同,不支持预览')
          return
        }
        window.open(window._CONFIG['imgDomainOssURL']+record.hwRequirement.serviceContract, '_blank', 'toolbar=yes')
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>