index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { Checkbox, Icon, Popup } from 'vant'
  2. import { defineComponent, PropType } from 'vue'
  3. import styles from './index.module.less'
  4. import activeButtonIcon from '@common/images/icon_checkbox.png'
  5. import activeButtonIconTenant from '@common/images/icon_checkbox-tenant.png'
  6. import inactiveButtonIcon from '@common/images/icon_checkbox_default.png'
  7. import ColHeader from '../col-header'
  8. import { state } from '@/state'
  9. import request from '@/helpers/request'
  10. const protocolText = {
  11. BUY_ORDER: '《酷乐秀平台服务协议》',
  12. REGISTER: '《酷乐秀平台注册协议》'
  13. }
  14. export default defineComponent({
  15. name: 'protocol',
  16. props: {
  17. showHeader: {
  18. type: Boolean,
  19. default: false
  20. },
  21. modelValue: {
  22. type: Boolean,
  23. default: false
  24. },
  25. prototcolType: {
  26. type: String as PropType<'BUY_ORDER' | 'REGISTER'>,
  27. default: 'BUY_ORDER'
  28. }
  29. },
  30. data() {
  31. return {
  32. exists: true,
  33. checked: this.modelValue,
  34. popupStatus: false,
  35. protocolHTML: '',
  36. protocolPopup: null as any,
  37. baseUrl:
  38. state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
  39. }
  40. },
  41. async mounted() {
  42. try {
  43. const res = await request.get(
  44. this.baseUrl + '/sysUserContractRecord/checkContractSign',
  45. {
  46. params: {
  47. contractType: this.prototcolType
  48. }
  49. }
  50. )
  51. // console.log(res)
  52. this.exists = res.data
  53. this.checked = this.checked || this.exists
  54. this.$emit('update:modelValue', this.checked || this.exists)
  55. } catch {}
  56. this.checked = this.modelValue
  57. // this.getContractDetail()
  58. window.addEventListener('hashchange', this.onHash, false)
  59. },
  60. unmounted() {
  61. window.removeEventListener('hashchange', this.onHash, false)
  62. },
  63. watch: {
  64. checked(val) {
  65. this.$emit('update:modelValue', val)
  66. }
  67. },
  68. methods: {
  69. async getContractDetail() {
  70. try {
  71. console.log('getContractDetail')
  72. // 判断是否有协议内容
  73. if (!this.protocolHTML) {
  74. const res = await request.get(
  75. this.baseUrl + '/sysUserContractRecord/queryContract',
  76. {
  77. params: {
  78. contractType: this.prototcolType
  79. }
  80. }
  81. )
  82. this.protocolHTML = res.data
  83. console.log(res)
  84. }
  85. this.onPopupClose()
  86. } catch {}
  87. },
  88. onHash() {
  89. this.popupStatus = false
  90. },
  91. onPopupClose() {
  92. this.popupStatus = !this.popupStatus
  93. // 打开弹窗
  94. if (this.popupStatus) {
  95. const route = this.$route
  96. let times = 0
  97. for (const i in route.query) {
  98. times += 1
  99. }
  100. const origin = window.location.href
  101. const url = times > 0 ? '&pto=' + +new Date() : '?pto=' + +new Date()
  102. history.pushState('', '', `${origin}${url}`)
  103. } else {
  104. window.history.go(-1)
  105. }
  106. if (this.protocolPopup) {
  107. ;(this.protocolPopup as any).scrollTop = 0
  108. }
  109. }
  110. },
  111. render() {
  112. return (
  113. <div class={styles.colProtocol}>
  114. {!this.exists && (
  115. <Checkbox
  116. v-model={this.checked}
  117. v-slots={{
  118. icon: (props: any) => (
  119. <Icon
  120. class={styles.boxStyle}
  121. name={
  122. props.checked
  123. ? state.projectType === 'tenant'
  124. ? activeButtonIconTenant
  125. : activeButtonIcon
  126. : inactiveButtonIcon
  127. }
  128. size="15"
  129. />
  130. )
  131. }}
  132. >
  133. 我已阅读并同意
  134. </Checkbox>
  135. )}
  136. {this.exists && <>查看</>}
  137. <span onClick={this.getContractDetail} class={styles.protocolText}>
  138. {protocolText[this.prototcolType]}
  139. </span>
  140. <Popup
  141. ref={this.protocolPopup}
  142. show={this.popupStatus}
  143. position="bottom"
  144. style={{ height: '100%' }}
  145. >
  146. {this.showHeader && <ColHeader title="酷乐秀平台服务协议" />}
  147. {this.popupStatus && (
  148. <div class={styles.protocolContent} id="mProtocol">
  149. <div
  150. class={styles.protocolContent}
  151. v-html={this.protocolHTML}
  152. ></div>
  153. </div>
  154. )}
  155. </Popup>
  156. </div>
  157. )
  158. }
  159. })