273 lines
7.3 KiB
Vue
273 lines
7.3 KiB
Vue
<script setup lang="ts">
|
|
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<ContractItem[]>([])
|
|
const totalCount = ref(0)
|
|
const pageNum = ref(1)
|
|
const loadingList = ref(false)
|
|
const loadingMore = ref(false)
|
|
|
|
let keywordTimer: ReturnType<typeof setTimeout> | null = null
|
|
|
|
const hasMore = computed(() => contractList.value.length < totalCount.value)
|
|
const loadFinished = computed(() => !hasMore.value && contractList.value.length > 0)
|
|
|
|
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() {
|
|
navigateBackWithFallback('/pages/personal-center/index')
|
|
}
|
|
|
|
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)}`,
|
|
})
|
|
}
|
|
|
|
function handlePreview(item: ContractItem) {
|
|
openContractPreview(item.id)
|
|
}
|
|
|
|
function handleDownload(item: ContractItem) {
|
|
downloadContractPdf(item.id)
|
|
}
|
|
|
|
function handleSign(item: ContractItem) {
|
|
uni.navigateTo({
|
|
url: `/pages/contract-center/sign/index?id=${encodeURIComponent(item.id)}`,
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<view class="contract-center">
|
|
<view class="contract-center__header">
|
|
<view
|
|
class="contract-center__back"
|
|
@tap="handleBack"
|
|
>
|
|
<image
|
|
class="contract-center__back-icon"
|
|
src="/static/icons/icon-back.svg"
|
|
mode="aspectFit"
|
|
/>
|
|
</view>
|
|
<text class="contract-center__title">
|
|
合同中心
|
|
</text>
|
|
<view class="contract-center__header-placeholder" />
|
|
</view>
|
|
|
|
<view class="contract-center__toolbar">
|
|
<view class="contract-center__search">
|
|
<image
|
|
class="contract-center__search-icon"
|
|
src="/static/icons/icon-search.svg"
|
|
mode="aspectFit"
|
|
/>
|
|
<input
|
|
v-model="keyword"
|
|
class="contract-center__search-input"
|
|
placeholder="搜索合同编号、标题、项目..."
|
|
placeholder-class="contract-center__search-placeholder"
|
|
>
|
|
</view>
|
|
|
|
<view class="contract-center__tabs">
|
|
<view
|
|
v-for="tab in CONTRACT_TABS"
|
|
:key="tab.value"
|
|
class="contract-center__tab"
|
|
:class="{ 'contract-center__tab--active': activeTab === tab.value }"
|
|
@tap="activeTab = tab.value"
|
|
>
|
|
<text class="contract-center__tab-text">
|
|
{{ tab.label }}
|
|
</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<scroll-view
|
|
class="contract-center__scroll"
|
|
scroll-y
|
|
:show-scrollbar="false"
|
|
@scrolltolower="handleLoadMore"
|
|
>
|
|
<view class="contract-center__list">
|
|
<view
|
|
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"
|
|
>
|
|
<view class="contract-center__card-top">
|
|
<text class="contract-center__contract-no">
|
|
合同编号: {{ item.contractNo }}
|
|
</text>
|
|
<view class="contract-center__badges">
|
|
<text
|
|
v-for="badge in item.badges"
|
|
:key="badge.label"
|
|
class="contract-center__badge"
|
|
:class="badgeClass(badge.type)"
|
|
>
|
|
{{ badge.label }}
|
|
</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="contract-center__title-row">
|
|
<text class="contract-center__card-title">
|
|
{{ item.title }}
|
|
</text>
|
|
<text
|
|
class="contract-center__detail-link"
|
|
@tap="handleViewDetail(item)"
|
|
>
|
|
查看详情
|
|
</text>
|
|
</view>
|
|
|
|
<text class="contract-center__related">
|
|
{{ item.relatedLabel }}: {{ item.relatedValue }}
|
|
</text>
|
|
|
|
<view
|
|
class="contract-center__actions"
|
|
:class="{ 'contract-center__actions--single': !item.showDownload && !item.showSign }"
|
|
>
|
|
<view
|
|
class="contract-center__action-btn contract-center__action-btn--outline"
|
|
@tap="handlePreview(item)"
|
|
>
|
|
预览
|
|
</view>
|
|
<view
|
|
v-if="item.showDownload"
|
|
class="contract-center__action-btn contract-center__action-btn--outline"
|
|
@tap="handleDownload(item)"
|
|
>
|
|
下载
|
|
</view>
|
|
<view
|
|
v-if="item.showSign"
|
|
class="contract-center__action-btn contract-center__action-btn--primary"
|
|
@tap="handleSign(item)"
|
|
>
|
|
立即签署
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<LoadMoreFooter
|
|
:loading="loadingMore"
|
|
:has-more="hasMore"
|
|
:finished="loadFinished"
|
|
@load-more="handleLoadMore"
|
|
/>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
@import './index.scss';
|
|
</style>
|