feat:财务和合同

This commit is contained in:
李伊帆
2026-11-05 13:50:25 +08:00
parent b0a711f70a
commit 31fcd273f1
173 changed files with 11040 additions and 1067 deletions

View File

@@ -1,28 +1,85 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { CONTRACT_LIST, CONTRACT_TABS } from '@/constants/contract'
import { computed, ref, watch } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getContractPage } from '@/api/contract'
import { CONTRACT_PAGE_SIZE, CONTRACT_TABS } from '@/constants/contract'
import type { ContractItem, ContractTab } from '@/types/contract'
import { ensureLoggedIn } from '@/utils/auth-guard'
import { downloadContractPdf, openContractPreview } from '@/utils/contract-preview'
import { mapContractTabToSignStatus, mapContractVosToItems } from '@/utils/map-contract'
import { navigateBackWithFallback } from '@/utils/navigate-back'
import LoadMoreFooter from '../case-library/components/LoadMoreFooter.vue'
const keyword = ref('')
const activeTab = ref<ContractTab>('all')
const contractList = ref(CONTRACT_LIST.map(item => ({ ...item })))
const contractList = ref<ContractItem[]>([])
const totalCount = ref(0)
const pageNum = ref(1)
const loadingList = ref(false)
const loadingMore = ref(false)
const filteredContracts = computed(() => {
const text = keyword.value.trim()
let keywordTimer: ReturnType<typeof setTimeout> | null = null
return contractList.value.filter((item) => {
const matchTab = activeTab.value === 'all'
|| (activeTab.value === 'pending' && item.signStatus === 'pending')
|| (activeTab.value === 'signed' && item.signStatus === 'signed')
const matchKeyword = !text
|| item.title.includes(text)
|| item.type.includes(text)
|| item.contractNo.includes(text)
|| item.relatedValue.includes(text)
const hasMore = computed(() => contractList.value.length < totalCount.value)
const loadFinished = computed(() => !hasMore.value && contractList.value.length > 0)
return matchTab && matchKeyword
})
async function fetchContractList(reset = false) {
if (reset) {
pageNum.value = 1
contractList.value = []
}
if (loadingList.value || loadingMore.value)
return
if (reset)
loadingList.value = true
else
loadingMore.value = true
try {
const result = await getContractPage({
keyword: keyword.value.trim() || undefined,
signStatus: mapContractTabToSignStatus(activeTab.value),
pageNum: pageNum.value,
pageSize: CONTRACT_PAGE_SIZE,
})
const rows = result?.rows ?? []
const mapped = mapContractVosToItems(rows)
totalCount.value = Number(result?.total ?? 0)
contractList.value = reset
? mapped
: [...contractList.value, ...mapped]
}
catch {
if (reset) {
contractList.value = []
totalCount.value = 0
}
}
finally {
loadingList.value = false
loadingMore.value = false
}
}
watch(keyword, () => {
if (keywordTimer)
clearTimeout(keywordTimer)
keywordTimer = setTimeout(() => {
fetchContractList(true)
}, 400)
})
watch(activeTab, () => {
fetchContractList(true)
})
onShow(() => {
if (!ensureLoggedIn())
return
fetchContractList(true)
})
function handleBack() {
@@ -33,6 +90,13 @@ function badgeClass(type: ContractItem['badges'][number]['type']) {
return `contract-center__badge--${type}`
}
function handleLoadMore() {
if (!hasMore.value || loadingList.value || loadingMore.value)
return
pageNum.value += 1
fetchContractList(false)
}
function handleViewDetail(item: ContractItem) {
uni.navigateTo({
url: `/pages/contract-center/detail/index?id=${encodeURIComponent(item.id)}`,
@@ -40,11 +104,11 @@ function handleViewDetail(item: ContractItem) {
}
function handlePreview(item: ContractItem) {
uni.showToast({ title: `预览${item.contractNo}开发中`, icon: 'none' })
openContractPreview(item.id)
}
function handleDownload(item: ContractItem) {
uni.showToast({ title: `下载${item.contractNo}开发中`, icon: 'none' })
downloadContractPdf(item.id)
}
function handleSign(item: ContractItem) {
@@ -83,7 +147,7 @@ function handleSign(item: ContractItem) {
<input
v-model="keyword"
class="contract-center__search-input"
placeholder="搜索项目标题、类型..."
placeholder="搜索合同编号、标题、项目..."
placeholder-class="contract-center__search-placeholder"
>
</view>
@@ -107,10 +171,29 @@ function handleSign(item: ContractItem) {
class="contract-center__scroll"
scroll-y
:show-scrollbar="false"
@scrolltolower="handleLoadMore"
>
<view class="contract-center__list">
<view
v-for="item in filteredContracts"
v-if="loadingList && !contractList.length"
class="contract-center__empty"
>
<text class="contract-center__empty-text">
加载中...
</text>
</view>
<view
v-else-if="!contractList.length"
class="contract-center__empty"
>
<text class="contract-center__empty-text">
暂无合同
</text>
</view>
<view
v-for="item in contractList"
:key="item.id"
class="contract-center__card"
>
@@ -172,6 +255,13 @@ function handleSign(item: ContractItem) {
</view>
</view>
</view>
<LoadMoreFooter
:loading="loadingMore"
:has-more="hasMore"
:finished="loadFinished"
@load-more="handleLoadMore"
/>
</view>
</scroll-view>
</view>