313 lines
7.4 KiB
Vue
313 lines
7.4 KiB
Vue
<script setup lang="ts">
|
||
import { reactive, watch } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import { AppButton, FileList, UploadArea } from '@/components'
|
||
import { useOssStore } from '@/stores/modules/oss'
|
||
import type { FileInfo } from '@/types/api'
|
||
import type { Qualification, QualificationInput, QualificationType } from '@/types/business/profile'
|
||
|
||
interface Props {
|
||
qualification?: Qualification
|
||
}
|
||
|
||
const props = defineProps<Props>()
|
||
|
||
const ossStore = useOssStore()
|
||
|
||
const visible = defineModel<boolean>('visible', { default: false })
|
||
|
||
const emit = defineEmits<{ save: [payload: QualificationInput] }>()
|
||
|
||
const TYPE_OPTIONS: QualificationType[] = [
|
||
'营业执照',
|
||
'生产许可证',
|
||
'体系认证',
|
||
'检测报告',
|
||
'授权书',
|
||
'其他资质',
|
||
]
|
||
|
||
const form = reactive({
|
||
type: '营业执照' as QualificationType,
|
||
certName: '',
|
||
certNo: '',
|
||
issuer: '',
|
||
validFrom: '',
|
||
validTo: '',
|
||
})
|
||
|
||
const attachments = reactive<FileInfo[]>([])
|
||
|
||
watch(visible, (open) => {
|
||
if (!open) return
|
||
form.type = props.qualification?.type ?? '营业执照'
|
||
form.certName = props.qualification?.certName ?? ''
|
||
form.certNo = props.qualification?.certNo ?? ''
|
||
form.issuer = props.qualification?.issuer ?? ''
|
||
form.validFrom = props.qualification?.validFrom ?? ''
|
||
form.validTo = props.qualification?.validTo ?? ''
|
||
attachments.splice(0, attachments.length, ...(props.qualification?.attachments ?? []))
|
||
})
|
||
|
||
function onUpload(file: File): void {
|
||
attachments.push({
|
||
name: file.name,
|
||
size: file.size,
|
||
uploadTime: new Date().toISOString().slice(0, 10),
|
||
url: '',
|
||
})
|
||
}
|
||
|
||
function onPreview(file: FileInfo): void {
|
||
ossStore.openPreview(file)
|
||
}
|
||
|
||
function onDeleteFile(file: FileInfo): void {
|
||
const index = attachments.indexOf(file)
|
||
if (index >= 0) attachments.splice(index, 1)
|
||
}
|
||
|
||
function onSave(): void {
|
||
if (!form.certName.trim()) {
|
||
ElMessage.warning('请填写证书名称')
|
||
return
|
||
}
|
||
if (!form.certNo.trim()) {
|
||
ElMessage.warning('请填写证书编号')
|
||
return
|
||
}
|
||
if (!form.issuer.trim()) {
|
||
ElMessage.warning('请填写发证单位')
|
||
return
|
||
}
|
||
if (!form.validFrom || !form.validTo) {
|
||
ElMessage.warning('请选择有效期起止时间')
|
||
return
|
||
}
|
||
emit('save', {
|
||
id: props.qualification?.id,
|
||
type: form.type,
|
||
certName: form.certName.trim(),
|
||
certNo: form.certNo.trim(),
|
||
issuer: form.issuer.trim(),
|
||
validFrom: form.validFrom,
|
||
validTo: form.validTo,
|
||
attachments: [...attachments],
|
||
})
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<Teleport to="body">
|
||
<div v-if="visible" class="qual-dialog" @click.self="visible = false">
|
||
<div class="qual-dialog__panel">
|
||
<h3 class="qual-dialog__title">
|
||
{{ props.qualification ? '编辑资质' : '新增资质' }}
|
||
</h3>
|
||
|
||
<div class="qual-dialog__field">
|
||
<label class="qual-dialog__label">资质类型</label>
|
||
<select v-model="form.type" class="qual-dialog__input">
|
||
<option v-for="item in TYPE_OPTIONS" :key="item" :value="item">
|
||
{{ item }}
|
||
</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="qual-dialog__field">
|
||
<label class="qual-dialog__label">证书名称</label>
|
||
<input
|
||
v-model="form.certName"
|
||
class="qual-dialog__input"
|
||
type="text"
|
||
placeholder="请输入证书名称"
|
||
maxlength="60"
|
||
>
|
||
</div>
|
||
|
||
<div class="qual-dialog__field">
|
||
<label class="qual-dialog__label">证书编号</label>
|
||
<input
|
||
v-model="form.certNo"
|
||
class="qual-dialog__input"
|
||
type="text"
|
||
placeholder="请输入证书编号"
|
||
maxlength="40"
|
||
>
|
||
</div>
|
||
|
||
<div class="qual-dialog__field">
|
||
<label class="qual-dialog__label">发证单位</label>
|
||
<input
|
||
v-model="form.issuer"
|
||
class="qual-dialog__input"
|
||
type="text"
|
||
placeholder="请输入发证单位"
|
||
maxlength="60"
|
||
>
|
||
</div>
|
||
|
||
<div class="qual-dialog__field">
|
||
<label class="qual-dialog__label">有效期</label>
|
||
<div class="qual-dialog__range">
|
||
<input v-model="form.validFrom" class="qual-dialog__input" type="date">
|
||
<span class="qual-dialog__sep text-secondary">至</span>
|
||
<input v-model="form.validTo" class="qual-dialog__input" type="date">
|
||
</div>
|
||
<p class="qual-dialog__hint text-secondary">
|
||
起始时间:{{ form.validFrom || '未选择' }} · 截止时间:{{ form.validTo || '未选择' }}
|
||
</p>
|
||
</div>
|
||
|
||
<div class="qual-dialog__field">
|
||
<label class="qual-dialog__label">附件</label>
|
||
<UploadArea @upload="onUpload" />
|
||
<FileList
|
||
:files="attachments"
|
||
@preview="onPreview"
|
||
@delete="onDeleteFile"
|
||
/>
|
||
</div>
|
||
|
||
<div class="qual-dialog__footer">
|
||
<AppButton type="default" @click="visible = false">
|
||
取消
|
||
</AppButton>
|
||
<AppButton type="primary" @click="onSave">
|
||
保存
|
||
</AppButton>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</Teleport>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.qual-dialog {
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 1000;
|
||
.flex(row, center);
|
||
background: transparent;
|
||
overflow-y: auto;
|
||
|
||
&__panel {
|
||
width: 700px;
|
||
max-width: calc(100vw - 32px);
|
||
max-height: calc(100vh - 48px);
|
||
overflow-y: auto;
|
||
padding: @spacing-base;
|
||
border-radius: @radius-lg;
|
||
background: @white;
|
||
box-shadow: @shadow-lg;
|
||
.flex(column, flex-start);
|
||
gap: @spacing-base;
|
||
.scrollbar();
|
||
}
|
||
|
||
&__title {
|
||
position: relative;
|
||
padding-left: 12px;
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
color: @heading-color;
|
||
line-height: 20px;
|
||
|
||
&::before {
|
||
content: '';
|
||
position: absolute;
|
||
left: 0;
|
||
top: 3px;
|
||
width: 3px;
|
||
height: 14px;
|
||
border-radius: 2px;
|
||
background: @primary-strong;
|
||
}
|
||
}
|
||
|
||
&__field {
|
||
.flex(column, flex-start);
|
||
gap: @spacing-xs;
|
||
width: 100%;
|
||
}
|
||
|
||
&__label {
|
||
font-size: 11px;
|
||
font-weight: 500;
|
||
color: @heading-color;
|
||
}
|
||
|
||
&__input {
|
||
width: 100%;
|
||
height: 32px;
|
||
padding: 0 12px;
|
||
border: 1px solid @profile-input-border;
|
||
border-radius: @profile-radius;
|
||
background: @white;
|
||
font-size: 11px;
|
||
color: @text-color;
|
||
outline: none;
|
||
transition: border-color 0.2s;
|
||
box-sizing: border-box;
|
||
|
||
&:focus {
|
||
border-color: @primary-strong;
|
||
}
|
||
|
||
&::placeholder {
|
||
color: @heading-color;
|
||
}
|
||
}
|
||
|
||
&__range {
|
||
.flex(row, center);
|
||
gap: @spacing-sm;
|
||
}
|
||
|
||
&__sep {
|
||
flex-shrink: 0;
|
||
font-size: 11px;
|
||
}
|
||
|
||
&__hint {
|
||
font-size: 11px;
|
||
}
|
||
|
||
&__footer {
|
||
.flex(row, flex-start);
|
||
gap: @spacing-sm;
|
||
width: 100%;
|
||
}
|
||
|
||
.app-button {
|
||
flex: 1;
|
||
height: 36px;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
border-radius: @profile-radius;
|
||
}
|
||
|
||
.app-button--primary {
|
||
border-color: @primary-strong;
|
||
background: @primary-strong;
|
||
|
||
&:hover {
|
||
border-color: darken(@primary-strong, 6%);
|
||
background: darken(@primary-strong, 6%);
|
||
}
|
||
}
|
||
|
||
.app-button--default {
|
||
border: none;
|
||
background: @profile-quiet-btn;
|
||
color: @text-color;
|
||
|
||
&:hover {
|
||
border: none;
|
||
background: darken(@profile-quiet-btn, 4%);
|
||
color: @text-color;
|
||
}
|
||
}
|
||
}
|
||
</style>
|