new_file.vue 9.2 KB

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