<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>

          <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="'companyBusiness:subcontract'">合同</a>
               <a-divider type="vertical"  v-has="'companyBusiness:evidence'" />
               <a @click="viewInvoice(record)" v-has="'companyBusiness:evidence'">打款凭证</a>
             </span>

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

          </a-table>
        </div>

       <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-card>

  </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'

  const getContract = (params) => getAction('/wisdom/hlwPayment/getContract', params)

  export default {
    name: 'HlwCompanyBusinessDetailsList',
    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 }
        },
        invoiceId: 0,
        idList: "",
        accept: '.pdf',
        confirmLoading: false,
        validatorRules: {},
        // 表头
        columns: [
          {
            title: '需求名称',
            align: 'center',
            dataIndex: 'requirementName',
            scopedSlots: { customRender: 'action3' }
          },
          {
            title: '付款时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '项目金额',
            align: 'center',
            dataIndex: 'totalPayment'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          },

        ],
        url: {
          list: '/wisdom/hlwSubcontractorAccountFlow/companyBusinessDetailList',
          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
        })
      },

      viewServiceContract(record){
        getContract(record).then((res) => {
          if (res.success) {
            console.log(res)
            var workContract=res.message
            if(workContract === null || workContract === ''){
              this.$message.warning('该合同为线下合同,不支持预览')
              return
            }
            //通过平台取慧盈前缀
            if(record.isThroughPlatform==1){
              this.$refs.hlgViewContractForm.edit(workContract,null);
            }else{
              this.$refs.hlgViewContractForm.edit(workContract,record.filePathPrefix);
            }
            this.$refs.hlgViewContractForm.title = '查看合同'
            this.$refs.hlgViewContractForm.disableSubmit = false
            this.$refs.hlgViewContractForm.contractName = '合同';
          } else {
            this.$error({
              title: '错误提示',
              content: res.message,
              okText: '确定',
              centered:true
            })
          }
        })
      },



      viewRequirementDescription(record){
        this.$refs.viewRequirementDescriptionForm.edit(record);
        this.$refs.viewRequirementDescriptionForm.title = '需求描述'
        this.$refs.viewRequirementDescriptionForm.disableSubmit = 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('暂无对账单')
        }
      },

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

</style>