import request from '@/helpers/request'
import { state } from '@/state'
import { defineComponent } from 'vue'
import styles from './index.module.less'

// 预览协议 - 原生实名认证使用
export default defineComponent({
  name: 'preview-protocol',
  data() {
    return {
      protocolHTML: '' as any
    }
  },
  async mounted() {
    let type = 'REGISTER'
    const queryType = this.$route.query.type

    if (queryType) {
      type = queryType.toString()
    } else {
      if (state.platformType === 'STUDENT') {
        type = 'REGISTER'
      } else {
        type = 'REGISTER_TEACHER'
      }
    }

    try {
      // 判断是否有协议内容
      if (!this.protocolHTML) {
        const { data } = await request.get(
          state.platformApi + '/open/userContractRecord/queryLatestContractTemplate',
          {
            params: {
              contractType: type || 'REGISTER'
            }
          }
        )
        this.protocolHTML = data.contractTemplateContent || ''
      }
    } catch {
      //
    }
  },
  render() {
    return (
      <div id="mProtocol">
        <div class={styles.mProtocol} v-html={this.protocolHTML}></div>
      </div>
    )
  }
})
