<!--
  盛付通： 【签约开通】 页面内容

  @author terrfly
  @site https://www.jeequan.com
  @date 2022/11/03 08:35
-->
<template>
  <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">电子合同签约</a-divider>
  <a-form-item label="签约状态">
    {{ vdata.bizSignInfo.state }} <span v-if="vdata.bizSignInfo.errInfo">【{{ vdata.bizSignInfo.errInfo }}】</span>
    <a-button
      class="jeepay-m-btn"
      data-type="text"
      :loading="vdata.bizSignInfoBtnLoading"
      size="small"
      style="margin-left: 20px;"
      type="primary"
      @click="getMchApplymentChannelSignInfoFunc"
    >
      <reload-outlined v-if="!vdata.bizSignInfoBtnLoading" />刷新
    </a-button>
    <a-button
      class="jeepay-m-btn"
      data-type="text"
      :loading="vdata.bizReSignBtnLoading"
      size="small"
      style="margin-left: 20px;"
      type="primary"
      danger
      @click="mchApplyReSignFunc"
    >
      <edit-outlined v-if="!vdata.bizReSignBtnLoading" />重签
    </a-button>
  </a-form-item>

  <a-form-item v-if="vdata.bizSignInfo.signUrl" label="合同地址">
    <p style="margin-top: 5px;"><a :href="vdata.bizSignInfo.signUrl" target="_blank">{{ vdata.bizSignInfo.signUrl }}</a></p>

    <p style="margin-top: 20px;">合同地址快捷访问二维码：</p>
    <QrcodeVue :value="vdata.bizSignInfo.signUrl" :size="150" class="qrcode" />
  </a-form-item>


  <NextBizsCommonPage ref="nextBizsCommonPage" :showBizSignInfo="false" />
</template>

<script lang="ts" setup>

import { ref } from 'vue'
import NextBizsCommonPage from '../../commons/NextBizsCommonPage.vue'
import { $getMchApplymentChannelSignInfo, $getMchApplyReSign } from '@/api/manage'

import { reactive } from 'vue'
import QrcodeVue from 'qrcode.vue'

const nextBizsCommonPage = ref()

// 对外暴露的 页面渲染函数  也用作初始化
function pageRender (applyId){
  vdata.recordId = applyId
  getMchApplymentChannelSignInfoFunc()
  nextBizsCommonPage.value.pageRender(applyId) // 直接调用通用组件
}

const vdata : any = reactive({
  recordId: null, // 更新对象ID
  bizSignInfo: {}, // 电子合同信息
  bizSignInfoBtnLoading: false,

  extSignInfo: {}, // 电子合同额外签约参数（用于重签等）
  bizReSignBtnLoading: false,
})

// 电子合同状态查询
function getMchApplymentChannelSignInfoFunc(){
  vdata.bizSignInfoBtnLoading = true
  $getMchApplymentChannelSignInfo(vdata.recordId).then(res => {
     vdata.bizSignInfo = res
  }).finally(() => {
    vdata.bizSignInfoBtnLoading = false
  })
}

// 电子合同重签
function mchApplyReSignFunc(){
  vdata.bizReSignBtnLoading = true
  $getMchApplyReSign(vdata.recordId, 'reSign').then(res => {
     vdata.bizSignInfo = res
  }).finally(() => {
    vdata.bizReSignBtnLoading = false
  })
}
defineExpose({ pageRender })
</script>
