new_file.vue 7.0 KB

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