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,44 +1,88 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { BUSINESS_TYPE_OPTIONS } from '@/constants/business-types'
import { getProjectDetail } from '@/constants/project-detail'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { getRequirementDetail, submitRequirementAfterSale, uploadRequirementAttachment } from '@/api/requirement'
import { useRequirementBusinessTypes } from '@/hooks/use-requirement-business-types'
import deleteIcon from '@/static/icons/X.png'
import pdfIcon from '@/static/icons/PDF.png'
import pngIcon from '@/static/icons/PNG.png'
import { ensureLoggedIn } from '@/utils/auth-guard'
import { getLoginPhoneNumber } from '@/utils/auth-storage'
import { buildAfterSaleActionBody } from '@/utils/build-after-sale-action'
import {
chooseLocalFiles,
REQUIREMENT_ATTACHMENT_MAX_COUNT,
} from '@/utils/choose-local-files'
import { navigateBackWithFallback } from '@/utils/navigate-back'
import { navigateToResultPage } from '@/utils/navigate-result'
const projectId = ref('1')
const { businessTypes, loadRequirementBusinessTypes } = useRequirementBusinessTypes()
const projectId = ref('')
const fallbackUrl = ref('/pages/project-center/index')
const businessType = ref('')
const businessTypeDropdownVisible = ref(false)
const businessTypeOptions = BUSINESS_TYPE_OPTIONS
const projectName = ref('')
const description = ref('')
const userName = ref('王永志')
const userPhone = ref('186****9618')
const userName = ref('')
const userPhone = ref('')
const remark = ref('')
const submitting = ref(false)
const uploadingAttachment = ref(false)
const attachments = ref([
{ id: '1', name: '需求文档.pdf', icon: pdfIcon },
{ id: '2', name: '系统....pdf', icon: pdfIcon },
{ id: '3', name: '参考图.png', icon: pngIcon },
])
interface AfterSaleAttachmentItem {
id: string
name: string
icon: string
ossId: string
}
const attachments = ref<AfterSaleAttachmentItem[]>([])
const descLength = computed(() => description.value.length)
onLoad((options) => {
const id = options?.id ? decodeURIComponent(String(options.id)) : '1'
projectId.value = id
fallbackUrl.value = `/pages/project-center/detail/index?id=${encodeURIComponent(id)}`
function resolveAttachmentIcon(name: string) {
const ext = name.split('.').pop()?.toLowerCase()
if (ext === 'png' || ext === 'jpg' || ext === 'jpeg')
return pngIcon
const detail = getProjectDetail(id)
if (detail) {
projectName.value = detail.title
if (BUSINESS_TYPE_OPTIONS.includes(detail.category))
businessType.value = detail.category
return pdfIcon
}
async function loadRequirement(id: string) {
try {
const detail = await getRequirementDetail(id)
projectName.value = detail.projectName || ''
if (detail.businessType)
businessType.value = detail.businessType
}
catch {
// 详情失败仍允许填写售后说明
}
}
onLoad((options) => {
if (!ensureLoggedIn())
return
const id = options?.id ? decodeURIComponent(String(options.id)) : ''
if (!id) {
uni.showToast({ title: '参数错误', icon: 'none' })
return
}
projectId.value = id
fallbackUrl.value = `/pages/project-center/detail/index?id=${encodeURIComponent(id)}&tab=aftersales`
loadRequirement(id)
})
onShow(() => {
if (!ensureLoggedIn())
return
loadRequirementBusinessTypes()
const phone = getLoginPhoneNumber()
if (phone && !userPhone.value)
userPhone.value = phone
})
function handleBack() {
@@ -63,23 +107,71 @@ function handleRemoveAttachment(id: string) {
attachments.value = attachments.value.filter(item => item.id !== id)
}
function handleAddAttachment() {
uni.showToast({ title: '附件上传开发中', icon: 'none' })
async function handleAddAttachment() {
if (!ensureLoggedIn())
return
if (uploadingAttachment.value)
return
const remain = REQUIREMENT_ATTACHMENT_MAX_COUNT - attachments.value.length
if (remain <= 0) {
uni.showToast({ title: `最多上传${REQUIREMENT_ATTACHMENT_MAX_COUNT}个附件`, icon: 'none' })
return
}
try {
const files = await chooseLocalFiles(remain)
if (!files.length)
return
uploadingAttachment.value = true
uni.showLoading({ title: '上传中...', mask: true })
for (const file of files) {
const uploaded = await uploadRequirementAttachment(file.path)
const ossId = uploaded.ossId ?? uploaded.id
if (ossId === undefined || ossId === null || ossId === '') {
uni.showToast({ title: '上传失败,未返回附件 ID', icon: 'none' })
continue
}
const ossIdText = String(ossId)
const name = uploaded.fileName || file.name
attachments.value.push({
id: ossIdText,
ossId: ossIdText,
name,
icon: resolveAttachmentIcon(name),
})
}
}
catch (error) {
const message = error instanceof Error ? error.message : '上传失败'
if (!/cancel/i.test(message))
uni.showToast({ title: message, icon: 'none' })
}
finally {
uploadingAttachment.value = false
uni.hideLoading()
}
}
function handleReset() {
description.value = ''
remark.value = ''
businessType.value = ''
const detail = getProjectDetail(projectId.value)
if (detail) {
projectName.value = detail.title
if (BUSINESS_TYPE_OPTIONS.includes(detail.category))
businessType.value = detail.category
}
attachments.value = []
if (projectId.value)
loadRequirement(projectId.value)
}
function handleSubmit() {
async function handleSubmit() {
if (submitting.value || !projectId.value)
return
if (!ensureLoggedIn())
return
if (!businessType.value) {
uni.showToast({ title: '请选择业务类型', icon: 'none' })
return
@@ -89,11 +181,39 @@ function handleSubmit() {
return
}
if (!description.value.trim()) {
uni.showToast({ title: '请填写核心需求描述', icon: 'none' })
uni.showToast({ title: '请填写问题描述', icon: 'none' })
return
}
navigateToResultPage('afterSalesSuccess', { id: projectId.value })
if (description.value.trim().length > 500) {
uni.showToast({ title: '问题描述不超过500字', icon: 'none' })
return
}
submitting.value = true
uni.showLoading({ title: '提交中...', mask: true })
try {
const body = buildAfterSaleActionBody({
requirementId: projectId.value,
reason: description.value,
remark: remark.value,
businessType: businessType.value,
contactName: userName.value,
contactPhone: userPhone.value,
attachmentOssIds: attachments.value.map(item => item.ossId || item.id),
})
await submitRequirementAfterSale(projectId.value, body)
navigateToResultPage('afterSalesSuccess', { id: projectId.value })
}
catch {
// request 层已 toast
}
finally {
submitting.value = false
uni.hideLoading()
}
}
</script>
@@ -152,7 +272,7 @@ function handleSubmit() {
@tap.stop
>
<view
v-for="option in businessTypeOptions"
v-for="option in businessTypes"
:key="option"
class="after-sales-apply__dropdown-item"
:class="{ 'after-sales-apply__dropdown-item--active': businessType === option }"
@@ -182,7 +302,7 @@ function handleSubmit() {
<view class="after-sales-apply__field">
<text class="after-sales-apply__label">
核心需求描述<text class="after-sales-apply__required">
问题描述<text class="after-sales-apply__required">
*
</text>
</text>