new_file.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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" >
  9. <up-grid-item v-for="(item, index) in serveiceList.slice(0,10)" :key="index"
  10. :custom-style="custmoStyle" @click="handleGridClick(item)">
  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" >
  22. <up-grid-item v-for="(item, index) in serveiceList.slice(10,serveiceList.length)" :key="index"
  23. :custom-style="custmoStyle" @click="handleGridClick(item)">
  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 (service) => {
  215. // const service = serveiceList.value[index]; // 获取点击的服务条目
  216. console.log('index',service);
  217. // 用户
  218. if (userType == 1) {
  219. // 动态获取 parentId
  220. // const parentId = getParentId(service); // 通过服务条目动态获取 parentId
  221. const params = {
  222. parentId: service.key
  223. }
  224. const res = await volunteerSeachgetTreeList(params)
  225. console.log(res, '>>>>>dictSort = null')
  226. // 只有第一条和第二条可以跳转
  227. if (service.key === 1 || service.key === 2) {
  228. uni.navigateTo({
  229. url: `/pages_home/pages/client/details?dataList=${encodeURIComponent(JSON.stringify(res.data))}`
  230. });
  231. } else {
  232. // 其他条目提示“敬请期待”
  233. uni.showToast({
  234. title: '敬请期待',
  235. icon: 'none'
  236. });
  237. }
  238. }
  239. // 志愿者
  240. if (userType == 2 ) {
  241. if (service.key !== 7) {
  242. const res = await getVolunteerInfo({
  243. serviceCategory: service.key
  244. });
  245. if (res.code === 200 && res.data) {
  246. //已有注册,跳转详情页面
  247. uni.navigateTo({
  248. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify(service))}`
  249. })
  250. return
  251. }
  252. [1,2].includes(service.key) ? uni.navigateTo({
  253. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify(service))}`
  254. }) : uni.showToast({
  255. title: '敬请期待',
  256. icon: 'none'
  257. })
  258. return;
  259. }
  260. init();
  261. }
  262. };
  263. const change = (e) => {
  264. console.log('change', e);
  265. let dates = [{
  266. date: e.fulldate,
  267. info: `${e.time.startTime}~${e.time.endTime}`,
  268. time: e.time
  269. }]
  270. if (e.range.before && e.range.after) {
  271. dates = e.range.data.map(item => {
  272. return {
  273. date: item,
  274. info: `${e.time.startTime}~${e.time.endTime}`,
  275. time: e.time
  276. }
  277. })
  278. }
  279. selected.value = [...selected.value, ...dates]
  280. }
  281. const onDelete = (e) => {
  282. selected.value = selected.value.filter(item => {
  283. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  284. return item.date !== e.fulldate
  285. })
  286. console.log(e, selected.value);
  287. }
  288. //排班时间去重处理
  289. const handleDates = computed(() => {
  290. const parmas = selected.value.map(item => {
  291. return {
  292. workDate: item.date,
  293. workStartTime: item.time.startTime,
  294. workEndTime: item.time.endTime
  295. }
  296. })
  297. return parmas.reduce((acc, current) => {
  298. const existing = acc.find(item => item.workDate === current.workDate);
  299. if (existing) {
  300. Object.assign(existing, current);
  301. } else {
  302. acc.push(current);
  303. }
  304. return acc;
  305. }, []);
  306. });
  307. const confirm = (e) => {
  308. const parmas = handleDates.value;
  309. console.log('确定', parmas);
  310. workDate(parmas).then(res => {
  311. if (res.code == 200) {
  312. uni.showToast({
  313. title: '修改成功',
  314. icon: 'success',
  315. success: () => {
  316. setTimeout(() => {
  317. close();
  318. }, 1000)
  319. }
  320. })
  321. return;
  322. }
  323. uni.showToast({
  324. title: res.msg,
  325. icon: 'none'
  326. })
  327. })
  328. };
  329. const close = () => {
  330. calendar.value.close();
  331. }
  332. const init = () => {
  333. getDataTime().then(res => {
  334. console.log('res', res);
  335. if (res.code === 200) {
  336. selected.value = res.data.map(item => {
  337. return {
  338. date: item.workDate,
  339. info: `${item.workStartTime}~${item.workEndTime}`,
  340. time: {
  341. startTime: item.workStartTime,
  342. endTime: item.workEndTime
  343. }
  344. }
  345. })
  346. calendar.value.open();
  347. }
  348. })
  349. }
  350. onMounted(() => {
  351. // init();
  352. });
  353. </script>
  354. <style scoped>
  355. .Wrapper-grid {
  356. margin-top: 36rpx;
  357. }
  358. /* 图标样式 */
  359. .service-img {}
  360. /* 文本样式 */
  361. .grid-text {
  362. font-size: 24rpx;
  363. color: #333;
  364. text-align: center;
  365. /* margin-top: 18rpx; */
  366. }
  367. .grid-box {
  368. display: flex;
  369. align-items: center;
  370. justify-content: center;
  371. flex-direction: column;
  372. margin-bottom: 12rpx;
  373. }
  374. .grid-icon {
  375. width: 100rpx;
  376. height: 100rpx;
  377. opacity: 1;
  378. border-radius: 12rpx;
  379. /* background: rgba(251, 229, 225, 1); */
  380. display: flex;
  381. align-items: center;
  382. justify-content: center;
  383. }
  384. .service-img {
  385. width: 78rpx;
  386. height: 78rpx;
  387. }
  388. .swiper {
  389. height: 340rpx;
  390. }
  391. .grid-text {
  392. font-size: 14px;
  393. color: #909399;
  394. /* padding: 10rpx 0 0 0rpx; */
  395. }
  396. .client-title {
  397. padding: 0 32rpx;
  398. }
  399. </style>