index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 } 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. }
  138. //根据类型获取表单item 值
  139. const com_column = computed(() => {
  140. let column_list = data.value ? register_column[data.value.key] : [];
  141. return column_list
  142. })
  143. function onSubmit() {
  144. try {
  145. // return;
  146. // 校验表单并获取数据
  147. cust_form_ref.value.onSubmit().then(async (res) => {
  148. console.log('===res===>', res, file_url);
  149. //文件必传校验
  150. for (let i = 0; i < updata_list.length; i++) {
  151. const element = updata_list[i];
  152. console.log(element.required, element.permission.includes(data.value.key), file_url[element.key]);
  153. const type = element.required && element.permission.includes(data.value.key) && !file_url[element.key];
  154. console.log('element', element, type);
  155. if (type) {
  156. uni.showToast({
  157. title: '请上传' + element.title,
  158. icon: 'error'
  159. })
  160. return;
  161. }
  162. }
  163. if(!(serviceKeys.itemKeyname || serviceKeys.classKeyname)){
  164. uni.showToast({
  165. title: '请选择服务',
  166. icon: 'none'
  167. })
  168. return
  169. }
  170. if(!serviceKeys.time){
  171. uni.showToast({
  172. title: '请选择服务时长',
  173. icon: 'none'
  174. })
  175. return
  176. }
  177. if(!serviceKeys.price){
  178. uni.showToast({
  179. title: '请输入服务价格',
  180. icon: 'none'
  181. })
  182. return
  183. }
  184. const parmas = {
  185. serviceCategory: data.value.key,
  186. ...file_url,
  187. businessManagementId:serviceKeys.itemKey || serviceKeys.classKey,
  188. businessPrice: serviceKeys.price,
  189. businessDuration: serviceKeys.time
  190. };
  191. for (const key in res) {
  192. parmas[key] = key == 'sex' ? sex_status[res[key]] : res[key];
  193. if (key === 'businessManagementIdkey') {
  194. parmas['businessManagementId'] = res[key]
  195. delete parmas['businessManagementIdkey'];
  196. }
  197. }
  198. console.log('提交', parmas);
  199. // return;
  200. // 提交接口,注册人员
  201. const submit_res = await add(parmas);
  202. if (submit_res.code == 200) {
  203. uni.showToast({
  204. title: '申请成功',
  205. icon: 'success',
  206. success: () => {
  207. setTimeout(() => {
  208. uni.navigateBack();
  209. }, 1000)
  210. }
  211. })
  212. return;
  213. }
  214. uni.showToast({
  215. title: res.msg,
  216. icon: 'none'
  217. })
  218. console.log('==submit_res====>', submit_res);
  219. })
  220. } catch (error) {
  221. console.log('error', error);
  222. } finally {
  223. }
  224. }
  225. function onChange({ key, url }) {
  226. console.log('onChange', key, url);
  227. Object.assign(file_url, {
  228. [key]: url
  229. })
  230. }
  231. function idToIndexs(array, targetId, path = []) {
  232. for (let i = 0; i < array.length; i++) {
  233. const item = array[i];
  234. const currentPath = path.concat(i);
  235. if (item.id === targetId) {
  236. console.log('indexs',item);
  237. return item
  238. }
  239. if (item.children) {
  240. const result = idToIndexs(item.children, targetId, currentPath);
  241. if (result) {
  242. return result;
  243. }
  244. }
  245. }
  246. return null; // 如果没有找到对应的项,返回 null
  247. }
  248. //重新提交的服务信息回显
  249. function servesInit(){
  250. const indexs = idToIndexs(serviceOptions.value,details.value.businessManagementId +'')
  251. const names = indexs.businessTierName.split('-');
  252. Object.assign(serviceKeys, {
  253. classKey: String(indexs.parentId)===String(data.value.key)? indexs.id :indexs.parentId,//服务类别
  254. classKeyname:names[1],
  255. itemKey: indexs.id,//服务项目
  256. itemKeyname: indexs.businessName,
  257. time:details.value.businessDuration,//时间
  258. price:details.value.businessPrice,//价格
  259. })
  260. }
  261. async function getRegister() {
  262. try {
  263. uni.showLoading({
  264. title: '数据加载中...'
  265. });
  266. const res = await getVolunteerInfo({ serviceCategory: data.value.key });
  267. if (res.data) {
  268. details.value = { ...res.data, age: res.data.age + '' };
  269. cust_form_ref.value.setData(details.value);
  270. Object.assign(file_url, {
  271. volunteerPicture: res.data.volunteerPicture,
  272. idCardPicture: res.data.idCardPicture,
  273. certificationPicture: res.data.certificationPicture
  274. })
  275. servesInit(data)
  276. isAdd.value = false;
  277. }
  278. } catch (error) {
  279. console.log('error', error);
  280. uni.showToast({
  281. title: error.msg,
  282. icon: 'error',
  283. });
  284. } finally {
  285. uni.hideLoading();
  286. }
  287. }
  288. const serviceChange = (item, key) => {
  289. console.log('----', item);
  290. if (key === 'classKey') {
  291. serviceItems.value = item.children;
  292. serviceKeys['itemKey'] = '';
  293. }
  294. Object.assign(serviceKeys, {
  295. [key]: serviceKeys[key] === item.id ? '' : item.id,
  296. [key + 'name']: serviceKeys[key + 'name'] === item.businessName ? '' : item.businessName,
  297. })
  298. }
  299. const getTreeListInit = () => {
  300. getTreeList({ parentId: data.value.key }).then(res => {
  301. console.log('----', res.data);
  302. serviceOptions.value = res.data;
  303. })
  304. }
  305. onMounted(() => {
  306. getTreeListInit();
  307. })
  308. onLoad((options) => {
  309. const option = JSON.parse(decodeURIComponent(options.data));
  310. data.value = option;
  311. console.log("option", option);
  312. uni.setNavigationBarTitle({
  313. title: option.name // 根据业务逻辑调整
  314. });
  315. setTimeout(() => {
  316. getRegister();
  317. }, 500);
  318. })
  319. </script>
  320. <style lang="scss" scoped>
  321. .register-main {
  322. padding: 12px;
  323. background-color: rgba(245, 245, 245, 1);
  324. // height: 100vh;
  325. .register-user-info {
  326. margin-bottom: 12px;
  327. background-color: #fff;
  328. border-radius: 8px;
  329. padding: 18px 16px;
  330. }
  331. .updata-imgs {
  332. margin-bottom: 12px;
  333. }
  334. }
  335. .register-card {
  336. margin-bottom: 12px;
  337. background-color: #fff;
  338. border-radius: 8px;
  339. padding: 18px 16px;
  340. }
  341. .info-list {
  342. flex: 1;
  343. font-size: 14px;
  344. font-weight: 500;
  345. letter-spacing: 0px;
  346. line-height: 23.27px;
  347. color: rgba(51, 51, 51, 1);
  348. }
  349. .status-btn {
  350. // width: 716rpx;
  351. height: 96rpx;
  352. border-radius: 16rpx;
  353. background: rgba(221, 94, 69, 1);
  354. display: flex;
  355. align-items: center;
  356. justify-content: center;
  357. font-size: 32rpx;
  358. font-weight: 400;
  359. color: rgba(255, 255, 255, 1);
  360. margin-bottom: 88rpx;
  361. }
  362. .font-title {
  363. margin-bottom: 32rpx;
  364. }
  365. .service-tile {
  366. font-size: 32rpx;
  367. font-weight: 400;
  368. line-height: 48rpx;
  369. color: rgba(51, 51, 51, 1);
  370. margin-bottom: 16rpx;
  371. }
  372. .service-list {
  373. display: flex;
  374. align-items: flex-start;
  375. flex-wrap: wrap;
  376. margin-bottom: 16rpx;
  377. }
  378. .servicetab {
  379. background: rgba(249, 250, 251, 1);
  380. color: rgba(51, 51, 51, 1);
  381. border: 1px solid #fff;
  382. padding: 8rpx 16rpx;
  383. border-radius: 16rpx;
  384. margin-right: 16rpx;
  385. margin-bottom: 16rpx;
  386. }
  387. .classActive {
  388. background: rgba(251, 229, 225, 1);
  389. color: rgba(221, 94, 69, 1);
  390. border: 1px solid rgba(221, 94, 69, 1);
  391. }
  392. .activeColor {
  393. color: rgba(221, 94, 69, 1);
  394. }
  395. </style>