new_file.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view>
  3. <template>
  4. <view class="Wrapper-grid">
  5. <view class="serve-title client-title" v-if="userType == 2"></view>
  6. <up-grid :border="false" col="3">
  7. <up-grid-item v-for="(item, index) in serveiceList" :key="index" @click="handleGridClick(item)">
  8. <view class="grid-box">
  9. <view class="grid-image">
  10. <image :src="item.businessIcon" class="service-img" mode="aspectFit" />
  11. </view>
  12. <view class="grid-content">
  13. <text class="grid-text">{{ item.businessName }}</text>
  14. <text class="grid-text-bone">{{ item.businessDescribe }}</text>
  15. </view>
  16. </view>
  17. </up-grid-item>
  18. </up-grid>
  19. <up-toast ref="uToastRef" />
  20. <view class="paiBanSty" v-if="userType == 2">
  21. <!-- 背景图片 -->
  22. <image src="/static/img/14147@2x.png" class="background-image" mode="aspectFill" />
  23. <!-- 左侧轮播图 -->
  24. <swiper class="zhiYuanZheSwiper" vertical circular autoplay :interval="4000" :duration="800"
  25. :previous-margin="'20rpx'" :next-margin="'20rpx'" @change="onSwiperChange">
  26. <swiper-item v-for="(imgUrl, index) in volunteerImages" :key="index">
  27. <view class="swiper-item-container" :class="{ 'active-swiper': currentSwiperIndex === index }">
  28. <image :src="imgUrl" class="zhiYuanZhe" mode="aspectFill" />
  29. </view>
  30. </swiper-item>
  31. </swiper>
  32. <!-- 右侧内容区域 -->
  33. <view class="content-wrapper">
  34. <view class="title-button-row">
  35. <view class="paiBanTitle">我的排班</view>
  36. <button class="paiBanBtn" @click="DataInit">去管理排班</button>
  37. </view>
  38. <view class="paiBanDesc">管理排班时间,合理分配服务订单</view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <Calendar ref="calendar" class="uni-calendar--hook" :clear-date="false" :date="info.date" :insert="info.insert"
  44. :lunar="info.lunar" :range="info.range" @change="change" :clearDate="true" @confirm="confirm" :selected="selected"
  45. @delete="onDelete" />
  46. </view>
  47. </template>
  48. <script setup>
  49. import {
  50. ref,
  51. onMounted,
  52. watch,
  53. computed,
  54. provide
  55. } from 'vue';
  56. import {
  57. workDate,
  58. getDataTime,
  59. getVolunteerInfo
  60. } from '@/api/volunteer.js'
  61. import {
  62. volunteerSeachgetTreeList,
  63. volunteerVolunteerPicture
  64. } from "@/api/volunteerDetailsApi/details.js"
  65. import { getTreeList } from '@/api/volunteer'
  66. import Calendar from '../../components/uni-calendar/components/uni-calendar/uni-calendar.vue'
  67. import { getToken } from '@/utils/auth'
  68. const swiperList = ['integral', 'kefu-ermai', 'coupon', 'gift', 'scan', 'pause-circle', 'wifi', 'email', 'list'];
  69. // Toast 控制宫格
  70. const uToastRef = ref(null);
  71. const userType = uni.getStorageSync('userType') //读取本地存储
  72. // 用户/志愿者 识别标识
  73. const userOrWorker = uni.getStorageSync('storage_data').vuex_userOrWorker //读取本地存储
  74. const calendar = ref(null)
  75. const info = ref({
  76. lunar: true,
  77. range: true,
  78. insert: false,
  79. })
  80. const selected = ref([])
  81. const serveiceList = ref([]);
  82. // 志愿者图片
  83. const volunteerImages = ref([]);
  84. const getVolunteerImages = () => {
  85. volunteerVolunteerPicture({}).then(res => {
  86. console.log('res', res);
  87. if (Array.isArray(res)) {
  88. volunteerImages.value = res;
  89. } else if (res.code === 200 && res.data) {
  90. volunteerImages.value = res.data;
  91. }
  92. })
  93. }
  94. // 当前显示的轮播图索引
  95. const currentSwiperIndex = ref(0);
  96. // 轮播图切换事件
  97. const onSwiperChange = (e) => {
  98. currentSwiperIndex.value = e.detail.current;
  99. };
  100. // 宫格点击事件
  101. const handleGridClick = async (service) => {
  102. // 用户
  103. if (userType == 1) {
  104. // 动态获取 parentId
  105. const params = {
  106. parentId: service.id,
  107. }
  108. const res = await volunteerSeachgetTreeList(params)
  109. uni.navigateTo({
  110. url: `/pages_home/pages/client/details?dataList=${encodeURIComponent(JSON.stringify(res.data))}&serviceCategory=${service.id}`
  111. });
  112. }
  113. // 志愿者
  114. if (userType == 2) {
  115. const res = await getVolunteerInfo({
  116. serviceCategory: service.id
  117. });
  118. if (res.code === 200 && res.data) {
  119. //已有注册,跳转详情页面
  120. uni.navigateTo({
  121. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify({ ...service, key: service.id }))}`
  122. })
  123. return
  124. }
  125. uni.navigateTo({
  126. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify({ ...service, key: service.id }))}`
  127. })
  128. }
  129. };
  130. const change = (e) => {
  131. console.log('change', e);
  132. let dates = [{
  133. date: e.fulldate,
  134. info: `${e.time.startTime}~${e.time.endTime}`,
  135. time: e.time
  136. }]
  137. if (e.range.before && e.range.after) {
  138. dates = e.range.data.map(item => {
  139. return {
  140. date: item,
  141. info: `${e.time.startTime}~${e.time.endTime}`,
  142. time: e.time
  143. }
  144. })
  145. }
  146. selected.value = [...selected.value, ...dates]
  147. }
  148. const onDelete = (e) => {
  149. selected.value = selected.value.filter(item => {
  150. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  151. return item.date !== e.fulldate
  152. })
  153. console.log(e, selected.value);
  154. }
  155. //排班时间去重处理
  156. const handleDates = computed(() => {
  157. const parmas = selected.value.map(item => {
  158. return {
  159. workDate: item.date,
  160. workStartTime: item.time.startTime,
  161. workEndTime: item.time.endTime
  162. }
  163. })
  164. return parmas.reduce((acc, current) => {
  165. const existing = acc.find(item => item.workDate === current.workDate);
  166. if (existing) {
  167. Object.assign(existing, current);
  168. } else {
  169. acc.push(current);
  170. }
  171. return acc;
  172. }, []);
  173. });
  174. const confirm = (e) => {
  175. const parmas = handleDates.value;
  176. console.log('确定', parmas);
  177. workDate(parmas).then(res => {
  178. if (res.code == 200) {
  179. uni.showToast({
  180. title: '修改成功',
  181. icon: 'success',
  182. success: () => {
  183. setTimeout(() => {
  184. close();
  185. }, 1000)
  186. }
  187. })
  188. return;
  189. }
  190. uni.showToast({
  191. title: res.msg,
  192. icon: 'none'
  193. })
  194. })
  195. };
  196. const close = () => {
  197. calendar.value.close();
  198. }
  199. const init = () => {
  200. getTreeList({ parentId: '0' }).then(res => {
  201. console.log("TCL: init -> res", res)
  202. serveiceList.value = res.data;
  203. })
  204. }
  205. const DataInit = () => {
  206. getDataTime().then(res => {
  207. console.log('res', res);
  208. if (res.code === 200) {
  209. selected.value = res.data.map(item => {
  210. return {
  211. date: item.workDate,
  212. info: `${item.workStartTime}~${item.workEndTime}`,
  213. time: {
  214. startTime: item.workStartTime,
  215. endTime: item.workEndTime
  216. }
  217. }
  218. })
  219. calendar.value.open();
  220. }
  221. })
  222. }
  223. onMounted(() => {
  224. init();
  225. const token = getToken();
  226. token && getVolunteerImages();
  227. });
  228. </script>
  229. <style scoped lang="scss">
  230. .grid-box {
  231. width: 226rpx;
  232. height: 116rpx;
  233. display: flex;
  234. flex-direction: row;
  235. align-items: center;
  236. justify-content: flex-start;
  237. margin-right: 5rpx;
  238. margin-left: 5rpx;
  239. background: #fff;
  240. border-radius: 14rpx;
  241. // background: red;
  242. background: linear-gradient(180deg, #FFF9F3 0%, #FFFFFF 100%);
  243. box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(0, 0, 0, 0.04);
  244. margin-top: 10rpx;
  245. .grid-image {
  246. width: 64rpx;
  247. height: 68rpx;
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. }
  252. }
  253. .grid-content {
  254. display: flex;
  255. flex-direction: column;
  256. align-items: flex-start;
  257. justify-content: center;
  258. .grid-text {
  259. width: 112rpx;
  260. height: 36rpx;
  261. font-family: PingFang SC;
  262. font-size: 28rpx;
  263. font-weight: 500;
  264. line-height: 36rpx;
  265. letter-spacing: normal;
  266. color: #313131;
  267. }
  268. .grid-text-bone {
  269. width: 130rpx;
  270. height: 28rpx;
  271. font-family: PingFang SC;
  272. font-size: 22rpx;
  273. font-weight: normal;
  274. line-height: 28rpx;
  275. letter-spacing: -0.02em;
  276. color: #818181;
  277. margin-left: 6rpx;
  278. margin-top: 10rpx;
  279. }
  280. }
  281. .paiBanSty {
  282. position: relative;
  283. margin-top: 30rpx;
  284. display: flex;
  285. flex-direction: row;
  286. background: #FFFFFF;
  287. border-radius: 20rpx;
  288. box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(0, 0, 0, 0.04);
  289. overflow: hidden;
  290. height: 300rpx;
  291. .background-image {
  292. position: absolute;
  293. width: 100%;
  294. height: 100%;
  295. object-fit: cover;
  296. z-index: 0;
  297. }
  298. .zhiYuanZheSwiper {
  299. width: 196rpx;
  300. height: 240rpx;
  301. border-radius: 38rpx;
  302. overflow: hidden;
  303. margin: 30rpx;
  304. z-index: 1;
  305. position: relative;
  306. }
  307. .swiper-item-container {
  308. width: 100%;
  309. height: 100%;
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. transition: all 0.3s;
  314. &.active-swiper {
  315. transform: scale(1);
  316. }
  317. }
  318. .zhiYuanZhe {
  319. width: 100%;
  320. height: 100%;
  321. border-radius: 38rpx;
  322. box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.1);
  323. }
  324. .content-wrapper {
  325. flex: 1;
  326. display: flex;
  327. flex-direction: column;
  328. justify-content: flex-start;
  329. padding: 30rpx;
  330. z-index: 1;
  331. position: relative;
  332. }
  333. .title-button-row {
  334. display: flex;
  335. flex-direction: row;
  336. justify-content: space-between;
  337. align-items: center;
  338. margin-bottom: 12rpx;
  339. width: 100%;
  340. margin-top: 129rpx;
  341. margin-left: 0rpx;
  342. }
  343. .paiBanTitle {
  344. font-family: PingFang SC;
  345. font-size: 34rpx;
  346. font-weight: 600;
  347. line-height: 40rpx;
  348. letter-spacing: normal;
  349. color: rgba(0, 0, 0, 0.8);
  350. width: 136rpx;
  351. height: 40rpx;
  352. position: relative;
  353. left: -2rpx;
  354. top: 17rpx;
  355. }
  356. .paiBanDesc {
  357. font-family: PingFang SC;
  358. font-size: 26rpx;
  359. font-weight: normal;
  360. line-height: 40rpx;
  361. color: rgba(0, 0, 0, 0.5);
  362. margin-top: 8rpx;
  363. left: -2rpx;
  364. position: relative;
  365. }
  366. .paiBanBtn {
  367. width: 200rpx;
  368. height: 70rpx;
  369. display: flex;
  370. justify-content: center;
  371. align-items: center;
  372. border-radius: 36rpx;
  373. background: #D94342;
  374. font-family: PingFang SC;
  375. font-size: 28rpx;
  376. font-weight: 500;
  377. line-height: 30rpx;
  378. color: #FFFFFF;
  379. border: none;
  380. padding: 0;
  381. position: relative;
  382. top: -20rpx;
  383. left: 4rpx;
  384. }
  385. }
  386. .home-ranking {}
  387. @keyframes fadeIn {
  388. from {
  389. opacity: 0;
  390. transform: scale(0.9) translateY(10rpx);
  391. }
  392. to {
  393. opacity: 1;
  394. transform: scale(1) translateY(0);
  395. }
  396. }
  397. @keyframes fadeOut {
  398. from {
  399. opacity: 1;
  400. transform: scale(1) translateY(0);
  401. }
  402. to {
  403. opacity: 0.8;
  404. transform: scale(0.95) translateY(-10rpx);
  405. }
  406. }
  407. </style>