feat:财务和合同
This commit is contained in:
@@ -40,6 +40,18 @@
|
||||
height: 64rpx;
|
||||
}
|
||||
|
||||
.contract-detail__loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 120rpx 24rpx;
|
||||
}
|
||||
|
||||
.contract-detail__loading-text {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.contract-detail__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { getContract } from '@/constants/contract'
|
||||
import { getContractDetail } from '@/api/contract'
|
||||
import type { ContractItem } from '@/types/contract'
|
||||
import pdfIcon from '@/static/icons/PDF.png'
|
||||
import { openContractPreview } from '@/utils/contract-preview'
|
||||
import { mapContractVoToItem } from '@/utils/map-contract'
|
||||
import { navigateBackWithFallback } from '@/utils/navigate-back'
|
||||
|
||||
const contract = ref<ContractItem | null>(null)
|
||||
const loading = ref(false)
|
||||
|
||||
const infoRows = [
|
||||
{ label: '合同名称', key: 'contractName' as const },
|
||||
@@ -19,15 +22,31 @@ const infoRows = [
|
||||
{ label: '合同状态', key: 'contractStatus' as const },
|
||||
]
|
||||
|
||||
onLoad((options) => {
|
||||
const rawId = options?.id
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : '1'
|
||||
contract.value = getContract(id)
|
||||
|
||||
if (!contract.value) {
|
||||
async function loadDetail(id: string) {
|
||||
if (!id) {
|
||||
uni.showToast({ title: '合同不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const vo = await getContractDetail(id)
|
||||
contract.value = mapContractVoToItem(vo)
|
||||
}
|
||||
catch {
|
||||
contract.value = null
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
const rawId = options?.id
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : ''
|
||||
loadDetail(id)
|
||||
})
|
||||
|
||||
function handleBack() {
|
||||
@@ -35,20 +54,23 @@ function handleBack() {
|
||||
}
|
||||
|
||||
function handleViewProject() {
|
||||
if (!contract.value)
|
||||
if (!contract.value?.projectId)
|
||||
return
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/project-center/detail/index?id=${encodeURIComponent(contract.value.projectId)}`,
|
||||
})
|
||||
}
|
||||
|
||||
function handlePreviewFile() {
|
||||
if (!contract.value?.id)
|
||||
return
|
||||
openContractPreview(contract.value.id)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view
|
||||
v-if="contract"
|
||||
class="contract-detail"
|
||||
>
|
||||
<view class="contract-detail">
|
||||
<view class="contract-detail__navbar">
|
||||
<view
|
||||
class="contract-detail__back"
|
||||
@@ -66,7 +88,17 @@ function handleViewProject() {
|
||||
<view class="contract-detail__navbar-placeholder" />
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-if="loading && !contract"
|
||||
class="contract-detail__loading"
|
||||
>
|
||||
<text class="contract-detail__loading-text">
|
||||
加载中...
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<scroll-view
|
||||
v-else-if="contract"
|
||||
class="contract-detail__scroll"
|
||||
scroll-y
|
||||
:show-scrollbar="false"
|
||||
@@ -92,7 +124,10 @@ function handleViewProject() {
|
||||
<text class="contract-detail__section-title">
|
||||
合同文件
|
||||
</text>
|
||||
<view class="contract-detail__file">
|
||||
<view
|
||||
class="contract-detail__file"
|
||||
@tap="handlePreviewFile"
|
||||
>
|
||||
<image
|
||||
class="contract-detail__file-icon"
|
||||
:src="pdfIcon"
|
||||
|
||||
@@ -227,3 +227,15 @@
|
||||
background: $color-primary;
|
||||
}
|
||||
}
|
||||
|
||||
.contract-center__empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 120rpx 24rpx;
|
||||
}
|
||||
|
||||
.contract-center__empty-text {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -79,6 +79,12 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sign-success__hero-time {
|
||||
margin-top: 12rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.sign-success__card {
|
||||
padding: 28rpx 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
@@ -148,6 +154,11 @@
|
||||
height: 200rpx;
|
||||
}
|
||||
|
||||
.sign-success__signature-empty {
|
||||
font-size: 24rpx;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.sign-success__footer {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
|
||||
@@ -5,13 +5,16 @@ import {
|
||||
CONTRACT_SIGN_PAYMENT_INFO,
|
||||
CONTRACT_SIGN_SIGNATURE_STORAGE_KEY,
|
||||
} from '@/constants/contract-sign'
|
||||
import { getContract } from '@/constants/contract'
|
||||
import { getContractDetail, getContractSignProgress } from '@/api/contract'
|
||||
import type { ContractItem } from '@/types/contract'
|
||||
import successIcon from '@/static/icons/icon-register-success.png'
|
||||
import { mapContractVoToItem } from '@/utils/map-contract'
|
||||
import { pickPartyBSignatureImg } from '@/utils/map-contract-sign'
|
||||
import { navigateBackWithFallback } from '@/utils/navigate-back'
|
||||
|
||||
const contract = ref<ContractItem | null>(null)
|
||||
const signaturePreview = ref('')
|
||||
const signedAt = ref('')
|
||||
|
||||
const paymentInfo = CONTRACT_SIGN_PAYMENT_INFO
|
||||
|
||||
@@ -21,10 +24,9 @@ const successSubtitle = computed(() => {
|
||||
return `您已成功签署《${contract.value.contractName}》`
|
||||
})
|
||||
|
||||
onLoad((options) => {
|
||||
onLoad(async (options) => {
|
||||
const rawId = options?.id
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : '2'
|
||||
contract.value = getContract(id)
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : ''
|
||||
|
||||
try {
|
||||
const stored = uni.getStorageSync(CONTRACT_SIGN_SIGNATURE_STORAGE_KEY)
|
||||
@@ -35,9 +37,30 @@ onLoad((options) => {
|
||||
// ignore storage read errors
|
||||
}
|
||||
|
||||
if (!contract.value) {
|
||||
if (!id) {
|
||||
uni.showToast({ title: '合同不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const [vo, progress] = await Promise.all([
|
||||
getContractDetail(id),
|
||||
getContractSignProgress(id).catch(() => null),
|
||||
])
|
||||
contract.value = mapContractVoToItem(vo)
|
||||
|
||||
const remoteSignature = pickPartyBSignatureImg(progress)
|
||||
if (remoteSignature)
|
||||
signaturePreview.value = remoteSignature
|
||||
|
||||
const partyB = progress?.parties?.find(item => item.signerType === 'PARTY_B')
|
||||
if (partyB?.signTime)
|
||||
signedAt.value = partyB.signTime.replace('T', ' ').slice(0, 19)
|
||||
}
|
||||
catch {
|
||||
contract.value = null
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -105,6 +128,12 @@ function handleViewDetail() {
|
||||
<text class="sign-success__hero-subtitle">
|
||||
{{ successSubtitle }}
|
||||
</text>
|
||||
<text
|
||||
v-if="signedAt"
|
||||
class="sign-success__hero-time"
|
||||
>
|
||||
签署时间:{{ signedAt }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view
|
||||
@@ -157,6 +186,12 @@ function handleViewDetail() {
|
||||
:src="signaturePreview"
|
||||
mode="aspectFit"
|
||||
/>
|
||||
<text
|
||||
v-else
|
||||
class="sign-success__signature-empty"
|
||||
>
|
||||
暂无签名图片
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -129,7 +129,7 @@ function handleClose() {
|
||||
class="signature-pad__action-btn"
|
||||
@tap="handleConfirm"
|
||||
>
|
||||
确认签署
|
||||
完成签名
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -142,12 +142,25 @@
|
||||
background: $color-bg-page;
|
||||
}
|
||||
|
||||
.contract-sign__body {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.8;
|
||||
.contract-sign__preview-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
padding: 28rpx 24rpx;
|
||||
background: #f8fafc;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.contract-sign__preview-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text-primary;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.contract-sign__preview-desc {
|
||||
font-size: 24rpx;
|
||||
color: $color-primary;
|
||||
}
|
||||
|
||||
.contract-sign__signature-row {
|
||||
@@ -168,7 +181,11 @@
|
||||
}
|
||||
|
||||
.contract-sign__signature-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 160rpx;
|
||||
overflow: hidden;
|
||||
background: #f3f4f6;
|
||||
border-radius: 12rpx;
|
||||
|
||||
@@ -178,6 +195,109 @@
|
||||
}
|
||||
}
|
||||
|
||||
.contract-sign__signature-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.contract-sign__form {
|
||||
margin-top: 36rpx;
|
||||
}
|
||||
|
||||
.contract-sign__field {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.contract-sign__field-label {
|
||||
display: block;
|
||||
margin-bottom: 12rpx;
|
||||
font-size: 26rpx;
|
||||
color: $color-text-primary;
|
||||
}
|
||||
|
||||
.contract-sign__input {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
padding: 0 24rpx;
|
||||
font-size: 28rpx;
|
||||
color: $color-text-primary;
|
||||
background: #f8fafc;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
border-radius: 12rpx;
|
||||
box-sizing: border-box;
|
||||
|
||||
&--code {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.contract-sign__placeholder {
|
||||
color: $color-text-placeholder;
|
||||
}
|
||||
|
||||
.contract-sign__code-row {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.contract-sign__code-btn {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 200rpx;
|
||||
height: 88rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 26rpx;
|
||||
color: $color-primary;
|
||||
background: #eff6ff;
|
||||
border-radius: 12rpx;
|
||||
|
||||
&--disabled {
|
||||
color: $color-text-secondary;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
}
|
||||
|
||||
.contract-sign__agreement {
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
align-items: flex-start;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.contract-sign__checkbox {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
margin-top: 4rpx;
|
||||
border: 2rpx solid #c5cdd8;
|
||||
border-radius: 50%;
|
||||
|
||||
&--checked {
|
||||
background: $color-primary;
|
||||
border-color: $color-primary;
|
||||
}
|
||||
}
|
||||
|
||||
.contract-sign__checkmark {
|
||||
font-size: 20rpx;
|
||||
line-height: 1;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.contract-sign__agreement-text {
|
||||
flex: 1;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.5;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
|
||||
.contract-sign__footer {
|
||||
flex-shrink: 0;
|
||||
padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
|
||||
@@ -195,4 +315,8 @@
|
||||
color: #ffffff;
|
||||
background: $color-primary;
|
||||
border-radius: 12rpx;
|
||||
|
||||
&--disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,97 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { computed, onUnmounted, ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import {
|
||||
CONTRACT_SIGN_BODY,
|
||||
CONTRACT_SIGN_SIGNATURE_STORAGE_KEY,
|
||||
CONTRACT_SIGN_STEPS,
|
||||
} from '@/constants/contract-sign'
|
||||
import { getContract } from '@/constants/contract'
|
||||
confirmContractSign,
|
||||
getContractDetail,
|
||||
getContractPreview,
|
||||
getContractSignProgress,
|
||||
initContractSign,
|
||||
sendContractSignSmsCode,
|
||||
} from '@/api/contract'
|
||||
import { uploadRequirementAttachment } from '@/api/requirement'
|
||||
import { CONTRACT_SIGN_SIGNATURE_STORAGE_KEY } from '@/constants/contract-sign'
|
||||
import type { ContractItem } from '@/types/contract'
|
||||
import type { ContractSignProgressVo } from '@/types/contract-api'
|
||||
import { getLoginPhoneNumber } from '@/utils/auth-storage'
|
||||
import { openContractPreview } from '@/utils/contract-preview'
|
||||
import { mapContractVoToItem } from '@/utils/map-contract'
|
||||
import {
|
||||
mapContractSignStatusLabel,
|
||||
mapContractSignSteps,
|
||||
pickPartyBSignId,
|
||||
} from '@/utils/map-contract-sign'
|
||||
import { navigateBackWithFallback } from '@/utils/navigate-back'
|
||||
import { validatePhone } from '@/utils/sms-code'
|
||||
import SignaturePad from './components/SignaturePad.vue'
|
||||
|
||||
const contract = ref<ContractItem | null>(null)
|
||||
const signSteps = CONTRACT_SIGN_STEPS
|
||||
const contractBody = CONTRACT_SIGN_BODY
|
||||
const progress = ref<ContractSignProgressVo | null>(null)
|
||||
const previewTitle = ref('')
|
||||
const previewReady = ref(false)
|
||||
const previewOpened = ref(false)
|
||||
const signaturePadVisible = ref(false)
|
||||
const partyBSignaturePreview = ref(false)
|
||||
const signatureLocalPath = ref('')
|
||||
const signaturePreview = ref(false)
|
||||
const agreed = ref(false)
|
||||
const mobile = ref('')
|
||||
const smsCode = ref('')
|
||||
const signId = ref('')
|
||||
const countdown = ref(0)
|
||||
const sendingCode = ref(false)
|
||||
const submitting = ref(false)
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
onLoad((options) => {
|
||||
const signSteps = computed(() => mapContractSignSteps(progress.value))
|
||||
const signStatusLabel = computed(() => mapContractSignStatusLabel(
|
||||
progress.value?.signStatus || (contract.value?.signStatus === 'signed' ? 'SIGNED' : 'PENDING'),
|
||||
))
|
||||
const alreadySigned = computed(() => progress.value?.signStatus === 'SIGNED')
|
||||
|
||||
onLoad(async (options) => {
|
||||
const rawId = options?.id
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : '2'
|
||||
contract.value = getContract(id)
|
||||
|
||||
if (!contract.value) {
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : ''
|
||||
if (!id) {
|
||||
uni.showToast({ title: '合同不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
return
|
||||
}
|
||||
|
||||
mobile.value = getLoginPhoneNumber()?.trim() || ''
|
||||
|
||||
try {
|
||||
const [vo, preview, signProgress] = await Promise.all([
|
||||
getContractDetail(id),
|
||||
getContractPreview(id),
|
||||
getContractSignProgress(id).catch(() => null),
|
||||
])
|
||||
contract.value = mapContractVoToItem(vo)
|
||||
previewTitle.value = preview.title || vo.title || '合同正文'
|
||||
previewReady.value = Boolean(preview.file)
|
||||
progress.value = signProgress
|
||||
const existingSignId = pickPartyBSignId(signProgress)
|
||||
if (existingSignId)
|
||||
signId.value = existingSignId
|
||||
|
||||
if (signProgress?.signStatus === 'SIGNED') {
|
||||
uni.showToast({ title: '合同已签署', icon: 'none' })
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: `/pages/contract-center/sign-success/index?id=${encodeURIComponent(id)}`,
|
||||
})
|
||||
}, 800)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
contract.value = null
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
})
|
||||
|
||||
@@ -32,7 +99,17 @@ function handleBack() {
|
||||
navigateBackWithFallback('/pages/contract-center/index')
|
||||
}
|
||||
|
||||
async function handleOpenFullContract() {
|
||||
if (!contract.value)
|
||||
return
|
||||
const result = await openContractPreview(contract.value.id)
|
||||
if (result)
|
||||
previewOpened.value = true
|
||||
}
|
||||
|
||||
function openSignaturePad() {
|
||||
if (alreadySigned.value)
|
||||
return
|
||||
signaturePadVisible.value = true
|
||||
}
|
||||
|
||||
@@ -40,25 +117,146 @@ function closeSignaturePad() {
|
||||
signaturePadVisible.value = false
|
||||
}
|
||||
|
||||
function handleSignConfirm(imagePath: string) {
|
||||
function handleSignatureConfirm(imagePath: string) {
|
||||
signatureLocalPath.value = imagePath
|
||||
signaturePreview.value = Boolean(imagePath)
|
||||
signaturePadVisible.value = false
|
||||
}
|
||||
|
||||
function startCountdown() {
|
||||
countdown.value = 60
|
||||
if (timer)
|
||||
clearInterval(timer)
|
||||
timer = setInterval(() => {
|
||||
countdown.value -= 1
|
||||
if (countdown.value <= 0 && timer) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
async function ensureSignInit() {
|
||||
if (!contract.value)
|
||||
throw new Error('合同不存在')
|
||||
if (signId.value)
|
||||
return signId.value
|
||||
|
||||
const mobileValue = mobile.value.trim()
|
||||
const id = await initContractSign(contract.value.id, {
|
||||
signType: 'sms',
|
||||
mobile: mobileValue,
|
||||
})
|
||||
signId.value = String(id)
|
||||
const latest = await getContractSignProgress(contract.value.id).catch(() => null)
|
||||
if (latest)
|
||||
progress.value = latest
|
||||
return signId.value
|
||||
}
|
||||
|
||||
async function handleSendCode() {
|
||||
if (!contract.value || countdown.value > 0 || sendingCode.value || alreadySigned.value)
|
||||
return
|
||||
|
||||
partyBSignaturePreview.value = true
|
||||
signaturePadVisible.value = false
|
||||
if (!validatePhone(mobile.value))
|
||||
return
|
||||
|
||||
if (imagePath) {
|
||||
try {
|
||||
uni.setStorageSync(CONTRACT_SIGN_SIGNATURE_STORAGE_KEY, imagePath)
|
||||
}
|
||||
catch {
|
||||
// ignore storage write errors
|
||||
}
|
||||
sendingCode.value = true
|
||||
try {
|
||||
await ensureSignInit()
|
||||
await sendContractSignSmsCode(contract.value.id, {
|
||||
mobile: mobile.value.trim(),
|
||||
})
|
||||
uni.showToast({ title: '验证码已发送', icon: 'none' })
|
||||
startCountdown()
|
||||
}
|
||||
catch {
|
||||
// request 统一提示
|
||||
}
|
||||
finally {
|
||||
sendingCode.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadSignatureUrl() {
|
||||
if (!signatureLocalPath.value)
|
||||
return ''
|
||||
|
||||
const uploaded = await uploadRequirementAttachment(signatureLocalPath.value)
|
||||
const url = uploaded.url?.trim() || ''
|
||||
if (!url)
|
||||
throw new Error('签名上传失败')
|
||||
if (url.length > 255)
|
||||
throw new Error('签名地址过长,请重试')
|
||||
return url
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!contract.value || submitting.value || alreadySigned.value)
|
||||
return
|
||||
|
||||
if (!previewReady.value) {
|
||||
uni.showToast({ title: '暂无合同文件,无法签署', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!previewOpened.value) {
|
||||
uni.showToast({ title: '请先查看完整合同', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!agreed.value) {
|
||||
uni.showToast({ title: '请勾选电子签服务协议', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!validatePhone(mobile.value))
|
||||
return
|
||||
if (!smsCode.value.trim()) {
|
||||
uni.showToast({ title: '请输入验证码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
uni.redirectTo({
|
||||
url: `/pages/contract-center/sign-success/index?id=${encodeURIComponent(contract.value.id)}`,
|
||||
})
|
||||
submitting.value = true
|
||||
uni.showLoading({ title: '签署中...', mask: true })
|
||||
try {
|
||||
const currentSignId = await ensureSignInit()
|
||||
let signatureImg = ''
|
||||
try {
|
||||
signatureImg = await uploadSignatureUrl()
|
||||
}
|
||||
catch (error) {
|
||||
const message = error instanceof Error ? error.message : '签名上传失败'
|
||||
uni.showToast({ title: message, icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (signatureLocalPath.value) {
|
||||
try {
|
||||
uni.setStorageSync(CONTRACT_SIGN_SIGNATURE_STORAGE_KEY, signatureLocalPath.value)
|
||||
}
|
||||
catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const result = await confirmContractSign(contract.value.id, {
|
||||
signId: currentSignId,
|
||||
code: smsCode.value.trim(),
|
||||
agreementFlag: true,
|
||||
signatureImg: signatureImg || undefined,
|
||||
signPosition: '乙方签字处',
|
||||
})
|
||||
progress.value = result
|
||||
|
||||
uni.redirectTo({
|
||||
url: `/pages/contract-center/sign-success/index?id=${encodeURIComponent(contract.value.id)}`,
|
||||
})
|
||||
}
|
||||
catch {
|
||||
// request 统一提示
|
||||
}
|
||||
finally {
|
||||
submitting.value = false
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -89,7 +287,7 @@ function handleSignConfirm(imagePath: string) {
|
||||
{{ contract.contractName }}
|
||||
</text>
|
||||
<text class="contract-sign__status">
|
||||
待签署
|
||||
{{ signStatusLabel }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
@@ -135,9 +333,17 @@ function handleSignConfirm(imagePath: string) {
|
||||
:show-scrollbar="false"
|
||||
>
|
||||
<view class="contract-sign__content">
|
||||
<text class="contract-sign__body">
|
||||
{{ contractBody }}
|
||||
</text>
|
||||
<view
|
||||
class="contract-sign__preview-card"
|
||||
@tap="handleOpenFullContract"
|
||||
>
|
||||
<text class="contract-sign__preview-title">
|
||||
{{ previewTitle || '合同正文' }}
|
||||
</text>
|
||||
<text class="contract-sign__preview-desc">
|
||||
{{ previewReady ? (previewOpened ? '已查看,可再次打开' : '点击查看完整合同(签署前必读)') : '暂无合同预览文件' }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view class="contract-sign__signature-row">
|
||||
<view class="contract-sign__signature-col">
|
||||
@@ -152,9 +358,77 @@ function handleSignConfirm(imagePath: string) {
|
||||
</text>
|
||||
<view
|
||||
class="contract-sign__signature-box"
|
||||
:class="{ 'contract-sign__signature-box--done': partyBSignaturePreview }"
|
||||
:class="{ 'contract-sign__signature-box--done': signaturePreview }"
|
||||
@tap="openSignaturePad"
|
||||
/>
|
||||
>
|
||||
<image
|
||||
v-if="signatureLocalPath"
|
||||
class="contract-sign__signature-image"
|
||||
:src="signatureLocalPath"
|
||||
mode="aspectFit"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="contract-sign__form">
|
||||
<view class="contract-sign__field">
|
||||
<text class="contract-sign__field-label">
|
||||
签署手机号
|
||||
</text>
|
||||
<input
|
||||
v-model="mobile"
|
||||
class="contract-sign__input"
|
||||
type="number"
|
||||
maxlength="11"
|
||||
placeholder="请输入注册手机号"
|
||||
placeholder-class="contract-sign__placeholder"
|
||||
:disabled="alreadySigned"
|
||||
>
|
||||
</view>
|
||||
|
||||
<view class="contract-sign__field">
|
||||
<text class="contract-sign__field-label">
|
||||
短信验证码
|
||||
</text>
|
||||
<view class="contract-sign__code-row">
|
||||
<input
|
||||
v-model="smsCode"
|
||||
class="contract-sign__input contract-sign__input--code"
|
||||
type="number"
|
||||
maxlength="6"
|
||||
placeholder="请输入验证码"
|
||||
placeholder-class="contract-sign__placeholder"
|
||||
:disabled="alreadySigned"
|
||||
>
|
||||
<view
|
||||
class="contract-sign__code-btn"
|
||||
:class="{ 'contract-sign__code-btn--disabled': countdown > 0 || sendingCode || alreadySigned }"
|
||||
@tap="handleSendCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
class="contract-sign__agreement"
|
||||
@tap="agreed = !agreed"
|
||||
>
|
||||
<view
|
||||
class="contract-sign__checkbox"
|
||||
:class="{ 'contract-sign__checkbox--checked': agreed }"
|
||||
>
|
||||
<text
|
||||
v-if="agreed"
|
||||
class="contract-sign__checkmark"
|
||||
>
|
||||
✓
|
||||
</text>
|
||||
</view>
|
||||
<text class="contract-sign__agreement-text">
|
||||
我已阅读并同意电子签服务协议,确认签署本合同
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -163,16 +437,17 @@ function handleSignConfirm(imagePath: string) {
|
||||
<view class="contract-sign__footer">
|
||||
<view
|
||||
class="contract-sign__submit-btn"
|
||||
@tap="openSignaturePad"
|
||||
:class="{ 'contract-sign__submit-btn--disabled': submitting || alreadySigned }"
|
||||
@tap="handleSubmit"
|
||||
>
|
||||
立即签署
|
||||
{{ alreadySigned ? '已签署' : '确认签署' }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<SignaturePad
|
||||
:visible="signaturePadVisible"
|
||||
@close="closeSignaturePad"
|
||||
@confirm="handleSignConfirm"
|
||||
@confirm="handleSignatureConfirm"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user