new_file.vue 6.2 KB

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