123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- <template>
- <view class="register-main">
- <view class="register-user-info">
- <FontTitle title="基本信息" />
- <CustForm :column="com_column" ref="cust_form_ref" :isCode="isAdd" />
- </view>
- <view class="register-card">
- <view class="info-list">
- <view class="font-title">服务类别( {{ serviceOptions.length }} )</view>
- <view class="service-list">
- <view v-for="item in serviceOptions" :key="item.id" @click="serviceChange(item, 'classKey')"
- :class="serviceKeys.classKey === item.id ? 'servicetab classActive' : 'servicetab'">
- {{ item.businessName }}
- </view>
- </view>
- <view v-if="serviceKeys.classKey && serviceItems && serviceItems.length > 0">
- <view class="font-title">服务项目</view>
- <view class="service-list">
- <view v-for="item in serviceItems" :key="item.id" @click="serviceChange(item, 'itemKey')"
- :class="serviceKeys.itemKey === item.id ? 'servicetab classActive' : 'servicetab'">
- {{ item.businessName }}
- </view>
- </view>
- </view>
- <view v-if="serviceKeys.classKey && serviceItems2 && serviceItems2.length > 0">
- <view class="font-title">服务项</view>
- <view class="service-list">
- <view v-for="item in serviceItems2" :key="item.id" @click="serviceChange(item, 'threeKey')"
- :class="serviceKeys.threeKey === item.id ? 'servicetab classActive' : 'servicetab'">
- {{ item.businessName }}
- </view>
- </view>
- </view>
- <view v-if="serviceKeys.itemKeyname || serviceKeys.classKeyname">
- <view class="font-title">服务时长(<text class="activeColor">{{ serviceKeys.threeKeyname ||
- serviceKeys.itemKeyname ||
- serviceKeys.classKeyname }}</text>)</view>
- <view class="service-list price-box">
- <up-input
- v-model="serviceKeys.time"
- placeholder="请输入服务时长"
- @blur="validateTimeInput"
- class="price-input"
- >
- <template #suffix>
- <text>分钟</text>
- </template>
- </up-input>
- </view>
- <view class="font-title">最少购买</view>
- <view class="service-list price-box">
- <up-input
- v-model="serviceKeys.minQuantity"
- placeholder="请输入最少购买数量"
- class="price-input"
- @blur="validateMinQuantity"
- ></up-input>
- </view>
- <view class="font-title">购买单位</view>
- <view class="service-list price-box">
- <up-input
- v-model="serviceKeys.businessUnit"
- placeholder="请输入购买单位,如:(次、平方、小时)"
- class="price-input"
- ></up-input>
- </view>
- <view class="font-title">服务描述</view>
- <view class="service-list">
- <up-textarea
- v-model="serviceKeys.businessDescribe"
- placeholder="服务描述内容,如:提供上门取衣、送衣服服务、您只需线上下单,我们工作人员便会按约定时间上门收取衣物"
- ></up-textarea>
- </view>
- <view class="font-title">服务价格(<text class="activeColor">{{ serviceKeys.threeKeyname ||
- serviceKeys.itemKeyname ||
- serviceKeys.classKeyname }}</text>)</view>
- <view class="service-list price-box">
- <up-input v-model="serviceKeys.price"
- :placeholder="min_max_price.minPrice && min_max_price.maxPrice ? `${min_max_price.minPrice}-${min_max_price.maxPrice}` : '请设置服务价格'"
- @blur="validatePriceInput" class="price-input">
- <template #suffix>
- <text>元</text>
- </template>
- </up-input>
- </view>
- <view class="price-describe" v-if="min_max_price.minPrice && min_max_price.maxPrice">
- 价格说明
- </view>
- </view>
- </view>
- </view>
- <view class="register-card" v-if="details.appStatus === '3'">
- <view class="font-title">驳回原因</view>
- <view class="info-list">
- {{ details.rejectReason }}
- </view>
- </view>
- <view v-for="item in updata_list" :key="item.key" class="updata-imgs">
- <UpdataImgs :fileList="file_url[item.key]" :data="item" ref="zsImg" @onSubmit="onChange" />
- </view>
- <view class="status-btn" @click="onSubmit">确定</view>
- </view>
- </template>
- <script setup>
- import { ref, reactive, onMounted, nextTick } from 'vue';
- import { onLoad } from '@dcloudio/uni-app';
- import FontTitle from "@/pages_home/components/font-title/index.vue";
- import CustForm from "@/pages_home/components/cust-form/index";
- import UpdataImgs from "@/pages_home/components/updata-imgs/index.vue";
- import { column } from "./data";
- import { add, getVolunteerInfo } from "@/api/volunteer";
- import { computed } from 'vue';
- import { getTreeList } from '@/api/volunteer'
- const userImg = ref(null);
- const zsImg = ref(null);
- const min_max_price = ref({
- minPrice: undefined,
- maxPrice: undefined
- })
- const updata_list = [
- {
- title: '上传头像',
- text: '上传您的头像',
- img: '/static/img/updata-user-img.png',
- key: 'volunteerPicture',
- ref: userImg,
- // permission: [1, 2],
- required: true
- },
- {
- title: '个人身份证',
- text: '上传您的个人身份证',
- img: '/static/img/updata-user-img.png',
- key: 'idCardPicture',
- ref: zsImg,
- // permission: [1, 2],
- required: true
- },
- {
- title: '职业、资质证书',
- text: '上传您的职业、资质证书',
- img: '/static/img/updata-user-img.png',
- key: 'certificationPicture',
- ref: zsImg,
- // permission: [1, 2],
- required: false
- }
- ]
- const cust_form_ref = ref(null);
- const data = ref(null);
- const file_url = reactive({});
- const isAdd = ref(true);//是否已经注册
- const details = ref({});//详情数据
- const serviceOptions = ref([]);//服务类目
- const serviceItems = ref([]);//服务项目
- const serviceItems2 = ref([]);//服务小类目
- const serviceKeys = reactive({
- classKey: '',//服务类别
- classKeyname: '',
- itemKey: '',//服务项目
- itemKeyname: '',
- threeKey: '',//服务项
- threeKeyname: '',
- time: '',//时间
- price: '',//价格
- minQuantity: '',//最小购买次数
- businessUnit: '',//购买单位
- businessDescribe: '',//服务描述
- })
- const timeList = [
- {
- lable: '60分钟',
- id: 60
- },
- {
- lable: '90分钟',
- id: 90
- },
- {
- lable: '120分钟',
- id: 120
- },
- ]
- const sex_status = {
- '男': 0,
- '女': 1
- }
- const validatePriceInput = (value) => {
- console.log("TCL: validatePriceInput -> value", value)
- // 确保输入是纯数字
- if (!/^\d*$/.test(value)) {
- serviceKeys.price = value.replace(/\D/g, ''); // 移除非数字字符
- return;
- }
- const price = parseInt(serviceKeys.price, 10);
- // 检查是否在允许的范围之内
- if (min_max_price.value.minPrice !== undefined && min_max_price.value.maxPrice !== undefined) {
- if (price >= min_max_price.value.minPrice && price <= min_max_price.value.maxPrice) {
- serviceKeys.price = serviceKeys.price.toString();
- } else {
- serviceKeys.price = null;
- uni.showToast({
- title: '请输入价格区间内的价格',
- icon: 'none'
- })
- console.log("TCL: validatePriceInput -> error", value)
- }
- }
- };
- const validateTimeInput = (value) => {
- // 确保输入是纯数字
- if (!/^\d*$/.test(value)) {
- serviceKeys.time = value.replace(/\D/g, ''); // 移除非数字字符
- return;
- }
- const time = parseInt(serviceKeys.time, 10);
- // 检查是否大于0
- if (time <= 0) {
- serviceKeys.time = null;
- uni.showToast({
- title: '请输入大于0的服务时长',
- icon: 'none'
- });
- }
- };
- const validateMinQuantity = (value) => {
- // 确保输入是纯数字
- if (!/^\d*$/.test(value)) {
- serviceKeys.minQuantity = value.replace(/\D/g, ''); // 移除非数字字符
- return;
- }
- const quantity = parseInt(serviceKeys.minQuantity, 10);
- // 检查是否大于0
- if (quantity <= 0) {
- serviceKeys.minQuantity = null;
- uni.showToast({
- title: '请输入大于0的购买数量',
- icon: 'none'
- });
- }
- };
- //根据类型获取表单item 值
- const com_column = computed(() => {
- let column_list = data.value ? column : [];
- return column_list
- })
- function onSubmit() {
- try {
- // return;
- // 校验表单并获取数据
- cust_form_ref.value.onSubmit().then(async (res) => {
- //文件必传校验
- for (let i = 0; i < updata_list.length; i++) {
- const element = updata_list[i];
- const type = element.required && !file_url[element.key];
- if (type) {
- uni.showToast({
- title: '请上传' + element.title,
- icon: 'error'
- })
- return;
- }
- }
- if (!(serviceKeys.threeKeyname || serviceKeys.itemKeyname || serviceKeys.classKeyname)) {
- uni.showToast({
- title: '请选择服务',
- icon: 'none'
- })
- return
- }
- if (!serviceKeys.time) {
- uni.showToast({
- title: '请输入服务时长',
- icon: 'none'
- })
- return
- }
- if (!serviceKeys.price) {
- uni.showToast({
- title: '请输入服务价格',
- icon: 'none'
- })
- return
- }
- if (!serviceKeys.minQuantity) {
- uni.showToast({
- title: '请输入最少购买数量',
- icon: 'none'
- })
- return
- }
- if (!serviceKeys.businessUnit) {
- uni.showToast({
- title: '请输入购买单位',
- icon: 'none'
- })
- return
- }
- if (!serviceKeys.businessDescribe) {
- uni.showToast({
- title: '请输入服务描述',
- icon: 'none'
- })
- return
- }
- const parmas = {
- serviceCategory: data.value.key,
- ...file_url,
- businessManagementId: serviceKeys.threeKey || serviceKeys.itemKey || serviceKeys.classKey,
- businessPrice: serviceKeys.price,
- businessDuration: serviceKeys.time,
- businessUnit: serviceKeys.businessUnit,
- minQuantity: serviceKeys.minQuantity,
- businessDescribe: serviceKeys.businessDescribe
- };
- for (const key in res) {
- parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
- if (key === 'businessManagementIdkey') {
- parmas['businessManagementId'] = res[key]
- delete parmas['businessManagementIdkey'];
- }
- }
- console.log('提交', parmas);
- // return;
- // 提交接口,注册人员
- const submit_res = await add(parmas);
- if (submit_res.code == 200) {
- uni.showToast({
- title: '申请成功',
- icon: 'success',
- success: () => {
- setTimeout(() => {
- uni.navigateBack();
- }, 1000)
- }
- })
- return;
- }
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- })
- } catch (error) {
- console.log('error', error);
- } finally {
- }
- }
- function onChange({ key, url }) {
- Object.assign(file_url, {
- [key]: url
- })
- }
- function handlerList(array, targetId, path = []) {
- for (let i = 0; i < array.length; i++) {
- const item = array[i];
- const currentPath = path.concat(i);
- if (item.id === targetId) {
- return item
- }
- if (item.children) {
- const result = handlerList(item.children, targetId, currentPath);
- if (result) {
- return result;
- }
- }
- }
- return null; // 如果没有找到对应的项,返回 null
- }
- /**
- * 根据目标id查找所有父级路径
- * @param {Array} data 树形数据源(如 serviceOptions.value)
- * @param {String|Number} targetId 要查找的目标id
- * @param {String} [idKey='id'] id字段名
- * @param {String} [childrenKey='children'] 子级字段名
- * @returns {Object|null}
- */
- function findParentPath(data, targetId, idKey = 'id', childrenKey = 'children') {
- for (const node of data) {
- // 当前节点匹配
- if (node[idKey] == targetId) {
- return {
- parentIdPath: [node[idKey]],
- businessTierName: node.businessName || ''
- };
- }
- // 搜索子级
- const result = node[childrenKey]?.length > 0
- ? findParentPath(node[childrenKey], targetId, idKey, childrenKey)
- : null;
- if (result) {
- return {
- parentIdPath: [...result.parentIdPath, node[idKey]],
- businessTierName: `${result.businessTierName}-${node.businessName || ''}`
- };
- }
- }
- return null;
- }
- function idToIndexs(targetId) {
- const res = findParentPath(serviceOptions.value, targetId);
- return res || {
- parentIdPath: [],
- businessTierName: ''
- };
- }
- const backfill = {
- 2: 'threeKey',
- 1: 'itemKey',
- 0: 'classKey',
- }
- //重新提交的服务信息回显
- function servesInit() {
- const indexs = idToIndexs(details.value.businessManagementId + '');
- const names = indexs.businessTierName.split('-').reverse();
- const ids = indexs.parentIdPath.reverse();
- const obj = {};
- for (let i = 0; i < names.length; i++) {
- obj[backfill[i]] = ids[i];
- obj[backfill[i] + 'name'] = names[i];
- }
- console.log('obj', obj, names, ids);
- console.log('indexs', indexs, names, ids);
- // const indexs = idToIndexs(serviceOptions.value, details.value.businessManagementId + '')
- // const names = indexs.businessTierName.split('-');
- // console.log('indexs',indexs,names);
- if (obj.itemKey) {
- const row = handlerList(serviceOptions.value, obj.classKey)
- console.log(1, row);
- serviceItems.value = row.children;
- }
- if (obj.threeKey) {
- const row = handlerList(serviceOptions.value, obj.itemKey)
- console.log(2, row);
- serviceItems2.value = row.children;
- }
- Object.assign(serviceKeys, {
- time: details.value.businessDuration,//时间
- price: details.value.businessPrice,//价格
- ...obj
- })
- handlerList(serviceOptions.value, serviceKeys.itemKey)
- console.log('serviceKeys', serviceKeys);
- }
- async function getRegister() {
- try {
- uni.showLoading({
- title: '数据加载中...'
- });
- const res = await getVolunteerInfo({ serviceCategory: data.value.key });
- if (res.data) {
- details.value = { ...res.data, age: res.data.age + '' };
- cust_form_ref.value.setData(details.value);
- Object.assign(file_url, {
- volunteerPicture: res.data.volunteerPicture,
- idCardPicture: res.data.idCardPicture,
- certificationPicture: res.data.certificationPicture
- })
- servesInit(data)
- isAdd.value = false;
- }
- if (data.value.record) {
- Object.assign(serviceKeys, {
- classKey: data.value.record.id,//服务类别
- classKeyname: data.value.record.businessName,
- })
- }
- } catch (error) {
- console.log('error', error);
- uni.showToast({
- title: error.msg,
- icon: 'error',
- });
- } finally {
- uni.hideLoading();
- }
- }
- const serviceChange = (item, key) => {
- console.log("TCL: serviceChange -> item", item)
- if (item.maxPrice && item.minPrice) {
- min_max_price.value = {
- minPrice: item.minPrice,
- maxPrice: item.maxPrice,
- }
- }
- if (key === 'classKey') {
- serviceItems.value = item.children;
- serviceKeys['itemKey'] = '';
- serviceKeys['itemKeyname'] = '';
- serviceKeys['threeKey'] = '';
- serviceKeys['threeKeyname'] = '';
- serviceItems2.value = [];
- }
- if (key === 'itemKey') {
- serviceItems2.value = item.children;
- serviceKeys['threeKey'] = '';
- serviceKeys['threeKeyname'] = '';
- }
- Object.assign(serviceKeys, {
- [key]: serviceKeys[key] === item.id ? '' : item.id,
- [key + 'name']: serviceKeys[key + 'name'] === item.businessName ? '' : item.businessName,
- })
- }
- const getTreeListInit = () => {
- getTreeList({ parentId: data.value.key }).then(res => {
- serviceOptions.value = res.data;
- })
- }
- onMounted(() => {
- getTreeListInit();
- })
- onLoad((options) => {
- const option = JSON.parse(decodeURIComponent(options.data));
- data.value = option;
- console.log("option", data.value);
- uni.setNavigationBarTitle({
- title: option.name // 根据业务逻辑调整
- });
- setTimeout(() => {
- getRegister();
- }, 500);
- })
- </script>
- <style lang="scss" scoped>
- .register-main {
- padding: 12px;
- background-color: rgba(245, 245, 245, 1);
- // height: 100vh;
- .register-user-info {
- margin-bottom: 12px;
- background-color: #fff;
- border-radius: 8px;
- padding: 18px 16px;
- }
- .updata-imgs {
- margin-bottom: 12px;
- }
- }
- .register-card {
- margin-bottom: 12px;
- background-color: #fff;
- border-radius: 8px;
- padding: 18px 16px;
- }
- .info-list {
- flex: 1;
- font-size: 14px;
- font-weight: 500;
- letter-spacing: 0px;
- line-height: 23.27px;
- color: rgba(51, 51, 51, 1);
- }
- .status-btn {
- // width: 716rpx;
- height: 96rpx;
- border-radius: 16rpx;
- background: rgba(221, 94, 69, 1);
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 32rpx;
- font-weight: 400;
- color: rgba(255, 255, 255, 1);
- margin-bottom: 88rpx;
- }
- .font-title {
- margin-bottom: 32rpx;
- }
- .service-tile {
- font-size: 32rpx;
- font-weight: 400;
- line-height: 48rpx;
- color: rgba(51, 51, 51, 1);
- margin-bottom: 16rpx;
- }
- .service-list {
- display: flex;
- align-items: flex-start;
- flex-wrap: wrap;
- margin-bottom: 16rpx;
- }
- .servicetab {
- background: rgba(249, 250, 251, 1);
- color: rgba(51, 51, 51, 1);
- border: 1px solid #fff;
- padding: 8rpx 16rpx;
- border-radius: 16rpx;
- margin-right: 16rpx;
- margin-bottom: 16rpx;
- }
- .classActive {
- background: rgba(251, 229, 225, 1);
- color: rgba(221, 94, 69, 1);
- border: 1px solid rgba(221, 94, 69, 1);
- }
- .activeColor {
- color: rgba(221, 94, 69, 1);
- }
- .price-box {
- display: flex;
- align-items: center;
- }
- .price-describe {
- font-size: 24rpx;
- font-weight: 500;
- letter-spacing: 0rpx;
- line-height: 34.76rpx;
- color: rgba(153, 153, 153, 1);
- margin-top: 16rpx;
- }
- </style>
|