index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. // 校验表单并获取数据
  76. cust_form_ref.value.onSubmit().then(async (res) => {
  77. console.log('===res===>', res, file_url);
  78. //文件必传校验
  79. for (let i = 0; i < updata_list.length; i++) {
  80. const element = updata_list[i];
  81. console.log(element.required, element.permission.includes(data.value.key), file_url[element.key]);
  82. const type = element.required && element.permission.includes(data.value.key) && !file_url[element.key];
  83. console.log('element', element, type);
  84. if (type) {
  85. uni.showToast({
  86. title: '请上传' + element.title,
  87. icon: 'error'
  88. })
  89. return;
  90. }
  91. }
  92. const parmas = {
  93. serviceCategory: data.value.key,
  94. ...file_url
  95. };
  96. for (const key in res) {
  97. parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
  98. }
  99. console.log('提交', parmas);
  100. // return;
  101. // 提交接口,注册人员
  102. const submit_res = await add(parmas);
  103. if (submit_res.code == 200) {
  104. uni.showToast({
  105. title: '注册成功',
  106. icon: 'none'
  107. })
  108. uni.navigateBack();
  109. return;
  110. }
  111. uni.showToast({
  112. title: res.msg,
  113. icon: 'none'
  114. })
  115. console.log('==submit_res====>', submit_res);
  116. })
  117. } catch (error) {
  118. console.log('error', error);
  119. } finally {
  120. }
  121. }
  122. function onChange({ key, url }) {
  123. console.log('onChange', key, url);
  124. Object.assign(file_url, {
  125. [key]: url
  126. })
  127. }
  128. function getRegister() {
  129. getVolunteerInfo({ serviceCategory: data.value.key }).then(res => {
  130. console.log('xxxxxxxxxxres', res, cust_form_ref.value);
  131. if (res.data) {
  132. cust_form_ref.value.setData(res.data);
  133. Object.assign(file_url, {
  134. volunteerPicture: res.data.volunteerPicture,
  135. idCardPicture: res.data.idCardPicture,
  136. certificationPicture: res.data.certificationPicture
  137. })
  138. isAdd.value = false;
  139. }
  140. })
  141. }
  142. // onMounted(() => {
  143. // nextTick(() => {
  144. // });
  145. // })
  146. onLoad((options) => {
  147. const option = JSON.parse(decodeURIComponent(options.data));
  148. data.value = option;
  149. console.log("option", option);
  150. uni.setNavigationBarTitle({
  151. title: option.name // 根据业务逻辑调整
  152. });
  153. setTimeout(() => {
  154. getRegister();
  155. }, 500);
  156. })
  157. </script>
  158. <style lang="scss" scoped>
  159. .register-main {
  160. padding: 12px;
  161. background-color: rgba(245, 245, 245, 1);
  162. // height: 100vh;
  163. .register-user-info {
  164. margin-bottom: 12px;
  165. background-color: #fff;
  166. border-radius: 8px;
  167. padding: 18px 16px;
  168. }
  169. .updata-imgs {
  170. margin-bottom: 12px;
  171. }
  172. }
  173. </style>