new_file.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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="4" @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/icon2.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/icon8.png',
  148. name: '排班管理',
  149. key: 7
  150. },
  151. ]);
  152. const parentIdMap = {
  153. '孩子陪护': 2,
  154. '陪伴陪聊': 1,
  155. '家庭助理': 3,
  156. '健康管理': 4,
  157. '家庭清洁': 5,
  158. '家务帮手': 6,
  159. '资讯与服务': 7,
  160. };
  161. const getParentId = (service) => parentIdMap[service.name] || 1;
  162. // 宫格点击事件
  163. const handleGridClick = async (index) => {
  164. const service = serviceList1.value[index]; // 获取点击的服务条目
  165. // 用户
  166. if (userType == 1) {
  167. // 动态获取 parentId
  168. const parentId = getParentId(service); // 通过服务条目动态获取 parentId
  169. const params = {
  170. parentId: parentId
  171. }
  172. const res = await volunteerSeachgetTreeList(params)
  173. console.log(res, '>>>>>dictSort = null')
  174. // 只有第一条和第二条可以跳转
  175. if (index === 0 || index === 1) {
  176. uni.navigateTo({
  177. url: `/pages_home/pages/client/details?dataList=${encodeURIComponent(JSON.stringify(res.data))}`
  178. });
  179. } else {
  180. // 其他条目提示“敬请期待”
  181. uni.showToast({
  182. title: '敬请期待',
  183. icon: 'none'
  184. });
  185. }
  186. }
  187. // 志愿者
  188. if (userType == 2 && uToastRef.value) {
  189. // pages_home/pages
  190. const data = serviceList2.value[index]
  191. if (data.key !== 7) {
  192. const res = await getVolunteerInfo({ serviceCategory: data.key });
  193. if (res.code === 200 && res.data) {
  194. //已有注册,跳转详情页面
  195. uni.navigateTo({
  196. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify(data))}`
  197. })
  198. return
  199. }
  200. data.key === 1 || data.key === 2 ? uni.navigateTo({
  201. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify(data))}`
  202. }) : uni.showToast({
  203. title: '敬请期待',
  204. icon: 'none'
  205. })
  206. return;
  207. }
  208. init();
  209. }
  210. };
  211. const change = (e) => {
  212. console.log('change', e);
  213. let dates = [{
  214. date: e.fulldate,
  215. info: `${e.time.startTime}~${e.time.endTime}`,
  216. time: e.time
  217. }]
  218. if (e.range.before && e.range.after) {
  219. dates = e.range.data.map(item => {
  220. return {
  221. date: item,
  222. info: `${e.time.startTime}~${e.time.endTime}`,
  223. time: e.time
  224. }
  225. })
  226. }
  227. selected.value = [...selected.value, ...dates]
  228. }
  229. const onDelete = (e) => {
  230. selected.value = selected.value.filter(item => {
  231. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  232. return item.date !== e.fulldate
  233. })
  234. console.log(e, selected.value);
  235. }
  236. //排班时间去重处理
  237. const handleDates = computed(() => {
  238. const parmas = selected.value.map(item => {
  239. return {
  240. workDate: item.date,
  241. workStartTime: item.time.startTime,
  242. workEndTime: item.time.endTime
  243. }
  244. })
  245. return parmas.reduce((acc, current) => {
  246. const existing = acc.find(item => item.workDate === current.workDate);
  247. if (existing) {
  248. Object.assign(existing, current);
  249. } else {
  250. acc.push(current);
  251. }
  252. return acc;
  253. }, []);
  254. });
  255. const confirm = (e) => {
  256. const parmas = handleDates.value;
  257. console.log('确定', parmas);
  258. workDate(parmas).then(res => {
  259. if (res.code == 200) {
  260. uni.showToast({
  261. title: '修改成功',
  262. icon: 'success',
  263. success: () => {
  264. setTimeout(() => {
  265. close();
  266. }, 1000)
  267. }
  268. })
  269. return;
  270. }
  271. uni.showToast({
  272. title: res.msg,
  273. icon: 'none'
  274. })
  275. })
  276. };
  277. const close = () => {
  278. calendar.value.close();
  279. }
  280. const init = () => {
  281. getDataTime().then(res => {
  282. console.log('res', res);
  283. if (res.code === 200) {
  284. selected.value = res.data.map(item => {
  285. return {
  286. date: item.workDate,
  287. info: `${item.workStartTime}~${item.workEndTime}`,
  288. time: {
  289. startTime: item.workStartTime,
  290. endTime: item.workEndTime
  291. }
  292. }
  293. })
  294. calendar.value.open();
  295. }
  296. })
  297. }
  298. onMounted(() => {
  299. // init();
  300. });
  301. </script>
  302. <style scoped>
  303. .Wrapper-grid {
  304. /* margin-top: 170rpx; */
  305. margin-top: 36rpx;
  306. }
  307. /* 图标样式 */
  308. .service-img {
  309. /* width: 80rpx;
  310. height: 80rpx; */
  311. /* margin-bottom: 15rpx; */
  312. }
  313. /* 文本样式 */
  314. .grid-text {
  315. font-size: 24rpx;
  316. color: #333;
  317. text-align: center;
  318. margin-top: 18rpx;
  319. }
  320. .grid-box {
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. flex-direction: column;
  325. margin-bottom: 48rpx;
  326. }
  327. .grid-icon {
  328. width: 96rpx;
  329. height: 96rpx;
  330. opacity: 1;
  331. border-radius: 8rpx;
  332. background: rgba(0, 122, 255, 0.1);
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. }
  337. .service-img {
  338. width: 48rpx;
  339. height: 48rpx;
  340. }
  341. </style>