new_file.vue 8.2 KB

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