feat:财务和合同
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { getProjectDetail, PAYMENT_PLAN_STATUS_LABEL } from '@/constants/project-detail'
|
||||
import type { PaymentPlanStatus } from '@/types/project-detail'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import { getContractsByProjectNo } from '@/api/contract'
|
||||
import { getRequirementDetail, withdrawRequirementAfterSale } from '@/api/requirement'
|
||||
import { PAYMENT_PLAN_STATUS_LABEL } from '@/constants/project-detail'
|
||||
import type { PaymentPlanStatus, ProjectFileItem } from '@/types/project-detail'
|
||||
import afterSalesIcon from '@/static/icons/售后.png'
|
||||
import cardBg from '@/static/icons/new-card.png'
|
||||
import deleteIcon from '@/static/icons/X.png'
|
||||
import type { ProjectDetail, ProjectDetailTab } from '@/types/project-detail'
|
||||
import { ensureLoggedIn } from '@/utils/auth-guard'
|
||||
import { openContractPreview } from '@/utils/contract-preview'
|
||||
import { mapContractVosToProjectFiles } from '@/utils/map-contract'
|
||||
import { navigateBackWithFallback } from '@/utils/navigate-back'
|
||||
import { mapProjectRequirementToDetail } from '@/utils/map-requirement-detail'
|
||||
|
||||
const detail = ref<ProjectDetail | null>(null)
|
||||
const requirementId = ref('')
|
||||
const loading = ref(true)
|
||||
const withdrawingAfterSale = ref(false)
|
||||
const activeTab = ref<ProjectDetailTab>('progress')
|
||||
|
||||
const tabs: Array<{ key: ProjectDetailTab, label: string }> = [
|
||||
@@ -19,19 +28,61 @@ const tabs: Array<{ key: ProjectDetailTab, label: string }> = [
|
||||
{ key: 'aftersales', label: '售后信息' },
|
||||
]
|
||||
|
||||
async function loadProjectContracts(projectNo?: string) {
|
||||
if (!detail.value || !projectNo)
|
||||
return
|
||||
|
||||
try {
|
||||
const rows = await getContractsByProjectNo(projectNo)
|
||||
detail.value.contractFiles = mapContractVosToProjectFiles(rows ?? [])
|
||||
}
|
||||
catch {
|
||||
detail.value.contractFiles = []
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetail(id: string) {
|
||||
loading.value = true
|
||||
uni.showLoading({ title: '加载中...', mask: true })
|
||||
|
||||
try {
|
||||
const data = await getRequirementDetail(id)
|
||||
detail.value = mapProjectRequirementToDetail(data)
|
||||
await loadProjectContracts(detail.value.projectNo)
|
||||
}
|
||||
catch {
|
||||
detail.value = null
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
setTimeout(() => {
|
||||
navigateBackWithFallback('/pages/project-center/index')
|
||||
}, 1500)
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
const rawId = options?.id
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : '1'
|
||||
const id = rawId ? decodeURIComponent(String(rawId)) : ''
|
||||
const tab = options?.tab ? decodeURIComponent(String(options.tab)) : ''
|
||||
detail.value = getProjectDetail(id)
|
||||
|
||||
if (tab === 'aftersales' || tab === 'progress' || tab === 'files' || tab === 'finance')
|
||||
activeTab.value = tab
|
||||
|
||||
if (!detail.value) {
|
||||
uni.showToast({ title: '项目不存在', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 1500)
|
||||
if (!id) {
|
||||
loading.value = false
|
||||
uni.showToast({ title: '参数错误', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
requirementId.value = id
|
||||
loadDetail(id)
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
ensureLoggedIn()
|
||||
})
|
||||
|
||||
function handleBack() {
|
||||
@@ -68,8 +119,72 @@ function handleApplyAfterSales() {
|
||||
})
|
||||
}
|
||||
|
||||
function handleOpenContractFile(file: ProjectFileItem) {
|
||||
if (file.contractId) {
|
||||
openContractPreview(file.contractId)
|
||||
return
|
||||
}
|
||||
if (file.url) {
|
||||
uni.downloadFile({
|
||||
url: file.url,
|
||||
success: (res) => {
|
||||
if (res.statusCode !== 200) {
|
||||
uni.showToast({ title: '打开失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.openDocument({
|
||||
filePath: res.tempFilePath,
|
||||
showMenu: true,
|
||||
fail: () => uni.showToast({ title: '无法打开文件', icon: 'none' }),
|
||||
})
|
||||
},
|
||||
fail: () => uni.showToast({ title: '打开失败', icon: 'none' }),
|
||||
})
|
||||
return
|
||||
}
|
||||
uni.showToast({ title: '暂无合同文件', icon: 'none' })
|
||||
}
|
||||
|
||||
function handleCancelAfterSales() {
|
||||
uni.showToast({ title: '取消售后功能开发中', icon: 'none' })
|
||||
if (!detail.value || !requirementId.value || withdrawingAfterSale.value)
|
||||
return
|
||||
|
||||
if (!ensureLoggedIn())
|
||||
return
|
||||
|
||||
if (!detail.value.afterSales.processing) {
|
||||
uni.showToast({ title: '当前没有进行中的售后申请', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '撤回售后',
|
||||
content: '确定要撤回当前售后申请吗?',
|
||||
confirmText: '撤回',
|
||||
cancelText: '取消',
|
||||
success: async (res) => {
|
||||
if (!res.confirm)
|
||||
return
|
||||
|
||||
withdrawingAfterSale.value = true
|
||||
uni.showLoading({ title: '提交中...', mask: true })
|
||||
|
||||
try {
|
||||
await withdrawRequirementAfterSale(requirementId.value, {
|
||||
reason: '用户撤回售后申请',
|
||||
})
|
||||
uni.showToast({ title: '已撤回售后申请', icon: 'success' })
|
||||
await loadDetail(requirementId.value)
|
||||
}
|
||||
catch {
|
||||
// request 层已 toast
|
||||
}
|
||||
finally {
|
||||
withdrawingAfterSale.value = false
|
||||
uni.hideLoading()
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleAddAfterSalesAttachment() {
|
||||
@@ -378,19 +493,16 @@ function handleAddAfterSalesAttachment() {
|
||||
<text class="project-detail__panel-title">
|
||||
合同文件
|
||||
</text>
|
||||
<view class="project-detail__files">
|
||||
<view
|
||||
v-if="detail.contractFiles.length"
|
||||
class="project-detail__files"
|
||||
>
|
||||
<view
|
||||
v-for="file in detail.contractFiles"
|
||||
:key="file.id"
|
||||
class="project-detail__file"
|
||||
@tap="handleOpenContractFile(file)"
|
||||
>
|
||||
<view class="project-detail__file-remove">
|
||||
<image
|
||||
class="project-detail__file-remove-icon"
|
||||
:src="deleteIcon"
|
||||
mode="aspectFit"
|
||||
/>
|
||||
</view>
|
||||
<image
|
||||
class="project-detail__file-icon"
|
||||
:src="file.icon"
|
||||
@@ -401,6 +513,12 @@ function handleAddAfterSalesAttachment() {
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<text
|
||||
v-else
|
||||
class="project-detail__empty-text"
|
||||
>
|
||||
暂无合同
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -509,8 +627,29 @@ function handleAddAfterSalesAttachment() {
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-else-if="!loading"
|
||||
class="project-detail project-detail--empty"
|
||||
>
|
||||
<text class="project-detail__empty-text">
|
||||
暂无详情
|
||||
</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import './index.scss';
|
||||
|
||||
.project-detail--empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.project-detail__empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999999;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user