378 lines
10 KiB
Vue
378 lines
10 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import { storeToRefs } from 'pinia'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { ElMessage } from 'element-plus'
|
||
import { AppButton, StepForm, UploadArea } from '@/components'
|
||
// 页面容器:数据只经 store,不直接 import api
|
||
import { useProjectStore } from '@/stores/modules/project'
|
||
import type { BusinessType, FileInfo } from '@/types/api'
|
||
import { formatDate } from '@/utils/format'
|
||
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const projectStore = useProjectStore()
|
||
const { current } = storeToRefs(projectStore)
|
||
|
||
const projectId = computed(() => String(route.params.id))
|
||
|
||
const STEP_TITLES = ['选择业务类型', '填写问题描述', '补充备注']
|
||
const step = ref(0)
|
||
|
||
const businessTypeOptions: Array<{ label: string; value: BusinessType }> = [
|
||
{ label: '互联网软件', value: 'internet' },
|
||
{ label: '硬件电路', value: 'hardware' },
|
||
{ label: '物联网全案', value: 'iot' },
|
||
{ label: '生产制造', value: 'manufacturing' },
|
||
]
|
||
|
||
const typeChips = ['BUG问题', '功能新增', '其他']
|
||
|
||
const businessType = ref<BusinessType | ''>('')
|
||
const projectName = ref('')
|
||
const type = ref('')
|
||
const description = ref('')
|
||
const remark = ref('')
|
||
const attachments = ref<FileInfo[]>([])
|
||
|
||
const projectNamePlaceholder = computed(() => current.value?.projectName || '默认当前项目')
|
||
const descriptionCount = computed(() => `${description.value.length}/500`)
|
||
const remarkCount = computed(() => `${remark.value.length}/500`)
|
||
|
||
function nextStep(): void {
|
||
if (step.value < STEP_TITLES.length - 1) step.value += 1
|
||
}
|
||
|
||
function prevStep(): void {
|
||
if (step.value > 0) step.value -= 1
|
||
}
|
||
|
||
function pickType(chip: string): void {
|
||
type.value = chip
|
||
}
|
||
|
||
function onUpload(file: File): void {
|
||
attachments.value.push({
|
||
name: file.name,
|
||
size: file.size,
|
||
uploadTime: formatDate(new Date()),
|
||
url: '',
|
||
})
|
||
}
|
||
|
||
function removeAttachment(index: number): void {
|
||
attachments.value.splice(index, 1)
|
||
}
|
||
|
||
function resetForm(): void {
|
||
step.value = 0
|
||
businessType.value = ''
|
||
projectName.value = ''
|
||
type.value = ''
|
||
description.value = ''
|
||
remark.value = ''
|
||
attachments.value = []
|
||
}
|
||
|
||
function onCancel(): void {
|
||
void router.push(`/project/${projectId.value}`)
|
||
}
|
||
|
||
async function onSubmit(): Promise<void> {
|
||
const effectiveName = projectName.value || current.value?.projectName || ''
|
||
if (!effectiveName) {
|
||
ElMessage.warning('请输入项目名称')
|
||
return
|
||
}
|
||
if (!type.value) {
|
||
ElMessage.warning('请选择或输入售后类型')
|
||
return
|
||
}
|
||
if (!description.value) {
|
||
ElMessage.warning('请填写问题描述')
|
||
return
|
||
}
|
||
await projectStore.submitAfterSales({
|
||
type: type.value,
|
||
description: description.value,
|
||
remark: remark.value,
|
||
attachments: attachments.value,
|
||
})
|
||
await router.push(`/project/${projectId.value}`)
|
||
}
|
||
|
||
onMounted(() => {
|
||
if (!current.value || current.value.id !== projectId.value) {
|
||
void projectStore.fetchDetail(projectId.value)
|
||
}
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="container after-sales">
|
||
<nav class="after-sales__breadcrumb text-secondary">
|
||
<RouterLink to="/project" class="link">
|
||
项目中心
|
||
</RouterLink>
|
||
<span> > </span>
|
||
<RouterLink :to="`/project/${projectId}`" class="link">
|
||
项目详情
|
||
</RouterLink>
|
||
<span> > </span>
|
||
<span>申请售后</span>
|
||
</nav>
|
||
|
||
<StepForm :titles="STEP_TITLES" :current="step">
|
||
<!-- 第一步:选择业务类型 -->
|
||
<div v-if="step === 0" class="after-sales__section">
|
||
<div class="after-sales__field">
|
||
<label class="after-sales__label">业务类型</label>
|
||
<div class="after-sales__options">
|
||
<button
|
||
v-for="option in businessTypeOptions"
|
||
:key="option.value"
|
||
class="after-sales__option"
|
||
:class="{ 'is-active': businessType === option.value }"
|
||
@click="businessType = option.value"
|
||
>
|
||
{{ option.label }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div class="after-sales__field">
|
||
<label class="after-sales__label" for="after-sales-project">项目名称</label>
|
||
<input
|
||
id="after-sales-project"
|
||
v-model="projectName"
|
||
class="after-sales__input"
|
||
:placeholder="projectNamePlaceholder"
|
||
>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 第二步:填写问题描述 -->
|
||
<div v-if="step === 1" class="after-sales__section">
|
||
<div class="after-sales__field">
|
||
<label class="after-sales__label" for="after-sales-type">售后类型</label>
|
||
<input
|
||
id="after-sales-type"
|
||
v-model="type"
|
||
class="after-sales__input"
|
||
placeholder="选择下方推荐的售后类型或手动输入售后类型"
|
||
>
|
||
<div class="after-sales__options">
|
||
<button
|
||
v-for="chip in typeChips"
|
||
:key="chip"
|
||
class="after-sales__option"
|
||
:class="{ 'is-active': type === chip }"
|
||
@click="pickType(chip)"
|
||
>
|
||
{{ chip }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div class="after-sales__field">
|
||
<label class="after-sales__label" for="after-sales-desc">问题描述</label>
|
||
<textarea
|
||
id="after-sales-desc"
|
||
v-model="description"
|
||
class="after-sales__textarea"
|
||
maxlength="500"
|
||
rows="5"
|
||
placeholder="请详细描述您的问题..."
|
||
/>
|
||
<span class="after-sales__count text-secondary">{{ descriptionCount }}</span>
|
||
</div>
|
||
<div class="after-sales__field">
|
||
<label class="after-sales__label">附件上传</label>
|
||
<UploadArea hint="支持图片/文档/压缩包,大小不超过1G" @upload="onUpload" />
|
||
<ul v-if="attachments.length > 0" class="after-sales__files">
|
||
<li
|
||
v-for="(file, index) in attachments"
|
||
:key="`${file.name}-${index}`"
|
||
class="after-sales__file"
|
||
>
|
||
<span class="after-sales__file-name" :title="file.name">{{ file.name }}</span>
|
||
<button
|
||
class="after-sales__file-remove"
|
||
@click="removeAttachment(index)"
|
||
>
|
||
移除
|
||
</button>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 第三步:补充备注 -->
|
||
<div v-if="step === 2" class="after-sales__section">
|
||
<div class="after-sales__field">
|
||
<label class="after-sales__label" for="after-sales-remark">补充备注</label>
|
||
<textarea
|
||
id="after-sales-remark"
|
||
v-model="remark"
|
||
class="after-sales__textarea"
|
||
maxlength="500"
|
||
rows="5"
|
||
placeholder="其他需要说明的事项..."
|
||
/>
|
||
<span class="after-sales__count text-secondary">{{ remarkCount }}</span>
|
||
<p class="after-sales__tip text-secondary">
|
||
备注为选填项,如有与问题描述相关的补充信息可在此说明,便于工程师更快定位问题。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</StepForm>
|
||
|
||
<div class="after-sales__footer">
|
||
<AppButton v-if="step > 0" @click="prevStep">
|
||
上一步
|
||
</AppButton>
|
||
<AppButton v-if="step < STEP_TITLES.length - 1" @click="nextStep">
|
||
下一步
|
||
</AppButton>
|
||
<AppButton v-if="step === STEP_TITLES.length - 1" type="primary" @click="onSubmit">
|
||
申请售后
|
||
</AppButton>
|
||
<AppButton @click="resetForm">
|
||
重置
|
||
</AppButton>
|
||
<AppButton @click="onCancel">
|
||
取消
|
||
</AppButton>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.after-sales {
|
||
.flex(column, flex-start, stretch);
|
||
gap: @spacing-base;
|
||
padding-top: @spacing-lg;
|
||
padding-bottom: @spacing-xxl;
|
||
|
||
&__breadcrumb {
|
||
font-size: @font-size-base;
|
||
}
|
||
|
||
&__section {
|
||
.flex(column, flex-start, stretch);
|
||
gap: @spacing-lg;
|
||
}
|
||
|
||
&__field {
|
||
.flex(column, flex-start, stretch);
|
||
gap: @spacing-sm;
|
||
}
|
||
|
||
&__label {
|
||
font-size: @font-size-base;
|
||
font-weight: 600;
|
||
color: @heading-color;
|
||
}
|
||
|
||
&__options {
|
||
.flex(row, flex-start, center);
|
||
flex-wrap: wrap;
|
||
gap: @spacing-sm;
|
||
}
|
||
|
||
&__option {
|
||
height: 30px;
|
||
padding: 0 @spacing-base;
|
||
border: 1px solid transparent;
|
||
border-radius: @radius-sm;
|
||
background: @bg-color;
|
||
color: @text-color;
|
||
font-size: @font-size-sm;
|
||
transition: all 0.2s;
|
||
|
||
&:hover {
|
||
color: @primary-color;
|
||
}
|
||
|
||
&.is-active {
|
||
border-color: @primary-color;
|
||
background: @primary-light;
|
||
color: @primary-color;
|
||
}
|
||
}
|
||
|
||
&__input {
|
||
width: 360px;
|
||
height: 36px;
|
||
padding: 0 @spacing-base;
|
||
border: 1px solid @border-color;
|
||
border-radius: @radius-base;
|
||
background: @white;
|
||
font-size: @font-size-base;
|
||
outline: none;
|
||
transition: border-color 0.2s;
|
||
|
||
&:focus {
|
||
border-color: @primary-color;
|
||
}
|
||
}
|
||
|
||
&__textarea {
|
||
width: 100%;
|
||
padding: @spacing-sm @spacing-base;
|
||
border: 1px solid @border-color;
|
||
border-radius: @radius-base;
|
||
background: @white;
|
||
font-size: @font-size-base;
|
||
line-height: 1.6;
|
||
resize: vertical;
|
||
outline: none;
|
||
transition: border-color 0.2s;
|
||
|
||
&:focus {
|
||
border-color: @primary-color;
|
||
}
|
||
}
|
||
|
||
&__count {
|
||
align-self: flex-end;
|
||
font-size: @font-size-sm;
|
||
}
|
||
|
||
&__tip {
|
||
font-size: @font-size-sm;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
&__files {
|
||
.flex(column, flex-start, stretch);
|
||
gap: @spacing-xs;
|
||
}
|
||
|
||
&__file {
|
||
.flex(row, space-between);
|
||
gap: @spacing-base;
|
||
width: 360px;
|
||
padding: @spacing-xs @spacing-sm;
|
||
border: 1px solid @border-color;
|
||
border-radius: @radius-sm;
|
||
background: @bg-color-light;
|
||
}
|
||
|
||
&__file-name {
|
||
font-size: @font-size-sm;
|
||
color: @text-color;
|
||
.ellipsis();
|
||
}
|
||
|
||
&__file-remove {
|
||
flex-shrink: 0;
|
||
font-size: @font-size-sm;
|
||
color: @danger-color;
|
||
}
|
||
|
||
&__footer {
|
||
.flex(row, flex-start);
|
||
gap: @spacing-sm;
|
||
}
|
||
}
|
||
</style>
|