index.vue 3.4 KB

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