index.tsx 4.4 KB

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