index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <view class="register-main">
  3. <view class="register-user-info">
  4. <FontTitle title="请完成注册信息填报" />
  5. <CustForm :column="com_column" ref="cust_form_ref" :isCode="isAdd" />
  6. </view>
  7. <view class="register-card">
  8. <view class="info-list">
  9. <view class="font-title">服务类别( {{ serviceOptions.length }} )</view>
  10. <view class="service-list">
  11. <view v-for="item in serviceOptions" :key="item.id" @click="serviceChange(item, 'classKey')"
  12. :class="serviceKeys.classKey === item.id ? 'servicetab classActive' : 'servicetab'">
  13. {{ item.businessName }}
  14. </view>
  15. </view>
  16. <view v-if="serviceKeys.classKey && serviceItems && serviceItems.length > 0">
  17. <view class="font-title">服务项目</view>
  18. <view class="service-list">
  19. <view v-for="item in serviceItems" :key="item.id" @click="serviceChange(item, 'itemKey')"
  20. :class="serviceKeys.itemKey === item.id ? 'servicetab classActive' : 'servicetab'">
  21. {{ item.businessName }}
  22. </view>
  23. </view>
  24. </view>
  25. <view v-if="serviceKeys.itemKeyname || serviceKeys.classKeyname">
  26. <view class="font-title">服务时长(<text class="activeColor">{{ serviceKeys.itemKeyname ||
  27. serviceKeys.classKeyname }}</text>)</view>
  28. <view class="service-list">
  29. <view v-for="item in timeList" :key="item.id" @click="serviceChange(item, 'time')"
  30. :class="serviceKeys.time === item.id ? 'servicetab classActive' : 'servicetab'">
  31. {{ item.lable }}
  32. </view>
  33. </view>
  34. <view class="font-title">服务价格(<text class="activeColor">{{ serviceKeys.itemKeyname ||
  35. serviceKeys.classKeyname }}</text>)</view>
  36. <view class="service-list">
  37. <up-input v-model="serviceKeys.price" placeholder="请设置服务价格">
  38. <template #suffix>
  39. <text>元</text>
  40. </template>
  41. </up-input>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="register-card" v-if="details.appStatus === '3'">
  47. <view class="font-title">驳回原因</view>
  48. <view class="info-list">
  49. {{ details.rejectReason }}
  50. </view>
  51. </view>
  52. <view v-for="item in updata_list" :key="item.key" class="updata-imgs">
  53. <UpdataImgs :fileList="file_url[item.key]" :data="item" ref="zsImg"
  54. v-if="item.permission.includes(data.key)" @onSubmit="onChange" />
  55. </view>
  56. <!-- <up-button color="rgba(221, 94, 69, 1)" text="确定" @click="onSubmit" ></up-button> -->
  57. <view class="status-btn" @click="onSubmit">确定</view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { ref, reactive, onMounted, nextTick } from 'vue';
  62. import { onLoad } from '@dcloudio/uni-app';
  63. import FontTitle from "@/pages_home/components/font-title/index.vue";
  64. import CustForm from "@/pages_home/components/cust-form/index";
  65. import UpdataImgs from "@/pages_home/components/updata-imgs/index.vue";
  66. import { chatting, education, health } from "./data";
  67. import { add, getVolunteerInfo } from "@/api/volunteer";
  68. import { computed } from 'vue';
  69. import { getTreeList } from '@/api/volunteer'
  70. const userImg = ref(null);
  71. const zsImg = ref(null);
  72. const updata_list = [
  73. {
  74. title: '上传头像',
  75. text: '上传您的头像',
  76. img: '/static/img/updata-user-img.png',
  77. key: 'volunteerPicture',
  78. ref: userImg,
  79. permission: [1, 2],
  80. required: true
  81. },
  82. {
  83. title: '个人身份证',
  84. text: '上传您的个人身份证',
  85. img: '/static/img/updata-user-img.png',
  86. key: 'idCardPicture',
  87. ref: zsImg,
  88. permission: [1, 2],
  89. required: true
  90. },
  91. {
  92. title: '职业、资质证书',
  93. text: '上传您的职业、资质证书',
  94. img: '/static/img/updata-user-img.png',
  95. key: 'certificationPicture',
  96. ref: zsImg,
  97. permission: [1, 2],
  98. required: false
  99. }
  100. ]
  101. const cust_form_ref = ref(null);
  102. const data = ref(null);
  103. const file_url = reactive({});
  104. const isAdd = ref(true);//是否已经注册
  105. const details = ref({});//详情数据
  106. const serviceOptions = ref([]);//服务类目
  107. const serviceItems = ref([]);//服务项目
  108. const serviceKeys = reactive({
  109. classKey: '',//服务类别
  110. classKeyname: '',
  111. itemKey: '',//服务项目
  112. itemKeyname: '',
  113. time:'',//时间
  114. price:'',//价格
  115. })
  116. const timeList = [
  117. {
  118. lable: '60分钟',
  119. id: 60
  120. },
  121. {
  122. lable: '90分钟',
  123. id: 90
  124. },
  125. {
  126. lable: '120分钟',
  127. id: 120
  128. },
  129. ]
  130. const sex_status = {
  131. '男': 0,
  132. '女': 1
  133. }
  134. const register_column = {
  135. 1: chatting,
  136. 2: education,
  137. 3: health
  138. }
  139. //根据类型获取表单item 值
  140. const com_column = computed(() => {
  141. let column_list = data.value ? register_column[data.value.key] : [];
  142. return column_list
  143. })
  144. function onSubmit() {
  145. try {
  146. // return;
  147. // 校验表单并获取数据
  148. cust_form_ref.value.onSubmit().then(async (res) => {
  149. console.log('===res===>', res, file_url);
  150. //文件必传校验
  151. for (let i = 0; i < updata_list.length; i++) {
  152. const element = updata_list[i];
  153. console.log(element.required, element.permission.includes(data.value.key), file_url[element.key]);
  154. const type = element.required && element.permission.includes(data.value.key) && !file_url[element.key];
  155. console.log('element', element, type);
  156. if (type) {
  157. uni.showToast({
  158. title: '请上传' + element.title,
  159. icon: 'error'
  160. })
  161. return;
  162. }
  163. }
  164. if(!(serviceKeys.itemKeyname || serviceKeys.classKeyname)){
  165. uni.showToast({
  166. title: '请选择服务',
  167. icon: 'none'
  168. })
  169. return
  170. }
  171. if(!serviceKeys.time){
  172. uni.showToast({
  173. title: '请选择服务时长',
  174. icon: 'none'
  175. })
  176. return
  177. }
  178. if(!serviceKeys.price){
  179. uni.showToast({
  180. title: '请输入服务价格',
  181. icon: 'none'
  182. })
  183. return
  184. }
  185. const parmas = {
  186. serviceCategory: data.value.key,
  187. ...file_url,
  188. businessManagementId:serviceKeys.itemKey || serviceKeys.classKey,
  189. businessPrice: serviceKeys.price,
  190. businessDuration: serviceKeys.time
  191. };
  192. for (const key in res) {
  193. parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
  194. if (key === 'businessManagementIdkey') {
  195. parmas['businessManagementId'] = res[key]
  196. delete parmas['businessManagementIdkey'];
  197. }
  198. }
  199. console.log('提交', parmas);
  200. // return;
  201. // 提交接口,注册人员
  202. const submit_res = await add(parmas);
  203. if (submit_res.code == 200) {
  204. uni.showToast({
  205. title: '申请成功',
  206. icon: 'success',
  207. success: () => {
  208. setTimeout(() => {
  209. uni.navigateBack();
  210. }, 1000)
  211. }
  212. })
  213. return;
  214. }
  215. uni.showToast({
  216. title: res.msg,
  217. icon: 'none'
  218. })
  219. console.log('==submit_res====>', submit_res);
  220. })
  221. } catch (error) {
  222. console.log('error', error);
  223. } finally {
  224. }
  225. }
  226. function onChange({ key, url }) {
  227. console.log('onChange', key, url);
  228. Object.assign(file_url, {
  229. [key]: url
  230. })
  231. }
  232. function idToIndexs(array, targetId, path = []) {
  233. for (let i = 0; i < array.length; i++) {
  234. const item = array[i];
  235. const currentPath = path.concat(i);
  236. if (item.id === targetId) {
  237. console.log('indexs',item);
  238. return item
  239. }
  240. if (item.children) {
  241. const result = idToIndexs(item.children, targetId, currentPath);
  242. if (result) {
  243. return result;
  244. }
  245. }
  246. }
  247. return null; // 如果没有找到对应的项,返回 null
  248. }
  249. //重新提交的服务信息回显
  250. function servesInit(){
  251. const indexs = idToIndexs(serviceOptions.value,details.value.businessManagementId +'')
  252. const names = indexs.businessTierName.split('-');
  253. Object.assign(serviceKeys, {
  254. classKey: String(indexs.parentId)===String(data.value.key)? indexs.id :indexs.parentId,//服务类别
  255. classKeyname:names[1],
  256. itemKey: indexs.id,//服务项目
  257. itemKeyname: indexs.businessName,
  258. time:details.value.businessDuration,//时间
  259. price:details.value.businessPrice,//价格
  260. })
  261. }
  262. async function getRegister() {
  263. try {
  264. uni.showLoading({
  265. title: '数据加载中...'
  266. });
  267. const res = await getVolunteerInfo({ serviceCategory: data.value.key });
  268. if (res.data) {
  269. details.value = { ...res.data, age: res.data.age + '' };
  270. cust_form_ref.value.setData(details.value);
  271. Object.assign(file_url, {
  272. volunteerPicture: res.data.volunteerPicture,
  273. idCardPicture: res.data.idCardPicture,
  274. certificationPicture: res.data.certificationPicture
  275. })
  276. servesInit(data)
  277. isAdd.value = false;
  278. }
  279. } catch (error) {
  280. console.log('error', error);
  281. uni.showToast({
  282. title: error.msg,
  283. icon: 'error',
  284. });
  285. } finally {
  286. uni.hideLoading();
  287. }
  288. }
  289. const serviceChange = (item, key) => {
  290. console.log('----', item);
  291. if (key === 'classKey') {
  292. serviceItems.value = item.children;
  293. serviceKeys['itemKey'] = '';
  294. }
  295. Object.assign(serviceKeys, {
  296. [key]: serviceKeys[key] === item.id ? '' : item.id,
  297. [key + 'name']: serviceKeys[key + 'name'] === item.businessName ? '' : item.businessName,
  298. })
  299. }
  300. const getTreeListInit = () => {
  301. getTreeList({ parentId: data.value.key }).then(res => {
  302. console.log('----', res.data);
  303. serviceOptions.value = res.data;
  304. })
  305. }
  306. onMounted(() => {
  307. getTreeListInit();
  308. })
  309. onLoad((options) => {
  310. const option = JSON.parse(decodeURIComponent(options.data));
  311. data.value = option;
  312. console.log("option", option);
  313. uni.setNavigationBarTitle({
  314. title: option.name // 根据业务逻辑调整
  315. });
  316. setTimeout(() => {
  317. getRegister();
  318. }, 500);
  319. })
  320. </script>
  321. <style lang="scss" scoped>
  322. .register-main {
  323. padding: 12px;
  324. background-color: rgba(245, 245, 245, 1);
  325. // height: 100vh;
  326. .register-user-info {
  327. margin-bottom: 12px;
  328. background-color: #fff;
  329. border-radius: 8px;
  330. padding: 18px 16px;
  331. }
  332. .updata-imgs {
  333. margin-bottom: 12px;
  334. }
  335. }
  336. .register-card {
  337. margin-bottom: 12px;
  338. background-color: #fff;
  339. border-radius: 8px;
  340. padding: 18px 16px;
  341. }
  342. .info-list {
  343. flex: 1;
  344. font-size: 14px;
  345. font-weight: 500;
  346. letter-spacing: 0px;
  347. line-height: 23.27px;
  348. color: rgba(51, 51, 51, 1);
  349. }
  350. .status-btn {
  351. // width: 716rpx;
  352. height: 96rpx;
  353. border-radius: 16rpx;
  354. background: rgba(221, 94, 69, 1);
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. font-size: 32rpx;
  359. font-weight: 400;
  360. color: rgba(255, 255, 255, 1);
  361. margin-bottom: 88rpx;
  362. }
  363. .font-title {
  364. margin-bottom: 32rpx;
  365. }
  366. .service-tile {
  367. font-size: 32rpx;
  368. font-weight: 400;
  369. line-height: 48rpx;
  370. color: rgba(51, 51, 51, 1);
  371. margin-bottom: 16rpx;
  372. }
  373. .service-list {
  374. display: flex;
  375. align-items: flex-start;
  376. flex-wrap: wrap;
  377. margin-bottom: 16rpx;
  378. }
  379. .servicetab {
  380. background: rgba(249, 250, 251, 1);
  381. color: rgba(51, 51, 51, 1);
  382. border: 1px solid #fff;
  383. padding: 8rpx 16rpx;
  384. border-radius: 16rpx;
  385. margin-right: 16rpx;
  386. margin-bottom: 16rpx;
  387. }
  388. .classActive {
  389. background: rgba(251, 229, 225, 1);
  390. color: rgba(221, 94, 69, 1);
  391. border: 1px solid rgba(221, 94, 69, 1);
  392. }
  393. .activeColor {
  394. color: rgba(221, 94, 69, 1);
  395. }
  396. </style>