index.vue 13 KB

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