submit.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="d-flex flex-column bg-base">
  3. <u-loading-page :loading="loading" />
  4. <SimpleDynamicFormUni
  5. ref="formRef"
  6. :formDefine="formDefine"
  7. :formProps="{
  8. labelPosition: 'top',
  9. labelWidth: '175',
  10. }"
  11. :formModelInit="formModelInit"
  12. />
  13. <u-button type="primary" @click="submit">提交</u-button>
  14. <u-safe-bottom />
  15. </view>
  16. </template>
  17. <script setup lang="ts">
  18. import ContributeApi, { ContributeItem } from '@/api/user/ContributeApi';
  19. import CheckUtils from '@/common/utils/CheckUtils';
  20. import { showError } from '@/common/composeabe/ErrorDisplay';
  21. import { ref } from 'vue';
  22. import type { FormDefine, FormExport } from '@/common/components/form';
  23. import type { DynamicSelectProps } from '@/common/components/form/components/DynamicSelect.vue';
  24. import SimpleDynamicFormUni from '@/common/components/form/SimpleDynamicFormUni.vue';
  25. const loading = ref(false);
  26. const formRef = ref<FormExport>();
  27. const formDefine : FormDefine = {
  28. items: [
  29. {
  30. name: '',
  31. children: {
  32. type: 'group',
  33. props: {
  34. class: 'form-block',
  35. },
  36. propNestType: 'nest',
  37. items: [
  38. {
  39. label: '认领村庄',
  40. name: 'village_id',
  41. type: 'dynamic-select',
  42. params: {
  43. loadData: async () =>
  44. (await ContributeApi.getCanClaimVallageList())
  45. .map((p) => ({
  46. value: p.id,
  47. text: p.villageName,
  48. }))
  49. ,
  50. } as DynamicSelectProps,
  51. rules: [{
  52. required: true,
  53. errorMessage: '请选择要认领的村庄',
  54. }],
  55. },
  56. {
  57. label: '姓名',
  58. name: 'name',
  59. type: 'text',
  60. defaultValue: '',
  61. params: {
  62. placeholder: '请输入姓名',
  63. },
  64. rules: [{
  65. required: true,
  66. errorMessage: '请输入姓名',
  67. }]
  68. },
  69. {
  70. label: '性别',
  71. name: 'sex',
  72. type: 'select',
  73. params: {
  74. localdata: [
  75. { value: 1, text: "男" },
  76. { value: 2, text: "女" },
  77. { value: 3, text: "不透露" },
  78. ],
  79. clear: false,
  80. },
  81. rules: [{
  82. required: true,
  83. errorMessage: '请选择性别',
  84. }]
  85. },
  86. {
  87. label: '联系方式',
  88. name: 'mobile',
  89. type: 'text',
  90. defaultValue: '',
  91. params: {
  92. placeholder: '请输入联系方式',
  93. },
  94. rules: [{
  95. required: true,
  96. errorMessage: '请输入手机号',
  97. },{
  98. required: true,
  99. validateFunction: (rule: any, value: any,data: any,callback: (e: any) => void) => {
  100. if (!CheckUtils.checkIsChinesePhoneNumber(value)) {
  101. callback('手机号格式不正确')
  102. return false
  103. }
  104. return true
  105. }
  106. }]
  107. },
  108. {
  109. label: '地址',
  110. name: 'address',
  111. type: 'text',
  112. defaultValue: '',
  113. params: {
  114. placeholder: '请输入地址',
  115. },
  116. rules: [{
  117. required: true,
  118. errorMessage: '请输入地址',
  119. }]
  120. },
  121. ]
  122. }
  123. },
  124. {
  125. name: '',
  126. children: {
  127. type: 'group',
  128. props: {
  129. class: 'form-block',
  130. },
  131. propNestType: 'nest',
  132. items: [
  133. {
  134. label: '申请理由',
  135. name: 'claim_reason',
  136. type: 'textarea',
  137. defaultValue: '',
  138. params: {
  139. placeholder: '请输入申请理由',
  140. },
  141. rules: [{
  142. required: true,
  143. errorMessage: '请输入申请理由',
  144. }]
  145. }
  146. ]
  147. }
  148. },
  149. ]
  150. }
  151. function formModelInit() {
  152. return new ContributeItem();
  153. }
  154. async function submit() {
  155. if (!formRef.value)
  156. return;
  157. try {
  158. const data = await formRef.value.submitForm<ContributeItem>();
  159. if (!data)
  160. return;
  161. loading.value = true;
  162. await ContributeApi.contribute(data);
  163. uni.showModal({
  164. title: '提交成功',
  165. content: '感谢您的投稿,我们将尽快审核并通知您结果。',
  166. });
  167. } catch (e) {
  168. showError(e);
  169. } finally {
  170. loading.value = false;
  171. }
  172. }
  173. </script>
  174. <style lang="scss">
  175. </style>