new_file.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. icon: '/static/serverImg/home/icon/icon4.png',
  115. name: '家庭辅导',
  116. key: 2,
  117. },
  118. {
  119. icon: '/static/serverImg/home/icon/icon2.png',
  120. name: '陪伴陪聊',
  121. key: 1,
  122. },
  123. {
  124. icon: '/static/serverImg/home/icon/icon1.png',
  125. name: '家庭助理',
  126. key: 3,
  127. },
  128. {
  129. icon: '/static/serverImg/home/icon/icon6.png',
  130. name: '健康管理',
  131. key: 4
  132. },
  133. {
  134. icon: '/static/serverImg/home/icon/icon2.png',
  135. name: '家庭清洁',
  136. key: 5
  137. },
  138. {
  139. icon: '/static/serverImg/home/icon/icon5.png',
  140. name: '家务帮手',
  141. key: 6
  142. },
  143. {
  144. icon: '/static/serverImg/home/icon/icon7.png',
  145. name: '咨询服务',
  146. key: 8
  147. },
  148. {
  149. icon: '/static/serverImg/home/icon/icon8.png',
  150. name: '排班管理',
  151. key: 7
  152. },
  153. ]);
  154. // 宫格点击事件
  155. const handleGridClick = async (index) => {
  156. const service = serviceList1.value[index]; // 获取点击的服务条目
  157. // 用户
  158. if (userType == 1) {
  159. // 只有第一条和第二条可以跳转
  160. if (index === 0 || index === 1) {
  161. uni.navigateTo({
  162. url: `/pages_home/pages/client/details?name=${encodeURIComponent(service.name)}`
  163. });
  164. } else {
  165. // 其他条目提示“敬请期待”
  166. uni.showToast({
  167. title: '敬请期待',
  168. icon: 'none'
  169. });
  170. }
  171. }
  172. // 志愿者
  173. if (userType == 2 && uToastRef.value) {
  174. // pages_home/pages
  175. const data = serviceList2.value[index]
  176. if (data.key !== 7) {
  177. const res = await getVolunteerInfo({ serviceCategory: data.key });
  178. if(res.code === 200 && res.data){
  179. //已有注册,跳转详情页面
  180. uni.navigateTo({
  181. url: `/pages_home/pages/details/index?data=${encodeURIComponent(JSON.stringify(data))}`
  182. })
  183. return
  184. }
  185. data.key === 1 || data.key === 2 ? uni.navigateTo({
  186. url: `/pages_home/pages/register/index?data=${encodeURIComponent(JSON.stringify(data))}`
  187. }) : uni.showToast({
  188. title: '敬请期待',
  189. icon: 'none'
  190. })
  191. return;
  192. }
  193. init();
  194. calendar.value.open();
  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. selected.value = res.data.map(item => {
  270. return {
  271. date: item.workDate,
  272. info: `${item.workStartTime}~${item.workEndTime}`,
  273. time: {
  274. startTime: item.workStartTime,
  275. endTime: item.workEndTime
  276. }
  277. }
  278. })
  279. })
  280. }
  281. onMounted(() => {
  282. // init();
  283. });
  284. </script>
  285. <style scoped>
  286. .Wrapper-grid {
  287. /* margin-top: 170rpx; */
  288. margin-top: 36rpx;
  289. }
  290. /* 图标样式 */
  291. .service-img {
  292. /* width: 80rpx;
  293. height: 80rpx; */
  294. /* margin-bottom: 15rpx; */
  295. }
  296. /* 文本样式 */
  297. .grid-text {
  298. font-size: 24rpx;
  299. color: #333;
  300. text-align: center;
  301. margin-top: 18rpx;
  302. }
  303. .grid-box {
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. flex-direction: column;
  308. margin-bottom: 48rpx;
  309. }
  310. .grid-icon {
  311. width: 96rpx;
  312. height: 96rpx;
  313. opacity: 1;
  314. border-radius: 8rpx;
  315. background: rgba(0, 122, 255, 0.1);
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. }
  320. .service-img {
  321. width: 48rpx;
  322. height: 48rpx;
  323. }
  324. </style>