new_file.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/register/register?data=${encodeURIComponent(JSON.stringify(data))}`
  162. }) : uni.showToast({
  163. title: '敬请期待',
  164. icon: 'none'
  165. })
  166. return;
  167. }
  168. calendar.value.open();
  169. }
  170. };
  171. const change = (e) => {
  172. console.log('change', e);
  173. let dates = [{
  174. date: e.fulldate,
  175. info: `${e.time.startTime}~${e.time.endTime}`,
  176. time: e.time
  177. }]
  178. if (e.range.before && e.range.after) {
  179. dates = e.range.data.map(item => {
  180. return {
  181. date: item,
  182. info: `${e.time.startTime}~${e.time.endTime}`,
  183. time: e.time
  184. }
  185. })
  186. }
  187. selected.value = [...selected.value, ...dates]
  188. }
  189. const onDelete = (e) => {
  190. selected.value = selected.value.filter(item => {
  191. console.log('item.fulldate !== e.date', item.date, e.fulldate);
  192. return item.date !== e.fulldate
  193. })
  194. console.log(e, selected.value);
  195. }
  196. const confirm = (e) => {
  197. const parmas = selected.value.map(item => {
  198. return {
  199. workDate: item.date,
  200. workStartTime: item.time.startTime,
  201. workEndTime: item.time.endTime
  202. }
  203. })
  204. console.log('确定', parmas);
  205. workDate(parmas).then(res => {
  206. if (res.code == 200) {
  207. uni.showToast({
  208. title: '修改成功',
  209. icon: 'none'
  210. })
  211. close();
  212. return;
  213. }
  214. uni.showToast({
  215. title: res.msg,
  216. icon: 'none'
  217. })
  218. })
  219. };
  220. const close = () => {
  221. calendar.value.close();
  222. }
  223. const init = () => {
  224. getDataTime().then(res => {
  225. console.log('res', res);
  226. selected.value = res.data.map(item => {
  227. return {
  228. date: item.workDate,
  229. info: `${item.workStartTime}~${item.workEndTime}`,
  230. time: {
  231. startTime: item.workStartTime,
  232. endTime: item.workEndTime
  233. }
  234. }
  235. })
  236. })
  237. }
  238. onMounted(() => {
  239. init();
  240. });
  241. </script>
  242. <style scoped>
  243. .Wrapper-grid {
  244. margin-top: 170rpx;
  245. }
  246. /* 图标样式 */
  247. .service-img {
  248. width: 80rpx;
  249. height: 80rpx;
  250. margin-bottom: 15rpx;
  251. }
  252. /* 文本样式 */
  253. .grid-text {
  254. font-size: 24rpx;
  255. color: #333;
  256. text-align: center;
  257. margin-top: 10rpx;
  258. }
  259. </style>