index.vue 10 KB

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