This commit is contained in:
qijq 2025-06-30 15:28:55 +08:00
parent 702275cde4
commit 6a18ad3dce

View File

@ -3,12 +3,12 @@
<uni-popup ref="popup" type="bottom" :safe-area="false"> <uni-popup ref="popup" type="bottom" :safe-area="false">
<view class="custom-picker"> <view class="custom-picker">
<view class="custom-picker__header"> <view class="custom-picker__header">
<view class="cancel" :style="{ color: canceColor }" @tap="onCancel"> <view class="cancel" :style="{ color: canceColor }" >
{{ cancelText }} <!-- {{ cancelText }} -->
</view> </view>
<view class="title">{{ title }}</view> <view class="title">{{ title }}</view>
<view class="confirm" :style="{ color: confirmColor }" @tap="onConfirm"> <view class="confirm" :style="{ color: confirmColor }" @tap="onCancel">
{{ confirmText }} <u-icon name="close"></u-icon>
</view> </view>
</view> </view>
<view class="time-tips"> <view class="time-tips">
@ -66,7 +66,26 @@
</picker-view> </picker-view>
</view> </view>
<view class="bottom-content"> <view class="bottom-content">
<view class="bottom-time">
<view class="">
<text>{{ startTime }}</text>
<text style="padding: 0 6rpx;"></text>
<text>{{ endTime }}</text>
</view>
<view class="">{{ totalTime }}</view>
</view>
<view class="bottom-btn">
<u-button
class="btn-time"
:hairline="true"
:plain="true"
shape="circle"
@tap="onConfirm"
>
确认
</u-button>
</view>
</view> </view>
</uni-popup> </uni-popup>
</template> </template>
@ -153,6 +172,9 @@ export default {
rangeList: [], rangeList: [],
pickerValue: [0, 0, 0, 0], pickerValue: [0, 0, 0, 0],
isScoll: false, // isScoll: false, //
startTime:"",
endTime:"",
totalTime:""
}; };
}, },
created() { created() {
@ -276,16 +298,47 @@ export default {
* @param {Object} e * @param {Object} e
*/ */
bindChange(e) { bindChange(e) {
const newValue = [...e.detail.value];
// Check if end hour (index 2) is being set to 24 const newValue = [...e.detail.value];
if (newValue[2] === this.rangeList[2]?.length - 1) {
// Assuming 24 is the last option // pickerValue
newValue[3] = 0; // Set to first (and only) option which is '00' this.pickerValue = newValue;
this.pickerValue = newValue;
this.generateRangeLists(); // Regenerate ranges to limit minutes // startTime (: )
} else { const startHour = this.rangeList[0][newValue[0]];
const startMinute = this.rangeList[1][newValue[1]];
const startTime = `${startHour}:${startMinute}`;
// endTime (: )
const endHour = this.rangeList[3][newValue[3]];
const endMinute = this.rangeList[4][newValue[4]];
const endTime = `${endHour}:${endMinute}`;
// totalTime
const startDate = new Date(2000, 0, 1, parseInt(startHour), parseInt(startMinute));
const endDate = new Date(2000, 0, 1, parseInt(endHour), parseInt(endMinute));
// 23:0001:00
if (endDate < startDate) {
endDate.setDate(endDate.getDate() + 1);
}
const diffMs = endDate - startDate;
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffMinutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
const totalTime = `${diffHours}小时${diffMinutes}`;
// data便
this.startTime = startTime;
this.endTime = endTime;
this.totalTime = totalTime;
// 24:0000
if (newValue[3] === this.rangeList[3]?.length - 1) { // 24
newValue[4] = 0; // 00
this.pickerValue = newValue; this.pickerValue = newValue;
this.generateRangeLists();
} }
}, },
}, },
@ -293,6 +346,7 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "@/styles/variables.scss";
.custom-picker { .custom-picker {
width: 100%; width: 100%;
height: 620rpx; height: 620rpx;
@ -383,4 +437,32 @@ export default {
height: 60%; height: 60%;
} }
.bottom-content{
background: #fff;
box-shadow: 0 0 4rpx 4rpx rgba(0, 0, 0, 0.1);
.bottom-time{
display: flex;
justify-content: space-between;
padding: 20rpx 28rpx;
font-size: 28rpx;
font-weight: bold;
}
.bottom-btn{
padding: 28rpx 40rpx 80rpx;
.btn-time{
background: $base-color;
color: #fff;
&::after {
border: none;
}
}
}
}
</style> </style>