Bläddra i källkod

fix: 多选、删除

chenjj 5 månader sedan
förälder
incheckning
013ec0bb98

+ 10 - 0
api/volunteer.js

@@ -17,4 +17,14 @@ export function workDate(data) {
         method: 'put',
         data: data
     })
+}
+
+
+
+//获取志愿者排班日期
+export function getDataTime() {
+    return request({
+        url: `/core/volunteer/work-date/getWorkDateAndTime`,
+        method: 'get',
+    })
 }

+ 3 - 3
components/uni-calendar/components/uni-calendar/uni-calendar-item.vue

@@ -168,9 +168,9 @@
 	}
 
 	.uni-calendar-item--checked {
-		background-color: $uni-primary;
-		color: #fff;
-		opacity: 0.8;
+		// background-color: $uni-primary;
+		// color: #fff;
+		// opacity: 0.8;
 	}
 
 	.uni-calendar-item--multiple {

+ 59 - 19
components/uni-calendar/components/uni-calendar/uni-calendar.vue

@@ -6,6 +6,12 @@
 				<view class="uni-calendar__header-btn-box" @click="close">
 					<text class="uni-calendar__header-text uni-calendar--fixed-width">{{cancelText}}</text>
 				</view>
+				<view class="uni-calendar__header-btn-swich">
+					<view class="swi-lable">单选</view>
+					<up-switch  v-model="switchValue" @change="onSwichChange"></up-switch>
+					<view class="swi-lable">多选</view>
+					
+					</view>
 				<view class="uni-calendar__header-btn-box" @click="confirm">
 					<text class="uni-calendar__header-text uni-calendar--fixed-width">{{okText}}</text>
 				</view>
@@ -50,7 +56,8 @@
 						<text class="uni-calendar__weeks-day-text">{{SATText}}</text>
 					</view>
 				</view>
-				<view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex">
+				<view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex"
+					>
 					<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
 						<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate"></calendar-item>
 					</view>
@@ -73,7 +80,7 @@
 	} from '@dcloudio/uni-i18n'
 	import messages from './i18n/index.js'
 	import timeSlot from "../../../wanghexu-timeslot/wanghexu-timeslot.vue"
-
+	import { ref, toRaw } from 'vue';
 	const {	t	} = initVueI18n(messages)
 	/**
 	 * Calendar 日历
@@ -100,7 +107,7 @@
 			calendarItem,
 			timeSlot
 		},
-		emits:['close','confirm','change','monthSwitch'],
+		emits:['close','confirm','change','monthSwitch','delete'],
 		props: {
 			date: {
 				type: String,
@@ -155,6 +162,8 @@
 				cheackDates:[],
 				startTime:'',
 				endTime:'',
+				switchValue:false,
+				datas:[]
 			}
 		},
 		computed:{
@@ -216,20 +225,22 @@
 			}
 		},
 		created() {
-			// 获取日历方法实例
-			this.cale = new Calendar({
-				// date: new Date(),
-				selected: this.selected,
-				startDate: this.startDate,
-				endDate: this.endDate,
-				range: this.range,
-			})
-			// 选中某一天
-			// this.cale.setDate(this.date)
-			this.init(this.date)
-			// this.setDay
+			this.calendarinit();
 		},
 		methods: {
+			calendarinit() {
+				// 获取日历方法实例
+				this.cale = new Calendar({
+					selected: this.selected,
+					startDate: this.startDate,
+					endDate: this.endDate,
+					range: this.switchValue,
+				})
+				// 选中某一天
+				// this.cale.setDate(this.date)
+				this.init(this.date)
+
+			},
 			// 取消穿透
 			clean() {},
 			bindDateChange(e) {
@@ -286,12 +297,25 @@
 			 * 变化触发
 			 */
 			change() {
-				// if (!this.insert) return
+				console.log('变化触发',this.cale,this.calendar.fullDate);
+				if(this.switchValue && !this.cale.multipleStatus.after){
+					return;
+				}
+				const  is_select =  this.selected.filter(item => {
+					console.log(3,item,item.data,this.calendar.fullDate,);
+					return item.date===this.calendar.fullDate
+				})
+				
+				if(is_select && is_select.length> 0){
+					console.log('is_select',is_select);
+					this.setEmit('delete')
+					return;
+				}
+				
 				this.$refs.timeslot.bindstartChange({detail:{value:[9,0]}})
 				this.$refs.timeslot.bindendChange({detail:{value:[18,0]}})
 				this.$refs.timeslot.open();
-				console.log('变化触发');
-				
+
 			},
 			/**
 			 * 选择月份触发
@@ -385,6 +409,10 @@
 				this.startTime = e.start.hour+":" + e.start.min;
 				this.endTime = e.end.hour+":" + e.end.min;
 				this.setEmit('change')
+			},
+			onSwichChange(e){
+				console.log('change', e);
+				this.calendarinit();
 			}
 		}
 	}
@@ -478,7 +506,12 @@
 		width: 50px;
 		// padding: 0 15px;
 	}
-
+	.uni-calendar__start {
+		position: absolute;
+		left: 25rpx;
+		top: 25rpx;
+		font-size: 12px;
+	}
 	.uni-calendar__backtoday {
 		position: absolute;
 		right: 0;
@@ -589,4 +622,11 @@
 		line-height: 1;
 		/* #endif */
 	}
+	.uni-calendar__header-btn-swich {
+		display: flex;
+		align-content: center;
+	}
+	.swi-lable {
+		margin: 0 6px;
+	}
 </style>

+ 1 - 1
config.js

@@ -3,7 +3,7 @@ const config = {
 	// baseUrl: 'https://vue.ruoyi.vip/prod-api',
 	//cloud后台网关地址
 	// baseUrl: 'http://192.168.10.3:8080',
-	baseUrl: 'http://192.168.100.102:9527',
+	baseUrl: 'http://192.168.100.101:9527',
 	// 应用信息
 	appInfo: {
 		// 应用名称

+ 65 - 52
pages/Client/new_file.vue

@@ -27,7 +27,7 @@
 						<image :src="item.icon" class="service-img" mode="aspectFit" />
 
 						<!-- 文本 -->
-						<text class="grid-text">111{{ item.name }}</text>
+						<text class="grid-text">{{ item.name }}</text>
 					</up-grid-item>
 				</up-grid>
 
@@ -36,8 +36,8 @@
 		</template>
 
 		<Calendar ref="calendar" class="uni-calendar--hook" :clear-date="false" :date="info.date" :insert="info.insert"
-			:lunar="info.lunar" :range="info.range" @change="change"
-			@confirm="confirm" :selected="selected" />
+			:lunar="info.lunar" :range="info.range" @change="change" :clearDate="true"
+			@confirm="confirm" :selected="selected" @delete="onDelete"/>
 
 
 	</view>
@@ -55,20 +55,18 @@
 		typeOptionSelect
 	} from "@/api/volunteerDetailsApi/details.js"
 	import dayjs from 'dayjs';
-	import { workDate } from '@/api/volunteer.js'
+	import { workDate,getDataTime } from '@/api/volunteer.js'
 	import Calendar from '../../components/uni-calendar/components/uni-calendar/uni-calendar.vue'
 
 	// Toast 控制宫格
 	const uToastRef = ref(null);
 	const userType = uni.getStorageSync('userType') //读取本地存储
 
-	const calendar =ref(null)
-	const datas = ref(["2025-04-10","2025-04-11",]);
+	const calendar = ref(null)
 	const info = ref({
 		lunar: true,
-		range: false,
+		range: true,
 		insert: false,
-		// mode:'multiple',//multiple:多选
 	})
 	const selected = ref([])
 
@@ -134,35 +132,16 @@
 	 	},
 	 	{
 	 		icon: '/static/img/清空.png',
-	 		name: '时间管理',
+	 		name: '排班管理',
 			key:7
 	 	},
 	 ]);
 	 
 	
-	//选中的日期展示格式;
-const formatter = (day) => {
-	
-	
-	const  d = dayjs(day.date).format('YYYY-MM-DD')
-	for (let i = 0; i < datas.value.length; i++) {
-		const e = datas.value[i].split(' ');
-		if(e[0] === d){
-			console.log('e',e,e[0] === d,d);
-			console.log(day,d.e);
-			day.bottomInfo = 'xx'
-			// day.dot = true
-		}
-		
-	}
-	
-
-	return day
-}
 // 宫格点击事件
 const handleGridClick = async (index) => {
-	console.log('userType',userType);
-	
+	console.log('userType', userType);
+
 	if (userType == 1) {
 		const res = await typeOptionSelect()
 		console.log((res, '获取健值成功'))
@@ -186,46 +165,80 @@ const handleGridClick = async (index) => {
 
 const change = (e) => {
 	console.log('change', e);
-	selected.value = [...selected.value,
-		{
-			date: e.fulldate,
-			info: `${e.time.startTime}~${e.time.endTime}`,
-			time:e.time
-		}
-	]
+	let dates = [{
+		date: e.fulldate,
+		info: `${e.time.startTime}~${e.time.endTime}`,
+		time: e.time
+	}]
+	if (e.range.before && e.range.after) {
+		dates = e.range.data.map(item => {
+			return {
+				date: item,
+				info: `${e.time.startTime}~${e.time.endTime}`,
+				time: e.time
+			}
+		})
+	}
+	selected.value = [...selected.value, ...dates]
 }
-const confirm = () => {
 
+const onDelete = (e) =>{
+	selected.value = selected.value.filter(item => {
+		console.log('item.fulldate !== e.date',item.date , e.fulldate);
+		
+		return item.date !== e.fulldate
+	})
+	console.log(e,selected.value);	
+}
+const confirm = (e) => {
 	const parmas = selected.value.map(item => {
 		return {
 			workDate: item.date,
-			workStartTime: item.startTime,
-			workEndTime: item.endTime
+			workStartTime: item.time.startTime,
+			workEndTime: item.time.endTime
 		}
 	})
-	console.log('确定',parmas);
-
+	console.log('确定', parmas);
 	workDate(parmas).then(res => {
-		if(res.code == 200){
-				uni.showToast({
-					title: '修改成功',
-					icon: 'none'
-				})
-				close();
-				return;
-			}
+		if (res.code == 200) {
 			uni.showToast({
-				title: res.msg,
+				title: '修改成功',
 				icon: 'none'
 			})
+			close();
+			return;
+		}
+		uni.showToast({
+			title: res.msg,
+			icon: 'none'
+		})
 	})
 };
 const close = () => {
 	calendar.value.close();
 }
 
-onMounted(() => {
+const init = () => {
+	getDataTime().then(res => {
+		console.log('res', res);
+		selected.value = res.data.map(item =>{
+			return {
+				date: item.workDate,
+				info: `${item.workStartTime}~${item.workEndTime}`,
+				time: {
+					startTime: item.workStartTime,
+					endTime: item.workEndTime
+				}
+			}
+		})
+
+	})
+}
 
+
+
+onMounted(() => {
+	init();
 });
 </script>