new_file.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view>
  3. <!-- 服务选择 -->
  4. <template v-if="userType == 1">
  5. <view class="Wrapper-grid">
  6. <up-grid :border="false" col="4" @click="handleGridClick">
  7. <up-grid-item v-for="(item, index) in serviceList1" :key="index"
  8. :custom-style="{ padding: '20rpx' }">
  9. <!-- 图标 -->
  10. <image :src="item.icon" class="service-img" mode="aspectFit" />
  11. <!-- 文本 -->
  12. <text class="grid-text">{{ item.name }}</text>
  13. </up-grid-item>
  14. </up-grid>
  15. <up-toast ref="uToastRef" />
  16. </view>
  17. </template>
  18. <template v-else-if="userType == 2">
  19. <view class="Wrapper-grid">
  20. <up-grid :border="false" col="4" @click="handleGridClick">
  21. <up-grid-item v-for="(item, index) in serviceList2" :key="index" :custom-style="custmoStyle">
  22. <view class="grid-box">
  23. <!-- 图标 -->
  24. <view class="grid-icon">
  25. <image :src="item.icon" class="service-img" mode="aspectFit" />
  26. </view>
  27. <!-- 文本 -->
  28. <text class="grid-text">{{ item.name }}</text>
  29. </view>
  30. </up-grid-item>
  31. </up-grid>
  32. <up-toast ref="uToastRef" />
  33. </view>
  34. </template>
  35. <Calendar ref="calendar" class="uni-calendar--hook" :clear-date="false" :date="info.date" :insert="info.insert"
  36. :lunar="info.lunar" :range="info.range" @change="change" :clearDate="true" @confirm="confirm"
  37. :selected="selected" @delete="onDelete" />
  38. </view>
  39. </template>
  40. <script setup>
  41. import {
  42. ref,
  43. onMounted,
  44. watch,
  45. computed
  46. } from 'vue';
  47. // import {
  48. // typeOptionSelect
  49. // } from "@/api/volunteerDetailsApi/details.js"
  50. import {
  51. workDate,
  52. getDataTime,
  53. getVolunteerInfo
  54. } from '@/api/volunteer.js'
  55. import Calendar from '../../components/uni-calendar/components/uni-calendar/uni-calendar.vue'
  56. // Toast 控制宫格
  57. const uToastRef = ref(null);
  58. const userType = uni.getStorageSync('userType') //读取本地存储
  59. // 用户/志愿者 识别标识
  60. const userOrWorker = uni.getStorageSync('storage_data').vuex_userOrWorker //读取本地存储
  61. const calendar = ref(null)
  62. const info = ref({
  63. lunar: true,
  64. range: true,
  65. insert: false,
  66. })
  67. const selected = ref([])
  68. const custmoStyle = {
  69. // borderRadius: '8px',
  70. display: 'flex',
  71. alignItems: 'center',
  72. justifyContent: 'center',
  73. // background:'rgba(0, 122, 255, 0.1);'
  74. }
  75. // 普通用户
  76. const serviceList1 = ref([{
  77. icon: '/static/img/统一知识平台-营运@1x.png',
  78. name: '孩子陪护',
  79. key: 1,
  80. },
  81. {
  82. icon: '/static/img/编组.png',
  83. name: '陪伴陪聊',
  84. key: 2,
  85. },
  86. {
  87. icon: '/static/img/清空.png',
  88. name: '家庭助理',
  89. key: 3,
  90. },
  91. {
  92. icon: '/static/img/构建.png',
  93. name: '健康管理',
  94. key: 4,
  95. },
  96. {
  97. icon: '/static/img/报事报修@6x.png',
  98. name: '家庭清洁',
  99. key: 5,
  100. },
  101. {
  102. icon: '/static/img/报事报修@6x.png',
  103. name: '家务帮手',
  104. key: 6,
  105. },
  106. {
  107. icon: '/static/img/报事报修@6x.png',
  108. name: '资讯与服务',
  109. key: 7,
  110. },
  111. ]);
  112. //志愿者
  113. const serviceList2 = ref([
  114. {
  115. icon: '/static/serverImg/home/icon/icon2.png',
  116. name: '陪伴陪聊',
  117. key: 1,
  118. },
  119. {
  120. icon: '/static/serverImg/home/icon/icon4.png',
  121. name: '孩子陪护',
  122. key: 2,
  123. },
  124. {
  125. icon: '/static/serverImg/home/icon/icon1.png',
  126. name: '家庭助理',
  127. key: 3,
  128. },
  129. {
  130. icon: '/static/serverImg/home/icon/icon6.png',
  131. name: '健康管理',
  132. key: 4
  133. },
  134. {
  135. icon: '/static/serverImg/home/icon/icon2.png',
  136. name: '家庭清洁',
  137. key: 5
  138. },
  139. {
  140. icon: '/static/serverImg/home/icon/icon5.png',
  141. name: '家务帮手',
  142. key: 6
  143. },
  144. {
  145. icon: '/static/serverImg/home/icon/icon7.png',
  146. name: '咨询服务',
  147. key: 8
  148. },
  149. {
  150. icon: '/static/serverImg/home/icon/icon8.png',
  151. name: '排班管理',
  152. key: 7
  153. },
  154. ]);
  155. // 宫格点击事件
  156. const handleGridClick = async (index) => {
  157. const service = serviceList1.value[index]; // 获取点击的服务条目
  158. // 用户
  159. if (userType == 1) {
  160. // 只有第一条和第二条可以跳转
  161. if (index === 0 || index === 1) {
  162. uni.navigateTo({
  163. url: `/pages_home/pages/client/details?name=${encodeURIComponent(service.name)}`
  164. });
  165. } else {
  166. // 其他条目提示“敬请期待”
  167. uni.showToast({
  168. title: '敬请期待',
  169. icon: 'none'
  170. });
  171. }
  172. }
  173. // 志愿者
  174. if (userType == 2 && uToastRef.value) {
  175. // pages_home/pages
  176. const data = serviceList2.value[index]
  177. if (data.key !== 7) {
  178. const res = await getVolunteerInfo({ serviceCategory: data.key });
  179. if (res.code === 200 && res.data) {
  180. //已有注册,跳转详情页面
  181. uni.navigateTo({
  182. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify(data))}`
  183. })
  184. return
  185. }
  186. data.key === 1 || data.key === 2 ? uni.navigateTo({
  187. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify(data))}`
  188. }) : uni.showToast({
  189. title: '敬请期待',
  190. icon: 'none'
  191. })
  192. return;
  193. }
  194. init();
  195. }
  196. };
  197. const change = (e) => {
  198. console.log('change', e);
  199. let dates = [{
  200. date: e.fulldate,
  201. info: `${e.time.startTime}~${e.time.endTime}`,
  202. time: e.time
  203. }]
  204. if (e.range.before && e.range.after) {
  205. dates = e.range.data.map(item => {
  206. return {
  207. date: item,
  208. info: `${e.time.startTime}~${e.time.endTime}`,
  209. time: e.time
  210. }
  211. })
  212. }
  213. selected.value = [...selected.value, ...dates]
  214. }
  215. const onDelete = (e) => {
  216. selected.value = selected.value.filter(item => {
  217. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  218. return item.date !== e.fulldate
  219. })
  220. console.log(e, selected.value);
  221. }
  222. //排班时间去重处理
  223. const handleDates = computed(() => {
  224. const parmas = selected.value.map(item => {
  225. return {
  226. workDate: item.date,
  227. workStartTime: item.time.startTime,
  228. workEndTime: item.time.endTime
  229. }
  230. })
  231. return parmas.reduce((acc, current) => {
  232. const existing = acc.find(item => item.workDate === current.workDate);
  233. if (existing) {
  234. Object.assign(existing, current);
  235. } else {
  236. acc.push(current);
  237. }
  238. return acc;
  239. }, []);
  240. });
  241. const confirm = (e) => {
  242. const parmas = handleDates.value;
  243. console.log('确定', parmas);
  244. workDate(parmas).then(res => {
  245. if (res.code == 200) {
  246. uni.showToast({
  247. title: '修改成功',
  248. icon: 'success',
  249. success: () => {
  250. setTimeout(() => {
  251. close();
  252. }, 1000)
  253. }
  254. })
  255. return;
  256. }
  257. uni.showToast({
  258. title: res.msg,
  259. icon: 'none'
  260. })
  261. })
  262. };
  263. const close = () => {
  264. calendar.value.close();
  265. }
  266. const init = () => {
  267. getDataTime().then(res => {
  268. console.log('res', res);
  269. if (res.code === 200) {
  270. selected.value = res.data.map(item => {
  271. return {
  272. date: item.workDate,
  273. info: `${item.workStartTime}~${item.workEndTime}`,
  274. time: {
  275. startTime: item.workStartTime,
  276. endTime: item.workEndTime
  277. }
  278. }
  279. })
  280. calendar.value.open();
  281. }
  282. })
  283. }
  284. onMounted(() => {
  285. // init();
  286. });
  287. </script>
  288. <style scoped>
  289. .Wrapper-grid {
  290. /* margin-top: 170rpx; */
  291. margin-top: 36rpx;
  292. }
  293. /* 图标样式 */
  294. .service-img {
  295. /* width: 80rpx;
  296. height: 80rpx; */
  297. /* margin-bottom: 15rpx; */
  298. }
  299. /* 文本样式 */
  300. .grid-text {
  301. font-size: 24rpx;
  302. color: #333;
  303. text-align: center;
  304. margin-top: 18rpx;
  305. }
  306. .grid-box {
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. flex-direction: column;
  311. margin-bottom: 48rpx;
  312. }
  313. .grid-icon {
  314. width: 96rpx;
  315. height: 96rpx;
  316. opacity: 1;
  317. border-radius: 8rpx;
  318. background: rgba(0, 122, 255, 0.1);
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. }
  323. .service-img {
  324. width: 48rpx;
  325. height: 48rpx;
  326. }
  327. </style>