new_file.vue 8.7 KB

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