index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 ||
  36. serviceKeys.itemKeyname ||
  37. serviceKeys.classKeyname }}</text>)</view>
  38. <view class="service-list price-box">
  39. <up-input
  40. v-model="serviceKeys.time"
  41. placeholder="请输入服务时长"
  42. @blur="validateTimeInput"
  43. class="price-input"
  44. >
  45. <template #suffix>
  46. <text>分钟</text>
  47. </template>
  48. </up-input>
  49. </view>
  50. <view class="font-title">最少购买</view>
  51. <view class="service-list price-box">
  52. <up-input
  53. v-model="serviceKeys.minQuantity"
  54. placeholder="请输入最少购买数量"
  55. class="price-input"
  56. @blur="validateMinQuantity"
  57. ></up-input>
  58. </view>
  59. <view class="font-title">购买单位</view>
  60. <view class="service-list price-box">
  61. <up-input
  62. v-model="serviceKeys.businessUnit"
  63. placeholder="请输入购买单位,如:(次、平方、小时)"
  64. class="price-input"
  65. ></up-input>
  66. </view>
  67. <view class="font-title">服务描述</view>
  68. <view class="service-list">
  69. <up-textarea
  70. v-model="serviceKeys.businessDescribe"
  71. placeholder="服务描述内容,如:提供上门取衣、送衣服服务、您只需线上下单,我们工作人员便会按约定时间上门收取衣物"
  72. ></up-textarea>
  73. </view>
  74. <view class="font-title">服务价格(<text class="activeColor">{{ serviceKeys.threeKeyname ||
  75. serviceKeys.itemKeyname ||
  76. serviceKeys.classKeyname }}</text>)</view>
  77. <view class="service-list price-box">
  78. <up-input v-model="serviceKeys.price"
  79. :placeholder="min_max_price.minPrice && min_max_price.maxPrice ? `${min_max_price.minPrice}-${min_max_price.maxPrice}` : '请设置服务价格'"
  80. @blur="validatePriceInput" class="price-input">
  81. <template #suffix>
  82. <text>元</text>
  83. </template>
  84. </up-input>
  85. </view>
  86. <view class="price-describe" v-if="min_max_price.minPrice && min_max_price.maxPrice">
  87. 价格说明
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <view class="register-card" v-if="details.appStatus === '3'">
  93. <view class="font-title">驳回原因</view>
  94. <view class="info-list">
  95. {{ details.rejectReason }}
  96. </view>
  97. </view>
  98. <view v-for="item in updata_list" :key="item.key" class="updata-imgs">
  99. <UpdataImgs :fileList="file_url[item.key]" :data="item" ref="zsImg" @onSubmit="onChange" />
  100. </view>
  101. <view class="status-btn" @click="onSubmit">确定</view>
  102. </view>
  103. </template>
  104. <script setup>
  105. import { ref, reactive, onMounted, nextTick } from 'vue';
  106. import { onLoad } from '@dcloudio/uni-app';
  107. import FontTitle from "@/pages_home/components/font-title/index.vue";
  108. import CustForm from "@/pages_home/components/cust-form/index";
  109. import UpdataImgs from "@/pages_home/components/updata-imgs/index.vue";
  110. import { column } from "./data";
  111. import { add, getVolunteerInfo } from "@/api/volunteer";
  112. import { computed } from 'vue';
  113. import { getTreeList } from '@/api/volunteer'
  114. const userImg = ref(null);
  115. const zsImg = ref(null);
  116. const min_max_price = ref({
  117. minPrice: undefined,
  118. maxPrice: undefined
  119. })
  120. const updata_list = [
  121. {
  122. title: '上传头像',
  123. text: '上传您的头像',
  124. img: '/static/img/updata-user-img.png',
  125. key: 'volunteerPicture',
  126. ref: userImg,
  127. // permission: [1, 2],
  128. required: true
  129. },
  130. {
  131. title: '身份证正面',
  132. text: '上传您的身份证正面',
  133. img: '/static/img/updata-user-img.png',
  134. key: 'idCardPictureFront',
  135. ref: zsImg,
  136. // permission: [1, 2],
  137. required: true
  138. },
  139. {
  140. title: '身份证反面',
  141. text: '上传您的身份证反面',
  142. img: '/static/img/updata-user-img.png',
  143. key: 'idCardPictureBack',
  144. ref: zsImg,
  145. // permission: [1, 2],
  146. required: true
  147. },
  148. {
  149. title: '职业、资质证书',
  150. text: '上传您的职业、资质证书',
  151. img: '/static/img/updata-user-img.png',
  152. key: 'certificationPicture',
  153. ref: zsImg,
  154. // permission: [1, 2],
  155. required: false
  156. }
  157. ]
  158. const cust_form_ref = ref(null);
  159. const data = ref(null);
  160. const file_url = reactive({});
  161. const isAdd = ref(true);//是否已经注册
  162. const details = ref({});//详情数据
  163. const serviceOptions = ref([]);//服务类目
  164. const serviceItems = ref([]);//服务项目
  165. const serviceItems2 = ref([]);//服务小类目
  166. const serviceKeys = reactive({
  167. classKey: '',//服务类别
  168. classKeyname: '',
  169. itemKey: '',//服务项目
  170. itemKeyname: '',
  171. threeKey: '',//服务项
  172. threeKeyname: '',
  173. time: '',//时间
  174. price: '',//价格
  175. minQuantity: '',//最小购买次数
  176. businessUnit: '',//购买单位
  177. businessDescribe: '',//服务描述
  178. })
  179. const timeList = [
  180. {
  181. lable: '60分钟',
  182. id: 60
  183. },
  184. {
  185. lable: '90分钟',
  186. id: 90
  187. },
  188. {
  189. lable: '120分钟',
  190. id: 120
  191. },
  192. ]
  193. const sex_status = {
  194. '男': 0,
  195. '女': 1
  196. }
  197. const validatePriceInput = (value) => {
  198. console.log("TCL: validatePriceInput -> value", value)
  199. // 确保输入是纯数字
  200. if (!/^\d*$/.test(value)) {
  201. serviceKeys.price = value.replace(/\D/g, ''); // 移除非数字字符
  202. return;
  203. }
  204. const price = parseInt(serviceKeys.price, 10);
  205. // 检查是否在允许的范围之内
  206. if (min_max_price.value.minPrice !== undefined && min_max_price.value.maxPrice !== undefined) {
  207. if (price >= min_max_price.value.minPrice && price <= min_max_price.value.maxPrice) {
  208. serviceKeys.price = serviceKeys.price.toString();
  209. } else {
  210. serviceKeys.price = null;
  211. uni.showToast({
  212. title: '请输入价格区间内的价格',
  213. icon: 'none'
  214. })
  215. console.log("TCL: validatePriceInput -> error", value)
  216. }
  217. }
  218. };
  219. const validateTimeInput = (value) => {
  220. // 确保输入是纯数字
  221. if (!/^\d*$/.test(value)) {
  222. serviceKeys.time = value.replace(/\D/g, ''); // 移除非数字字符
  223. return;
  224. }
  225. const time = parseInt(serviceKeys.time, 10);
  226. // 检查是否大于0
  227. if (time <= 0) {
  228. serviceKeys.time = null;
  229. uni.showToast({
  230. title: '请输入大于0的服务时长',
  231. icon: 'none'
  232. });
  233. }
  234. };
  235. const validateMinQuantity = (value) => {
  236. // 确保输入是纯数字
  237. if (!/^\d*$/.test(value)) {
  238. serviceKeys.minQuantity = value.replace(/\D/g, ''); // 移除非数字字符
  239. return;
  240. }
  241. const quantity = parseInt(serviceKeys.minQuantity, 10);
  242. // 检查是否大于0
  243. if (quantity <= 0) {
  244. serviceKeys.minQuantity = null;
  245. uni.showToast({
  246. title: '请输入大于0的购买数量',
  247. icon: 'none'
  248. });
  249. }
  250. };
  251. //根据类型获取表单item 值
  252. const com_column = computed(() => {
  253. let column_list = data.value ? column : [];
  254. return column_list
  255. })
  256. function onSubmit() {
  257. try {
  258. // return;
  259. // 校验表单并获取数据
  260. cust_form_ref.value.onSubmit().then(async (res) => {
  261. //文件必传校验
  262. for (let i = 0; i < updata_list.length; i++) {
  263. const element = updata_list[i];
  264. const type = element.required && !file_url[element.key];
  265. if (type) {
  266. uni.showToast({
  267. title: '请上传' + element.title,
  268. icon: 'error'
  269. })
  270. return;
  271. }
  272. }
  273. if (!(serviceKeys.threeKeyname || serviceKeys.itemKeyname || serviceKeys.classKeyname)) {
  274. uni.showToast({
  275. title: '请选择服务',
  276. icon: 'none'
  277. })
  278. return
  279. }
  280. if (!serviceKeys.time) {
  281. uni.showToast({
  282. title: '请输入服务时长',
  283. icon: 'none'
  284. })
  285. return
  286. }
  287. if (!serviceKeys.price) {
  288. uni.showToast({
  289. title: '请输入服务价格',
  290. icon: 'none'
  291. })
  292. return
  293. }
  294. if (!serviceKeys.minQuantity) {
  295. uni.showToast({
  296. title: '请输入最少购买数量',
  297. icon: 'none'
  298. })
  299. return
  300. }
  301. if (!serviceKeys.businessUnit) {
  302. uni.showToast({
  303. title: '请输入购买单位',
  304. icon: 'none'
  305. })
  306. return
  307. }
  308. if (!serviceKeys.businessDescribe) {
  309. uni.showToast({
  310. title: '请输入服务描述',
  311. icon: 'none'
  312. })
  313. return
  314. }
  315. const parmas = {
  316. serviceCategory: data.value.key,
  317. ...file_url,
  318. businessManagementId: serviceKeys.threeKey || serviceKeys.itemKey || serviceKeys.classKey,
  319. businessPrice: serviceKeys.price,
  320. businessDuration: serviceKeys.time,
  321. businessUnit: serviceKeys.businessUnit,
  322. minQuantity: serviceKeys.minQuantity,
  323. businessDescribe: serviceKeys.businessDescribe
  324. };
  325. for (const key in res) {
  326. parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
  327. if (key === 'businessManagementIdkey') {
  328. parmas['businessManagementId'] = res[key]
  329. delete parmas['businessManagementIdkey'];
  330. }
  331. }
  332. console.log('提交', parmas);
  333. // return;
  334. // 提交接口,注册人员
  335. const submit_res = await add(parmas);
  336. if (submit_res.code == 200) {
  337. uni.showToast({
  338. title: '申请成功',
  339. icon: 'success',
  340. success: () => {
  341. setTimeout(() => {
  342. uni.navigateBack();
  343. }, 1000)
  344. }
  345. })
  346. return;
  347. }
  348. uni.showToast({
  349. title: res.msg,
  350. icon: 'none'
  351. })
  352. })
  353. } catch (error) {
  354. console.log('error', error);
  355. } finally {
  356. }
  357. }
  358. function onChange({ key, url }) {
  359. Object.assign(file_url, {
  360. [key]: url
  361. })
  362. }
  363. function handlerList(array, targetId, path = []) {
  364. for (let i = 0; i < array.length; i++) {
  365. const item = array[i];
  366. const currentPath = path.concat(i);
  367. if (item.id === targetId) {
  368. return item
  369. }
  370. if (item.children) {
  371. const result = handlerList(item.children, targetId, currentPath);
  372. if (result) {
  373. return result;
  374. }
  375. }
  376. }
  377. return null; // 如果没有找到对应的项,返回 null
  378. }
  379. /**
  380. * 根据目标id查找所有父级路径
  381. * @param {Array} data 树形数据源(如 serviceOptions.value)
  382. * @param {String|Number} targetId 要查找的目标id
  383. * @param {String} [idKey='id'] id字段名
  384. * @param {String} [childrenKey='children'] 子级字段名
  385. * @returns {Object|null}
  386. */
  387. function findParentPath(data, targetId, idKey = 'id', childrenKey = 'children') {
  388. for (const node of data) {
  389. // 当前节点匹配
  390. if (node[idKey] == targetId) {
  391. return {
  392. parentIdPath: [node[idKey]],
  393. businessTierName: node.businessName || ''
  394. };
  395. }
  396. // 搜索子级
  397. const result = node[childrenKey]?.length > 0
  398. ? findParentPath(node[childrenKey], targetId, idKey, childrenKey)
  399. : null;
  400. if (result) {
  401. return {
  402. parentIdPath: [...result.parentIdPath, node[idKey]],
  403. businessTierName: `${result.businessTierName}-${node.businessName || ''}`
  404. };
  405. }
  406. }
  407. return null;
  408. }
  409. function idToIndexs(targetId) {
  410. const res = findParentPath(serviceOptions.value, targetId);
  411. return res || {
  412. parentIdPath: [],
  413. businessTierName: ''
  414. };
  415. }
  416. const backfill = {
  417. 2: 'threeKey',
  418. 1: 'itemKey',
  419. 0: 'classKey',
  420. }
  421. //重新提交的服务信息回显
  422. function servesInit() {
  423. const indexs = idToIndexs(details.value.businessManagementId + '');
  424. const names = indexs.businessTierName.split('-').reverse();
  425. const ids = indexs.parentIdPath.reverse();
  426. const obj = {};
  427. for (let i = 0; i < names.length; i++) {
  428. obj[backfill[i]] = ids[i];
  429. obj[backfill[i] + 'name'] = names[i];
  430. }
  431. console.log('obj', obj, names, ids);
  432. console.log('indexs', indexs, names, ids);
  433. // const indexs = idToIndexs(serviceOptions.value, details.value.businessManagementId + '')
  434. // const names = indexs.businessTierName.split('-');
  435. // console.log('indexs',indexs,names);
  436. if (obj.itemKey) {
  437. const row = handlerList(serviceOptions.value, obj.classKey)
  438. console.log(1, row);
  439. serviceItems.value = row.children;
  440. }
  441. if (obj.threeKey) {
  442. const row = handlerList(serviceOptions.value, obj.itemKey)
  443. console.log(2, row);
  444. serviceItems2.value = row.children;
  445. }
  446. Object.assign(serviceKeys, {
  447. time: details.value.businessDuration,//时间
  448. price: details.value.businessPrice,//价格
  449. ...obj
  450. })
  451. handlerList(serviceOptions.value, serviceKeys.itemKey)
  452. console.log('serviceKeys', serviceKeys);
  453. }
  454. async function getRegister() {
  455. try {
  456. uni.showLoading({
  457. title: '数据加载中...'
  458. });
  459. const res = await getVolunteerInfo({ serviceCategory: data.value.key });
  460. if (res.data) {
  461. details.value = { ...res.data, age: res.data.age + '' };
  462. cust_form_ref.value.setData(details.value);
  463. Object.assign(file_url, {
  464. volunteerPicture: res.data.volunteerPicture,
  465. idCardPictureFront: res.data.idCardPictureFront,
  466. idCardPictureBack: res.data.idCardPictureBack,
  467. certificationPicture: res.data.certificationPicture
  468. })
  469. servesInit(data)
  470. isAdd.value = false;
  471. }
  472. if (data.value.record) {
  473. Object.assign(serviceKeys, {
  474. classKey: data.value.record.id,//服务类别
  475. classKeyname: data.value.record.businessName,
  476. })
  477. }
  478. } catch (error) {
  479. console.log('error', error);
  480. uni.showToast({
  481. title: error.msg,
  482. icon: 'error',
  483. });
  484. } finally {
  485. uni.hideLoading();
  486. }
  487. }
  488. const serviceChange = (item, key) => {
  489. console.log("TCL: serviceChange -> item", item)
  490. if (item.maxPrice && item.minPrice) {
  491. min_max_price.value = {
  492. minPrice: item.minPrice,
  493. maxPrice: item.maxPrice,
  494. }
  495. }
  496. if (key === 'classKey') {
  497. serviceItems.value = item.children;
  498. serviceKeys['itemKey'] = '';
  499. serviceKeys['itemKeyname'] = '';
  500. serviceKeys['threeKey'] = '';
  501. serviceKeys['threeKeyname'] = '';
  502. serviceItems2.value = [];
  503. }
  504. if (key === 'itemKey') {
  505. serviceItems2.value = item.children;
  506. serviceKeys['threeKey'] = '';
  507. serviceKeys['threeKeyname'] = '';
  508. }
  509. Object.assign(serviceKeys, {
  510. [key]: serviceKeys[key] === item.id ? '' : item.id,
  511. [key + 'name']: serviceKeys[key + 'name'] === item.businessName ? '' : item.businessName,
  512. })
  513. }
  514. const getTreeListInit = () => {
  515. getTreeList({ parentId: data.value.key }).then(res => {
  516. serviceOptions.value = res.data;
  517. })
  518. }
  519. onMounted(() => {
  520. getTreeListInit();
  521. })
  522. onLoad((options) => {
  523. const option = JSON.parse(decodeURIComponent(options.data));
  524. data.value = option;
  525. console.log("option", data.value);
  526. uni.setNavigationBarTitle({
  527. title: option.name // 根据业务逻辑调整
  528. });
  529. setTimeout(() => {
  530. getRegister();
  531. }, 500);
  532. })
  533. </script>
  534. <style lang="scss" scoped>
  535. .register-main {
  536. padding: 12px;
  537. background-color: rgba(245, 245, 245, 1);
  538. // height: 100vh;
  539. .register-user-info {
  540. margin-bottom: 12px;
  541. background-color: #fff;
  542. border-radius: 8px;
  543. padding: 18px 16px;
  544. }
  545. .updata-imgs {
  546. margin-bottom: 12px;
  547. }
  548. }
  549. .register-card {
  550. margin-bottom: 12px;
  551. background-color: #fff;
  552. border-radius: 8px;
  553. padding: 18px 16px;
  554. }
  555. .info-list {
  556. flex: 1;
  557. font-size: 14px;
  558. font-weight: 500;
  559. letter-spacing: 0px;
  560. line-height: 23.27px;
  561. color: rgba(51, 51, 51, 1);
  562. }
  563. .status-btn {
  564. // width: 716rpx;
  565. height: 96rpx;
  566. border-radius: 16rpx;
  567. background: rgba(221, 94, 69, 1);
  568. display: flex;
  569. align-items: center;
  570. justify-content: center;
  571. font-size: 32rpx;
  572. font-weight: 400;
  573. color: rgba(255, 255, 255, 1);
  574. margin-bottom: 88rpx;
  575. }
  576. .font-title {
  577. margin-bottom: 32rpx;
  578. }
  579. .service-tile {
  580. font-size: 32rpx;
  581. font-weight: 400;
  582. line-height: 48rpx;
  583. color: rgba(51, 51, 51, 1);
  584. margin-bottom: 16rpx;
  585. }
  586. .service-list {
  587. display: flex;
  588. align-items: flex-start;
  589. flex-wrap: wrap;
  590. margin-bottom: 16rpx;
  591. }
  592. .servicetab {
  593. background: rgba(249, 250, 251, 1);
  594. color: rgba(51, 51, 51, 1);
  595. border: 1px solid #fff;
  596. padding: 8rpx 16rpx;
  597. border-radius: 16rpx;
  598. margin-right: 16rpx;
  599. margin-bottom: 16rpx;
  600. }
  601. .classActive {
  602. background: rgba(251, 229, 225, 1);
  603. color: rgba(221, 94, 69, 1);
  604. border: 1px solid rgba(221, 94, 69, 1);
  605. }
  606. .activeColor {
  607. color: rgba(221, 94, 69, 1);
  608. }
  609. .price-box {
  610. display: flex;
  611. align-items: center;
  612. }
  613. .price-describe {
  614. font-size: 24rpx;
  615. font-weight: 500;
  616. letter-spacing: 0rpx;
  617. line-height: 34.76rpx;
  618. color: rgba(153, 153, 153, 1);
  619. margin-top: 16rpx;
  620. }
  621. </style>