index.tsx 4.2 KB

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