new_file.vue 8.8 KB

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