<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :bodyStyle="bodyStyle"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    :footer="null">



    <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="10">
              <a-form-item label="到款时间">
                <j-date v-model="queryParam.paymentResultTime_end" :showTime="true" date-format="YYYY-MM-DD" style="width:45%" placeholder="请选择到款时间" ></j-date>
              </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="searchReset1" 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>

      <!-- table区域-begin -->
      <div>
        <p >* 纳税金额仅作参考,实际以缴纳至税务局的纳税额为准</p>
        <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="'userBusiness:subcontract'">合同</a>
              <a-divider type="vertical"  v-has="'userBusiness:invoice'" />
              <a @click="viewInvoice(record)" v-has="'userBusiness:invoice'">打款凭证</a>
              <a-divider type="vertical"  v-has="'userBusiness:taxPaymentReceipt'" />
              <a @click="viewTaxPaymentReceipt(record)" v-has="'userBusiness:taxPaymentReceipt'">完税证明</a>

            </span>
          <span slot="action3" slot-scope="text, record">
                 {{record.requirementName}} <a @click="viewRequirementDescription(record)" >详情</a>
            </span>
        </a-table>
      </div>



    </a-card>
    <hlw-picture-modal ref="hwViewPictureForm" @ok="modalFormOk"></hlw-picture-modal>
    <hlw-business-requirement-description-modal ref="viewRequirementDescriptionForm" @ok="modalFormOk"></hlw-business-requirement-description-modal>
    <hlw-view-contract-modal ref="hlgViewContractForm"></hlw-view-contract-modal>
  </a-modal>
</template>
<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  import HlwPictureModal from './modules/HlwPictureModal'
  import HlwBusinessRequirementDescriptionModal from './modules/hlwBusinessRequirementDescriptionModal'
  import HlwViewContractModal from '../hlwcpmanager/modules/HlwViewContractModal'
  import JDate from '@/components/jeecg/JDate.vue'





  export default {
    name: 'HlwBusinessDetailsList',
    mixins: [JeecgListMixin],
    components: {
      HlwViewContractModal,
      HlwBusinessRequirementDescriptionModal,
      HlwPictureModal,
      JDate


    },
    data() {
      return {
        paymentResultTime_endOut:null,
        paymentResultTime_beginOut:null,
        // 查询条件
        queryParam: {

        },
        description: '业务明细页面',
        headers: {},
        fileList: [],
        form: this.$form.createForm(this),
        title: '操作',
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.66) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '80%',
          style: { top: '20px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        accept: '.pdf',
        confirmLoading: false,
        validatorRules: {},
        // 表头
        columns: [
          {
            title: '需求名称',
            align: 'center',
            dataIndex: 'requirementName',
            scopedSlots: { customRender: 'action3' }
          },
          {
            title: '姓名',
            align: 'center',
            dataIndex: 'userName'
          },
          {
            title: '手机号',
            align: 'center',
            dataIndex: 'phone'
          },
          {
            title: '身份证号',
            align: 'center',
            dataIndex: 'idcardNumber'
          },
          {
            title: '到款时间',
            align: 'center',
            dataIndex: 'paymentResultTime'
          },
          {
            title: '收入金额',
            align: 'center',
            dataIndex: 'netPayment'
          },
          {
            title: '纳税金额',
            align: 'center',
            dataIndex: 'taxFee'

          },
          {
            title: '收款银行',
            align: 'center',
            dataIndex: 'eacbnk',
            customRender:function (text) {
              return !text?"招商银行":text
            }
          },
          {
            title: '银行账号',
            align: 'center',
            dataIndex: 'cardNumber'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          },


        ],
        url: {
          list: '/wisdom/hlwPaymentDetail/businessDetailsList',
          imgerver: window._CONFIG['imgDomainOssURL']
        },
        dictOptions: {}
      }
    },


    computed: {},
    methods: {
      close() {
        this.visible = false
      },
      edit(record) {
        this.paymentResultTime_beginOut=null
        this.paymentResultTime_endOut=null
        this.form.resetFields()
        this.queryParam={}
        this.model = Object.assign({}, record);
        this.paymentResultTime_beginOut=this.model.paymentResultTime_begin
        this.paymentResultTime_endOut=this.model.paymentResultTime_end
        this.visible = true
        this.ipagination.current=1
        this.loadData1(this.model)
      },
      handleOk() {
        this.close()
        this.visible = false
      },
      handleCancel() {
        this.close()
      },

      // 重置
      searchReset1(){
        this.queryParam={}
        var params=this.model
        params.paymentResultTime_end=this.paymentResultTime_endOut
        params.paymentResultTime_begin=this.paymentResultTime_beginOut
        this.loadData1(params)
      },



      searchQuery(){
        var params=this.model
        if(this.queryParam.paymentResultTime_end!=null){
          params.paymentResultTime_end=this.queryParam.paymentResultTime_end
          params.paymentResultTime_begin=null
        }else{
          params.paymentResultTime_end=this.paymentResultTime_endOut
          params.paymentResultTime_begin=this.paymentResultTime_beginOut
        }
        this.loadData1(params)
      },

      loadData1(record) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        var params= Object.assign({pageNo:this.ipagination.current,pageSize:this.ipagination.pageSize},record)
        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.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },

      handleTableChange(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        this.ipagination = pagination;
        this.loadData1(this.model)
      },

      //打款凭证
      viewInvoice(record){
        var statementUrl = record.statementUrl;
        if(statementUrl){
          statementUrl = this.url.imgerver + statementUrl;
          //预览pdf
          window.open(statementUrl,'_blank','location=no');
        }else{
          this.$message.warning('暂无对账单')
        }
      },

      viewTaxPaymentReceipt(record){
        var taxPaymentReceipt=record.taxPaymentReceipt;
        var idcard = [];
        if(taxPaymentReceipt){
          var arr=taxPaymentReceipt.split(",")
          for (let i = 0; i <arr.length ; i++) {
            if( arr[i].indexOf("http")!=-1){
              idcard.push(arr[i])
            }else{
              idcard.push(this.url.imgerver +arr[i])
            }
          }
          this.$refs.hwViewPictureForm.edit(idcard);
          this.$refs.hwViewPictureForm.title = '完税证明'
          this.$refs.hwViewPictureForm.disableSubmit = false
        }else{
          this.$message.warning('未上传')
        }
      },



      viewServiceContract(record){
        if(record.workContract === null || record.workContract === ''){
          this.$message.warning('该合同为线下合同,不支持预览')
          return
        }
        this.$refs.hlgViewContractForm.edit(record.workContract,record.filePathPrefix);
        this.$refs.hlgViewContractForm.title = '查看合同'
        this.$refs.hlgViewContractForm.disableSubmit = false
        this.$refs.hlgViewContractForm.contractName = '合同';
      },
      viewRequirementDescription(record){
        this.$refs.viewRequirementDescriptionForm.edit(record);
        this.$refs.viewRequirementDescriptionForm.title = '需求描述'
        this.$refs.viewRequirementDescriptionForm.disableSubmit = false
      },


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

</style>