new_file.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. {
  78. icon: '/static/Tioimages/1v专业指导.png',
  79. name: '陪伴陪聊',
  80. key: 1,
  81. },
  82. {
  83. icon: '/static/Tioimages/1 妇女儿童权益保护服务.png',
  84. name: '孩子陪伴',
  85. key: 2,
  86. },
  87. {
  88. icon: '/static/Tioimages/临时帮手.png',
  89. name: '临时帮手',
  90. key: 3,
  91. },
  92. {
  93. icon: '/static/Tioimages/专家服务.png',
  94. name: '专家服务',
  95. key: 4,
  96. },
  97. {
  98. icon: '/static/Tioimages/家电维修.png',
  99. name: '家电维护',
  100. key: 5,
  101. },
  102. {
  103. icon: '/static/Tioimages/家庭保洁.png',
  104. name: '家庭保洁',
  105. key: 6,
  106. },
  107. {
  108. icon: '/static/Tioimages/旅游服务.png',
  109. name: '旅游服务',
  110. key: 7,
  111. },
  112. {
  113. icon: '/static/Tioimages/健康管理.png',
  114. name: '健康管理',
  115. key: 8,
  116. },
  117. {
  118. icon: '/static/Tioimages/交友.png',
  119. name: '交友专区',
  120. key: 9,
  121. },
  122. {
  123. icon: '/static/Tioimages/购物商城.png',
  124. name: '商城购物',
  125. key: 10,
  126. },
  127. {
  128. icon: '/static/Tioimages/本地生活.png',
  129. name: '本地生活',
  130. key: 11,
  131. },
  132. ]
  133. //志愿者
  134. const serviceList2 = [
  135. {
  136. icon: '/static/Tioimages/1v专业指导.png',
  137. name: '陪伴陪聊',
  138. key: 1,
  139. },
  140. {
  141. icon: '/static/Tioimages/1 妇女儿童权益保护服务.png',
  142. name: '孩子陪护',
  143. key: 2,
  144. },
  145. {
  146. icon: '/static/Tioimages/健康管理.png',
  147. name: '健康管理',
  148. key: 3,
  149. },
  150. {
  151. icon: '/static/Tioimages/家庭保洁.png',
  152. name: '家庭保洁',
  153. key: 4
  154. },
  155. {
  156. icon: '/static/Tioimages/临时帮手.png',
  157. name: '临时帮手',
  158. key: 5
  159. },
  160. {
  161. icon: '/static/Tioimages/专家服务.png',
  162. name: '专家服务',
  163. key: 6
  164. },
  165. {
  166. icon: '/static/Tioimages/家电维修.png',
  167. name: '家电维护',
  168. key: 8
  169. },
  170. {
  171. icon: '/static/Tioimages/旅游服务.png',
  172. name: '旅游服务',
  173. key: 9
  174. },
  175. {
  176. icon: '/static/Tioimages/交友.png',
  177. name: '交友专区',
  178. key: 10
  179. },
  180. {
  181. icon: '/static/Tioimages/购物商城.png',
  182. name: '商城购物',
  183. key: 11
  184. },
  185. {
  186. icon: '/static/Tioimages/本地生活.png',
  187. name: '本地生活',
  188. key: 12
  189. },
  190. {
  191. icon: '/static/serverImg/home/icon/icon8.png',
  192. name: '排班管理',
  193. key: 7
  194. },
  195. ]
  196. const serveiceList =computed(()=>{
  197. console.log('userType ____>',userType);
  198. if(userType === 1){
  199. return serviceList1
  200. }
  201. return serviceList2
  202. })
  203. const parentIdMap = {
  204. '孩子陪护': 2,
  205. '陪伴陪聊': 1,
  206. '家庭助理': 3,
  207. '健康管理': 4,
  208. '家庭清洁': 5,
  209. '家务帮手': 6,
  210. '资讯与服务': 7,
  211. };
  212. // const getParentId = (service) => parentIdMap[service.name] || 1;
  213. // 宫格点击事件
  214. const handleGridClick = async (index) => {
  215. const service = serveiceList.value[index]; // 获取点击的服务条目
  216. // 用户
  217. if (userType == 1) {
  218. // 动态获取 parentId
  219. // const parentId = getParentId(service); // 通过服务条目动态获取 parentId
  220. const params = {
  221. parentId: service.key
  222. }
  223. const res = await volunteerSeachgetTreeList(params)
  224. console.log(res, '>>>>>dictSort = null')
  225. // 只有第一条和第二条可以跳转
  226. if (service.key === 1 || service.key === 2) {
  227. uni.navigateTo({
  228. url: `/pages_home/pages/client/details?dataList=${encodeURIComponent(JSON.stringify(res.data))}`
  229. });
  230. } else {
  231. // 其他条目提示“敬请期待”
  232. uni.showToast({
  233. title: '敬请期待',
  234. icon: 'none'
  235. });
  236. }
  237. }
  238. // 志愿者
  239. if (userType == 2 ) {
  240. if (service.key !== 7) {
  241. const res = await getVolunteerInfo({
  242. serviceCategory: service.key
  243. });
  244. if (res.code === 200 && res.data) {
  245. //已有注册,跳转详情页面
  246. uni.navigateTo({
  247. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify(service))}`
  248. })
  249. return
  250. }
  251. service.key === 1 || service.key === 2 ? uni.navigateTo({
  252. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify(service))}`
  253. }) : uni.showToast({
  254. title: '敬请期待',
  255. icon: 'none'
  256. })
  257. return;
  258. }
  259. init();
  260. }
  261. };
  262. const change = (e) => {
  263. console.log('change', e);
  264. let dates = [{
  265. date: e.fulldate,
  266. info: `${e.time.startTime}~${e.time.endTime}`,
  267. time: e.time
  268. }]
  269. if (e.range.before && e.range.after) {
  270. dates = e.range.data.map(item => {
  271. return {
  272. date: item,
  273. info: `${e.time.startTime}~${e.time.endTime}`,
  274. time: e.time
  275. }
  276. })
  277. }
  278. selected.value = [...selected.value, ...dates]
  279. }
  280. const onDelete = (e) => {
  281. selected.value = selected.value.filter(item => {
  282. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  283. return item.date !== e.fulldate
  284. })
  285. console.log(e, selected.value);
  286. }
  287. //排班时间去重处理
  288. const handleDates = computed(() => {
  289. const parmas = selected.value.map(item => {
  290. return {
  291. workDate: item.date,
  292. workStartTime: item.time.startTime,
  293. workEndTime: item.time.endTime
  294. }
  295. })
  296. return parmas.reduce((acc, current) => {
  297. const existing = acc.find(item => item.workDate === current.workDate);
  298. if (existing) {
  299. Object.assign(existing, current);
  300. } else {
  301. acc.push(current);
  302. }
  303. return acc;
  304. }, []);
  305. });
  306. const confirm = (e) => {
  307. const parmas = handleDates.value;
  308. console.log('确定', parmas);
  309. workDate(parmas).then(res => {
  310. if (res.code == 200) {
  311. uni.showToast({
  312. title: '修改成功',
  313. icon: 'success',
  314. success: () => {
  315. setTimeout(() => {
  316. close();
  317. }, 1000)
  318. }
  319. })
  320. return;
  321. }
  322. uni.showToast({
  323. title: res.msg,
  324. icon: 'none'
  325. })
  326. })
  327. };
  328. const close = () => {
  329. calendar.value.close();
  330. }
  331. const init = () => {
  332. getDataTime().then(res => {
  333. console.log('res', res);
  334. if (res.code === 200) {
  335. selected.value = res.data.map(item => {
  336. return {
  337. date: item.workDate,
  338. info: `${item.workStartTime}~${item.workEndTime}`,
  339. time: {
  340. startTime: item.workStartTime,
  341. endTime: item.workEndTime
  342. }
  343. }
  344. })
  345. calendar.value.open();
  346. }
  347. })
  348. }
  349. onMounted(() => {
  350. // init();
  351. });
  352. </script>
  353. <style scoped>
  354. .Wrapper-grid {
  355. margin-top: 36rpx;
  356. }
  357. /* 图标样式 */
  358. .service-img {}
  359. /* 文本样式 */
  360. .grid-text {
  361. font-size: 24rpx;
  362. color: #333;
  363. text-align: center;
  364. /* margin-top: 18rpx; */
  365. }
  366. .grid-box {
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. flex-direction: column;
  371. margin-bottom: 12rpx;
  372. }
  373. .grid-icon {
  374. width: 100rpx;
  375. height: 100rpx;
  376. opacity: 1;
  377. border-radius: 12rpx;
  378. /* background: rgba(251, 229, 225, 1); */
  379. display: flex;
  380. align-items: center;
  381. justify-content: center;
  382. }
  383. .service-img {
  384. width: 78rpx;
  385. height: 78rpx;
  386. }
  387. .swiper {
  388. height: 340rpx;
  389. }
  390. .grid-text {
  391. font-size: 14px;
  392. color: #909399;
  393. /* padding: 10rpx 0 0 0rpx; */
  394. }
  395. .client-title {
  396. padding: 0 32rpx;
  397. }
  398. </style>