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" :fileCount="item.fileCount" 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. fileCount:1,
  130. dece:'点击服务图片'
  131. },
  132. {
  133. title: '身份证国徽面',
  134. text: '上传您的身份证国徽面',
  135. img: '/static/img/updata-user-img.png',
  136. key: 'idCardPictureFront',
  137. ref: zsImg,
  138. // permission: [1, 2],
  139. required: true,
  140. fileCount:1,
  141. dece:'点击上传身份证国徽面'
  142. },
  143. {
  144. title: '身份证人像面',
  145. text: '上传您的身份证人像面',
  146. img: '/static/img/updata-user-img.png',
  147. key: 'idCardPictureBack',
  148. ref: zsImg,
  149. // permission: [1, 2],
  150. required: true,
  151. fileCount:1,
  152. dece:'点击上传身份证人像面'
  153. },
  154. {
  155. title: '职业、资质证书',
  156. text: '上传您的职业、资质证书',
  157. img: '/static/img/updata-user-img.png',
  158. key: 'certificationPicture',
  159. ref: zsImg,
  160. // permission: [1, 2],
  161. required: false,
  162. fileCount:6,
  163. dece:'点击上传职业、资质证书'
  164. }
  165. ]
  166. const cust_form_ref = ref(null);
  167. const data = ref(null);
  168. const file_url = reactive({});
  169. const isAdd = ref(true);//是否已经注册
  170. const details = ref({});//详情数据
  171. const serviceOptions = ref([]);//服务类目
  172. const serviceItems = ref([]);//服务项目
  173. const serviceItems2 = ref([]);//服务小类目
  174. const serviceKeys = reactive({
  175. classKey: '',//服务类别
  176. classKeyname: '',
  177. itemKey: '',//服务项目
  178. itemKeyname: '',
  179. threeKey: '',//服务项
  180. threeKeyname: '',
  181. time: '',//时间
  182. price: '',//价格
  183. minQuantity: '',//最小购买次数
  184. businessUnit: '',//购买单位
  185. businessDescribe: '',//服务描述
  186. })
  187. const timeList = [
  188. {
  189. lable: '60分钟',
  190. id: 60
  191. },
  192. {
  193. lable: '90分钟',
  194. id: 90
  195. },
  196. {
  197. lable: '120分钟',
  198. id: 120
  199. },
  200. ]
  201. const sex_status = {
  202. '男': 0,
  203. '女': 1
  204. }
  205. const validatePriceInput = (value) => {
  206. // 确保输入是纯数字
  207. if (!/^\d*$/.test(value)) {
  208. serviceKeys.price = value.replace(/[^0-9.]/g, '');// 移除非数字字符
  209. return;
  210. }
  211. const price = parseFloat(serviceKeys.price, 10);
  212. // 检查是否在允许的范围之内
  213. if (min_max_price.value.minPrice !== undefined && min_max_price.value.maxPrice !== undefined) {
  214. if (price >= min_max_price.value.minPrice && price <= min_max_price.value.maxPrice) {
  215. serviceKeys.price = serviceKeys.price.toString();
  216. } else {
  217. serviceKeys.price = null;
  218. uni.showToast({
  219. title: '请输入价格区间内的价格',
  220. icon: 'none'
  221. })
  222. }
  223. }
  224. };
  225. const validateTimeInput = (value) => {
  226. // 确保输入是纯数字
  227. if (!/^\d*$/.test(value)) {
  228. serviceKeys.time = value.replace(/\D/g, ''); // 移除非数字字符
  229. return;
  230. }
  231. const time = parseInt(serviceKeys.time, 10);
  232. // 检查是否大于0
  233. if (time <= 0) {
  234. serviceKeys.time = null;
  235. uni.showToast({
  236. title: '请输入大于0的服务时长',
  237. icon: 'none'
  238. });
  239. }
  240. };
  241. const validateMinQuantity = (value) => {
  242. // 确保输入是纯数字
  243. if (!/^\d*$/.test(value)) {
  244. serviceKeys.minQuantity = value.replace(/\D/g, ''); // 移除非数字字符
  245. return;
  246. }
  247. const quantity = parseInt(serviceKeys.minQuantity, 10);
  248. // 检查是否大于0
  249. if (quantity <= 0) {
  250. serviceKeys.minQuantity = null;
  251. uni.showToast({
  252. title: '请输入大于0的购买数量',
  253. icon: 'none'
  254. });
  255. }
  256. };
  257. //根据类型获取表单item 值
  258. const com_column = computed(() => {
  259. let column_list = data.value ? column : [];
  260. return column_list
  261. })
  262. const onSubmit = () =>{
  263. uni.$u.debounce(submitForm, 300)
  264. }
  265. function submitForm() {
  266. try {
  267. // return;
  268. // 校验表单并获取数据
  269. cust_form_ref.value.onSubmit().then(async (res) => {
  270. //文件必传校验
  271. for (let i = 0; i < updata_list.length; i++) {
  272. const element = updata_list[i];
  273. const type = element.required && !file_url[element.key];
  274. if (type) {
  275. uni.showToast({
  276. title: '请上传' + element.title,
  277. icon: 'error'
  278. })
  279. return;
  280. }
  281. }
  282. if (!(serviceKeys.threeKeyname || serviceKeys.itemKeyname || serviceKeys.classKeyname)) {
  283. uni.showToast({
  284. title: '请选择服务',
  285. icon: 'none'
  286. })
  287. return
  288. }
  289. if (!serviceKeys.time) {
  290. uni.showToast({
  291. title: '请输入服务时长',
  292. icon: 'none'
  293. })
  294. return
  295. }
  296. if (!serviceKeys.price) {
  297. uni.showToast({
  298. title: '请输入服务价格',
  299. icon: 'none'
  300. })
  301. return
  302. }
  303. if (!serviceKeys.minQuantity) {
  304. uni.showToast({
  305. title: '请输入最少购买数量',
  306. icon: 'none'
  307. })
  308. return
  309. }
  310. if (!serviceKeys.businessUnit) {
  311. uni.showToast({
  312. title: '请输入购买单位',
  313. icon: 'none'
  314. })
  315. return
  316. }
  317. if (!serviceKeys.businessDescribe) {
  318. uni.showToast({
  319. title: '请输入服务描述',
  320. icon: 'none'
  321. })
  322. return
  323. }
  324. const parmas = {
  325. serviceCategory: data.value.key,
  326. ...file_url,
  327. businessManagementId: serviceKeys.threeKey || serviceKeys.itemKey || serviceKeys.classKey,
  328. businessPrice: serviceKeys.price,
  329. businessDuration: serviceKeys.time,
  330. businessUnit: serviceKeys.businessUnit,
  331. minQuantity: serviceKeys.minQuantity,
  332. businessDescribe: serviceKeys.businessDescribe
  333. };
  334. for (const key in res) {
  335. parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
  336. if (key === 'businessManagementIdkey') {
  337. parmas['businessManagementId'] = res[key]
  338. delete parmas['businessManagementIdkey'];
  339. }
  340. }
  341. console.log('提交', parmas);
  342. // return;
  343. // 提交接口,注册人员
  344. const submit_res = await add(parmas);
  345. if (submit_res.code == 200) {
  346. uni.showToast({
  347. title: '申请成功',
  348. icon: 'success',
  349. success: () => {
  350. setTimeout(() => {
  351. uni.navigateBack();
  352. }, 1000)
  353. }
  354. })
  355. return;
  356. }
  357. uni.showToast({
  358. title: res.msg,
  359. icon: 'none'
  360. })
  361. })
  362. } catch (error) {
  363. console.log('error', error);
  364. } finally {
  365. }
  366. }
  367. function onChange({ key, url }) {
  368. Object.assign(file_url, {
  369. [key]: url
  370. })
  371. }
  372. function handlerList(array, targetId, path = []) {
  373. for (let i = 0; i < array.length; i++) {
  374. const item = array[i];
  375. const currentPath = path.concat(i);
  376. if (item.id === targetId) {
  377. return item
  378. }
  379. if (item.children) {
  380. const result = handlerList(item.children, targetId, currentPath);
  381. if (result) {
  382. return result;
  383. }
  384. }
  385. }
  386. return null; // 如果没有找到对应的项,返回 null
  387. }
  388. /**
  389. * 根据目标id查找所有父级路径
  390. * @param {Array} data 树形数据源(如 serviceOptions.value)
  391. * @param {String|Number} targetId 要查找的目标id
  392. * @param {String} [idKey='id'] id字段名
  393. * @param {String} [childrenKey='children'] 子级字段名
  394. * @returns {Object|null}
  395. */
  396. function findParentPath(data, targetId, idKey = 'id', childrenKey = 'children') {
  397. for (const node of data) {
  398. // 当前节点匹配
  399. if (node[idKey] == targetId) {
  400. return {
  401. parentIdPath: [node[idKey]],
  402. businessTierName: node.businessName || ''
  403. };
  404. }
  405. // 搜索子级
  406. const result = node[childrenKey]?.length > 0
  407. ? findParentPath(node[childrenKey], targetId, idKey, childrenKey)
  408. : null;
  409. if (result) {
  410. return {
  411. parentIdPath: [...result.parentIdPath, node[idKey]],
  412. businessTierName: `${result.businessTierName}-${node.businessName || ''}`
  413. };
  414. }
  415. }
  416. return null;
  417. }
  418. function idToIndexs(targetId) {
  419. const res = findParentPath(serviceOptions.value, targetId);
  420. return res || {
  421. parentIdPath: [],
  422. businessTierName: ''
  423. };
  424. }
  425. const backfill = {
  426. 2: 'threeKey',
  427. 1: 'itemKey',
  428. 0: 'classKey',
  429. }
  430. //重新提交的服务信息回显
  431. function servesInit() {
  432. const indexs = idToIndexs(details.value.businessManagementId + '');
  433. const names = indexs.businessTierName.split('-').reverse();
  434. const ids = indexs.parentIdPath.reverse();
  435. const obj = {};
  436. for (let i = 0; i < names.length; i++) {
  437. obj[backfill[i]] = ids[i];
  438. obj[backfill[i] + 'name'] = names[i];
  439. }
  440. if (obj.itemKey) {
  441. const row = handlerList(serviceOptions.value, obj.classKey)
  442. serviceItems.value = row.children;
  443. }
  444. if (obj.threeKey) {
  445. const row = handlerList(serviceOptions.value, obj.itemKey)
  446. serviceItems2.value = row.children;
  447. }
  448. Object.assign(serviceKeys, {
  449. time: details.value.businessDuration,//时间
  450. price: details.value.businessPrice,//价格
  451. ...obj
  452. })
  453. handlerList(serviceOptions.value, serviceKeys.itemKey)
  454. }
  455. async function getRegister() {
  456. try {
  457. // uni.showLoading({
  458. // title: '数据加载中...'
  459. // });
  460. const res = await getVolunteerInfo({ serviceCategory: data.value.key });
  461. if (res.data) {
  462. details.value = { ...res.data, age: res.data.age + '' };
  463. cust_form_ref.value.setData(details.value);
  464. Object.assign(file_url, {
  465. volunteerPicture: res.data.volunteerPicture,
  466. idCardPictureFront: res.data.idCardPictureFront,
  467. idCardPictureBack: res.data.idCardPictureBack,
  468. certificationPicture: res.data.certificationPicture
  469. })
  470. servesInit(data)
  471. isAdd.value = false;
  472. }
  473. if (data.value.record) {
  474. Object.assign(serviceKeys, {
  475. classKey: data.value.record.id,//服务类别
  476. classKeyname: data.value.record.businessName,
  477. })
  478. }
  479. } catch (error) {
  480. console.log('error', error);
  481. uni.showToast({
  482. title: error.msg,
  483. icon: 'error',
  484. });
  485. } finally {
  486. // uni.hideLoading();
  487. }
  488. }
  489. const serviceChange = (item, key) => {
  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.businessName // 根据业务逻辑调整
  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: 10rpx;
  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>