index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="theme-regist-content-info-container">
  3. <view class="title-container">
  4. <view class="title-content-text">{{ title }}</view>
  5. <view class="title-content-date">{{ date }}</view>
  6. </view>
  7. <rich-text :content="content"></rich-text>
  8. <u-popup :show="show" :round="5" mode="bottom" :closeOnClickOverlay="true" :overlay="true" @close="popClose">
  9. <view class="pop-form-content">
  10. <RegistForm
  11. v-if="rules"
  12. :rules="rules"
  13. ref="registForm"
  14. @onSubmitHandle="onSubmit"
  15. :regist-info="model1.userInfo"
  16. ></RegistForm>
  17. </view>
  18. </u-popup>
  19. <view class="regist-btn">
  20. <u-button
  21. text="报名"
  22. size="normal"
  23. type="primary"
  24. @click="onRegistClick"
  25. ></u-button>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { fetchContentDetail, fetchUsrApplyDetail, formCfg, putUsrRegist } from '@/common/api';
  31. import { CONTENT_TYPE, FORM_MOD, USR_TYPE_LIST } from '@/common/EnumConst';
  32. import RegistForm from '@/components/RegistForm';
  33. import RichText from '@/components/RichText/index.vue';
  34. import { authLogin, getStorageObj, storageKey } from '@/util';
  35. const staticRules = {
  36. 'userInfo.email': {
  37. pattern: /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
  38. },
  39. };
  40. export default {
  41. name: 'content',
  42. components: {
  43. RichText,
  44. RegistForm,
  45. },
  46. props: {},
  47. data() {
  48. return {
  49. CONTENT_TYPE,
  50. content: null,
  51. queryParams: {},
  52. title: '',
  53. date: '',
  54. contentType: '',
  55. show: false,
  56. id: '',
  57. USR_TYPE_LIST,
  58. loading: false,
  59. model1: {
  60. userInfo: {
  61. usrName: '',
  62. conferenceFlag: '0',
  63. },
  64. },
  65. rules: null,
  66. };
  67. },
  68. created() {
  69. },
  70. onLoad(res) {
  71. // 登录返回之后的页面
  72. this.queryParams = getStorageObj(storageKey.regtheme);
  73. this.getContentInfo();
  74. formCfg('theme_form_cfg').then(res => {
  75. const { msg } = res;
  76. if (msg) {
  77. const cfgJson = JSON.parse(msg);
  78. Object.keys(staticRules).forEach(item => {
  79. if (!cfgJson[item]) {
  80. Object.assign(cfgJson[item], staticRules[item]);
  81. }
  82. });
  83. this.rules = cfgJson;
  84. }
  85. this.$refs.registForm?.setFormRules();
  86. if (this.queryParams.mode === FORM_MOD.modify) {
  87. this.getUsrMeetingInfo(this.queryParams.apply);
  88. this.show = true;
  89. }
  90. });
  91. },
  92. methods: {
  93. async onSubmit(userInfo) {
  94. const {
  95. id,
  96. type,
  97. } = this.queryParams;
  98. const { code } = await putUsrRegist({
  99. ...userInfo,
  100. contentId: id,
  101. }, type);
  102. if (code !== 200) {
  103. return;
  104. }
  105. uni.showToast({
  106. mask: true,
  107. title: '报名完成',
  108. icon: 'success',
  109. success: async () => {
  110. this.show = false;
  111. },
  112. });
  113. },
  114. popClose() {
  115. console.log(this.queryParams);
  116. this.show = false;
  117. },
  118. async getContentInfo() {
  119. const {
  120. data: {
  121. content,
  122. title,
  123. createTime,
  124. contentType,
  125. id,
  126. },
  127. } = await fetchContentDetail(this.queryParams.id);
  128. this.content = content;
  129. this.title = title;
  130. this.contentType = contentType;
  131. this.id = id;
  132. uni.setNavigationBarTitle({
  133. title,
  134. });
  135. this.date = uni.$u.timeFormat(createTime, 'yyyy-mm-dd');
  136. },
  137. onRegistClick() {
  138. authLogin(async (usr) => {
  139. this.show = true;
  140. // this.$refs.registForm?.restForm();
  141. // this.$refs.registForm?.clearValidate();
  142. });
  143. },
  144. async getUsrMeetingInfo(id) {
  145. const { data } = await fetchUsrApplyDetail(id);
  146. if (!data) {
  147. return;
  148. }
  149. this.model1.userInfo = data;
  150. },
  151. },
  152. };
  153. </script>
  154. <style lang="scss" src="./index.scss" />;