new_file.vue 8.5 KB

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