index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="register-main">
  3. <up-alert description="您已完成账户注册" type="success" showIcon closable v-if="!isAdd"></up-alert>
  4. <view class="register-user-info">
  5. <FontTitle title="请完成注册信息填报" />
  6. <CustForm :column="com_column" ref="cust_form_ref" :isCode="isAdd" />
  7. </view>
  8. <view v-for="item in updata_list" :key="item.key" class="updata-imgs">
  9. <UpdataImgs :fileList="file_url[item.key]" :data="item" ref="zsImg"
  10. v-if="item.permission.includes(data.key)" @onSubmit="onChange" />
  11. </view>
  12. <up-button type="primary" text="确定" @click="onSubmit" v-if="isAdd"></up-button>
  13. </view>
  14. </template>
  15. <script setup>
  16. import { ref, reactive, onMounted, nextTick } from 'vue';
  17. import { onLoad } from '@dcloudio/uni-app';
  18. import FontTitle from "@/components/font-title/index.vue";
  19. import CustForm from "@/components/cust-form/index";
  20. import UpdataImgs from "@/components/updata-imgs/index.vue";
  21. import { chatting, education, clean } from "./data";
  22. import { add, getVolunteerInfo } from "@/api/volunteer";
  23. import { computed } from 'vue';
  24. const userImg = ref(null);
  25. const zsImg = ref(null);
  26. const updata_list = [
  27. {
  28. title: '上传头像',
  29. text: '上传您的头像',
  30. img: '/static/img/updata-user-img.png',
  31. key: 'volunteerPicture',
  32. ref: userImg,
  33. permission: [1, 2],
  34. required: true
  35. },
  36. {
  37. title: '个人身份证',
  38. text: '上传您的个人身份证',
  39. img: '/static/img/updata-user-img.png',
  40. key: 'idCardPicture',
  41. ref: zsImg,
  42. permission: [1, 2],
  43. required: true
  44. },
  45. {
  46. title: '职业、资质证书',
  47. text: '上传您的职业、资质证书',
  48. img: '/static/img/updata-user-img.png',
  49. key: 'certificationPicture',
  50. ref: zsImg,
  51. permission: [1, 2],
  52. required: false
  53. }
  54. ]
  55. const cust_form_ref = ref(null);
  56. const data = ref(null);
  57. const file_url = reactive({});
  58. const isAdd = ref(true);//是否已经注册
  59. const sex_status = {
  60. '男': 0,
  61. '女': 1
  62. }
  63. const register_column = {
  64. 1: chatting,
  65. 2: education,
  66. 5: clean
  67. }
  68. //根据类型获取表单item 值
  69. const com_column = computed(() => {
  70. let column_list = data.value ? register_column[data.value.key] : [];
  71. return column_list
  72. })
  73. function onSubmit() {
  74. try {
  75. // return;
  76. // 校验表单并获取数据
  77. cust_form_ref.value.onSubmit().then(async (res) => {
  78. console.log('===res===>', res, file_url);
  79. //文件必传校验
  80. for (let i = 0; i < updata_list.length; i++) {
  81. const element = updata_list[i];
  82. console.log(element.required, element.permission.includes(data.value.key), file_url[element.key]);
  83. const type = element.required && element.permission.includes(data.value.key) && !file_url[element.key];
  84. console.log('element', element, type);
  85. if (type) {
  86. uni.showToast({
  87. title: '请上传' + element.title,
  88. icon: 'error'
  89. })
  90. return;
  91. }
  92. }
  93. const parmas = {
  94. serviceCategory: data.value.key,
  95. ...file_url
  96. };
  97. for (const key in res) {
  98. parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
  99. }
  100. console.log('提交', parmas);
  101. // return;
  102. // 提交接口,注册人员
  103. const submit_res = await add(parmas);
  104. if (submit_res.code == 200) {
  105. uni.showToast({
  106. title: '注册成功',
  107. icon: 'success',
  108. success: () => {
  109. setTimeout(() => {
  110. uni.navigateBack();
  111. }, 1000)
  112. }
  113. })
  114. return;
  115. }
  116. uni.showToast({
  117. title: res.msg,
  118. icon: 'none'
  119. })
  120. console.log('==submit_res====>', submit_res);
  121. })
  122. } catch (error) {
  123. console.log('error', error);
  124. } finally {
  125. }
  126. }
  127. function onChange({ key, url }) {
  128. console.log('onChange', key, url);
  129. Object.assign(file_url, {
  130. [key]: url
  131. })
  132. }
  133. async function getRegister() {
  134. try {
  135. uni.showLoading({
  136. title: '数据加载中...'
  137. });
  138. const res = await getVolunteerInfo({ serviceCategory: data.value.key });
  139. if (res.data) {
  140. cust_form_ref.value.setData(res.data);
  141. Object.assign(file_url, {
  142. volunteerPicture: res.data.volunteerPicture,
  143. idCardPicture: res.data.idCardPicture,
  144. certificationPicture: res.data.certificationPicture
  145. })
  146. isAdd.value = false;
  147. }
  148. } catch (error) {
  149. console.log('error', error);
  150. uni.showToast({
  151. title: error.msg,
  152. icon: 'error',
  153. });
  154. } finally {
  155. uni.hideLoading();
  156. }
  157. }
  158. // onMounted(() => {
  159. // nextTick(() => {
  160. // });
  161. // })
  162. onLoad((options) => {
  163. const option = JSON.parse(decodeURIComponent(options.data));
  164. data.value = option;
  165. console.log("option", option);
  166. uni.setNavigationBarTitle({
  167. title: option.name // 根据业务逻辑调整
  168. });
  169. setTimeout(() => {
  170. getRegister();
  171. }, 500);
  172. })
  173. </script>
  174. <style lang="scss" scoped>
  175. .register-main {
  176. padding: 12px;
  177. background-color: rgba(245, 245, 245, 1);
  178. // height: 100vh;
  179. .register-user-info {
  180. margin-bottom: 12px;
  181. background-color: #fff;
  182. border-radius: 8px;
  183. padding: 18px 16px;
  184. }
  185. .updata-imgs {
  186. margin-bottom: 12px;
  187. }
  188. }
  189. </style>