<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">
        <!-- 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'





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


    },
    data() {
      return {
        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: '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.form.resetFields()
        this.model = Object.assign({}, record);
        this.visible = true
        this.loadData1(this.model)
      },
      handleOk() {
        this.close()
        this.visible = false
      },
      handleCancel() {
        this.close()
      },



      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>