Files
zkxw/mobile-h5/pages/oa/cc/index.vue
2026-08-13 16:50:36 +08:00

1052 lines
25 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="page">
<view class="page-head" :style="{ paddingTop: statusBarPx + 'px' }">
<view class="nav__inner">
<view class="nav__back" @click="goBack">
<view class="nav__back-ico" aria-hidden="true" />
</view>
<text class="nav__title">抄送我的</text>
</view>
<view class="toolbar">
<view class="toolbar-row">
<view class="search-box" :class="{ 'is-focus': searchFocused }">
<view class="search-ico" aria-hidden="true" />
<input
class="search-input"
:value="keyword"
confirm-type="search"
placeholder="搜索流程名称、申请人"
placeholder-class="search-ph"
@input="onSearchInput"
@confirm="onSearchConfirm"
@focus="searchFocused = true"
@blur="searchFocused = false"
/>
<view v-if="keyword" class="search-clear" @click="clearKeyword">
<text class="search-clear__x">×</text>
</view>
</view>
<view
class="manage-ico-btn"
:class="{ 'is-done': manageMode }"
@click="toggleManage"
>
<view
v-if="!manageMode"
class="manage-ico manage-ico--more"
aria-hidden="true"
>
<view class="manage-ico__dot" />
<view class="manage-ico__dot" />
<view class="manage-ico__dot" />
</view>
<view
v-else
class="manage-ico manage-ico--check"
aria-hidden="true"
/>
</view>
</view>
<scroll-view scroll-x class="tabs" :show-scrollbar="false">
<view class="tabs-inner">
<view
v-for="tab in readTabs"
:key="tab.value"
class="tab"
:class="{ active: readStatus === tab.value }"
@click="setReadStatus(tab.value)"
>
{{ tab.label }}
</view>
</view>
</scroll-view>
</view>
</view>
<view v-if="manageMode && selectedIds.length" class="batch-bar">
<text class="batch-bar__hint">已选 {{ selectedIds.length }} 项</text>
<view
class="batch-bar__btn oa-btn-loading"
:class="{
'is-disabled': batchReadDisabled && !batchMarking,
'is-loading': batchMarking
}"
@click="batchMarkRead"
>
<text class="oa-btn-loading__label">批量已读</text>
<view
v-if="batchMarking"
class="oa-btn-loading__spin"
aria-hidden="true"
/>
</view>
</view>
<view v-if="loading && !list.length" class="state state-loading">
<view class="pulse-dots" aria-hidden="true">
<view class="pulse-dot" />
<view class="pulse-dot" />
<view class="pulse-dot" />
</view>
<text class="state-loading__text">加载抄送…</text>
</view>
<view v-else-if="!list.length" class="oa-empty-wrap">
<VanEmpty
:description="keyword ? '未找到相关抄送' : '暂无抄送'"
:tip="
keyword
? '试试其他关键词,或清空搜索'
: '抄送给你的审批会出现在这里'
"
/>
</view>
<view v-else class="pending-list">
<view
v-for="(row, idx) in list"
:key="row.id"
class="cc-row"
:class="{ 'is-manage': manageMode, 'is-selected': isSelected(row.id) }"
>
<view
v-if="manageMode"
class="cc-check"
@click.stop="toggleSelect(row.id)"
>
<view class="cc-check__box" :class="{ on: isSelected(row.id) }">
<text v-if="isSelected(row.id)" class="cc-check__mark">✓</text>
</view>
</view>
<view
class="dd-card"
:class="{ 'is-unread': !row.isRead, 'is-selected': isSelected(row.id) }"
@click="onCardOpen(row)"
@longpress="onCardLongPress(row)"
>
<view class="dd-card__corner" aria-hidden="true">
<text class="dd-card__corner-num">{{ cornerIndex(idx) }}</text>
</view>
<view class="dd-card__head">
<view class="dd-card__title-wrap">
<view v-if="!row.isRead" class="dd-card__unread" />
<text class="dd-card__title">{{ cardTitle(row) }}</text>
</view>
<text class="dd-card__time">{{
formatRelativeTime(row.applyTime || row.createTime)
}}</text>
</view>
<view v-if="metaLines(row).length" class="dd-card__meta">
<text
v-for="(line, idx) in metaLines(row)"
:key="idx"
class="dd-card__meta-line"
>
{{ line }}
</text>
</view>
<view class="dd-card__foot">
<view class="dd-card__user">
<view class="dd-card__avatar">{{ avatarText(row) }}</view>
<text class="dd-card__user-text">{{ submitterText(row) }}</text>
</view>
<text
class="dd-card__status"
:class="'is-' + statusTone(row.instanceStatus)"
>
{{ statusText(row.instanceStatus) }}
</text>
</view>
</view>
</view>
<view v-if="loadingMore" class="oa-task-list__end">加载更多…</view>
<view v-else-if="!hasMore" class="oa-task-list__end">已经到底了</view>
</view>
</view>
</template>
<script>
import VanEmpty from '../../../components/van-empty/van-empty.vue'
import {
fetchBatchMarkOaCcTasksRead,
fetchMarkOaCcTaskRead,
fetchOaTasks
} from '../../../utils/oa-api.js'
import { forceRelogin, getToken } from '../../../utils/auth.js'
import { stashOaDetailTitle } from '../../../utils/oa-h5.js'
import { formatCornerIndex } from '../../../utils/oa-corner-index.js'
const PAGE_SIZE = 10
const STATUS_MAP = {
pending: '待处理',
running: '进行中',
approved: '已同意',
rejected: '已拒绝',
completed: '已完成',
cancelled: '已撤销',
done: '已结束',
returned: '已打回',
transferred: '已转交'
}
function pad2(n) {
return n < 10 ? '0' + n : String(n)
}
function parseDateTime(str) {
if (!str) return null
const s = String(str).trim().replace(/-/g, '/')
const d = new Date(s)
return Number.isNaN(d.getTime()) ? null : d
}
export default {
components: { VanEmpty },
data() {
return {
statusBarPx: 0,
keyword: '',
readStatus: 'unread',
searchFocused: false,
list: [],
page: 1,
total: 0,
loading: false,
loadingMore: false,
hasMore: true,
manageMode: false,
selectedIds: [],
openingId: '',
markingId: '',
batchMarking: false,
_searchTimer: null,
readTabs: [
{ value: 'all', label: '全部' },
{ value: 'read', label: '已读' },
{ value: 'unread', label: '未读' }
]
}
},
computed: {
batchReadDisabled() {
const ids = this.selectedIds || []
if (!ids.length) return true
return !this.list.some(
(r) => r && ids.indexOf(r.id) >= 0 && !r.isRead
)
}
},
onLoad() {
try {
const sys = uni.getSystemInfoSync() || {}
this.statusBarPx = Number(sys.statusBarHeight) || 0
} catch (_) {
this.statusBarPx = 0
}
},
onShow() {
if (!getToken()) {
forceRelogin('请先登录')
return
}
this.loadList(true)
},
onPullDownRefresh() {
this.loadList(true)
.catch(() => {})
.finally(() => {
uni.stopPullDownRefresh()
})
},
onReachBottom() {
if (!this.hasMore || this.loading || this.loadingMore) return
this.loadList(false)
},
onUnload() {
if (this._searchTimer) {
clearTimeout(this._searchTimer)
this._searchTimer = null
}
},
methods: {
goBack() {
uni.navigateBack({
fail: () => {
uni.reLaunch({ url: '/pages/index/index' })
}
})
},
cornerIndex(idx) {
return formatCornerIndex(Number(idx) + 1)
},
cardTitle(row) {
return (row && (row.appName || row.title)) || '-'
},
avatarText(row) {
const name = (row && row.initiatorUserName) || ''
if (!name) return '申'
return String(name).slice(0, 2)
},
submitterText(row) {
const name = (row && row.initiatorUserName) || ''
return name ? '由' + name + '提交' : '抄送'
},
statusText(s) {
if (!s) return '-'
return STATUS_MAP[s] || s
},
statusTone(s) {
if (s === 'pending' || s === 'running') return 'warn'
if (s === 'approved' || s === 'completed' || s === 'done') return 'success'
if (s === 'rejected' || s === 'cancelled' || s === 'returned') return 'danger'
return 'info'
},
metaLines(row) {
const lines = []
const fields = (row && row.previewFields) || []
for (let i = 0; i < fields.length && i < 3; i++) {
const f = fields[i] || {}
const label = String(f.label || '').trim() || '字段'
const value =
f.value != null && String(f.value).trim() !== ''
? String(f.value)
: '-'
lines.push(label + ':' + value)
}
return lines
},
formatRelativeTime(str) {
const d = parseDateTime(str)
if (!d) return str || '-'
const now = new Date()
const startToday = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate()
)
const startThat = new Date(d.getFullYear(), d.getMonth(), d.getDate())
const dayDiff = Math.round(
(startToday.getTime() - startThat.getTime()) / 86400000
)
if (dayDiff === 0) {
return pad2(d.getHours()) + ':' + pad2(d.getMinutes())
}
if (dayDiff === 1) return '昨天'
if (dayDiff === 2) return '前天'
if (dayDiff > 2 && dayDiff < 7) return dayDiff + '天前'
return (
d.getFullYear() +
'.' +
pad2(d.getMonth() + 1) +
'.' +
pad2(d.getDate())
)
},
isSelected(id) {
return this.selectedIds.indexOf(id) >= 0
},
_inputVal(e) {
if (e && e.detail && e.detail.value != null) return String(e.detail.value)
if (e && e.target) return String(e.target.value || '')
return ''
},
onSearchInput(e) {
this.keyword = this._inputVal(e)
if (this._searchTimer) clearTimeout(this._searchTimer)
this._searchTimer = setTimeout(() => {
this.loadList(true)
}, 400)
},
onSearchConfirm() {
if (this._searchTimer) {
clearTimeout(this._searchTimer)
this._searchTimer = null
}
this.loadList(true)
},
clearKeyword() {
this.keyword = ''
this.onSearchConfirm()
},
setReadStatus(value) {
if (this.readStatus === value) return
this.readStatus = value
this.loadList(true)
},
toggleManage() {
this.manageMode = !this.manageMode
if (!this.manageMode) this.selectedIds = []
},
toggleSelect(id) {
if (!id) return
const i = this.selectedIds.indexOf(id)
if (i >= 0) {
this.selectedIds = this.selectedIds.filter((x) => x !== id)
} else {
this.selectedIds = this.selectedIds.concat([id])
}
},
onCardOpen(row) {
if (this.manageMode) {
this.toggleSelect(row && row.id)
return
}
this.openView(row)
},
onCardLongPress(row) {
if (!row || this.manageMode) return
const itemList = []
if (!row.isRead) itemList.push('标记已读')
itemList.push('打印')
uni.showActionSheet({
itemList,
success: (res) => {
const tap = res && res.tapIndex
const label = itemList[tap]
if (label === '标记已读') this.markOneRead(row)
else if (label === '打印') this.openView(row, { autoPrint: true })
}
})
},
async markOneRead(row) {
if (!row || row.isRead || this.markingId) return
const taskId = String(row.id || '').trim()
if (!taskId) return
this.markingId = taskId
try {
await fetchMarkOaCcTaskRead(taskId)
uni.showToast({ title: '已标记已读', icon: 'success' })
await this.loadList(true)
} catch (e) {
uni.showToast({
title: (e && e.message) || '标记已读失败',
icon: 'none'
})
} finally {
this.markingId = ''
}
},
async batchMarkRead() {
if (this.batchReadDisabled || this.batchMarking) return
const selected = this.selectedIds || []
const ids = this.list
.filter((r) => r && selected.indexOf(r.id) >= 0 && !r.isRead)
.map((r) => String(r.id || '').trim())
.filter(Boolean)
if (!ids.length) return
this.batchMarking = true
try {
await fetchBatchMarkOaCcTasksRead(ids)
uni.showToast({ title: '已标记已读', icon: 'success' })
this.selectedIds = []
this.manageMode = false
await this.loadList(true)
} catch (e) {
uni.showToast({
title: (e && e.message) || '批量已读失败',
icon: 'none'
})
} finally {
this.batchMarking = false
}
},
async openView(row, opts) {
if (!row || this.openingId) return
const instanceId = String(row.instanceId || '').trim()
const taskId = String(row.id || '').trim()
if (!instanceId) {
uni.showToast({ title: '缺少实例 ID', icon: 'none' })
return
}
const autoPrint = !!(opts && opts.autoPrint)
this.openingId = taskId || instanceId
try {
if (taskId && !row.isRead) {
try {
await fetchMarkOaCcTaskRead(taskId)
row.isRead = true
} catch (e) {
uni.showToast({
title: (e && e.message) || '标记已读失败',
icon: 'none'
})
}
}
stashOaDetailTitle(row.appName || row.title)
uni.navigateTo({
url:
'/pages/oa/webview/index?instanceId=' +
encodeURIComponent(instanceId) +
'&mode=view' +
(autoPrint ? '&autoPrint=1' : '')
})
} finally {
this.openingId = ''
}
},
async loadList(reset) {
if (!getToken()) {
forceRelogin('请先登录')
return
}
const isReset = !!reset
if (isReset) {
this.page = 1
this.hasMore = true
this.loading = true
this.selectedIds = []
} else {
this.loadingMore = true
}
try {
const res = await fetchOaTasks('cc', {
keyword: (this.keyword || '').trim() || undefined,
readStatus: this.readStatus || 'unread',
page: this.page,
pageSize: PAGE_SIZE
})
const rows = (res && res.list) || []
const total = (res && res.total) != null ? Number(res.total) : 0
this.total = total
if (isReset) this.list = rows
else this.list = this.list.concat(rows)
const loaded = this.list.length
this.hasMore = loaded < total && rows.length > 0
if (rows.length > 0) this.page += 1
} catch (e) {
if (isReset) this.list = []
uni.showToast({
title: (e && e.message) || '加载失败',
icon: 'none'
})
} finally {
this.loading = false
this.loadingMore = false
}
}
}
}
</script>
<style scoped>
.page {
min-height: 100vh;
padding-bottom: 48rpx;
background: #f5f6f8;
box-sizing: border-box;
}
.page-head {
position: sticky;
top: 0;
z-index: 20;
background: #ecfdf5;
border-bottom: 1rpx solid #e8eeeb;
}
.nav__inner {
height: 88rpx;
display: flex;
align-items: center;
padding: 0 16rpx 0 8rpx;
position: relative;
box-sizing: border-box;
background: #ecfdf5;
}
.nav__back {
width: 72rpx;
height: 72rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.nav__back-ico {
width: 20rpx;
height: 20rpx;
border-left: 4rpx solid #0f291e;
border-bottom: 4rpx solid #0f291e;
transform: rotate(45deg);
margin-left: 8rpx;
box-sizing: border-box;
}
.nav__title {
position: absolute;
left: 50%;
transform: translateX(-50%);
font-size: 32rpx;
font-weight: 650;
color: #0f291e;
}
.toolbar {
background: #fff;
padding: 16rpx 24rpx 0;
box-sizing: border-box;
}
.toolbar-row {
display: flex;
align-items: center;
gap: 16rpx;
}
.search-box {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
gap: 16rpx;
height: 72rpx;
padding: 0 24rpx;
border-radius: 20rpx;
border: 1rpx solid #e8eaed;
background: #fafafa;
box-sizing: border-box;
transition:
border-color 0.15s,
background 0.15s,
box-shadow 0.15s;
}
.manage-ico-btn {
flex-shrink: 0;
width: 72rpx;
height: 72rpx;
border-radius: 20rpx;
border: 1rpx solid #c6f0dc;
background: #ecfdf5;
color: #166534;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.manage-ico-btn.is-done {
border-color: #e2e8f0;
background: #f8fafc;
color: #64748b;
}
.manage-ico-btn:active {
opacity: 0.72;
}
.manage-ico--more {
width: 34rpx;
height: 10rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.manage-ico__dot {
width: 8rpx;
height: 8rpx;
border-radius: 50%;
background: currentColor;
flex-shrink: 0;
}
.manage-ico--check {
width: 20rpx;
height: 12rpx;
border-left: 4rpx solid currentColor;
border-bottom: 4rpx solid currentColor;
transform: rotate(-45deg);
margin-top: -4rpx;
box-sizing: border-box;
}
.search-box.is-focus {
border-color: #cbd5e1;
background: #fff;
box-shadow: 0 0 0 6rpx rgba(148, 163, 184, 0.18);
}
.search-ico {
position: relative;
width: 26rpx;
height: 26rpx;
border: 3rpx solid #94a3b8;
border-radius: 50%;
box-sizing: border-box;
flex-shrink: 0;
}
.search-ico::after {
content: '';
position: absolute;
width: 12rpx;
height: 3rpx;
right: -8rpx;
bottom: -5rpx;
background: #94a3b8;
border-radius: 3rpx;
transform: rotate(45deg);
}
.search-input {
flex: 1;
height: 72rpx;
font-size: 28rpx;
color: #1f2937;
min-width: 0;
}
.search-ph {
color: #b0b7c3;
}
.search-clear {
display: flex;
align-items: center;
justify-content: center;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
background: #e5e7eb;
flex-shrink: 0;
}
.search-clear__x {
font-size: 28rpx;
line-height: 1;
color: #6b7280;
margin-top: -2rpx;
}
.tabs {
width: 100%;
white-space: nowrap;
margin-top: 8rpx;
padding: 0 8rpx;
box-sizing: border-box;
border-bottom: 1rpx solid #f1f5f9;
}
.tabs-inner {
display: inline-flex;
align-items: stretch;
padding: 0 8rpx;
}
.tab {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
height: 80rpx;
padding: 0 28rpx;
font-size: 28rpx;
color: #64748b;
flex-shrink: 0;
}
.tab.active {
color: #166534;
font-weight: 600;
}
.tab.active::after {
content: '';
position: absolute;
left: 28rpx;
right: 28rpx;
bottom: 0;
height: 4rpx;
border-radius: 4rpx 4rpx 0 0;
background: #22c55e;
}
.batch-bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
margin: 16rpx 24rpx 0;
padding: 20rpx 24rpx;
border-radius: 16rpx;
background: #fff;
border: 1rpx solid #e8eaed;
box-shadow: 0 4rpx 20rpx rgba(15, 23, 42, 0.04);
box-sizing: border-box;
}
.batch-bar__hint {
font-size: 26rpx;
color: #646a73;
}
.batch-bar__btn {
min-height: 64rpx;
padding: 0 28rpx;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 14rpx;
font-size: 26rpx;
font-weight: 600;
color: #fff;
background: #0a9f6d;
box-sizing: border-box;
}
.batch-bar__btn.is-disabled {
opacity: 0.45;
pointer-events: none;
}
.batch-bar__btn:active {
opacity: 0.78;
}
.pending-list {
padding: 20rpx 24rpx 0;
display: flex;
flex-direction: column;
gap: 20rpx;
box-sizing: border-box;
}
.cc-row {
display: flex;
align-items: center;
gap: 16rpx;
width: 100%;
box-sizing: border-box;
}
.cc-check {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.cc-check__box {
width: 40rpx;
height: 40rpx;
border-radius: 50%;
border: 2rpx solid #cbd5e1;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.cc-check__box.on {
border-color: #0a9f6d;
background: #0a9f6d;
}
.cc-check__mark {
font-size: 22rpx;
line-height: 1;
color: #fff;
font-weight: 700;
}
.dd-card {
flex: 1;
min-width: 0;
width: 100%;
background: #fff;
border-radius: 20rpx;
padding: 28rpx 28rpx 24rpx 84rpx;
box-sizing: border-box;
box-shadow: 0 4rpx 20rpx rgba(15, 23, 42, 0.04);
}
.dd-card:active {
opacity: 0.92;
}
.dd-card.is-selected {
box-shadow: 0 4rpx 20rpx rgba(10, 159, 109, 0.16);
outline: 2rpx solid rgba(10, 159, 109, 0.35);
}
.dd-card__head {
display: flex;
align-items: flex-start;
gap: 16rpx;
}
.dd-card__title-wrap {
flex: 1;
min-width: 0;
display: flex;
align-items: flex-start;
gap: 12rpx;
}
.dd-card__unread {
flex-shrink: 0;
width: 14rpx;
height: 14rpx;
margin-top: 12rpx;
border-radius: 50%;
background: #ef4444;
}
.dd-card__title {
flex: 1;
min-width: 0;
font-size: 30rpx;
font-weight: 700;
line-height: 1.4;
color: #1f2329;
}
.dd-card__time {
flex-shrink: 0;
font-size: 24rpx;
line-height: 1.4;
color: #8f959e;
padding-top: 4rpx;
}
.dd-card__meta {
margin-top: 16rpx;
display: flex;
flex-direction: column;
gap: 8rpx;
}
.dd-card__meta-line {
font-size: 26rpx;
line-height: 1.45;
color: #8f959e;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.dd-card__foot {
margin-top: 24rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.dd-card__user {
display: flex;
align-items: center;
gap: 12rpx;
min-width: 0;
}
.dd-card__avatar {
width: auto;
min-width: 52rpx;
height: 52rpx;
padding: 0 12rpx;
border-radius: 12rpx;
background: linear-gradient(145deg, #0a9f6d, #087f57);
color: #fff;
font-size: 24rpx;
font-weight: 700;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
box-sizing: border-box;
}
.dd-card__user-text {
font-size: 24rpx;
color: #646a73;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.dd-card__status {
flex-shrink: 0;
font-size: 24rpx;
font-weight: 600;
color: #d97706;
}
.dd-card__status.is-success {
color: #0a9f6d;
}
.dd-card__status.is-danger {
color: #ef4444;
}
.dd-card__status.is-info {
color: #64748b;
}
.state {
padding: 80rpx 24rpx;
text-align: center;
color: #999;
font-size: 28rpx;
}
.state-loading {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 28rpx;
min-height: 50vh;
padding: 96rpx 32rpx;
box-sizing: border-box;
}
.pulse-dots {
display: flex;
align-items: center;
gap: 16rpx;
}
.pulse-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: var(--brand-green, #22c55e);
animation: oa-pulse-bounce 1.2s ease-in-out infinite;
}
.pulse-dot:nth-child(2) {
animation-delay: 0.15s;
opacity: 0.75;
}
.pulse-dot:nth-child(3) {
animation-delay: 0.3s;
opacity: 0.55;
}
.state-loading__text {
font-size: 26rpx;
font-weight: 500;
color: var(--text-muted, #5f7a6d);
line-height: 1.4;
}
@keyframes oa-pulse-bounce {
0%,
80%,
100% {
transform: translateY(0);
}
40% {
transform: translateY(-12rpx);
}
}
</style>