Files
yunzerwebsiteallinone/uniapp/pages/tools/schedule/detail.vue
T

280 lines
6.0 KiB
Vue

<template>
<view class="page">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<template v-else-if="item">
<view class="detail-card">
<view class="content-block">
<view class="content-header">
<text class="info-label">日程内容</text>
<u-tag
:text="item.completed ? '已完成' : '待办'"
:type="item.completed ? 'success' : 'primary'"
size="mini"
/>
</view>
<text class="content-text">{{ item.content || '无内容' }}</text>
</view>
<view class="info-row">
<text class="info-label">发生时间</text>
<text class="info-value">{{ formatDate(item.datetime, true) }}</text>
</view>
<view class="info-row channel-row">
<text class="info-label">提醒渠道</text>
<view class="channel-tags">
<u-tag
v-for="channel in item.remindChannels"
:key="channel"
:text="getRemindChannelLabel(channel)"
type="primary"
size="mini"
plain
/>
<text v-if="!item.remindChannels?.length" class="info-value muted">未设置</text>
</view>
</view>
<view class="info-row">
<text class="info-label">提前提醒时间</text>
<text class="info-value">{{ remindText }}</text>
</view>
<view class="meta-row">
<text>创建于 {{ formatDate(item.createdAt, true) }}</text>
<text v-if="item.updatedAt !== item.createdAt">更新于 {{ formatDate(item.updatedAt, true) }}</text>
</view>
</view>
</template>
<view v-if="item" class="footer">
<view class="footer-btn">
<u-button
:type="item.completed ? 'info' : 'primary'"
:icon="item.completed ? 'reload' : 'checkmark'"
:text="item.completed ? '标为待办' : '标记完成'"
:plain="item.completed"
@click="onToggleComplete"
/>
</view>
<view v-if="!item.completed" class="footer-btn">
<u-button type="primary" plain icon="edit-pen" text="编辑" @click="openEdit" />
</view>
<view class="footer-btn">
<u-button type="error" plain icon="trash" text="删除" @click="onDelete" />
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import {
getSchedule,
deleteSchedule,
toggleScheduleComplete,
getRemindChannelLabel,
getRemindMinutesLabel
} from '@/api/schedule.js'
import { formatDate } from '@/utils/date.js'
const scheduleId = ref('')
const item = ref(null)
const loading = ref(false)
const remindText = computed(() => {
if (!item.value) return ''
return getRemindMinutesLabel(item.value.remindMinutes)
})
onLoad((query) => {
if (query?.id) {
scheduleId.value = query.id
loadDetail()
}
})
onShow(() => {
if (scheduleId.value) loadDetail()
})
async function loadDetail() {
loading.value = true
try {
const data = await getSchedule(scheduleId.value)
if (!data) {
uni.showToast({ title: '日程不存在', icon: 'none' })
setTimeout(() => uni.navigateBack(), 800)
return
}
item.value = data
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function openEdit() {
uni.navigateTo({ url: `/pages/tools/schedule/edit?id=${scheduleId.value}` })
}
async function onToggleComplete() {
if (!item.value) return
const wasCompleted = item.value.completed
try {
await toggleScheduleComplete(item.value.id)
// toggle 接口只返回 is_finished,需重新拉取完整详情
await loadDetail()
uni.showToast({
title: wasCompleted ? '已标为待办' : '已标记完成',
icon: 'none'
})
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
function onDelete() {
const summary = (item.value?.content || '').split('\n')[0] || '该日程'
uni.showModal({
title: '删除日程',
content: `确定删除「${summary}」吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await deleteSchedule(scheduleId.value)
uni.showToast({ title: '已删除', icon: 'success' })
setTimeout(() => uni.navigateBack(), 400)
} catch (e) {
uni.showToast({ title: '删除失败', icon: 'none' })
}
}
})
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding: 24rpx $page-padding-x;
padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
overflow-x: hidden;
}
.detail-card {
@include card;
padding: 32rpx 28rpx;
}
.content-block {
padding-bottom: 24rpx;
margin-bottom: 8rpx;
.info-label {
display: block;
margin-bottom: 12rpx;
}
}
.content-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
}
.content-text {
display: block;
font-size: 30rpx;
color: $color-text;
line-height: 1.7;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
}
.info-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24rpx;
padding: 20rpx 0;
border-top: 1rpx solid $color-divider;
}
.channel-row {
align-items: flex-start;
}
.info-label {
font-size: 26rpx;
color: $color-text-muted;
flex-shrink: 0;
}
.info-value {
font-size: 28rpx;
color: $color-text;
text-align: right;
&.muted {
color: $color-text-muted;
}
}
.channel-tags {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 10rpx;
flex: 1;
}
.meta-row {
display: flex;
flex-direction: column;
gap: 8rpx;
padding-top: 24rpx;
margin-top: 8rpx;
border-top: 1rpx solid $color-divider;
font-size: 24rpx;
color: $color-text-muted;
}
.footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
gap: 16rpx;
padding: 20rpx $page-padding-x;
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
background: $color-card;
border-top: 1rpx solid $color-border;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.04);
}
.footer-btn {
flex: 1;
}
.state-box {
display: flex;
justify-content: center;
padding: 160rpx 0;
}
.state-text {
font-size: 28rpx;
color: $color-text-muted;
}
</style>