优化小程序报销模块
This commit is contained in:
1 parent
1e9666cefd
commit
48f3bd997c
21 files changed
+5738
-1750
No files matched your search
@@ -0,0 +1,277 @@
|
||||
import { request } from '@/api/request.js'
|
||||
import { getBaseURL } from '@/api/config.js'
|
||||
import { getToken } from '@/utils/auth.js'
|
||||
|
||||
/**
|
||||
* OA 报销管理接口封装,对应后端 /api/oa/expense/*。
|
||||
* 与 Web 后台 /backend/reimbursements* 是同一套数据(yz_backend_reimbursements),
|
||||
* 状态机:0草稿 → 1审批中 → 2已通过 / 3已驳回 / 4已撤回 → 5已打款。
|
||||
*/
|
||||
|
||||
/** 报销单状态常量 */
|
||||
export const EXPENSE_STATUS = {
|
||||
DRAFT: 0,
|
||||
APPROVING: 1,
|
||||
APPROVED: 2,
|
||||
REJECTED: 3,
|
||||
WITHDRAWN: 4,
|
||||
PAID: 5
|
||||
}
|
||||
|
||||
/** 状态选项(label 与 Web 端一致;type 为 u-tag 颜色) */
|
||||
export const EXPENSE_STATUS_OPTIONS = [
|
||||
{ value: 0, label: '草稿', type: 'info' },
|
||||
{ value: 1, label: '审批中', type: 'primary' },
|
||||
{ value: 2, label: '已通过', type: 'success' },
|
||||
{ value: 3, label: '已驳回', type: 'error' },
|
||||
{ value: 4, label: '已撤回', type: 'warning' },
|
||||
{ value: 5, label: '已打款', type: 'success' }
|
||||
]
|
||||
|
||||
/** 审批记录动作文案(与 Web 端 detail 页 actionLabel 一致) */
|
||||
export const EXPENSE_ACTION_LABELS = {
|
||||
1: '提交申请',
|
||||
2: '审批通过',
|
||||
3: '审批驳回',
|
||||
4: '转审',
|
||||
5: '撤回'
|
||||
}
|
||||
|
||||
export function getExpenseStatusLabel(status) {
|
||||
return EXPENSE_STATUS_OPTIONS.find(item => item.value === Number(status))?.label || '未知'
|
||||
}
|
||||
|
||||
export function getExpenseStatusType(status) {
|
||||
return EXPENSE_STATUS_OPTIONS.find(item => item.value === Number(status))?.type || 'info'
|
||||
}
|
||||
|
||||
export function getExpenseActionLabel(action) {
|
||||
return EXPENSE_ACTION_LABELS[Number(action)] || '审批操作'
|
||||
}
|
||||
|
||||
/** 金额展示:统一两位小数 */
|
||||
export function moneyText(value) {
|
||||
return Number(value || 0).toFixed(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* 报销单列表(支持状态/关键词筛选)
|
||||
* 返回 { list, total }
|
||||
*/
|
||||
export async function fetchExpenses(params = {}) {
|
||||
const data = await request({
|
||||
url: '/api/oa/expense/list',
|
||||
data: {
|
||||
page: params.page || 1,
|
||||
pageSize: params.pageSize || 20,
|
||||
keyword: params.keyword || '',
|
||||
status: params.status ?? ''
|
||||
}
|
||||
})
|
||||
return { list: data.list || [], total: data.total || 0 }
|
||||
}
|
||||
|
||||
/**
|
||||
* 报销单详情(含费用明细与发票文件)
|
||||
*/
|
||||
export async function getExpense(id) {
|
||||
const data = await request({ url: `/api/oa/expense/detail/${id}` })
|
||||
if (!data) return null
|
||||
return {
|
||||
...data,
|
||||
items: (data.items || []).map(normalizeExpenseItem)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建报销单(草稿),返回新单据 id
|
||||
*/
|
||||
export async function createExpense(payload) {
|
||||
const res = await request({
|
||||
url: '/api/oa/expense/create',
|
||||
method: 'POST',
|
||||
data: {
|
||||
apply_date: payload.applyDate,
|
||||
description: payload.description || ''
|
||||
}
|
||||
})
|
||||
return res?.id
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑报销单基本信息(仅草稿)
|
||||
*/
|
||||
export function updateExpense(id, payload) {
|
||||
return request({
|
||||
url: `/api/oa/expense/update/${id}`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
apply_date: payload.applyDate,
|
||||
description: payload.description || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除报销单(仅草稿,软删除)
|
||||
*/
|
||||
export async function deleteExpense(id) {
|
||||
await request({ url: `/api/oa/expense/delete/${id}`, method: 'DELETE' })
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增费用明细(仅草稿)
|
||||
* item: { expenseType, expenseDate, amount, quantity, unitPrice, description, receipts: [{id,url,name}] }
|
||||
*/
|
||||
export async function addExpenseItem(reimbursementId, item) {
|
||||
return request({
|
||||
url: `/api/oa/expense/item/add/${reimbursementId}`,
|
||||
method: 'POST',
|
||||
data: buildExpenseItemPayload(item)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新费用明细(仅草稿)
|
||||
*/
|
||||
export async function updateExpenseItem(reimbursementId, itemId, item) {
|
||||
return request({
|
||||
url: `/api/oa/expense/item/update/${reimbursementId}/${itemId}`,
|
||||
method: 'POST',
|
||||
data: buildExpenseItemPayload(item)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除费用明细(仅草稿)
|
||||
*/
|
||||
export async function deleteExpenseItem(reimbursementId, itemId) {
|
||||
await request({
|
||||
url: `/api/oa/expense/item/delete/${reimbursementId}/${itemId}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交审批(仅草稿;需租户已配置启用的审批流程)
|
||||
*/
|
||||
export async function submitExpense(id) {
|
||||
await request({ url: `/api/oa/expense/submit/${id}`, method: 'POST' })
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动确认更改单据状态(与 Web 端「手动确认」能力一致)
|
||||
*/
|
||||
export async function updateExpenseStatus(id, status) {
|
||||
const res = await request({
|
||||
url: `/api/oa/expense/status/${id}`,
|
||||
method: 'POST',
|
||||
data: { status }
|
||||
})
|
||||
return res?.status
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批记录(时间线)
|
||||
*/
|
||||
export async function fetchExpenseRecords(id) {
|
||||
const rows = await request({ url: `/api/oa/expense/records/${id}` })
|
||||
return Array.isArray(rows) ? rows : []
|
||||
}
|
||||
|
||||
/**
|
||||
* 费用类型下拉(全局通用 + 本租户专有,仅启用)
|
||||
*/
|
||||
export async function fetchExpenseTypes() {
|
||||
const rows = await request({ url: '/api/oa/expense/types' })
|
||||
return (Array.isArray(rows) ? rows : []).map(row => ({
|
||||
id: row.id,
|
||||
name: row.name
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传报销发票附件(multipart,图片或 PDF,单个 ≤10MB)
|
||||
* 文件落入租户文件管理,返回 { id, url, name } 引用信息
|
||||
*/
|
||||
export function uploadExpenseReceipt(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: `${getBaseURL().replace(/\/$/, '')}/api/oa/expense/upload`,
|
||||
filePath,
|
||||
name: 'file',
|
||||
header: { Authorization: `Bearer ${getToken()}` },
|
||||
success(res) {
|
||||
let body = {}
|
||||
try {
|
||||
body = JSON.parse(res.data || '{}')
|
||||
} catch (e) {
|
||||
// 非 JSON 响应按失败处理
|
||||
}
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && body.code === 200 && body.data) {
|
||||
resolve(body.data)
|
||||
} else {
|
||||
const msg = body.msg || `上传失败(${res.statusCode})`
|
||||
uni.showToast({ title: msg, icon: 'none' })
|
||||
reject(new Error(msg))
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
uni.showToast({ title: '网络异常,上传失败', icon: 'none' })
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/** 组装后端要求的费用明细请求体(发票只传文件 ID 列表,发票金额暂不在端上维护) */
|
||||
function buildExpenseItemPayload(item) {
|
||||
const receipts = item.receipts || []
|
||||
return {
|
||||
expense_type: item.expenseType,
|
||||
expense_date: item.expenseDate,
|
||||
amount: Number(item.amount) || 0,
|
||||
quantity: Number(item.quantity) || 1,
|
||||
unit_price: Number(item.unitPrice) || 0,
|
||||
description: item.description || '',
|
||||
receipt_flag: receipts.length > 0 ? 1 : 0,
|
||||
receipt_file_ids: receipts.map(r => r.id).join(',')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片地址兜底:后端可能返回相对路径(如 /uploads/...),
|
||||
* 小程序 image 组件无法加载相对路径,统一拼上 baseURL。
|
||||
*/
|
||||
export function resolveImageUrl(url) {
|
||||
const value = String(url || '').trim()
|
||||
if (!value) return ''
|
||||
if (/^https?:\/\//i.test(value) || value.startsWith('data:')) return value
|
||||
return `${getBaseURL().replace(/\/$/, '')}${value.startsWith('/') ? '' : '/'}${value}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 发票引用是否为 PDF 文件:PDF 不能用 image 组件渲染(会被 ORB 拦截不显示),
|
||||
* 需要走 openDocument 打开。
|
||||
*/
|
||||
export function isPdfReceipt(receipt) {
|
||||
const target = `${receipt?.name || ''} ${receipt?.url || ''}`.toLowerCase()
|
||||
return target.includes('.pdf')
|
||||
}
|
||||
|
||||
/** 归一化明细:日期取前 10 位,发票引用统一为 {id,url,name}(后端 receipt_files 元素为 file_id) */
|
||||
function normalizeExpenseItem(item) {
|
||||
const receipts = (Array.isArray(item.receipt_files) ? item.receipt_files : []).map(img => ({
|
||||
id: img.file_id,
|
||||
url: resolveImageUrl(img.url),
|
||||
name: img.name || ''
|
||||
}))
|
||||
return {
|
||||
...item,
|
||||
expense_date: String(item.expense_date || '').slice(0, 10),
|
||||
receipts
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import { request } from '@/api/request.js'
|
||||
import { getBaseURL } from '@/api/config.js'
|
||||
import { getToken } from '@/utils/auth.js'
|
||||
|
||||
/**
|
||||
* OA 工作日程(日历待办)接口封装,对应后端 /api/oa/schedule/*。
|
||||
* 数据表 yz_backend_oa_schedule,与「日程提醒」(/api/schedule/*,
|
||||
* yz_backend_schedule)是两个独立功能,不要混用。
|
||||
*/
|
||||
|
||||
/** 优先级选项(与 Web 后台一致:0 普通 / 1 重要 / 2 紧急) */
|
||||
export const OA_SCHEDULE_PRIORITY_OPTIONS = [
|
||||
{ value: 0, label: '普通' },
|
||||
{ value: 1, label: '重要' },
|
||||
{ value: 2, label: '紧急' }
|
||||
]
|
||||
|
||||
/** 归一化单条日程:补齐端上排序/分组用的时间戳与派生字段 */
|
||||
export function normalizeOaSchedule(item) {
|
||||
const date = String(item.schedule_date || '').slice(0, 10)
|
||||
const startTime = item.start_time || ''
|
||||
// 拼一个 Date 时间戳便于日历分组与时间排序(全天事件按 00:00)
|
||||
let timestamp = 0
|
||||
if (date) {
|
||||
const [y, m, d] = date.split('-').map(Number)
|
||||
const [hh = 0, mm = 0] = startTime ? startTime.split(':').map(Number) : [0, 0]
|
||||
timestamp = new Date(y, m - 1, d, hh, mm).getTime()
|
||||
}
|
||||
return {
|
||||
...item,
|
||||
schedule_date: date,
|
||||
completed: item.status === 1,
|
||||
allDay: item.all_day === 1,
|
||||
timestamp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工作日程列表(支持日期区间 / 分类筛选)
|
||||
* 返回 { list, total, counts },counts 为各分类数量角标
|
||||
*/
|
||||
export async function fetchOaSchedules(params = {}) {
|
||||
const data = await request({
|
||||
url: '/api/oa/schedule/list',
|
||||
data: {
|
||||
page: params.page || 1,
|
||||
pageSize: params.pageSize || 500,
|
||||
keyword: params.keyword || '',
|
||||
status: params.status || '',
|
||||
priority: params.priority || '',
|
||||
start_date: params.startDate || '',
|
||||
end_date: params.endDate || '',
|
||||
category: params.category || 'all'
|
||||
}
|
||||
})
|
||||
const list = (data.list || []).map(normalizeOaSchedule)
|
||||
return { list, total: data.total || 0, counts: data.counts || {} }
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条日程详情
|
||||
*/
|
||||
export async function getOaSchedule(id) {
|
||||
const data = await request({ url: `/api/oa/schedule/detail/${id}` })
|
||||
if (!data || !data.item) return null
|
||||
return { ...normalizeOaSchedule(data.item), images: data.images || [] }
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建日程
|
||||
*/
|
||||
export async function createOaSchedule(payload) {
|
||||
return request({
|
||||
url: '/api/oa/schedule/create',
|
||||
method: 'POST',
|
||||
data: buildOaSchedulePayload(payload)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新日程
|
||||
*/
|
||||
export async function updateOaSchedule(id, payload) {
|
||||
return request({
|
||||
url: `/api/oa/schedule/update/${id}`,
|
||||
method: 'POST',
|
||||
data: buildOaSchedulePayload(payload)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除日程(软删除)
|
||||
*/
|
||||
export async function deleteOaSchedule(id) {
|
||||
await request({ url: `/api/oa/schedule/delete/${id}`, method: 'DELETE' })
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换完成状态(待办 <-> 已完成)
|
||||
*/
|
||||
export async function toggleOaScheduleComplete(id) {
|
||||
const res = await request({ url: `/api/oa/schedule/finish/${id}`, method: 'POST' })
|
||||
return { status: res?.status ?? 0, completed: res?.status === 1 }
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传日程资料图片(multipart,单张 ≤10MB)
|
||||
* 文件落入租户文件管理,返回 { id, url, name } 引用信息
|
||||
*/
|
||||
export function uploadOaScheduleImage(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: `${getBaseURL().replace(/\/$/, '')}/api/oa/schedule/upload`,
|
||||
filePath,
|
||||
name: 'file',
|
||||
header: { Authorization: `Bearer ${getToken()}` },
|
||||
success(res) {
|
||||
let body = {}
|
||||
try {
|
||||
body = JSON.parse(res.data || '{}')
|
||||
} catch (e) {
|
||||
// 非 JSON 响应按失败处理
|
||||
}
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && body.code === 200 && body.data) {
|
||||
resolve(body.data)
|
||||
} else {
|
||||
const msg = body.msg || `上传失败(${res.statusCode})`
|
||||
uni.showToast({ title: msg, icon: 'none' })
|
||||
reject(new Error(msg))
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
uni.showToast({ title: '网络异常,上传失败', icon: 'none' })
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存日程资料图片引用列表(整体覆盖)
|
||||
*/
|
||||
export async function setOaScheduleImages(id, images) {
|
||||
const res = await request({
|
||||
url: `/api/oa/schedule/images/${id}`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
images: (images || []).map(img => ({
|
||||
id: Number(img.id) || 0,
|
||||
url: img.url,
|
||||
name: img.name || ''
|
||||
}))
|
||||
}
|
||||
})
|
||||
return res?.images || []
|
||||
}
|
||||
|
||||
/** 组装后端要求的请求体(提醒绑定暂不在小程序端开放) */
|
||||
function buildOaSchedulePayload(p) {
|
||||
return {
|
||||
title: p.title,
|
||||
content: p.content || '',
|
||||
schedule_date: p.scheduleDate,
|
||||
start_time: p.allDay ? '' : p.startTime || '',
|
||||
end_time: p.allDay ? '' : p.endTime || '',
|
||||
all_day: p.allDay ? 1 : 0,
|
||||
priority: p.priority || 0,
|
||||
color: p.color || '#409EFF',
|
||||
reminder_enabled: false
|
||||
}
|
||||
}
|
||||
|
||||
export function getOaPriorityLabel(priority) {
|
||||
return (
|
||||
OA_SCHEDULE_PRIORITY_OPTIONS.find(item => item.value === Number(priority))?.label || '普通'
|
||||
)
|
||||
}
|
||||
@@ -37,15 +37,19 @@
|
||||
</view>
|
||||
|
||||
<block v-else>
|
||||
<!-- OA 工作台仪表盘(Web 版内容搬到首页顶部) -->
|
||||
<!-- 首页卡片流:flex 纵向 + 统一 gap,避免跨组件 margin 不折叠导致间距不均 -->
|
||||
<view class="home-stack">
|
||||
<!-- OA 工作台仪表盘上半:公告 + 数据统计(常用功能插在下面) -->
|
||||
<SubOaDashboard
|
||||
v-if="isOa && dash"
|
||||
part="top"
|
||||
:data="dash"
|
||||
@view-notices="goNotices"
|
||||
@view-schedules="goSchedules"
|
||||
/>
|
||||
|
||||
<!-- 概览 -->
|
||||
<!-- 概览 / 日程待办 / 最新公告:非 OA 子系统,或 OA 仪表盘加载失败时兜底展示 -->
|
||||
<block v-if="!(isOa && dash)">
|
||||
<view class="kpi-card">
|
||||
<view class="kpi-item">
|
||||
<text class="kpi-value">{{ leafMenus.length }}</text>
|
||||
@@ -120,44 +124,58 @@
|
||||
<text class="list-time">{{ item.publish_time || item.publisher_name || '' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 常用功能:与仪表盘卡片统一的样式,点「全部」切到功能页签 -->
|
||||
<view class="quick-card">
|
||||
<view class="quick-head">
|
||||
<view class="quick-head-left">
|
||||
<view class="head-icon">
|
||||
<FaIcon name="star" color="#f59e0b" :size="12" />
|
||||
</view>
|
||||
<text class="quick-title">常用功能</text>
|
||||
</view>
|
||||
<view class="block-more" @tap="goFunctions">
|
||||
<text class="block-more-text">全部</text>
|
||||
<FaIcon name="chevron-right" color="#94a3b8" :size="11" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="grid">
|
||||
<view
|
||||
v-for="(item, index) in quickMenus"
|
||||
:key="item.id"
|
||||
class="cell"
|
||||
@tap="openMenu(item, item.title)"
|
||||
>
|
||||
<view class="fn-card" :class="{ locked: item.locked }">
|
||||
<view class="tint-icon fn-icon" :class="item.locked ? 'tint-off' : 'tint-' + (index % 8)">
|
||||
<FaIcon :name="item.icon || fallbackIcon" color="#ffffff" :size="18" />
|
||||
</view>
|
||||
<text class="fn-name">{{ item.title }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 末位固定「+」:点击选择要加入常用功能的功能 -->
|
||||
<view class="cell">
|
||||
<view class="fn-card fn-add" @tap="openPicker">
|
||||
<view class="add-icon">
|
||||
<FaIcon name="plus" color="#8a94ad" :size="18" />
|
||||
</view>
|
||||
<text class="fn-name">添加</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 常用功能:仪表盘式快捷入口,点「全部」切到功能页签 -->
|
||||
<view class="block">
|
||||
<view class="block-head">
|
||||
<text class="block-title">常用功能</text>
|
||||
<view class="block-more" @tap="goFunctions">
|
||||
<text class="block-more-text">全部</text>
|
||||
<FaIcon name="chevron-right" color="#8a94ad" :size="11" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="quick-card">
|
||||
<view class="grid">
|
||||
<view
|
||||
v-for="(item, index) in quickMenus"
|
||||
:key="item.id"
|
||||
class="cell"
|
||||
@tap="openMenu(item, item.title)"
|
||||
>
|
||||
<view class="fn-card" :class="{ locked: item.locked }">
|
||||
<view class="tint-icon fn-icon" :class="item.locked ? 'tint-off' : 'tint-' + (index % 8)">
|
||||
<FaIcon :name="item.icon || fallbackIcon" color="#ffffff" :size="18" />
|
||||
</view>
|
||||
<text class="fn-name">{{ item.title }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 末位固定「+」:点击选择要加入常用功能的功能 -->
|
||||
<view class="cell">
|
||||
<view class="fn-card fn-add" @tap="openPicker">
|
||||
<view class="add-icon">
|
||||
<FaIcon name="plus" color="#8a94ad" :size="18" />
|
||||
</view>
|
||||
<text class="fn-name">添加</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- OA 工作台仪表盘下半:报销趋势 + 状态分布 -->
|
||||
<SubOaDashboard
|
||||
v-if="isOa && dash"
|
||||
part="bottom"
|
||||
:data="dash"
|
||||
@view-notices="goNotices"
|
||||
@view-schedules="goSchedules"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
@@ -489,8 +507,11 @@ onShow(() => {
|
||||
padding: 28rpx $page-padding-x 0;
|
||||
}
|
||||
|
||||
.block + .block {
|
||||
margin-top: 32rpx;
|
||||
/* 首页卡片流:统一纵向间距(跨组件 margin 不折叠,故用 flex gap) */
|
||||
.home-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24rpx;
|
||||
}
|
||||
|
||||
.block-head {
|
||||
@@ -517,7 +538,6 @@ onShow(() => {
|
||||
@include card;
|
||||
display: flex;
|
||||
padding: 30rpx 0;
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.kpi-item {
|
||||
@@ -634,9 +654,39 @@ onShow(() => {
|
||||
/* ============ 常用功能宫格:一行 4 个 ============
|
||||
cell 占 25% 宽并自带右侧间隙,容器用负 margin 抵消末列间隙,
|
||||
避免使用 calc 除法——小程序端 wxss 对复杂 calc 支持不稳。 */
|
||||
/* 与 SubOaDashboard 的 dash-card 保持同一视觉语言 */
|
||||
.quick-card {
|
||||
@include card;
|
||||
padding: 24rpx 20rpx 8rpx;
|
||||
padding: 26rpx 24rpx 10rpx;
|
||||
}
|
||||
|
||||
.quick-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 22rpx;
|
||||
}
|
||||
|
||||
.quick-head-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.head-icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #fff7e6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.quick-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.grid {
|
||||
@@ -656,7 +706,7 @@ onShow(() => {
|
||||
height: 100%;
|
||||
padding: 18rpx 6rpx 16rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
background: transparent;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,157 +1,150 @@
|
||||
<template>
|
||||
<view class="oa-dash">
|
||||
<!-- 待办概览:今日 / 本周 / 本月 未完成 -->
|
||||
<view class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">待办概览</text>
|
||||
<text v-if="overdue > 0" class="dash-badge">逾期 {{ overdue }}</text>
|
||||
</view>
|
||||
<view class="todo-row">
|
||||
<view class="todo-cell">
|
||||
<text class="todo-value">{{ todayPending }}</text>
|
||||
<text class="todo-label">今日待办</text>
|
||||
<text class="todo-sub">共 {{ num(ss.today_total) }} · 完成 {{ num(ss.today_done) }}</text>
|
||||
</view>
|
||||
<view class="todo-cell">
|
||||
<text class="todo-value">{{ weekPending }}</text>
|
||||
<text class="todo-label">本周待办</text>
|
||||
<text class="todo-sub">共 {{ num(ss.week_total) }} · 完成 {{ num(ss.week_done) }}</text>
|
||||
</view>
|
||||
<view class="todo-cell">
|
||||
<text class="todo-value">{{ monthPending }}</text>
|
||||
<text class="todo-label">本月待办</text>
|
||||
<text class="todo-sub">共 {{ num(ss.month_total) }} · 完成 {{ num(ss.month_done) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 我的报销:本周 / 本月 / 本年 已打款金额 -->
|
||||
<view class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">我的报销</text>
|
||||
</view>
|
||||
<view class="money-row">
|
||||
<view v-for="item in moneyCards" :key="item.label" class="money-cell">
|
||||
<text class="money-label">{{ item.label }}</text>
|
||||
<view class="money-amount">
|
||||
<text class="currency">¥</text>
|
||||
<text class="number">{{ money(item.data.paid) }}</text>
|
||||
<!-- ============ 上半:公告 + 数据统计 ============ -->
|
||||
<template v-if="part !== 'bottom'">
|
||||
<!-- 通知公告 -->
|
||||
<view class="dash-card">
|
||||
<view class="dash-head">
|
||||
<view class="dash-head-left">
|
||||
<view class="head-icon hi-notice">
|
||||
<FaIcon name="bullhorn" color="#2563eb" :size="12" />
|
||||
</view>
|
||||
<text class="dash-title">公告</text>
|
||||
</view>
|
||||
<text class="money-meta">{{ num(item.data.count) }} 单 · 待报 ¥{{ money(item.data.unpaid) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 近 6 个月报销趋势(CSS 双色堆叠柱,移动端不引 echarts) -->
|
||||
<view v-if="trend.length" class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">近6个月报销趋势</text>
|
||||
<view class="legend">
|
||||
<view class="legend-item"><view class="legend-dot paid" /><text>已报销</text></view>
|
||||
<view class="legend-item"><view class="legend-dot unpaid" /><text>未报销</text></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="trend-chart">
|
||||
<view v-for="t in trend" :key="t.month" class="trend-col">
|
||||
<view class="trend-bar-wrap">
|
||||
<view class="trend-bar unpaid" :style="{ height: barH(t.unpaid) }" />
|
||||
<view class="trend-bar paid" :style="{ height: barH(t.paid) }" />
|
||||
<view class="dash-more" @tap="emit('view-notices')">
|
||||
<text class="dash-more-text">查看全部</text>
|
||||
<FaIcon name="chevron-right" color="#94a3b8" :size="11" />
|
||||
</view>
|
||||
<text class="trend-month">{{ monthLabel(t.month) }}</text>
|
||||
</view>
|
||||
<view v-if="!notices.length" class="dash-empty">
|
||||
<FaIcon name="bullhorn" color="#c0c4cc" :size="24" />
|
||||
<text class="dash-empty-text">暂无公告</text>
|
||||
</view>
|
||||
<!-- 单行垂直轮播公告 -->
|
||||
<swiper
|
||||
v-else
|
||||
class="notice-swiper"
|
||||
vertical
|
||||
autoplay
|
||||
circular
|
||||
:interval="3000"
|
||||
:duration="500"
|
||||
>
|
||||
<swiper-item v-for="n in notices" :key="n.id" @tap="emit('view-notices')">
|
||||
<view class="notice-line">
|
||||
<view class="notice-main">
|
||||
<text class="notice-tag" :class="'nt-' + (n.notice_type || 0)">
|
||||
{{ noticeTypeLabel(n.notice_type) }}
|
||||
</text>
|
||||
<text v-if="n.is_top === 1" class="notice-top">置顶</text>
|
||||
<text class="notice-title">{{ n.title }}</text>
|
||||
</view>
|
||||
<text class="notice-time">{{ noticeTime(n.publish_time) }}</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 状态分布(CSS 进度条) -->
|
||||
<view v-if="statusList.length" class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">状态分布</text>
|
||||
</view>
|
||||
<view v-for="s in statusList" :key="s.key" class="dist-row">
|
||||
<text class="dist-name" :style="{ color: statusColor(s.key) }">{{ s.name }}</text>
|
||||
<view class="dist-bar-wrap">
|
||||
<view class="dist-bar" :style="{ width: s.pct, background: statusColor(s.key) }" />
|
||||
</view>
|
||||
<text class="dist-count">{{ num(s.count) }}单 / ¥{{ money(s.amount) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 报销类型分析(仅已打款费用明细) -->
|
||||
<view v-if="expenseTypes.length" class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">报销类型分析</text>
|
||||
</view>
|
||||
<view v-for="e in expenseTypesTop" :key="e.name" class="type-row">
|
||||
<text class="type-name">{{ e.name }}</text>
|
||||
<view class="type-bar-wrap">
|
||||
<view class="type-bar" :style="{ width: typePct(e.amount) }" />
|
||||
</view>
|
||||
<text class="type-amount">¥{{ money(e.amount) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 通知公告 -->
|
||||
<view class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">通知公告</text>
|
||||
<view class="dash-more" @tap="emit('view-notices')">
|
||||
<text class="dash-more-text">查看全部</text>
|
||||
<FaIcon name="chevron-right" color="#94a3b8" :size="11" />
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!notices.length" class="dash-empty">
|
||||
<FaIcon name="bullhorn" color="#c0c4cc" :size="24" />
|
||||
<text class="dash-empty-text">暂无公告</text>
|
||||
</view>
|
||||
<view
|
||||
v-for="n in notices"
|
||||
:key="n.id"
|
||||
class="notice-item"
|
||||
@tap="emit('view-notices')"
|
||||
>
|
||||
<view class="notice-main">
|
||||
<text class="notice-tag" :class="'nt-' + (n.notice_type || 0)">
|
||||
{{ noticeTypeLabel(n.notice_type) }}
|
||||
</text>
|
||||
<text v-if="n.is_top === 1" class="notice-top">置顶</text>
|
||||
<text class="notice-title">{{ n.title }}</text>
|
||||
</view>
|
||||
<text class="notice-time">{{ noticeTime(n.publish_time) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 工作日程提醒(今日) -->
|
||||
<view class="dash-card">
|
||||
<view class="dash-head">
|
||||
<text class="dash-title">工作日程提醒</text>
|
||||
<view class="dash-more" @tap="emit('view-schedules')">
|
||||
<text class="dash-more-text">查看全部</text>
|
||||
<FaIcon name="chevron-right" color="#94a3b8" :size="11" />
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!todaySchedules.length" class="dash-empty">
|
||||
<FaIcon name="calendar-day" color="#c0c4cc" :size="24" />
|
||||
<text class="dash-empty-text">今日暂无日程</text>
|
||||
</view>
|
||||
<view
|
||||
v-for="s in todaySchedules"
|
||||
:key="s.id"
|
||||
class="sched-item"
|
||||
:class="{ done: s.status === 1 }"
|
||||
@tap="emit('view-schedules')"
|
||||
>
|
||||
<view class="sched-dot" :style="{ background: s.status === 1 ? '#cbd5e1' : (s.color || '#2563eb') }" />
|
||||
<view class="sched-main">
|
||||
<view class="sched-title-row">
|
||||
<text class="sched-title" :class="{ done: s.status === 1 }">{{ s.title }}</text>
|
||||
<text v-if="s.priority > 0" class="sched-priority" :class="s.priority === 2 ? 'p-urgent' : 'p-important'">
|
||||
{{ s.priority === 2 ? '紧急' : '重要' }}
|
||||
</text>
|
||||
<!-- 数据统计:待办 + 报销 -->
|
||||
<view class="dash-card">
|
||||
<view class="dash-head">
|
||||
<view class="dash-head-left">
|
||||
<view class="head-icon hi-stat">
|
||||
<FaIcon name="chart-column" color="#2563eb" :size="12" />
|
||||
</view>
|
||||
<text class="dash-title">数据统计</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 待办 -->
|
||||
<view class="stat-tile" @tap="emit('view-schedules')">
|
||||
<view class="stat-tile-head">
|
||||
<view class="tile-icon ti-todo">
|
||||
<FaIcon name="clipboard-list" color="#2563eb" :size="11" />
|
||||
</view>
|
||||
<text class="tile-name">待办</text>
|
||||
<text v-if="overdue > 0" class="dash-badge">逾期 {{ overdue }}</text>
|
||||
<FaIcon name="chevron-right" color="#c0c4cc" :size="10" />
|
||||
</view>
|
||||
<view class="stat-row">
|
||||
<view class="stat-cell">
|
||||
<text class="stat-value primary">{{ todayPending }}</text>
|
||||
<text class="stat-label">今日</text>
|
||||
<text class="stat-sub">共 {{ num(ss.today_total) }} · 完成 {{ num(ss.today_done) }}</text>
|
||||
</view>
|
||||
<view class="stat-cell">
|
||||
<text class="stat-value primary">{{ weekPending }}</text>
|
||||
<text class="stat-label">本周</text>
|
||||
<text class="stat-sub">共 {{ num(ss.week_total) }} · 完成 {{ num(ss.week_done) }}</text>
|
||||
</view>
|
||||
<view class="stat-cell">
|
||||
<text class="stat-value primary">{{ monthPending }}</text>
|
||||
<text class="stat-label">本月</text>
|
||||
<text class="stat-sub">共 {{ num(ss.month_total) }} · 完成 {{ num(ss.month_done) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 报销 -->
|
||||
<view class="stat-tile">
|
||||
<view class="stat-tile-head">
|
||||
<view class="tile-icon ti-money">
|
||||
<FaIcon name="money-bill-wave" color="#10b981" :size="11" />
|
||||
</view>
|
||||
<text class="tile-name">报销</text>
|
||||
</view>
|
||||
<view class="stat-row">
|
||||
<view v-for="item in moneyCards" :key="item.label" class="stat-cell">
|
||||
<view class="stat-amount">
|
||||
<text class="stat-currency">¥</text>
|
||||
<text class="stat-value">{{ money(item.data.paid) }}</text>
|
||||
</view>
|
||||
<text class="stat-label">{{ item.label }}</text>
|
||||
<text class="stat-sub">{{ num(item.data.count) }} 单 · 待报 ¥{{ money(item.data.unpaid) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="sched-time">{{ schedTime(s) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- ============ 下半:报销趋势 + 状态分布 ============ -->
|
||||
<template v-else>
|
||||
<view v-if="trend.length || statusList.length" class="dash-card">
|
||||
<view class="dash-head">
|
||||
<view class="dash-head-left">
|
||||
<view class="head-icon hi-trend">
|
||||
<FaIcon name="chart-column" color="#8b5cf6" :size="12" />
|
||||
</view>
|
||||
<text class="dash-title">近6个月报销趋势</text>
|
||||
</view>
|
||||
<view class="legend">
|
||||
<view class="legend-item"><view class="legend-dot paid" /><text>已报销</text></view>
|
||||
<view class="legend-item"><view class="legend-dot unpaid" /><text>未报销</text></view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="trend.length" class="trend-chart">
|
||||
<view v-for="t in trend" :key="t.month" class="trend-col">
|
||||
<view class="trend-bar-wrap">
|
||||
<view class="trend-bar unpaid" :style="{ height: barH(t.unpaid) }" />
|
||||
<view class="trend-bar paid" :style="{ height: barH(t.paid) }" />
|
||||
</view>
|
||||
<text class="trend-month">{{ monthLabel(t.month) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 状态分布 -->
|
||||
<view v-if="statusList.length" class="status-block">
|
||||
<text class="status-title">状态分布</text>
|
||||
<view v-for="s in statusList" :key="s.key" class="dist-row">
|
||||
<text class="dist-name" :style="{ color: statusColor(s.key) }">{{ s.name }}</text>
|
||||
<view class="dist-bar-wrap">
|
||||
<view class="dist-bar" :style="{ width: s.pct, background: statusColor(s.key) }" />
|
||||
</view>
|
||||
<text class="dist-count">{{ num(s.count) }}单 / ¥{{ money(s.amount) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -160,7 +153,9 @@ import { computed } from 'vue'
|
||||
import FaIcon from '@/components/FaIcon.vue'
|
||||
|
||||
const props = defineProps({
|
||||
data: { type: Object, default: () => ({}) }
|
||||
data: { type: Object, default: () => ({}) },
|
||||
// top:公告 + 数据统计;bottom:报销趋势 + 状态分布(中间由首页插入「常用功能」)
|
||||
part: { type: String, default: 'top' }
|
||||
})
|
||||
const emit = defineEmits(['view-notices', 'view-schedules'])
|
||||
|
||||
@@ -205,19 +200,8 @@ const statusList = computed(() => {
|
||||
.map((x) => ({ ...x, pct: Math.round((num(x.count) / total) * 100) + '%' }))
|
||||
})
|
||||
|
||||
// ---------- 报销类型分析 ----------
|
||||
const expenseTypes = computed(() => rb.value.expense_types || [])
|
||||
const expenseTypesTop = computed(() => expenseTypes.value.slice(0, 6))
|
||||
const expMax = computed(() => {
|
||||
let m = 1
|
||||
expenseTypes.value.forEach((e) => { m = Math.max(m, num(e.amount)) })
|
||||
return m
|
||||
})
|
||||
const typePct = (a) => Math.round((num(a) / expMax.value) * 100) + '%'
|
||||
|
||||
// ---------- 公告 / 日程 ----------
|
||||
// ---------- 公告 ----------
|
||||
const notices = computed(() => props.data?.notices || [])
|
||||
const todaySchedules = computed(() => props.data?.today_schedules || [])
|
||||
|
||||
const noticeTypeLabel = (type) => ({ 1: '公告', 2: '活动' }[type] || '通知')
|
||||
|
||||
@@ -234,12 +218,6 @@ function noticeTime(ts) {
|
||||
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
|
||||
}
|
||||
|
||||
function schedTime(s) {
|
||||
if (s.all_day === 1) return '全天'
|
||||
if (s.end_time) return `${s.start_time || ''} - ${s.end_time}`
|
||||
return s.start_time || '时间待定'
|
||||
}
|
||||
|
||||
const money = (value) =>
|
||||
Number(value || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
</script>
|
||||
@@ -251,7 +229,6 @@ const money = (value) =>
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24rpx;
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.dash-card {
|
||||
@@ -266,6 +243,30 @@ const money = (value) =>
|
||||
margin-bottom: 22rpx;
|
||||
}
|
||||
|
||||
.dash-head-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.head-icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border-radius: 12rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&.hi-notice,
|
||||
&.hi-stat {
|
||||
background: $color-primary-bg;
|
||||
}
|
||||
|
||||
&.hi-trend {
|
||||
background: #f3f0ff;
|
||||
}
|
||||
}
|
||||
|
||||
.dash-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
@@ -304,90 +305,95 @@ const money = (value) =>
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
/* ============ 待办概览 ============ */
|
||||
.todo-row {
|
||||
/* ============ 数据统计:待办 / 报销 双磁贴 ============ */
|
||||
.stat-tile {
|
||||
padding: 20rpx 20rpx 8rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
|
||||
& + & {
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-tile-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.tile-icon {
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
border-radius: 10rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&.ti-todo {
|
||||
background: $color-primary-bg;
|
||||
}
|
||||
|
||||
&.ti-money {
|
||||
background: #ecfdf5;
|
||||
}
|
||||
}
|
||||
|
||||
.tile-name {
|
||||
flex: 1;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.stat-row {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.todo-cell {
|
||||
.stat-cell {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6rpx;
|
||||
position: relative;
|
||||
|
||||
& + &::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 8rpx;
|
||||
bottom: 8rpx;
|
||||
width: 1rpx;
|
||||
background: $color-divider;
|
||||
}
|
||||
gap: 4rpx;
|
||||
padding-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.todo-value {
|
||||
font-size: 44rpx;
|
||||
font-weight: 600;
|
||||
line-height: 1.1;
|
||||
color: $color-primary;
|
||||
}
|
||||
|
||||
.todo-label {
|
||||
font-size: 24rpx;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.todo-sub {
|
||||
font-size: 20rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
/* ============ 报销统计 ============ */
|
||||
.money-row {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.money-cell {
|
||||
flex: 1;
|
||||
padding: 20rpx 16rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.money-label {
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.money-amount {
|
||||
.stat-amount {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.currency {
|
||||
font-size: 22rpx;
|
||||
color: $color-text;
|
||||
margin-right: 4rpx;
|
||||
}
|
||||
.stat-currency {
|
||||
font-size: 20rpx;
|
||||
color: $color-text;
|
||||
margin-right: 2rpx;
|
||||
}
|
||||
|
||||
.number {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
.stat-value {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
line-height: 1.15;
|
||||
color: $color-text;
|
||||
|
||||
&.primary {
|
||||
color: $color-primary;
|
||||
}
|
||||
}
|
||||
|
||||
.money-meta {
|
||||
font-size: 20rpx;
|
||||
.stat-label {
|
||||
font-size: 22rpx;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.stat-sub {
|
||||
font-size: 18rpx;
|
||||
color: $color-text-muted;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -464,9 +470,22 @@ const money = (value) =>
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
/* ============ 分布 / 类型 进度条 ============ */
|
||||
.dist-row,
|
||||
.type-row {
|
||||
/* ============ 状态分布 ============ */
|
||||
.status-block {
|
||||
margin-top: 26rpx;
|
||||
padding-top: 22rpx;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.status-title {
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.dist-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
@@ -482,18 +501,7 @@ const money = (value) =>
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.type-name {
|
||||
width: 140rpx;
|
||||
flex-shrink: 0;
|
||||
font-size: 22rpx;
|
||||
color: $color-text-secondary;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.dist-bar-wrap,
|
||||
.type-bar-wrap {
|
||||
.dist-bar-wrap {
|
||||
flex: 1;
|
||||
height: 14rpx;
|
||||
background: $color-divider;
|
||||
@@ -501,35 +509,29 @@ const money = (value) =>
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dist-bar,
|
||||
.type-bar {
|
||||
.dist-bar {
|
||||
height: 100%;
|
||||
border-radius: $radius-full;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.type-bar {
|
||||
background: linear-gradient(90deg, $color-primary, $color-primary-light);
|
||||
}
|
||||
|
||||
.dist-count,
|
||||
.type-amount {
|
||||
.dist-count {
|
||||
flex-shrink: 0;
|
||||
font-size: 20rpx;
|
||||
color: $color-text-muted;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ============ 公告 ============ */
|
||||
.notice-item {
|
||||
/* ============ 公告(单行垂直轮播) ============ */
|
||||
.notice-swiper {
|
||||
height: 68rpx;
|
||||
}
|
||||
|
||||
.notice-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
padding: 18rpx 0;
|
||||
|
||||
& + & {
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
height: 68rpx;
|
||||
|
||||
&:active {
|
||||
opacity: 0.6;
|
||||
@@ -579,78 +581,4 @@ const money = (value) =>
|
||||
font-size: 20rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
/* ============ 日程 ============ */
|
||||
.sched-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 14rpx;
|
||||
padding: 18rpx 0;
|
||||
|
||||
& + & {
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
&.done {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.sched-dot {
|
||||
width: 14rpx;
|
||||
height: 14rpx;
|
||||
margin-top: 12rpx;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sched-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.sched-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.sched-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 26rpx;
|
||||
color: $color-text;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
&.done {
|
||||
text-decoration: line-through;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
}
|
||||
|
||||
.sched-priority {
|
||||
flex-shrink: 0;
|
||||
font-size: 18rpx;
|
||||
padding: 2rpx 10rpx;
|
||||
border-radius: $radius-sm;
|
||||
|
||||
&.p-important {
|
||||
background: #fffbeb;
|
||||
color: $color-warning;
|
||||
}
|
||||
|
||||
&.p-urgent {
|
||||
background: #fef3f2;
|
||||
color: $color-danger;
|
||||
}
|
||||
}
|
||||
|
||||
.sched-time {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
</style>
|
||||
Generated
+1826
-848
File diff suppressed because it is too large.
Load diff
@@ -337,6 +337,27 @@
|
||||
"navigationBarTitleText": "新建日程",
|
||||
"navigationBarBackgroundColor": "#F8FAFC"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/tools/expense/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "报销管理",
|
||||
"navigationBarBackgroundColor": "#F8FAFC"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/tools/expense/edit",
|
||||
"style": {
|
||||
"navigationBarTitleText": "新建报销单",
|
||||
"navigationBarBackgroundColor": "#F8FAFC"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/tools/expense/detail",
|
||||
"style": {
|
||||
"navigationBarTitleText": "报销详情",
|
||||
"navigationBarBackgroundColor": "#F8FAFC"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
|
||||
@@ -0,0 +1,532 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<view v-if="loading" class="state-box">
|
||||
<text class="state-text">加载中...</text>
|
||||
</view>
|
||||
<template v-else-if="detail">
|
||||
<!-- 单据信息 -->
|
||||
<view class="detail-card">
|
||||
<view class="head-row">
|
||||
<text class="head-amount">¥{{ moneyText(detail.total_amount) }}</text>
|
||||
<u-tag
|
||||
:text="getExpenseStatusLabel(detail.status)"
|
||||
:type="getExpenseStatusType(detail.status)"
|
||||
size="mini"
|
||||
/>
|
||||
</view>
|
||||
<text v-if="descText" class="head-desc">{{ descText }}</text>
|
||||
|
||||
<view class="info-row">
|
||||
<text class="info-label">申请人</text>
|
||||
<text class="info-value">{{ detail.user_name || '-' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">申请日期</text>
|
||||
<text class="info-value">{{ detail.apply_date }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">费用笔数</text>
|
||||
<text class="info-value">{{ items.length }} 笔</text>
|
||||
</view>
|
||||
|
||||
<view class="meta-row">
|
||||
<text>创建于 {{ formatTime(detail.create_time) }}</text>
|
||||
<text v-if="detail.update_time">更新于 {{ formatTime(detail.update_time) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 费用明细 -->
|
||||
<view class="block-card">
|
||||
<view class="block-head">
|
||||
<text class="block-title">费用明细</text>
|
||||
<text class="block-total">¥{{ moneyText(detail.total_amount) }}</text>
|
||||
</view>
|
||||
<view v-if="!items.length" class="items-empty">
|
||||
<text>暂无费用明细</text>
|
||||
</view>
|
||||
<view v-for="item in items" :key="item.id" class="exp-item">
|
||||
<view class="exp-item-main">
|
||||
<view class="exp-item-line">
|
||||
<text class="exp-item-type">{{ item.expense_type || '未分类' }}</text>
|
||||
<text class="exp-item-amount">¥{{ moneyText(item.amount) }}</text>
|
||||
</view>
|
||||
<view class="exp-item-sub">
|
||||
<text>{{ item.expense_date }}{{ item.quantity > 1 ? ` × ${item.quantity}` : '' }}</text>
|
||||
<text v-if="item.description" class="exp-item-desc">{{ item.description }}</text>
|
||||
</view>
|
||||
<view v-if="item.receipts?.length" class="receipt-grid">
|
||||
<template v-for="(img, index) in item.receipts" :key="img.id || index">
|
||||
<image
|
||||
v-if="!isPdfReceipt(img)"
|
||||
class="receipt-item"
|
||||
:src="img.url"
|
||||
mode="aspectFill"
|
||||
@click="previewReceipt(item.receipts, index)"
|
||||
/>
|
||||
<view v-else class="receipt-file" @click="openReceiptFile(img)">
|
||||
<FaIcon name="file-pdf" color="#e74c3c" :size="26" />
|
||||
<text class="receipt-file-name">{{ img.name || 'PDF 文件' }}</text>
|
||||
<text class="receipt-file-hint">点击打开</text>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 审批记录 -->
|
||||
<view class="block-card">
|
||||
<view class="block-head">
|
||||
<text class="block-title">审批记录</text>
|
||||
</view>
|
||||
<view v-if="!records.length" class="items-empty">
|
||||
<text>暂无审批记录</text>
|
||||
</view>
|
||||
<view v-else class="timeline">
|
||||
<view v-for="record in records" :key="record.id" class="timeline-item">
|
||||
<view class="timeline-dot" />
|
||||
<view class="timeline-content">
|
||||
<text class="timeline-title">
|
||||
{{ getExpenseActionLabel(record.action) }} · {{ record.approver_name || '-' }}
|
||||
</text>
|
||||
<text v-if="record.comment" class="timeline-comment">{{ record.comment }}</text>
|
||||
<text class="timeline-time">{{ formatTime(record.create_time) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 操作按钮(统一放详情页,仅草稿可操作) -->
|
||||
<view v-if="detail && isDraft" class="footer">
|
||||
<view class="footer-btn">
|
||||
<u-button type="error" plain icon="trash" text="删除" @click="onDelete" />
|
||||
</view>
|
||||
<view class="footer-btn">
|
||||
<u-button type="primary" plain icon="edit-pen" text="编辑" @click="openEdit" />
|
||||
</view>
|
||||
<view class="footer-btn">
|
||||
<u-button type="primary" icon="arrow-up" text="提交审批" @click="onSubmit" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import {
|
||||
getExpense,
|
||||
deleteExpense,
|
||||
submitExpense,
|
||||
fetchExpenseRecords,
|
||||
getExpenseStatusLabel,
|
||||
getExpenseStatusType,
|
||||
getExpenseActionLabel,
|
||||
isPdfReceipt,
|
||||
moneyText,
|
||||
EXPENSE_STATUS
|
||||
} from '@/api/expense.js'
|
||||
|
||||
const expenseId = ref('')
|
||||
const detail = ref(null)
|
||||
const items = ref([])
|
||||
const records = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
const isDraft = computed(() => Number(detail.value?.status) === EXPENSE_STATUS.DRAFT)
|
||||
|
||||
const descText = computed(() => {
|
||||
const desc = (detail.value?.description || '').trim()
|
||||
return desc || ''
|
||||
})
|
||||
|
||||
onLoad((query) => {
|
||||
if (query?.id) {
|
||||
expenseId.value = query.id
|
||||
loadDetail()
|
||||
}
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
if (expenseId.value) loadDetail()
|
||||
})
|
||||
|
||||
/** 后端时间字段可能为 "YYYY-MM-DD HH:mm:ss" 格式,iOS 需转 T 分隔 */
|
||||
function formatTime(value) {
|
||||
if (!value) return ''
|
||||
return String(value).replace(' ', 'T').slice(0, 16).replace('T', ' ')
|
||||
}
|
||||
|
||||
async function loadDetail() {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await getExpense(expenseId.value)
|
||||
if (!data) {
|
||||
uni.showToast({ title: '报销单不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
return
|
||||
}
|
||||
detail.value = data
|
||||
items.value = data.items || []
|
||||
records.value = await fetchExpenseRecords(expenseId.value)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 图片预览:只把图片类发票给 previewImage,PDF 不参与 */
|
||||
function previewReceipt(receipts, index) {
|
||||
const current = receipts?.[index]
|
||||
const urls = (receipts || [])
|
||||
.filter(img => !isPdfReceipt(img))
|
||||
.map(img => img.url)
|
||||
.filter(Boolean)
|
||||
if (!urls.length) return
|
||||
uni.previewImage({ urls, current: current && !isPdfReceipt(current) ? current.url : urls[0] })
|
||||
}
|
||||
|
||||
/** PDF 发票:下载后用文档查看器打开(image 组件无法渲染 PDF,会被 ORB 拦截) */
|
||||
function openReceiptFile(file) {
|
||||
if (!file?.url) return
|
||||
uni.showLoading({ title: '打开中...' })
|
||||
uni.downloadFile({
|
||||
url: file.url,
|
||||
success: (res) => {
|
||||
uni.openDocument({
|
||||
filePath: res.tempFilePath,
|
||||
fileType: 'pdf',
|
||||
showMenu: true,
|
||||
fail: () => uni.showToast({ title: '当前环境无法打开 PDF', icon: 'none' })
|
||||
})
|
||||
},
|
||||
fail: () => uni.showToast({ title: '文件下载失败', icon: 'none' }),
|
||||
complete: () => uni.hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
function openEdit() {
|
||||
uni.navigateTo({ url: `/pages/tools/expense/edit?id=${expenseId.value}` })
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
uni.showModal({
|
||||
title: '提交审批',
|
||||
content: '提交后将进入审批流程,草稿期间仍可修改,确定提交吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await submitExpense(expenseId.value)
|
||||
uni.showToast({ title: '已提交审批', icon: 'success' })
|
||||
loadDetail()
|
||||
} catch (e) {
|
||||
// request 封装已弹出服务端错误提示
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function onDelete() {
|
||||
uni.showModal({
|
||||
title: '删除报销单',
|
||||
content: '删除后不可恢复,确定删除吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deleteExpense(expenseId.value)
|
||||
uni.showToast({ title: '已删除', icon: 'success' })
|
||||
setTimeout(() => uni.navigateBack(), 400)
|
||||
} catch (e) {
|
||||
// request 封装已弹出服务端错误提示
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
</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,
|
||||
.block-card {
|
||||
@include card;
|
||||
padding: 32rpx 28rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.head-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.head-amount {
|
||||
font-size: 44rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.head-desc {
|
||||
display: block;
|
||||
margin-top: 14rpx;
|
||||
font-size: 28rpx;
|
||||
color: $color-text-secondary;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 24rpx;
|
||||
padding: 20rpx 0 0;
|
||||
margin-top: 20rpx;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 26rpx;
|
||||
color: $color-text-muted;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.meta-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
padding-top: 24rpx;
|
||||
margin-top: 20rpx;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.block-head {
|
||||
@include block-head;
|
||||
}
|
||||
|
||||
.block-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.block-total {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.items-empty {
|
||||
padding: 32rpx 0;
|
||||
font-size: 26rpx;
|
||||
color: $color-text-muted;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.exp-item {
|
||||
padding: 20rpx 0;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
|
||||
&:first-of-type {
|
||||
border-top: none;
|
||||
padding-top: 4rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.exp-item-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.exp-item-type {
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.exp-item-amount {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.exp-item-sub {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
|
||||
.exp-item-desc {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.receipt-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.receipt-item {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
}
|
||||
|
||||
.receipt-file {
|
||||
width: 200rpx;
|
||||
height: 120rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4rpx;
|
||||
padding: 0 12rpx;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.receipt-file-name {
|
||||
max-width: 100%;
|
||||
font-size: 22rpx;
|
||||
color: $color-text;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.receipt-file-hint {
|
||||
font-size: 20rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.timeline {
|
||||
padding-top: 4rpx;
|
||||
}
|
||||
|
||||
.timeline-item {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
padding-bottom: 28rpx;
|
||||
position: relative;
|
||||
|
||||
&:last-child {
|
||||
padding-bottom: 4rpx;
|
||||
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 9rpx;
|
||||
top: 24rpx;
|
||||
bottom: 0;
|
||||
width: 2rpx;
|
||||
background: $color-divider;
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-dot {
|
||||
width: 20rpx;
|
||||
height: 20rpx;
|
||||
border-radius: 50%;
|
||||
background: #2563eb;
|
||||
flex-shrink: 0;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.timeline-title {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
color: $color-text;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.timeline-comment {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-secondary;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.timeline-time {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
font-size: 22rpx;
|
||||
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>
|
||||
@@ -0,0 +1,746 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 基本信息 -->
|
||||
<view class="form-card">
|
||||
<view class="field">
|
||||
<text class="field-label">申请日期 <text class="required">*</text></text>
|
||||
<picker mode="date" :value="form.applyDate" @change="onDateChange">
|
||||
<view class="picker-value">
|
||||
<text>{{ form.applyDate }}</text>
|
||||
<FaIcon name="calendar-days" color="#909399" :size="16" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">报销说明</text>
|
||||
<u-textarea
|
||||
v-model="form.description"
|
||||
placeholder="填写报销事由,便于审批人了解(选填)"
|
||||
:maxlength="500"
|
||||
count
|
||||
height="100"
|
||||
border="none"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 费用明细 -->
|
||||
<view class="items-card">
|
||||
<view class="items-head">
|
||||
<text class="items-title">费用明细</text>
|
||||
<text class="items-total">合计 ¥{{ totalText }}</text>
|
||||
</view>
|
||||
|
||||
<view v-if="!items.length" class="items-empty">
|
||||
<text>尚未添加费用明细</text>
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in items"
|
||||
:key="index"
|
||||
class="item-row"
|
||||
@tap="openItemEditor(index)"
|
||||
>
|
||||
<view class="item-main">
|
||||
<view class="item-line">
|
||||
<text class="item-type">{{ item.expenseType || '未分类' }}</text>
|
||||
<text class="item-amount">¥{{ moneyText(item.amount) }}</text>
|
||||
</view>
|
||||
<view class="item-sub">
|
||||
<text>{{ item.expenseDate }}</text>
|
||||
<text v-if="item.receipts?.length" class="item-receipt">发票 ×{{ item.receipts.length }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="item-del" @tap.stop="onRemoveItem(index)">
|
||||
<FaIcon name="trash-can" color="#f56c6c" :size="18" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="item-add" @tap="openItemEditor(-1)">
|
||||
<FaIcon name="plus" color="#2563eb" :size="16" />
|
||||
<text>添加费用明细</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="footer">
|
||||
<u-button
|
||||
type="primary"
|
||||
color="#2563eb"
|
||||
shape="circle"
|
||||
:loading="saving"
|
||||
loading-text="保存中..."
|
||||
text="保存"
|
||||
@click="onSave"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 明细编辑弹层 -->
|
||||
<view v-if="itemEditorVisible" class="mask" @tap="closeItemEditor">
|
||||
<view class="sheet" @tap.stop>
|
||||
<view class="sheet-head">
|
||||
<text class="sheet-cancel" @tap="closeItemEditor">取消</text>
|
||||
<text class="sheet-title">{{ editingIndex >= 0 ? '编辑费用' : '添加费用' }}</text>
|
||||
<text class="sheet-save" @tap="confirmItem">确定</text>
|
||||
</view>
|
||||
<scroll-view class="sheet-body" scroll-y>
|
||||
<view class="field">
|
||||
<text class="field-label">费用类型 <text class="required">*</text></text>
|
||||
<picker :range="typeNames" :value="typeIndex" @change="onTypeChange">
|
||||
<view class="picker-value">
|
||||
<text>{{ typeNames[typeIndex] || '选择费用类型' }}</text>
|
||||
<FaIcon name="layer-group" color="#909399" :size="16" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">费用日期 <text class="required">*</text></text>
|
||||
<picker mode="date" :value="itemForm.expenseDate" @change="onItemDateChange">
|
||||
<view class="picker-value">
|
||||
<text>{{ itemForm.expenseDate }}</text>
|
||||
<FaIcon name="calendar-days" color="#909399" :size="16" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">金额 <text class="required">*</text></text>
|
||||
<u-input
|
||||
v-model="itemForm.amount"
|
||||
type="digit"
|
||||
placeholder="0.00"
|
||||
border="none"
|
||||
/>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">数量</text>
|
||||
<u-input
|
||||
v-model="itemForm.quantity"
|
||||
type="number"
|
||||
placeholder="1"
|
||||
border="none"
|
||||
/>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">说明</text>
|
||||
<u-input
|
||||
v-model="itemForm.description"
|
||||
placeholder="费用用途说明(选填)"
|
||||
:maxlength="200"
|
||||
border="none"
|
||||
/>
|
||||
</view>
|
||||
<view class="field">
|
||||
<view class="receipt-head">
|
||||
<text class="field-label no-margin">发票附件</text>
|
||||
<text v-if="itemForm.receipts.length" class="receipt-hint">长按可删除</text>
|
||||
</view>
|
||||
<view class="receipt-grid">
|
||||
<template v-for="(img, index) in itemForm.receipts" :key="img.id || index">
|
||||
<image
|
||||
v-if="!isPdfReceipt(img)"
|
||||
class="receipt-item"
|
||||
:src="img.url"
|
||||
mode="aspectFill"
|
||||
@click="previewReceipt(index)"
|
||||
@longpress="onRemoveReceipt(index)"
|
||||
/>
|
||||
<view v-else class="receipt-file" @longpress="onRemoveReceipt(index)">
|
||||
<FaIcon name="file-pdf" color="#e74c3c" :size="26" />
|
||||
<text class="receipt-file-name">{{ img.name || 'PDF 文件' }}</text>
|
||||
</view>
|
||||
</template>
|
||||
<view class="receipt-add" @tap="onUploadReceipt">
|
||||
<FaIcon name="camera" color="#94a3b8" :size="20" />
|
||||
<text>{{ uploading ? '上传中...' : '上传' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import {
|
||||
getExpense,
|
||||
createExpense,
|
||||
updateExpense,
|
||||
addExpenseItem,
|
||||
deleteExpenseItem,
|
||||
fetchExpenseTypes,
|
||||
uploadExpenseReceipt,
|
||||
resolveImageUrl,
|
||||
isPdfReceipt,
|
||||
moneyText,
|
||||
EXPENSE_STATUS
|
||||
} from '@/api/expense.js'
|
||||
import { formatDate } from '@/utils/date.js'
|
||||
|
||||
const expenseId = ref('')
|
||||
const isDraft = ref(true)
|
||||
const saving = ref(false)
|
||||
const uploading = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
applyDate: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
/** 本地明细列表:编辑已有明细时带 id,保存时全量重建 */
|
||||
const items = ref([])
|
||||
|
||||
const typeOptions = ref([])
|
||||
const typeNames = computed(() => typeOptions.value.map(t => t.name))
|
||||
|
||||
const itemEditorVisible = ref(false)
|
||||
const editingIndex = ref(-1)
|
||||
const typeIndex = ref(0)
|
||||
|
||||
const itemForm = reactive({
|
||||
expenseType: '',
|
||||
expenseDate: '',
|
||||
amount: '',
|
||||
quantity: '1',
|
||||
description: '',
|
||||
receipts: []
|
||||
})
|
||||
|
||||
const totalText = computed(() =>
|
||||
moneyText(items.value.reduce((sum, item) => sum + (Number(item.amount) || 0), 0))
|
||||
)
|
||||
|
||||
onLoad(async (query) => {
|
||||
form.applyDate = formatDate(new Date())
|
||||
|
||||
loadTypes()
|
||||
|
||||
if (query?.id) {
|
||||
expenseId.value = query.id
|
||||
uni.setNavigationBarTitle({ title: '编辑报销单' })
|
||||
await loadDetail(query.id)
|
||||
} else {
|
||||
uni.setNavigationBarTitle({ title: '新建报销单' })
|
||||
}
|
||||
})
|
||||
|
||||
async function loadTypes() {
|
||||
try {
|
||||
typeOptions.value = await fetchExpenseTypes()
|
||||
if (!typeOptions.value.length) typeOptions.value = [{ id: 0, name: '其他' }]
|
||||
} catch (e) {
|
||||
typeOptions.value = [{ id: 0, name: '其他' }]
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetail(id) {
|
||||
try {
|
||||
const data = await getExpense(id)
|
||||
if (!data) {
|
||||
uni.showToast({ title: '报销单不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
return
|
||||
}
|
||||
isDraft.value = Number(data.status) === EXPENSE_STATUS.DRAFT
|
||||
if (!isDraft.value) {
|
||||
uni.showToast({ title: '只有草稿可以编辑', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
return
|
||||
}
|
||||
form.applyDate = data.apply_date || formatDate(new Date())
|
||||
form.description = data.description || ''
|
||||
items.value = (data.items || []).map(item => ({
|
||||
id: item.id,
|
||||
expenseType: item.expense_type,
|
||||
expenseDate: item.expense_date,
|
||||
amount: String(item.amount ?? ''),
|
||||
quantity: String(item.quantity || 1),
|
||||
description: item.description || '',
|
||||
receipts: item.receipts || []
|
||||
}))
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
function onDateChange(e) {
|
||||
form.applyDate = e.detail.value
|
||||
}
|
||||
|
||||
function openItemEditor(index) {
|
||||
editingIndex.value = index
|
||||
if (index >= 0) {
|
||||
const item = items.value[index]
|
||||
Object.assign(itemForm, {
|
||||
expenseType: item.expenseType,
|
||||
expenseDate: item.expenseDate,
|
||||
amount: item.amount,
|
||||
quantity: item.quantity,
|
||||
unitPrice: item.unitPrice,
|
||||
description: item.description,
|
||||
receipts: [...(item.receipts || [])]
|
||||
})
|
||||
typeIndex.value = Math.max(
|
||||
typeOptions.value.findIndex(t => t.name === item.expenseType),
|
||||
0
|
||||
)
|
||||
} else {
|
||||
Object.assign(itemForm, {
|
||||
expenseType: typeOptions.value[0]?.name || '',
|
||||
expenseDate: form.applyDate,
|
||||
amount: '',
|
||||
quantity: '1',
|
||||
description: '',
|
||||
receipts: []
|
||||
})
|
||||
typeIndex.value = 0
|
||||
}
|
||||
itemEditorVisible.value = true
|
||||
}
|
||||
|
||||
function closeItemEditor() {
|
||||
itemEditorVisible.value = false
|
||||
}
|
||||
|
||||
function onTypeChange(e) {
|
||||
typeIndex.value = Number(e.detail.value)
|
||||
itemForm.expenseType = typeOptions.value[typeIndex.value]?.name || ''
|
||||
}
|
||||
|
||||
function onItemDateChange(e) {
|
||||
itemForm.expenseDate = e.detail.value
|
||||
}
|
||||
|
||||
function confirmItem() {
|
||||
const amount = Number(itemForm.amount)
|
||||
if (!itemForm.expenseType) {
|
||||
uni.showToast({ title: '请选择费用类型', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!itemForm.expenseDate) {
|
||||
uni.showToast({ title: '请选择费用日期', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!amount || amount <= 0) {
|
||||
uni.showToast({ title: '费用金额必须大于0', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (editingIndex.value >= 0) {
|
||||
const old = items.value[editingIndex.value]
|
||||
Object.assign(old, {
|
||||
expenseType: itemForm.expenseType,
|
||||
expenseDate: itemForm.expenseDate,
|
||||
amount: amount,
|
||||
quantity: Math.max(Number(itemForm.quantity) || 1, 1),
|
||||
description: itemForm.description.trim(),
|
||||
receipts: [...itemForm.receipts]
|
||||
})
|
||||
} else {
|
||||
items.value.push({
|
||||
expenseType: itemForm.expenseType,
|
||||
expenseDate: itemForm.expenseDate,
|
||||
amount: amount,
|
||||
quantity: Math.max(Number(itemForm.quantity) || 1, 1),
|
||||
description: itemForm.description.trim(),
|
||||
receipts: [...itemForm.receipts]
|
||||
})
|
||||
}
|
||||
itemEditorVisible.value = false
|
||||
}
|
||||
|
||||
function onRemoveItem(index) {
|
||||
items.value.splice(index, 1)
|
||||
}
|
||||
|
||||
function previewReceipt(index) {
|
||||
const current = itemForm.receipts[index]
|
||||
const urls = itemForm.receipts
|
||||
.filter(img => !isPdfReceipt(img))
|
||||
.map(img => img.url)
|
||||
.filter(Boolean)
|
||||
if (!urls.length) return
|
||||
uni.previewImage({ urls, current: current && !isPdfReceipt(current) ? current.url : urls[0] })
|
||||
}
|
||||
|
||||
function onRemoveReceipt(index) {
|
||||
itemForm.receipts.splice(index, 1)
|
||||
}
|
||||
|
||||
/** 上传发票:选择图片(拍照/相册)或从聊天文件选 PDF */
|
||||
function onUploadReceipt() {
|
||||
if (uploading.value) return
|
||||
uni.showActionSheet({
|
||||
itemList: ['拍摄或从相册选择', '从聊天文件选择'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
chooseImageReceipt()
|
||||
} else if (res.tapIndex === 1) {
|
||||
chooseFileReceipt()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function chooseImageReceipt() {
|
||||
uni.chooseImage({
|
||||
count: 9,
|
||||
success: async (res) => {
|
||||
await uploadReceipts(res.tempFilePaths || [])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 小程序沙箱内选择本地 PDF 只能走微信会话文件(chooseMessageFile) */
|
||||
function chooseFileReceipt() {
|
||||
if (typeof uni.chooseMessageFile !== 'function') {
|
||||
uni.showToast({ title: '当前环境不支持选择文件', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.chooseMessageFile({
|
||||
count: 9,
|
||||
type: 'file',
|
||||
extension: ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'],
|
||||
success: async (res) => {
|
||||
const paths = (res.tempFiles || []).map(f => f.path).filter(Boolean)
|
||||
if (!paths.length) return
|
||||
await uploadReceipts(paths)
|
||||
},
|
||||
fail: () => {
|
||||
// 用户取消选择,静默处理
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function uploadReceipts(paths) {
|
||||
if (!paths.length || uploading.value) return
|
||||
uploading.value = true
|
||||
try {
|
||||
for (const p of paths) {
|
||||
const uploaded = await uploadExpenseReceipt(p)
|
||||
itemForm.receipts.push({ ...uploaded, url: resolveImageUrl(uploaded.url) })
|
||||
}
|
||||
uni.showToast({ title: '上传成功', icon: 'success' })
|
||||
} catch (e) {
|
||||
// 上传封装已提示错误
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onSave() {
|
||||
if (saving.value) return
|
||||
if (!form.applyDate) {
|
||||
uni.showToast({ title: '请选择申请日期', icon: 'none' })
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
let id = expenseId.value
|
||||
const payload = { applyDate: form.applyDate, description: form.description }
|
||||
if (id) {
|
||||
await updateExpense(id, payload)
|
||||
// 明细全量重建:先删旧再逐条新增(草稿单,明细量少)
|
||||
const oldItems = await getExpense(id)
|
||||
for (const item of oldItems?.items || []) {
|
||||
await deleteExpenseItem(id, item.id)
|
||||
}
|
||||
} else {
|
||||
id = await createExpense(payload)
|
||||
}
|
||||
for (const item of items.value) {
|
||||
await addExpenseItem(id, item)
|
||||
}
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => uni.navigateBack(), 400)
|
||||
} catch (e) {
|
||||
// request 封装已弹出服务端错误提示
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</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));
|
||||
}
|
||||
|
||||
.form-card,
|
||||
.items-card {
|
||||
@include card;
|
||||
padding: 8rpx 0;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.field {
|
||||
padding: 24rpx 28rpx;
|
||||
|
||||
& + & {
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
margin-bottom: 12rpx;
|
||||
|
||||
&.no-margin {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.required {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 72rpx;
|
||||
padding: 0 20rpx;
|
||||
background: $color-bg-page;
|
||||
border-radius: $radius-md;
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.items-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 28rpx 28rpx 8rpx;
|
||||
}
|
||||
|
||||
.items-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.items-total {
|
||||
font-size: 26rpx;
|
||||
color: #f56c6c;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.items-empty {
|
||||
padding: 32rpx 28rpx;
|
||||
font-size: 26rpx;
|
||||
color: $color-text-muted;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 24rpx 28rpx;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
|
||||
&:active {
|
||||
background: $color-bg-page;
|
||||
}
|
||||
}
|
||||
|
||||
.item-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.item-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.item-type {
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.item-amount {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.item-sub {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.item-receipt {
|
||||
color: #2563eb;
|
||||
}
|
||||
|
||||
.item-del {
|
||||
padding: 12rpx 0 12rpx 24rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.item-add {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
margin: 16rpx 28rpx 28rpx;
|
||||
height: 80rpx;
|
||||
border: 1rpx dashed $color-border;
|
||||
border-radius: $radius-md;
|
||||
font-size: 26rpx;
|
||||
color: #2563eb;
|
||||
|
||||
&:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
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);
|
||||
}
|
||||
|
||||
.mask {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(15, 23, 42, 0.45);
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
@include mask-responsive;
|
||||
}
|
||||
|
||||
.sheet {
|
||||
width: 100%;
|
||||
background: $color-card;
|
||||
border-radius: 28rpx 28rpx 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 80vh;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
@include sheet-responsive;
|
||||
}
|
||||
|
||||
.sheet-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 28rpx $page-padding-x;
|
||||
border-bottom: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.sheet-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.sheet-cancel {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.sheet-save {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: $color-primary;
|
||||
}
|
||||
|
||||
.sheet-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 60vh;
|
||||
}
|
||||
|
||||
.receipt-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.receipt-hint {
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.receipt-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.receipt-item {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
}
|
||||
|
||||
.receipt-file {
|
||||
width: 200rpx;
|
||||
height: 140rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6rpx;
|
||||
padding: 0 12rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.receipt-file-name {
|
||||
max-width: 100%;
|
||||
font-size: 22rpx;
|
||||
color: $color-text;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.receipt-add {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border: 1rpx dashed $color-border;
|
||||
border-radius: $radius-md;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6rpx;
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
|
||||
&:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,313 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索 + 状态筛选 -->
|
||||
<view class="filter-bar">
|
||||
<view class="search-box">
|
||||
<FaIcon name="magnifying-glass" color="#94a3b8" :size="16" />
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索报销说明"
|
||||
confirm-type="search"
|
||||
@confirm="onSearch"
|
||||
/>
|
||||
<text v-if="keyword" class="search-clear" @tap="clearKeyword">清空</text>
|
||||
</view>
|
||||
<scroll-view class="tab-scroll" scroll-x :show-scrollbar="false">
|
||||
<view class="tab-list">
|
||||
<view
|
||||
v-for="tab in tabs"
|
||||
:key="String(tab.value)"
|
||||
class="tab-item"
|
||||
:class="{ active: currentStatus === tab.value }"
|
||||
@tap="onTabChange(tab.value)"
|
||||
>
|
||||
<text>{{ tab.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 报销单列表 -->
|
||||
<view v-if="loading && !list.length" class="state-box">
|
||||
<text class="state-text">加载中...</text>
|
||||
</view>
|
||||
<view v-else-if="!list.length" class="state-box">
|
||||
<u-empty mode="list" text="暂无报销单" />
|
||||
</view>
|
||||
<template v-else>
|
||||
<view
|
||||
v-for="row in list"
|
||||
:key="row.id"
|
||||
class="expense-card"
|
||||
@tap="openDetail(row)"
|
||||
>
|
||||
<view class="card-top">
|
||||
<text class="card-amount">¥{{ moneyText(row.total_amount) }}</text>
|
||||
<u-tag
|
||||
:text="getExpenseStatusLabel(row.status)"
|
||||
:type="getExpenseStatusType(row.status)"
|
||||
size="mini"
|
||||
/>
|
||||
</view>
|
||||
<text class="card-desc">{{ descText(row) }}</text>
|
||||
<view class="card-meta">
|
||||
<text>申请日期 {{ row.apply_date }}</text>
|
||||
<FaIcon name="chevron-right" color="#cbd5e1" :size="14" />
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="finished" class="load-done">
|
||||
<text>{{ list.length ? '没有更多了' : '' }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 新建入口 -->
|
||||
<view class="fab" @tap="openCreate">
|
||||
<FaIcon name="plus" color="#ffffff" :size="22" />
|
||||
<text>新建报销</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app'
|
||||
import {
|
||||
fetchExpenses,
|
||||
getExpenseStatusLabel,
|
||||
getExpenseStatusType,
|
||||
moneyText,
|
||||
EXPENSE_STATUS_OPTIONS
|
||||
} from '@/api/expense.js'
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
|
||||
const tabs = [{ value: '', label: '全部' }, ...EXPENSE_STATUS_OPTIONS]
|
||||
|
||||
const list = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const keyword = ref('')
|
||||
const currentStatus = ref('')
|
||||
|
||||
onShow(() => {
|
||||
refresh()
|
||||
})
|
||||
|
||||
onReachBottom(() => {
|
||||
if (finished.value || loading.value) return
|
||||
loadMore()
|
||||
})
|
||||
|
||||
async function refresh() {
|
||||
page.value = 1
|
||||
finished.value = false
|
||||
list.value = []
|
||||
await loadPage()
|
||||
}
|
||||
|
||||
async function loadMore() {
|
||||
page.value += 1
|
||||
await loadPage()
|
||||
}
|
||||
|
||||
async function loadPage() {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await fetchExpenses({
|
||||
page: page.value,
|
||||
pageSize: PAGE_SIZE,
|
||||
keyword: keyword.value.trim(),
|
||||
status: currentStatus.value
|
||||
})
|
||||
const rows = data.list || []
|
||||
list.value = page.value === 1 ? rows : [...list.value, ...rows]
|
||||
total.value = data.total || 0
|
||||
finished.value = list.value.length >= total.value
|
||||
} catch (e) {
|
||||
if (page.value > 1) page.value -= 1
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
function clearKeyword() {
|
||||
keyword.value = ''
|
||||
refresh()
|
||||
}
|
||||
|
||||
function onTabChange(value) {
|
||||
if (currentStatus.value === value) return
|
||||
currentStatus.value = value
|
||||
refresh()
|
||||
}
|
||||
|
||||
function descText(row) {
|
||||
const desc = (row.description || '').trim()
|
||||
return desc || '无报销说明'
|
||||
}
|
||||
|
||||
function openDetail(row) {
|
||||
uni.navigateTo({ url: `/pages/tools/expense/detail?id=${row.id}` })
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
uni.navigateTo({ url: '/pages/tools/expense/edit' })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import '@/src/styles/page-common.scss';
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: $color-bg-page;
|
||||
padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
background: $color-bg-page;
|
||||
padding: 20rpx $page-padding-x 8rpx;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
height: 72rpx;
|
||||
padding: 0 24rpx;
|
||||
background: $color-card;
|
||||
border-radius: $radius-full;
|
||||
box-shadow: $shadow-card;
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.search-clear {
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
}
|
||||
|
||||
.tab-scroll {
|
||||
margin-top: 20rpx;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tab-list {
|
||||
display: inline-flex;
|
||||
gap: 16rpx;
|
||||
padding: 4rpx 0 12rpx;
|
||||
}
|
||||
|
||||
.tab-item {
|
||||
padding: 10rpx 28rpx;
|
||||
border-radius: $radius-full;
|
||||
background: $color-card;
|
||||
font-size: 26rpx;
|
||||
color: $color-text-secondary;
|
||||
box-shadow: $shadow-card;
|
||||
|
||||
&.active {
|
||||
background: #2563eb;
|
||||
color: #ffffff;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.expense-card {
|
||||
@include card;
|
||||
margin: 0 $page-padding-x 24rpx;
|
||||
padding: 28rpx;
|
||||
|
||||
&:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
.card-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 14rpx;
|
||||
}
|
||||
|
||||
.card-amount {
|
||||
font-size: 36rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.card-desc {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
color: $color-text-secondary;
|
||||
line-height: 1.6;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.card-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 16rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.state-box {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 140rpx 0;
|
||||
}
|
||||
|
||||
.state-text {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.load-done {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 8rpx 0 24rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.fab {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
bottom: calc(48rpx + env(safe-area-inset-bottom));
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
height: 88rpx;
|
||||
padding: 0 48rpx;
|
||||
border-radius: $radius-full;
|
||||
background: #2563eb;
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
box-shadow: 0 8rpx 24rpx rgba(37, 99, 235, 0.4);
|
||||
|
||||
&:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -5,46 +5,70 @@
|
||||
</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 class="head-block">
|
||||
<view class="head-row">
|
||||
<text class="head-text" :class="{ done: item.completed }">{{ headText }}</text>
|
||||
<view class="head-tags">
|
||||
<u-tag
|
||||
v-if="priorityLabel !== '普通'"
|
||||
:text="priorityLabel"
|
||||
:type="Number(item.priority) === 2 ? 'error' : 'warning'"
|
||||
size="mini"
|
||||
plain
|
||||
/>
|
||||
<u-tag
|
||||
:text="item.completed ? '已完成' : '待办'"
|
||||
:type="item.completed ? 'success' : 'primary'"
|
||||
size="mini"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<text class="content-text">{{ item.content || '无内容' }}</text>
|
||||
<text v-if="extraContent" class="head-extra">{{ extraContent }}</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>
|
||||
<text class="info-label">日期</text>
|
||||
<text class="info-value">{{ dayLabel(item.timestamp) }}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-row">
|
||||
<text class="info-label">提前提醒时间</text>
|
||||
<text class="info-value">{{ remindText }}</text>
|
||||
<text class="info-label">时间</text>
|
||||
<text class="info-value">{{ timeRangeText }}</text>
|
||||
</view>
|
||||
|
||||
<!-- <view class="info-row">
|
||||
<text class="info-label">优先级</text>
|
||||
<text class="info-value">{{ priorityLabel }}</text>
|
||||
</view> -->
|
||||
|
||||
<view
|
||||
v-if="item.images?.length || item.completed"
|
||||
class="image-block"
|
||||
>
|
||||
<view class="image-head">
|
||||
<text class="info-label">任务资料</text>
|
||||
<text v-if="item.images?.length" class="image-hint">长按图片可删除</text>
|
||||
</view>
|
||||
<view class="image-grid">
|
||||
<image
|
||||
v-for="(img, index) in item.images"
|
||||
:key="img.id || index"
|
||||
class="image-item"
|
||||
:src="img.url"
|
||||
mode="aspectFill"
|
||||
@click="previewImage(index)"
|
||||
@longpress="onRemoveImage(index)"
|
||||
/>
|
||||
<view v-if="item.completed" class="image-add" @tap="onUploadMaterial">
|
||||
<FaIcon name="plus" color="#94a3b8" :size="20" />
|
||||
<text>{{ uploading ? '上传中...' : '上传' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="meta-row">
|
||||
<text>创建于 {{ formatDate(item.createdAt, true) }}</text>
|
||||
<text v-if="item.updatedAt !== item.createdAt">更新于 {{ formatDate(item.updatedAt, true) }}</text>
|
||||
<text>创建于 {{ formatTime(item.create_time) }}</text>
|
||||
<text v-if="item.update_time">更新于 {{ formatTime(item.update_time) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -54,17 +78,19 @@
|
||||
<u-button
|
||||
:type="item.completed ? 'info' : 'primary'"
|
||||
:icon="item.completed ? 'reload' : 'checkmark'"
|
||||
:text="item.completed ? '标为待办' : '标记完成'"
|
||||
: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>
|
||||
<template v-if="!item.completed">
|
||||
<view 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>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -73,21 +99,46 @@
|
||||
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'
|
||||
getOaSchedule,
|
||||
deleteOaSchedule,
|
||||
toggleOaScheduleComplete,
|
||||
uploadOaScheduleImage,
|
||||
setOaScheduleImages,
|
||||
getOaPriorityLabel
|
||||
} from '@/api/oaSchedule.js'
|
||||
import { dayLabel, formatDate } from '@/utils/date.js'
|
||||
|
||||
const scheduleId = ref('')
|
||||
const item = ref(null)
|
||||
const loading = ref(false)
|
||||
const uploading = ref(false)
|
||||
|
||||
const remindText = computed(() => {
|
||||
const priorityLabel = computed(() => {
|
||||
if (!item.value) return ''
|
||||
return getRemindMinutesLabel(item.value.remindMinutes)
|
||||
return getOaPriorityLabel(item.value.priority)
|
||||
})
|
||||
|
||||
/** 标题即内容:标题作为正文主文本展示 */
|
||||
const headText = computed(() => {
|
||||
if (!item.value) return ''
|
||||
return (item.value.title || '').trim() || '无标题'
|
||||
})
|
||||
|
||||
/** content 与标题相同(或为空)时不重复展示,仅在有额外内容时补充显示 */
|
||||
const extraContent = computed(() => {
|
||||
if (!item.value) return ''
|
||||
const c = (item.value.content || '').trim()
|
||||
if (!c || c === (item.value.title || '').trim()) return ''
|
||||
return c
|
||||
})
|
||||
|
||||
const timeRangeText = computed(() => {
|
||||
if (!item.value) return ''
|
||||
if (item.value.allDay) return '全天'
|
||||
const start = item.value.start_time || ''
|
||||
const end = item.value.end_time || ''
|
||||
if (!start) return '未设置'
|
||||
return end ? `${start} - ${end}` : start
|
||||
})
|
||||
|
||||
onLoad((query) => {
|
||||
@@ -101,10 +152,16 @@ onShow(() => {
|
||||
if (scheduleId.value) loadDetail()
|
||||
})
|
||||
|
||||
/** 后端时间字段可能为 "YYYY-MM-DD HH:mm:ss" 格式,iOS 需转 T 分隔 */
|
||||
function formatTime(value) {
|
||||
if (!value) return ''
|
||||
return formatDate(new Date(String(value).replace(' ', 'T')), true)
|
||||
}
|
||||
|
||||
async function loadDetail() {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await getSchedule(scheduleId.value)
|
||||
const data = await getOaSchedule(scheduleId.value)
|
||||
if (!data) {
|
||||
uni.showToast({ title: '日程不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
@@ -118,6 +175,64 @@ async function loadDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
function previewImage(index) {
|
||||
const urls = (item.value?.images || []).map(img => img.url).filter(Boolean)
|
||||
if (!urls.length) return
|
||||
uni.previewImage({ urls, current: urls[index] || urls[0] })
|
||||
}
|
||||
|
||||
/** 上传资料图片:选图 → 逐张上传 → 引用写回日程 */
|
||||
function onUploadMaterial() {
|
||||
if (uploading.value) return
|
||||
uni.chooseImage({
|
||||
count: 9,
|
||||
success: async (res) => {
|
||||
const paths = res.tempFilePaths || []
|
||||
if (!paths.length) return
|
||||
uploading.value = true
|
||||
try {
|
||||
const uploaded = []
|
||||
for (const p of paths) {
|
||||
uploaded.push(await uploadOaScheduleImage(p))
|
||||
}
|
||||
const saved = await setOaScheduleImages(
|
||||
scheduleId.value,
|
||||
[...(item.value.images || []), ...uploaded]
|
||||
)
|
||||
item.value.images = saved
|
||||
uni.showToast({ title: '上传成功', icon: 'success' })
|
||||
} catch (e) {
|
||||
// 上传/请求封装已提示错误
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 长按删除资料图片(仅移除引用,不动文件管理里的文件) */
|
||||
function onRemoveImage(index) {
|
||||
const img = item.value?.images?.[index]
|
||||
if (!img || uploading.value) return
|
||||
uni.showModal({
|
||||
title: '删除资料',
|
||||
content: `确定删除「${img.name || '该图片'}」吗?`,
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
const saved = await setOaScheduleImages(
|
||||
scheduleId.value,
|
||||
item.value.images.filter((_, i) => i !== index)
|
||||
)
|
||||
item.value.images = saved
|
||||
uni.showToast({ title: '已删除', icon: 'none' })
|
||||
} catch (e) {
|
||||
// request 封装已提示错误
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function openEdit() {
|
||||
uni.navigateTo({ url: `/pages/tools/schedule/edit?id=${scheduleId.value}` })
|
||||
}
|
||||
@@ -126,31 +241,30 @@ async function onToggleComplete() {
|
||||
if (!item.value) return
|
||||
const wasCompleted = item.value.completed
|
||||
try {
|
||||
await toggleScheduleComplete(item.value.id)
|
||||
// toggle 接口只返回 is_finished,需重新拉取完整详情
|
||||
await loadDetail()
|
||||
const res = await toggleOaScheduleComplete(item.value.id)
|
||||
item.value = { ...item.value, completed: res.completed, status: res.status }
|
||||
uni.showToast({
|
||||
title: wasCompleted ? '已标为待办' : '已标记完成',
|
||||
title: wasCompleted ? '已反审核' : '已标记完成',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
// request 封装已弹出服务端错误提示
|
||||
}
|
||||
}
|
||||
|
||||
function onDelete() {
|
||||
const summary = (item.value?.content || '').split('\n')[0] || '该日程'
|
||||
const summary = item.value?.title || '该日程'
|
||||
uni.showModal({
|
||||
title: '删除日程',
|
||||
content: `确定删除「${summary}」吗?`,
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deleteSchedule(scheduleId.value)
|
||||
await deleteOaSchedule(scheduleId.value)
|
||||
uni.showToast({ title: '已删除', icon: 'success' })
|
||||
setTimeout(() => uni.navigateBack(), 400)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
// request 封装已弹出服务端错误提示
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -173,27 +287,45 @@ function onDelete() {
|
||||
padding: 32rpx 28rpx;
|
||||
}
|
||||
|
||||
.content-block {
|
||||
.head-block {
|
||||
padding-bottom: 24rpx;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
display: block;
|
||||
margin-bottom: 12rpx;
|
||||
.head-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.head-text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 30rpx;
|
||||
color: $color-text;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
|
||||
&.done {
|
||||
color: $color-text-muted;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
}
|
||||
|
||||
.content-header {
|
||||
.head-tags {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12rpx;
|
||||
gap: 10rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.content-text {
|
||||
.head-extra {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
color: $color-text;
|
||||
margin-top: 12rpx;
|
||||
font-size: 28rpx;
|
||||
color: $color-text-secondary;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
@@ -209,10 +341,6 @@ function onDelete() {
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.channel-row {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 26rpx;
|
||||
color: $color-text-muted;
|
||||
@@ -223,18 +351,54 @@ function onDelete() {
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
text-align: right;
|
||||
|
||||
&.muted {
|
||||
color: $color-text-muted;
|
||||
}
|
||||
}
|
||||
|
||||
.channel-tags {
|
||||
.image-block {
|
||||
padding: 20rpx 0;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.image-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.image-hint {
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
gap: 10rpx;
|
||||
flex: 1;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
border-radius: $radius-md;
|
||||
background: $color-bg-page;
|
||||
}
|
||||
|
||||
.image-add {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
border: 1rpx dashed $color-border;
|
||||
border-radius: $radius-md;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6rpx;
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
|
||||
&:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-row {
|
||||
|
||||
@@ -7,20 +7,18 @@
|
||||
|
||||
<view class="form-card" :class="{ 'is-disabled': isCompleted }">
|
||||
<view class="field">
|
||||
<text class="field-label">日程内容 <text class="required">*</text></text>
|
||||
<u-textarea
|
||||
v-model="form.content"
|
||||
placeholder="输入日程内容,支持多行"
|
||||
:maxlength="1000"
|
||||
count
|
||||
height="120"
|
||||
<text class="field-label">标题 <text class="required">*</text></text>
|
||||
<u-input
|
||||
v-model="form.title"
|
||||
placeholder="输入日程标题"
|
||||
:maxlength="80"
|
||||
border="none"
|
||||
:disabled="isCompleted"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">发生日期 <text class="required">*</text></text>
|
||||
<text class="field-label">日期 <text class="required">*</text></text>
|
||||
<picker mode="date" :value="form.date" @change="onDateChange" :disabled="isCompleted">
|
||||
<view class="picker-value">
|
||||
<text>{{ form.date || '选择日期' }}</text>
|
||||
@@ -29,65 +27,60 @@
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">发生时间 <text class="required">*</text></text>
|
||||
<picker mode="time" :value="form.time" @change="onTimeChange" :disabled="isCompleted">
|
||||
<view class="field switch-field">
|
||||
<view class="switch-info">
|
||||
<text class="field-label">全天</text>
|
||||
<text class="form-tip">开启后无需填写起止时间</text>
|
||||
</view>
|
||||
<u-switch
|
||||
v-model="form.allDay"
|
||||
active-color="#2563eb"
|
||||
size="22"
|
||||
:disabled="isCompleted"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view v-if="!form.allDay" class="field">
|
||||
<text class="field-label">开始时间 <text class="required">*</text></text>
|
||||
<picker mode="time" :value="form.startTime" @change="onStartTimeChange" :disabled="isCompleted">
|
||||
<view class="picker-value">
|
||||
<text>{{ form.time || '选择时间' }}</text>
|
||||
<text>{{ form.startTime || '选择开始时间' }}</text>
|
||||
<FaIcon name="clock" color="#909399" :size="16" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">提醒渠道</text>
|
||||
<text class="field-hint">可多选,接入接口后按渠道下发提醒</text>
|
||||
<view class="channel-grid">
|
||||
<u-tag
|
||||
v-for="channel in channelOptions"
|
||||
:key="channel.value"
|
||||
:text="channel.label"
|
||||
:name="channel.value"
|
||||
:type="isChannelActive(channel.value) ? 'primary' : 'info'"
|
||||
:plain="!isChannelActive(channel.value)"
|
||||
size="medium"
|
||||
@click="onChannelTap"
|
||||
/>
|
||||
</view>
|
||||
<view v-if="!form.allDay" class="field">
|
||||
<text class="field-label">结束时间</text>
|
||||
<picker mode="time" :value="form.endTime" @change="onEndTimeChange" :disabled="isCompleted">
|
||||
<view class="picker-value">
|
||||
<text>{{ form.endTime || '选填,不填则只记开始时间' }}</text>
|
||||
<FaIcon name="clock" color="#909399" :size="16" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="field picker-field">
|
||||
<text class="field-label">提前提醒时间</text>
|
||||
<picker :range="remindLabels" :value="remindIndex" @change="onRemindChange" :disabled="isCompleted">
|
||||
<text class="field-label">优先级</text>
|
||||
<picker :range="priorityLabels" :value="priorityIndex" @change="onPriorityChange" :disabled="isCompleted">
|
||||
<view class="picker-value">
|
||||
<text>{{ remindLabels[remindIndex] }}</text>
|
||||
<FaIcon name="bell" color="#909399" :size="16" />
|
||||
<text>{{ priorityLabels[priorityIndex] }}</text>
|
||||
<FaIcon name="flag" color="#909399" :size="16" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">重复提醒间隔(分钟)</text>
|
||||
<u-number-box
|
||||
v-model="form.repeatIntervalMinutes"
|
||||
:min="0"
|
||||
:max="1440"
|
||||
integer
|
||||
<text class="field-label">内容</text>
|
||||
<u-textarea
|
||||
v-model="form.content"
|
||||
placeholder="补充日程详细内容(选填)"
|
||||
:maxlength="1000"
|
||||
count
|
||||
height="120"
|
||||
border="none"
|
||||
:disabled="isCompleted"
|
||||
/>
|
||||
<text class="form-tip">0表示不重复,仅发送一次</text>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">最多提醒次数</text>
|
||||
<u-number-box
|
||||
v-model="form.maxSendCount"
|
||||
:min="1"
|
||||
:max="100"
|
||||
integer
|
||||
:disabled="isCompleted"
|
||||
/>
|
||||
<text class="form-tip">最多发送的提醒次数</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -109,40 +102,36 @@
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import {
|
||||
getSchedule,
|
||||
createSchedule,
|
||||
updateSchedule,
|
||||
REMIND_CHANNEL_OPTIONS,
|
||||
REMIND_MINUTES_OPTIONS
|
||||
} from '@/api/schedule.js'
|
||||
import { formatDate, pad } from '@/utils/date.js'
|
||||
getOaSchedule,
|
||||
createOaSchedule,
|
||||
updateOaSchedule,
|
||||
OA_SCHEDULE_PRIORITY_OPTIONS
|
||||
} from '@/api/oaSchedule.js'
|
||||
import { formatDate } from '@/utils/date.js'
|
||||
|
||||
const scheduleId = ref('')
|
||||
const saving = ref(false)
|
||||
const isCompleted = ref(false)
|
||||
const channelOptions = REMIND_CHANNEL_OPTIONS
|
||||
const remindOptions = REMIND_MINUTES_OPTIONS
|
||||
const remindLabels = remindOptions.map(item => item.label)
|
||||
const priorityOptions = OA_SCHEDULE_PRIORITY_OPTIONS
|
||||
const priorityLabels = priorityOptions.map(item => item.label)
|
||||
|
||||
const form = reactive({
|
||||
title: '',
|
||||
content: '',
|
||||
date: '',
|
||||
time: '',
|
||||
remindChannels: ['app'],
|
||||
remindMinutes: 0,
|
||||
repeatIntervalMinutes: 0,
|
||||
maxSendCount: 1
|
||||
allDay: true,
|
||||
startTime: '09:00',
|
||||
endTime: '',
|
||||
priority: 0
|
||||
})
|
||||
|
||||
const remindIndex = computed(() => {
|
||||
const index = remindOptions.findIndex(item => item.value === form.remindMinutes)
|
||||
return index >= 0 ? index : 3
|
||||
const priorityIndex = computed(() => {
|
||||
const index = priorityOptions.findIndex(item => item.value === Number(form.priority))
|
||||
return index >= 0 ? index : 0
|
||||
})
|
||||
|
||||
onLoad(async (query) => {
|
||||
const now = new Date()
|
||||
form.date = formatDate(now)
|
||||
form.time = `${pad(now.getHours())}:${pad(now.getMinutes())}`
|
||||
form.date = formatDate(new Date())
|
||||
|
||||
if (query?.id) {
|
||||
scheduleId.value = query.id
|
||||
@@ -155,105 +144,86 @@ onLoad(async (query) => {
|
||||
|
||||
async function loadSchedule(id) {
|
||||
try {
|
||||
const item = await getSchedule(id)
|
||||
const item = await getOaSchedule(id)
|
||||
if (!item) {
|
||||
uni.showToast({ title: '日程不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
return
|
||||
}
|
||||
const d = new Date(item.datetime)
|
||||
form.title = item.title || ''
|
||||
form.content = item.content || ''
|
||||
form.date = formatDate(d)
|
||||
form.time = `${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
form.remindChannels = [...(item.remindChannels || [])]
|
||||
form.remindMinutes = item.remindMinutes ?? 0
|
||||
form.repeatIntervalMinutes = item.repeatIntervalMinutes ?? 0
|
||||
form.maxSendCount = item.maxSendCount ?? 1
|
||||
form.date = item.schedule_date || formatDate(new Date())
|
||||
form.allDay = !!item.allDay
|
||||
form.startTime = item.start_time || '09:00'
|
||||
form.endTime = item.end_time || ''
|
||||
form.priority = Number(item.priority) || 0
|
||||
isCompleted.value = !!item.completed
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
/** 渠道是否已选中 */
|
||||
function isChannelActive(value) {
|
||||
return form.remindChannels.includes(value)
|
||||
}
|
||||
|
||||
function onChannelTap(name) {
|
||||
if (isCompleted.value) return
|
||||
const index = form.remindChannels.indexOf(name)
|
||||
if (index >= 0) {
|
||||
form.remindChannels.splice(index, 1)
|
||||
} else {
|
||||
form.remindChannels.push(name)
|
||||
}
|
||||
}
|
||||
|
||||
function onDateChange(e) {
|
||||
form.date = e.detail.value
|
||||
}
|
||||
|
||||
function onTimeChange(e) {
|
||||
form.time = e.detail.value
|
||||
function onStartTimeChange(e) {
|
||||
form.startTime = e.detail.value
|
||||
}
|
||||
|
||||
function onRemindChange(e) {
|
||||
function onEndTimeChange(e) {
|
||||
form.endTime = e.detail.value
|
||||
}
|
||||
|
||||
function onPriorityChange(e) {
|
||||
const index = Number(e.detail.value)
|
||||
form.remindMinutes = remindOptions[index].value
|
||||
}
|
||||
|
||||
function buildDatetime() {
|
||||
const [year, month, day] = form.date.split('-').map(Number)
|
||||
const [hour, minute] = form.time.split(':').map(Number)
|
||||
return new Date(year, month - 1, day, hour, minute).getTime()
|
||||
form.priority = priorityOptions[index].value
|
||||
}
|
||||
|
||||
async function onSave() {
|
||||
if (saving.value) return
|
||||
if (!form.content.trim()) {
|
||||
uni.showToast({ title: '请输入日程内容', icon: 'none' })
|
||||
if (!form.title.trim()) {
|
||||
uni.showToast({ title: '请输入日程标题', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.date || !form.time) {
|
||||
uni.showToast({ title: '请选择发生时间', icon: 'none' })
|
||||
if (!form.date) {
|
||||
uni.showToast({ title: '请选择日期', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const datetime = buildDatetime()
|
||||
if (datetime < Date.now() - 60000 && !scheduleId.value) {
|
||||
uni.showModal({
|
||||
title: '时间提示',
|
||||
content: '发生时间已过去,仍要保存吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) await saveData(datetime)
|
||||
}
|
||||
})
|
||||
return
|
||||
if (!form.allDay) {
|
||||
if (!form.startTime) {
|
||||
uni.showToast({ title: '请选择开始时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (form.endTime && form.endTime <= form.startTime) {
|
||||
uni.showToast({ title: '结束时间需晚于开始时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
}
|
||||
await saveData(datetime)
|
||||
await saveData()
|
||||
}
|
||||
|
||||
async function saveData(datetime) {
|
||||
async function saveData() {
|
||||
saving.value = true
|
||||
const payload = {
|
||||
title: form.title.trim(),
|
||||
content: form.content,
|
||||
datetime,
|
||||
remindChannels: [...form.remindChannels],
|
||||
remindMinutes: form.remindMinutes,
|
||||
repeatIntervalMinutes: form.repeatIntervalMinutes,
|
||||
maxSendCount: form.maxSendCount
|
||||
scheduleDate: form.date,
|
||||
allDay: form.allDay,
|
||||
startTime: form.startTime,
|
||||
endTime: form.endTime,
|
||||
priority: form.priority
|
||||
}
|
||||
try {
|
||||
if (scheduleId.value) {
|
||||
await updateSchedule(scheduleId.value, payload)
|
||||
await updateOaSchedule(scheduleId.value, payload)
|
||||
} else {
|
||||
await createSchedule(payload)
|
||||
await createOaSchedule(payload)
|
||||
}
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => uni.navigateBack(), 400)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
// request 封装已弹出服务端错误提示
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
@@ -308,17 +278,28 @@ async function saveData(datetime) {
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.field-hint {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.required {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.switch-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.switch-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
margin-bottom: 4rpx;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -331,12 +312,6 @@ async function saveData(datetime) {
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.channel-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
|
||||
@@ -91,42 +91,31 @@
|
||||
>
|
||||
<view class="sched-main" @tap="openDetail(item.id)">
|
||||
<view class="sched-left">
|
||||
<text class="sched-day">{{ dayLabel(item.datetime) }}</text>
|
||||
<text class="sched-time">{{ timeText(item.datetime) }}</text>
|
||||
</view>
|
||||
<view class="sched-sep" />
|
||||
<view class="sched-right">
|
||||
<view class="sched-title-row">
|
||||
<text class="sched-content">{{ item.content || item.title }}</text>
|
||||
<view class="status-chip" :class="item.completed ? 'done' : 'pending'">
|
||||
<text>{{ item.completed ? '已完成' : '待办' }}</text>
|
||||
<text class="sched-day">{{ dayLabel(item.timestamp) }}</text>
|
||||
<text class="sched-time">{{ timeRangeText(item) }}</text>
|
||||
</view>
|
||||
<view class="sched-sep" />
|
||||
<view class="sched-right">
|
||||
<view class="sched-title-row">
|
||||
<text class="sched-content">{{ item.title }}</text>
|
||||
<view class="status-chip" :class="item.completed ? 'done' : 'pending'">
|
||||
<text>{{ item.completed ? '已完成' : '待办' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="item.priority > 0 || item.reminder_id > 0" class="sched-meta">
|
||||
<text
|
||||
v-if="item.priority > 0"
|
||||
class="priority-tag"
|
||||
:class="item.priority === 2 ? 'urgent' : 'important'"
|
||||
>{{ item.priority === 2 ? '紧急' : '重要' }}</text>
|
||||
<FaIcon v-if="item.reminder_id > 0" name="bell" color="#94a3b8" :size="11" />
|
||||
<text v-if="item.reminder_id > 0">已设提醒</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="item.remindChannels.length" class="sched-meta">
|
||||
<FaIcon name="bell" color="#94a3b8" :size="11" />
|
||||
<text>{{ getRemindMinutesLabel(item.remindMinutes) }}</text>
|
||||
<text v-if="item.repeatIntervalMinutes > 0">· 每 {{ item.repeatIntervalMinutes }} 分钟</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="action-row">
|
||||
<view class="action-btn" @tap="onToggleComplete(item)">
|
||||
<FaIcon :name="item.completed ? 'rotate-left' : 'check'" color="#8a94ad" :size="12" />
|
||||
<text>{{ item.completed ? '标为待办' : '标记完成' }}</text>
|
||||
</view>
|
||||
<view class="action-btn" @tap="openEdit(item.id)">
|
||||
<FaIcon name="pen" color="#8a94ad" :size="12" />
|
||||
<text>编辑</text>
|
||||
</view>
|
||||
<view class="action-btn danger" @tap="onDelete(item)">
|
||||
<FaIcon name="trash" color="#f56c6c" :size="12" />
|
||||
<text>删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="bottom-space" />
|
||||
<view class="bottom-space" />
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -139,12 +128,7 @@
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import {
|
||||
fetchSchedules,
|
||||
deleteSchedule,
|
||||
toggleScheduleComplete,
|
||||
getRemindMinutesLabel
|
||||
} from '@/api/schedule.js'
|
||||
import { fetchOaSchedules } from '@/api/oaSchedule.js'
|
||||
import { pad, startOfDay, isToday, isTomorrow, dayLabel } from '@/utils/date.js'
|
||||
import { isLoggedIn } from '@/utils/auth.js'
|
||||
|
||||
@@ -209,22 +193,25 @@ const monthCells = computed(() => {
|
||||
|
||||
const gridCells = computed(() => (expanded.value ? monthCells.value : weekCells.value))
|
||||
|
||||
/** 日程按日期聚合,key 为 YYYY-MM-DD */
|
||||
/** 日程按日期聚合,key 为 YYYY-MM-DD(OA 日程的 schedule_date) */
|
||||
const dayMap = computed(() => {
|
||||
const map = {}
|
||||
schedules.value.forEach((item) => {
|
||||
if (!item.datetime) return
|
||||
const key = dateKey(new Date(item.datetime))
|
||||
if (!map[key]) map[key] = []
|
||||
map[key].push(item)
|
||||
if (!item.schedule_date) return
|
||||
if (!map[item.schedule_date]) map[item.schedule_date] = []
|
||||
map[item.schedule_date].push(item)
|
||||
})
|
||||
return map
|
||||
})
|
||||
|
||||
/** 选中日期的日程,按时间升序 */
|
||||
/** 选中日期的日程:全天在前,其余按开始时间升序 */
|
||||
const dayItems = computed(() => {
|
||||
const list = dayMap.value[selectedKey.value] || []
|
||||
return list.slice().sort((a, b) => a.datetime - b.datetime)
|
||||
return list.slice().sort((a, b) => {
|
||||
if (a.allDay !== b.allDay) return a.allDay ? -1 : 1
|
||||
const cmp = String(a.start_time || '').localeCompare(String(b.start_time || ''))
|
||||
return cmp !== 0 ? cmp : Number(b.id) - Number(a.id)
|
||||
})
|
||||
})
|
||||
|
||||
/** 本周(周一~周日)范围与日程数 */
|
||||
@@ -238,11 +225,11 @@ const weekRange = computed(() => {
|
||||
|
||||
const weekCount = computed(() => {
|
||||
const { start, end } = weekRange.value
|
||||
return schedules.value.filter((item) => {
|
||||
if (!item.datetime) return false
|
||||
const d = new Date(item.datetime)
|
||||
return d >= start && d < end
|
||||
}).length
|
||||
const startKey = dateKey(start)
|
||||
const endKey = dateKey(end)
|
||||
return schedules.value.filter(
|
||||
(item) => item.schedule_date >= startKey && item.schedule_date < endKey
|
||||
).length
|
||||
})
|
||||
|
||||
const heroRangeLabel = computed(() => {
|
||||
@@ -263,27 +250,44 @@ function dotCount(key) {
|
||||
return Math.min(3, (dayMap.value[key] || []).length)
|
||||
}
|
||||
|
||||
function timeText(timestamp) {
|
||||
const d = new Date(timestamp)
|
||||
return `${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
/** 时间展示:全天显示「全天」,其余显示开始时间或起止区间 */
|
||||
function timeRangeText(item) {
|
||||
if (item.allDay) return '全天'
|
||||
if (!item.start_time) return ''
|
||||
return item.end_time ? `${item.start_time} - ${item.end_time}` : item.start_time
|
||||
}
|
||||
|
||||
/** 数据加载区间:当前日历月前后各扩 7 天,覆盖周视图跨月格子 */
|
||||
function currentRange() {
|
||||
const year = monthCursor.value.getFullYear()
|
||||
const month = monthCursor.value.getMonth()
|
||||
const start = new Date(year, month, -6)
|
||||
const end = new Date(year, month + 1, 7)
|
||||
return { startDate: dateKey(start), endDate: dateKey(end) }
|
||||
}
|
||||
|
||||
function shiftMonth(step) {
|
||||
const cur = monthCursor.value
|
||||
monthCursor.value = new Date(cur.getFullYear(), cur.getMonth() + step, 1)
|
||||
loadSchedules()
|
||||
}
|
||||
|
||||
function goToday() {
|
||||
const now = new Date()
|
||||
monthCursor.value = new Date(now.getFullYear(), now.getMonth(), 1)
|
||||
selectedDate.value = startOfDay(now)
|
||||
loadSchedules()
|
||||
}
|
||||
|
||||
function pickDay(cell) {
|
||||
const monthChanged =
|
||||
cell.date.getFullYear() !== monthCursor.value.getFullYear() ||
|
||||
cell.date.getMonth() !== monthCursor.value.getMonth()
|
||||
selectedDate.value = startOfDay(cell.date)
|
||||
monthCursor.value = new Date(cell.date.getFullYear(), cell.date.getMonth(), 1)
|
||||
// 月历里选完日期后自动收回周栏
|
||||
if (expanded.value) expanded.value = false
|
||||
if (monthChanged) loadSchedules()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -301,8 +305,9 @@ onShow(() => {
|
||||
async function loadSchedules() {
|
||||
loading.value = true
|
||||
try {
|
||||
// 后端暂不支持按日期区间过滤,取最近一页在端上按月/按天聚合
|
||||
const res = await fetchSchedules({ pageSize: 100 })
|
||||
// OA 工作日程:按日历区间拉取(前后各扩 7 天),端上按天聚合
|
||||
const { startDate, endDate } = currentRange()
|
||||
const res = await fetchOaSchedules({ startDate, endDate, pageSize: 500 })
|
||||
schedules.value = res.list
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
@@ -318,42 +323,6 @@ function createSchedule() {
|
||||
function openDetail(id) {
|
||||
uni.navigateTo({ url: `/pages/tools/schedule/detail?id=${id}` })
|
||||
}
|
||||
|
||||
function openEdit(id) {
|
||||
uni.navigateTo({ url: `/pages/tools/schedule/edit?id=${id}` })
|
||||
}
|
||||
|
||||
async function onToggleComplete(item) {
|
||||
try {
|
||||
await toggleScheduleComplete(item.id)
|
||||
await loadSchedules()
|
||||
uni.showToast({
|
||||
title: item.completed ? '已标为待办' : '已标记完成',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
function onDelete(item) {
|
||||
uni.showModal({
|
||||
title: '删除日程',
|
||||
content: '删除后该日程及其提醒将一并移除,确定继续吗?',
|
||||
confirmText: '删除',
|
||||
cancelText: '取消',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deleteSchedule(item.id)
|
||||
uni.showToast({ title: '已删除', icon: 'none' })
|
||||
await loadSchedules()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -688,27 +657,19 @@ function onDelete(item) {
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.action-row {
|
||||
display: flex;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
.priority-tag {
|
||||
padding: 2rpx 12rpx;
|
||||
border-radius: $radius-full;
|
||||
font-size: 21rpx;
|
||||
|
||||
.action-btn {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
padding: 18rpx 0;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-secondary;
|
||||
|
||||
&:active {
|
||||
background: $color-bg-page;
|
||||
&.important {
|
||||
background: #fff7ed;
|
||||
color: #ea580c;
|
||||
}
|
||||
|
||||
&.danger {
|
||||
color: #f56c6c;
|
||||
&.urgent {
|
||||
background: #fef2f2;
|
||||
color: #dc2626;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ const NATIVE_RULES = [
|
||||
// 「日程提醒」与「工作日程」是两个独立功能:提醒在前,命中"提醒"后即不再落到日历页
|
||||
{ pattern: /提醒|reminder/i, route: '/pages/tools/schedule/reminder' },
|
||||
{ pattern: /工作日程|日程|日历|待办|calendar|schedule/i, route: '/pages/tools/schedule/index' },
|
||||
// 报销管理(注意放在日程规则之后即可,与日程关键词无冲突)
|
||||
{ pattern: /报销|reimburse|expense/i, route: '/pages/tools/expense/index' },
|
||||
// OA 协同办公
|
||||
{ pattern: /通知公告|公告|notice/i, route: '/pages/oa/notice/index' },
|
||||
{ pattern: /文档库|文档管理|文档图谱|document/i, route: '/pages/oa/document/index' },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* 子系统数据获取(共享逻辑)
|
||||
*
|
||||
* 三个子系统页面(概览 / 功能 / 待办)都需要:
|
||||
@@ -24,8 +24,15 @@ export function useSubsystem(slug) {
|
||||
// 用户自定义「常用功能」菜单 ID(有序);为空表示未自定义,前端回落默认
|
||||
const quickMenuIds = ref([])
|
||||
|
||||
/** 该子系统下所有菜单(含目录) */
|
||||
const allMenus = computed(() => menus.value.filter((m) => m.module === sub.module))
|
||||
/** 该子系统下所有菜单(含目录);小程序端不支持的功能在此隐藏 */
|
||||
const MP_HIDDEN_TITLES = ['文档图谱']
|
||||
const allMenus = computed(() =>
|
||||
menus.value.filter(
|
||||
(m) =>
|
||||
m.module === sub.module &&
|
||||
!MP_HIDDEN_TITLES.includes(String(m.title || '').trim())
|
||||
)
|
||||
)
|
||||
|
||||
/** 可直接跳转的叶子菜单,未开通/锁定的排除 */
|
||||
const leafMenus = computed(() =>
|
||||
|
||||
Reference in new issue
Block a user