345 lines
9.9 KiB
Vue
345 lines
9.9 KiB
Vue
<template>
|
||
<view class="bx-page">
|
||
<view class="topbar" :style="safeAreaStyle">
|
||
<view class="topbar-left">
|
||
<text class="topbar-back" @click="goBack">←</text>
|
||
<text class="topbar-title">ETC/油卡充值申请</text>
|
||
</view>
|
||
<view class="topbar-right" />
|
||
</view>
|
||
|
||
<view class="fab-add" @click="goForm()">
|
||
<view class="fab-add__bar fab-add__bar--h" />
|
||
<view class="fab-add__bar fab-add__bar--v" />
|
||
</view>
|
||
|
||
<view class="search-wrap">
|
||
<view class="search-box">
|
||
<input
|
||
class="search-input"
|
||
v-model="keyword"
|
||
placeholder="搜索申请单号/车牌"
|
||
confirm-type="search"
|
||
@confirm="onRefresh"
|
||
/>
|
||
<view v-if="keyword.trim()" class="search-box__clear" @click="clearKeyword">×</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="search-wrap" style="padding-top: 0">
|
||
<scroll-view scroll-x class="search-filter-scroll" :show-scrollbar="false">
|
||
<view class="search-filter">
|
||
<view
|
||
v-for="tab in tabs"
|
||
:key="tab.value === '' ? '__all' : tab.value"
|
||
class="filter-tag"
|
||
:class="{ active: activeTab === tab.value }"
|
||
@click="onTabChange(tab.value)"
|
||
>
|
||
{{ tab.label }}
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
|
||
<scroll-view
|
||
class="page-padded list-scroll"
|
||
scroll-y
|
||
:style="{ height: listHeight }"
|
||
refresher-enabled
|
||
:refresher-triggered="refreshing"
|
||
@refresherrefresh="onPullRefresh"
|
||
@scrolltolower="onLoadMore"
|
||
>
|
||
<view v-if="!list.length && !loading" class="empty-state empty-state--fill">
|
||
<text>暂无充值申请</text>
|
||
</view>
|
||
|
||
<view
|
||
v-for="item in list"
|
||
:key="item.id"
|
||
class="expense-card"
|
||
@click="goForm(item.id)"
|
||
>
|
||
<view class="ec-top">
|
||
<view class="ec-type">
|
||
<text class="advance-list-card__title">{{ item.licensePlate || '—' }}</text>
|
||
</view>
|
||
<text class="status-tag" :class="statusTagClass(item.status)">
|
||
{{ statusLabel(item.status) }}
|
||
</text>
|
||
</view>
|
||
<view class="list-card-kv">
|
||
<view class="list-card-kv__row">
|
||
<text class="list-card-kv__k">申请单号</text>
|
||
<text class="list-card-kv__v">{{ item.applyNo || '—' }}</text>
|
||
</view>
|
||
<view class="list-card-kv__row">
|
||
<text class="list-card-kv__k">申请日期</text>
|
||
<text class="list-card-kv__v">{{ item.applyDate || '—' }}</text>
|
||
</view>
|
||
<view class="list-card-kv__row">
|
||
<text class="list-card-kv__k">申请人</text>
|
||
<text class="list-card-kv__v">{{ item.applicantName || '—' }}</text>
|
||
</view>
|
||
<view class="list-card-kv__row">
|
||
<text class="list-card-kv__k">充值类型</text>
|
||
<text class="list-card-kv__v">{{ typeLabel(item.rechargeType) }}</text>
|
||
</view>
|
||
<view class="list-card-kv__row">
|
||
<text class="list-card-kv__k">期初公里数</text>
|
||
<text class="list-card-kv__v">{{ item.odometerKm != null ? item.odometerKm : '—' }}</text>
|
||
</view>
|
||
<view v-if="item.remark" class="list-card-kv__row">
|
||
<text class="list-card-kv__k">备注</text>
|
||
<text class="list-card-kv__v">{{ item.remark }}</text>
|
||
</view>
|
||
</view>
|
||
<view class="ec-bottom" @click.stop>
|
||
<view class="op-actions">
|
||
<button class="btn btn-sm btn-ghost" @click="handleCopy(item)">复制发群</button>
|
||
<template v-if="canWrite(item)">
|
||
<button class="btn btn-sm btn-ghost" @click="handleSubmit(item)">提交</button>
|
||
<button class="btn btn-sm btn-primary" @click="goForm(item.id)">编辑</button>
|
||
<button class="btn btn-sm btn-danger" @click="handleCancel(item)">作废</button>
|
||
</template>
|
||
<template v-else-if="canWithdraw(item)">
|
||
<button class="btn btn-sm btn-ghost" @click="handleWithdraw(item)">撤回</button>
|
||
<button class="btn btn-sm btn-primary" @click="goForm(item.id)">查看</button>
|
||
</template>
|
||
<button v-else class="btn btn-sm btn-primary" @click="goForm(item.id)">查看</button>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view v-if="list.length" class="list-footer-tip">
|
||
{{ finished ? '没有更多了' : loading ? '加载中...' : '上拉加载更多' }}
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref } from 'vue'
|
||
import { onShow } from '@dcloudio/uni-app'
|
||
import { PAGE_PATHS } from '@/config/api'
|
||
import { vehicleRechargeApplyApi } from '@/api/pl'
|
||
import { useUserStore } from '@/stores/user'
|
||
import { getSafeAreaStyle } from '@/utils/safeArea'
|
||
import { copyVehicleRechargeApplyToClipboard } from '@/utils/plVehicleRechargeCopy'
|
||
|
||
const safeAreaStyle = getSafeAreaStyle()
|
||
const userStore = useUserStore()
|
||
|
||
const tabs = [
|
||
{ label: '全部', value: '' },
|
||
{ label: '草稿', value: 'draft' },
|
||
{ label: '审批中', value: 'in_approval' },
|
||
{ label: '已驳回', value: 'rejected' },
|
||
{ label: '已发放', value: 'disbursed' },
|
||
{ label: '已作废', value: 'cancelled' }
|
||
]
|
||
|
||
const keyword = ref('')
|
||
const activeTab = ref('')
|
||
const list = ref([])
|
||
const loading = ref(false)
|
||
const finished = ref(false)
|
||
const refreshing = ref(false)
|
||
const currentPage = ref(1)
|
||
const pageSize = 10
|
||
const listHeight = ref('60vh')
|
||
|
||
function currentUserId() {
|
||
const info = userStore.userInfo || {}
|
||
return String(info.id || info.userId || '')
|
||
}
|
||
|
||
function canWrite(item) {
|
||
if (!item) return false
|
||
if (!['draft', 'rejected'].includes(item.status)) return false
|
||
return String(item.applicantId || '') === currentUserId()
|
||
}
|
||
|
||
function canWithdraw(item) {
|
||
if (!item) return false
|
||
if (item.status !== 'in_approval') return false
|
||
return String(item.applicantId || '') === currentUserId()
|
||
}
|
||
|
||
function typeLabel(v) {
|
||
if (v === 'etc') return 'ETC'
|
||
if (v === 'fuel') return '油卡'
|
||
if (v === 'shanxia') return '山峡'
|
||
return v || '—'
|
||
}
|
||
|
||
function statusLabel(v) {
|
||
const map = {
|
||
draft: '草稿',
|
||
in_approval: '审批中',
|
||
rejected: '已驳回',
|
||
disbursed: '已发放',
|
||
cancelled: '已作废',
|
||
pending: '待发放'
|
||
}
|
||
return map[v] || v || '—'
|
||
}
|
||
|
||
function statusTagClass(v) {
|
||
if (v === 'draft') return 's-draft'
|
||
if (v === 'in_approval' || v === 'pending') return 's-pending'
|
||
if (v === 'rejected') return 's-rejected'
|
||
if (v === 'disbursed') return 's-approved'
|
||
if (v === 'cancelled') return 's-withdrawn'
|
||
return 's-draft'
|
||
}
|
||
|
||
function computeListHeight() {
|
||
try {
|
||
const sys = uni.getSystemInfoSync()
|
||
const h = (sys.windowHeight || 600) - 210
|
||
listHeight.value = `${Math.max(h, 320)}px`
|
||
} catch (e) {
|
||
listHeight.value = '60vh'
|
||
}
|
||
}
|
||
|
||
async function fetchPage() {
|
||
if (loading.value && !refreshing.value) return
|
||
loading.value = true
|
||
try {
|
||
const params = {
|
||
page: currentPage.value,
|
||
pageSize
|
||
}
|
||
if (activeTab.value) params.status = activeTab.value
|
||
if (keyword.value.trim()) params.q = keyword.value.trim()
|
||
const { items, total } = await vehicleRechargeApplyApi.list(params)
|
||
if (currentPage.value === 1) {
|
||
list.value = items
|
||
} else {
|
||
list.value = list.value.concat(items)
|
||
}
|
||
currentPage.value += 1
|
||
finished.value = items.length < pageSize || list.value.length >= total
|
||
} catch (e) {
|
||
finished.value = true
|
||
} finally {
|
||
loading.value = false
|
||
refreshing.value = false
|
||
}
|
||
}
|
||
|
||
function onRefresh() {
|
||
currentPage.value = 1
|
||
finished.value = false
|
||
loading.value = false
|
||
list.value = []
|
||
fetchPage()
|
||
}
|
||
|
||
function onPullRefresh() {
|
||
refreshing.value = true
|
||
currentPage.value = 1
|
||
finished.value = false
|
||
fetchPage()
|
||
}
|
||
|
||
function onLoadMore() {
|
||
if (finished.value || loading.value) return
|
||
fetchPage()
|
||
}
|
||
|
||
function onTabChange(value) {
|
||
activeTab.value = value
|
||
onRefresh()
|
||
}
|
||
|
||
function clearKeyword() {
|
||
keyword.value = ''
|
||
onRefresh()
|
||
}
|
||
|
||
function goBack() {
|
||
uni.navigateBack({ fail: () => uni.reLaunch({ url: PAGE_PATHS.workbench }) })
|
||
}
|
||
|
||
function goForm(id) {
|
||
const q = id ? `?id=${id}` : ''
|
||
uni.navigateTo({ url: `${PAGE_PATHS.plVehicleRechargeApplyForm}${q}` })
|
||
}
|
||
|
||
function handleCopy(item) {
|
||
copyVehicleRechargeApplyToClipboard(item)
|
||
}
|
||
|
||
function handleSubmit(item) {
|
||
uni.showModal({
|
||
title: '提交确认',
|
||
content: '确定提交该充值申请进入审批吗?',
|
||
confirmText: '提交',
|
||
success: async (res) => {
|
||
if (!res.confirm) return
|
||
try {
|
||
await vehicleRechargeApplyApi.submit(item.id)
|
||
uni.showToast({ title: '已提交', icon: 'success' })
|
||
onRefresh()
|
||
} catch (e) {
|
||
// toasted
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
function handleCancel(item) {
|
||
import('@/utils/prompt-cancel-reason').then(async ({ promptOptionalCancelReason }) => {
|
||
const reason = await promptOptionalCancelReason({
|
||
title: '作废确认',
|
||
content: '确定作废该充值申请吗?作废原因选填。'
|
||
})
|
||
if (reason === null) return
|
||
try {
|
||
await vehicleRechargeApplyApi.cancel(item.id, {
|
||
cancelReason: reason || undefined
|
||
})
|
||
uni.showToast({ title: '已作废', icon: 'success' })
|
||
onRefresh()
|
||
} catch (e) {
|
||
// toasted
|
||
}
|
||
})
|
||
}
|
||
|
||
function handleWithdraw(item) {
|
||
uni.showModal({
|
||
title: '撤回确认',
|
||
content: '确定撤回该充值申请?撤回后变为草稿,可修改后再提交。',
|
||
confirmText: '确定撤回',
|
||
success: async (res) => {
|
||
if (!res.confirm) return
|
||
try {
|
||
await vehicleRechargeApplyApi.withdraw(item.id)
|
||
uni.showToast({ title: '已撤回', icon: 'success' })
|
||
onRefresh()
|
||
} catch (e) {
|
||
// toasted by request layer
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
onShow(() => {
|
||
computeListHeight()
|
||
onRefresh()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import '@/styles/bx-theme.scss';
|
||
|
||
.list-scroll {
|
||
box-sizing: border-box;
|
||
}
|
||
</style>
|