new_file.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view>
  3. <!-- 服务选择 -->
  4. <template v-if="userType == 1">
  5. <view class="Wrapper-grid">
  6. <!-- 横向滚动容器 -->
  7. <scroll-view scroll-x class="grid-scroll-view" shows-horizontal-scroll-indicator="false">
  8. <up-grid :border="false" col="5" @click="handleGridClick" class="grid-container">
  9. <up-grid-item v-for="(item, index) in serviceList1" :key="index"
  10. :custom-style="{ padding: '20rpx' }">
  11. <!-- 图标 -->
  12. <image :src="item.icon" class="service-img" mode="aspectFit" />
  13. <!-- 文本 -->
  14. <text class="grid-text">{{ item.name }}</text>
  15. </up-grid-item>
  16. </up-grid>
  17. </scroll-view>
  18. <up-toast ref="uToastRef" />
  19. </view>
  20. </template>
  21. <template v-else-if="userType == 2">
  22. <view class="Wrapper-grid">
  23. <swiper :indicator-dots="true" class="swiper">
  24. <swiper-item>
  25. <up-grid :border="false" col="5" @click="handleGridClick">
  26. <up-grid-item v-for="(item, index) in serviceList2.slice(0,10)" :key="index"
  27. :custom-style="custmoStyle">
  28. <view class="grid-box">
  29. <view class="grid-icon">
  30. <image :src="item.icon" class="service-img" mode="aspectFit" />
  31. </view>
  32. <text class="grid-text">{{ item.name }}</text>
  33. </view>
  34. </up-grid-item>
  35. </up-grid>
  36. </swiper-item>
  37. <swiper-item>
  38. <up-grid :border="false" col="4" @click="handleGridClick">
  39. <up-grid-item v-for="(item, index) in serviceList2.slice(10,12)" :key="index"
  40. :custom-style="custmoStyle">
  41. <view class="grid-box">
  42. <view class="grid-icon">
  43. <image :src="item.icon" class="service-img" mode="aspectFit" />
  44. </view>
  45. <text class="grid-text">{{ item.name }}</text>
  46. </view>
  47. </up-grid-item>
  48. </up-grid>
  49. </swiper-item>
  50. </swiper>
  51. <up-toast ref="uToastRef" />
  52. </view>
  53. </template>
  54. <Calendar ref="calendar" class="uni-calendar--hook" :clear-date="false" :date="info.date" :insert="info.insert"
  55. :lunar="info.lunar" :range="info.range" @change="change" :clearDate="true" @confirm="confirm"
  56. :selected="selected" @delete="onDelete" />
  57. </view>
  58. </template>
  59. <script setup>
  60. import {
  61. ref,
  62. onMounted,
  63. watch,
  64. computed,
  65. provide
  66. } from 'vue';
  67. // import {
  68. // typeOptionSelect
  69. // } from "@/api/volunteerDetailsApi/details.js"
  70. import {
  71. workDate,
  72. getDataTime,
  73. getVolunteerInfo
  74. } from '@/api/volunteer.js'
  75. import {
  76. volunteerSeachgetTreeList,
  77. } from "@/api/volunteerDetailsApi/details.js"
  78. import Calendar from '../../components/uni-calendar/components/uni-calendar/uni-calendar.vue'
  79. const swiperList = ['integral', 'kefu-ermai', 'coupon', 'gift', 'scan', 'pause-circle', 'wifi', 'email', 'list'];
  80. // Toast 控制宫格
  81. const uToastRef = ref(null);
  82. const userType = uni.getStorageSync('userType') //读取本地存储
  83. // 用户/志愿者 识别标识
  84. const userOrWorker = uni.getStorageSync('storage_data').vuex_userOrWorker //读取本地存储
  85. const calendar = ref(null)
  86. const info = ref({
  87. lunar: true,
  88. range: true,
  89. insert: false,
  90. })
  91. const selected = ref([])
  92. // 普通用户
  93. const serviceList1 = ref([{
  94. icon: '/static/Tioimages/1 妇女儿童权益保护服务.png',
  95. name: '孩子陪伴',
  96. key: 2,
  97. },
  98. {
  99. icon: '/static/Tioimages/家庭保洁.png',
  100. name: '家庭保洁',
  101. key: 1,
  102. },
  103. {
  104. icon: '/static/Tioimages/临时帮手.png',
  105. name: '临时帮手',
  106. key: 3,
  107. },
  108. {
  109. icon: '/static/Tioimages/专家服务.png',
  110. name: '专家服务',
  111. key: 4,
  112. },
  113. {
  114. icon: '/static/Tioimages/家电维修.png',
  115. name: '家电维护',
  116. key: 5,
  117. },
  118. {
  119. icon: '/static/Tioimages/1v专业指导.png',
  120. name: '陪伴陪聊',
  121. key: 6,
  122. },
  123. {
  124. icon: '/static/Tioimages/旅游服务.png',
  125. name: '旅游服务',
  126. key: 7,
  127. },
  128. {
  129. icon: '/static/Tioimages/健康管理.png',
  130. name: '健康管理',
  131. key: 8,
  132. },
  133. {
  134. icon: '/static/Tioimages/交友.png',
  135. name: '交友专区',
  136. key: 9,
  137. },
  138. {
  139. icon: '/static/Tioimages/购物商城.png',
  140. name: '商城购物',
  141. key: 10,
  142. },
  143. {
  144. icon: '/static/Tioimages/本地生活.png',
  145. name: '本地生活',
  146. key: 11,
  147. },
  148. ]);
  149. //志愿者
  150. const serviceList2 = ref([{
  151. icon: '/static/Tioimages/1v专业指导.png',
  152. name: '陪伴陪聊',
  153. key: 1,
  154. },
  155. {
  156. icon: '/static/Tioimages/1 妇女儿童权益保护服务.png',
  157. name: '孩子陪护',
  158. key: 2,
  159. },
  160. {
  161. icon: '/static/Tioimages/健康管理.png',
  162. name: '健康管理',
  163. key: 3,
  164. },
  165. {
  166. icon: '/static/Tioimages/家庭保洁.png',
  167. name: '家庭保洁',
  168. key: 4
  169. },
  170. {
  171. icon: '/static/Tioimages/临时帮手.png',
  172. name: '临时帮手',
  173. key: 5
  174. },
  175. {
  176. icon: '/static/Tioimages/专家服务.png',
  177. name: '专家服务',
  178. key: 6
  179. },
  180. {
  181. icon: '/static/Tioimages/家电维修.png',
  182. name: '家电维护',
  183. key: 8
  184. },
  185. {
  186. icon: '/static/Tioimages/旅游服务.png',
  187. name: '旅游服务',
  188. key: 9
  189. },
  190. {
  191. icon: '/static/Tioimages/交友.png',
  192. name: '交友专区',
  193. key: 10
  194. },
  195. {
  196. icon: '/static/Tioimages/购物商城.png',
  197. name: '商城购物',
  198. key: 11
  199. },
  200. {
  201. icon: '/static/Tioimages/本地生活.png',
  202. name: '本地生活',
  203. key: 12
  204. },
  205. {
  206. icon: '/static/serverImg/home/icon/icon8.png',
  207. name: '排班管理',
  208. key: 7
  209. },
  210. ]);
  211. const parentIdMap = {
  212. '孩子陪护': 2,
  213. '陪伴陪聊': 1,
  214. '家庭助理': 3,
  215. '健康管理': 4,
  216. '家庭清洁': 5,
  217. '家务帮手': 6,
  218. '资讯与服务': 7,
  219. };
  220. const getParentId = (service) => parentIdMap[service.name] || 1;
  221. // 宫格点击事件
  222. const handleGridClick = async (index) => {
  223. const service = serviceList1.value[index]; // 获取点击的服务条目
  224. // 用户
  225. if (userType == 1) {
  226. // 动态获取 parentId
  227. const parentId = getParentId(service); // 通过服务条目动态获取 parentId
  228. const params = {
  229. parentId: parentId
  230. }
  231. const res = await volunteerSeachgetTreeList(params)
  232. console.log(res, '>>>>>dictSort = null')
  233. // 只有第一条和第二条可以跳转
  234. if (index === 0 || index === 1) {
  235. uni.navigateTo({
  236. url: `/pages_home/pages/client/details?dataList=${encodeURIComponent(JSON.stringify(res.data))}`
  237. });
  238. } else {
  239. // 其他条目提示“敬请期待”
  240. uni.showToast({
  241. title: '敬请期待',
  242. icon: 'none'
  243. });
  244. }
  245. }
  246. // 志愿者
  247. if (userType == 2 && uToastRef.value) {
  248. // pages_home/pages
  249. const data = serviceList2.value[index]
  250. if (data.key !== 7) {
  251. const res = await getVolunteerInfo({
  252. serviceCategory: data.key
  253. });
  254. if (res.code === 200 && res.data) {
  255. //已有注册,跳转详情页面
  256. uni.navigateTo({
  257. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify(data))}`
  258. })
  259. return
  260. }
  261. data.key === 1 || data.key === 2 ? uni.navigateTo({
  262. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify(data))}`
  263. }) : uni.showToast({
  264. title: '敬请期待',
  265. icon: 'none'
  266. })
  267. return;
  268. }
  269. init();
  270. }
  271. };
  272. const change = (e) => {
  273. console.log('change', e);
  274. let dates = [{
  275. date: e.fulldate,
  276. info: `${e.time.startTime}~${e.time.endTime}`,
  277. time: e.time
  278. }]
  279. if (e.range.before && e.range.after) {
  280. dates = e.range.data.map(item => {
  281. return {
  282. date: item,
  283. info: `${e.time.startTime}~${e.time.endTime}`,
  284. time: e.time
  285. }
  286. })
  287. }
  288. selected.value = [...selected.value, ...dates]
  289. }
  290. const onDelete = (e) => {
  291. selected.value = selected.value.filter(item => {
  292. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  293. return item.date !== e.fulldate
  294. })
  295. console.log(e, selected.value);
  296. }
  297. //排班时间去重处理
  298. const handleDates = computed(() => {
  299. const parmas = selected.value.map(item => {
  300. return {
  301. workDate: item.date,
  302. workStartTime: item.time.startTime,
  303. workEndTime: item.time.endTime
  304. }
  305. })
  306. return parmas.reduce((acc, current) => {
  307. const existing = acc.find(item => item.workDate === current.workDate);
  308. if (existing) {
  309. Object.assign(existing, current);
  310. } else {
  311. acc.push(current);
  312. }
  313. return acc;
  314. }, []);
  315. });
  316. const confirm = (e) => {
  317. const parmas = handleDates.value;
  318. console.log('确定', parmas);
  319. workDate(parmas).then(res => {
  320. if (res.code == 200) {
  321. uni.showToast({
  322. title: '修改成功',
  323. icon: 'success',
  324. success: () => {
  325. setTimeout(() => {
  326. close();
  327. }, 1000)
  328. }
  329. })
  330. return;
  331. }
  332. uni.showToast({
  333. title: res.msg,
  334. icon: 'none'
  335. })
  336. })
  337. };
  338. const close = () => {
  339. calendar.value.close();
  340. }
  341. const init = () => {
  342. getDataTime().then(res => {
  343. console.log('res', res);
  344. if (res.code === 200) {
  345. selected.value = res.data.map(item => {
  346. return {
  347. date: item.workDate,
  348. info: `${item.workStartTime}~${item.workEndTime}`,
  349. time: {
  350. startTime: item.workStartTime,
  351. endTime: item.workEndTime
  352. }
  353. }
  354. })
  355. calendar.value.open();
  356. }
  357. })
  358. }
  359. onMounted(() => {
  360. // init();
  361. });
  362. </script>
  363. <style scoped>
  364. .Wrapper-grid {
  365. margin-top: 36rpx;
  366. }
  367. /* 图标样式 */
  368. .service-img {}
  369. /* 文本样式 */
  370. .grid-text {
  371. font-size: 24rpx;
  372. color: #333;
  373. text-align: center;
  374. margin-top: 18rpx;
  375. }
  376. .grid-box {
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. flex-direction: column;
  381. margin-bottom: 12rpx;
  382. }
  383. .grid-icon {
  384. width: 100rpx;
  385. height: 100rpx;
  386. opacity: 1;
  387. border-radius: 12rpx;
  388. background: rgba(251, 229, 225, 1);
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. }
  393. .service-img {
  394. width: 58rpx;
  395. height: 58rpx;
  396. }
  397. .swiper {
  398. height: 205px;
  399. }
  400. .grid-text {
  401. font-size: 14px;
  402. color: #909399;
  403. padding: 10rpx 0 20rpx 0rpx;
  404. }
  405. </style>