feat(purchase): 新增采购管理前端页面与路由(列表+新建+审批)
This commit is contained in:
91
inventory-web/src/api/purchase.ts
Normal file
91
inventory-web/src/api/purchase.ts
Normal file
@ -0,0 +1,91 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export interface PurchaseItem {
|
||||
id?: number
|
||||
request_no?: string
|
||||
name: string
|
||||
spec_model?: string
|
||||
quantity: number
|
||||
purchase_date: string
|
||||
supplier_link?: string
|
||||
remark?: string
|
||||
images?: string[]
|
||||
unit_price?: number
|
||||
total_price?: number
|
||||
status: number
|
||||
status_text?: string
|
||||
requester_id?: number
|
||||
requester_name?: string
|
||||
approver_id?: number
|
||||
approver_name?: string
|
||||
approved_at?: string
|
||||
reject_reason?: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface Approver {
|
||||
id: number
|
||||
username: string
|
||||
email: string
|
||||
role: string
|
||||
}
|
||||
|
||||
// 获取采购申请列表
|
||||
export function getPurchaseList(params: {
|
||||
page?: number
|
||||
limit?: number
|
||||
status?: number
|
||||
}) {
|
||||
return request({
|
||||
url: '/purchase',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
// 创建采购申请
|
||||
export function createPurchase(data: PurchaseItem) {
|
||||
return request({
|
||||
url: '/purchase',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 获取采购申请详情
|
||||
export function getPurchaseDetail(id: number) {
|
||||
return request({
|
||||
url: `/purchase/${id}`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 审批采购申请
|
||||
export function approvePurchase(id: number, data: {
|
||||
action: 'approve' | 'reject'
|
||||
reject_reason?: string
|
||||
}) {
|
||||
return request({
|
||||
url: `/purchase/${id}/approve`,
|
||||
method: 'patch',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 获取可选审批人列表
|
||||
export function getPurchaseApprovers() {
|
||||
return request({
|
||||
url: '/purchase/approvers',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 根据名称/规格自动补全
|
||||
export function autoFillPurchase(keyword: string) {
|
||||
return request({
|
||||
url: '/purchase/auto-fill',
|
||||
method: 'get',
|
||||
params: { keyword }
|
||||
})
|
||||
}
|
||||
@ -180,6 +180,21 @@ const routes: Array<RouteRecordRaw> = [
|
||||
]
|
||||
},
|
||||
|
||||
// 5.1 采购管理
|
||||
{
|
||||
path: '/purchase',
|
||||
component: Layout,
|
||||
meta: { title: '采购管理', icon: 'ShoppingCart' },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'PurchaseList',
|
||||
component: () => import('@/views/purchase/index.vue'),
|
||||
meta: { title: '采购申请' }
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// 6. 借库管理
|
||||
{
|
||||
path: '/operation',
|
||||
|
||||
502
inventory-web/src/views/purchase/index.vue
Normal file
502
inventory-web/src/views/purchase/index.vue
Normal file
@ -0,0 +1,502 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
|
||||
<!-- 顶部工具栏 -->
|
||||
<div class="filter-container">
|
||||
<span style="font-weight: bold; font-size: 15px; margin-right: 8px;">审批状态:</span>
|
||||
<el-radio-group v-model="filterStatus" size="default" @change="handleStatusChange">
|
||||
<el-radio-button label="">全部</el-radio-button>
|
||||
<el-radio-button :label="0">待审批</el-radio-button>
|
||||
<el-radio-button :label="1">已通过</el-radio-button>
|
||||
<el-radio-button :label="2">已驳回</el-radio-button>
|
||||
<el-radio-button :label="3">已完成</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-button type="primary" :icon="Refresh" @click="fetchData">刷新</el-button>
|
||||
<el-button v-if="userStore.hasPermission('purchase_manage:operation')" type="success" :icon="Plus" @click="openCreateDialog">
|
||||
新建采购申请
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<el-table v-loading="loading" :data="list" border stripe style="margin-top: 16px;" row-key="id">
|
||||
<el-table-column prop="request_no" label="申请单号" width="180" />
|
||||
<el-table-column prop="name" label="采购物品" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="spec_model" label="规格型号" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="quantity" label="数量" width="80" align="center" />
|
||||
<el-table-column prop="purchase_date" label="采购日期" width="110" />
|
||||
<el-table-column label="单价/总价" width="120" align="right">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.unit_price || row.total_price">
|
||||
{{ row.unit_price || '-' }} / {{ row.total_price || '-' }}
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="requester_name" label="申请人" width="100" />
|
||||
<el-table-column prop="approver_name" label="审批人" width="100" />
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusTagType(row.status)" size="small">{{ row.status_text }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" fixed="right" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link size="small" @click="openDetailDialog(row)">详情</el-button>
|
||||
<template v-if="row.status === 0 && canApprove">
|
||||
<el-button type="success" link size="small" @click="handleApprove(row)">通过</el-button>
|
||||
<el-button type="danger" link size="small" @click="openRejectDialog(row)">驳回</el-button>
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<el-pagination
|
||||
background
|
||||
style="margin-top: 16px; justify-content: flex-end; display: flex;"
|
||||
v-model:current-page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, prev, pager, next, sizes"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handlePageChange"
|
||||
/>
|
||||
|
||||
<!-- ========== 新建/编辑弹窗 ========== -->
|
||||
<el-dialog v-model="formDialogVisible" :title="dialogTitle" width="700px" destroy-on-close :close-on-click-modal="false">
|
||||
<el-form ref="formRef" :model="form" label-width="110px">
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="采购物品" required>
|
||||
<el-input v-model="form.name" placeholder="输入物品名称,可自动补全规格" clearable @blur="onNameBlur" @change="onNameChange" />
|
||||
<div v-if="autoFillHint" style="font-size: 12px; color: #67C23A; margin-top: 4px;">{{ autoFillHint }}</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="规格型号">
|
||||
<el-input v-model="form.spec_model" placeholder="可自动补全" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="采购数量" required>
|
||||
<el-input-number v-model="form.quantity" :min="1" style="width: 100%;" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="采购日期" required>
|
||||
<el-date-picker v-model="form.purchase_date" type="date" value-format="YYYY-MM-DD" placeholder="选择日期" style="width: 100%;" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="审批人" required>
|
||||
<el-select v-model="form.approver_id" placeholder="请选择审批人" style="width: 100%;" filterable>
|
||||
<el-option v-for="u in approvers" :key="u.id" :label="`${u.username} (${u.role === 'SUPER_ADMIN' ? '超级管理员' : '主管'})`" :value="u.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="单价">
|
||||
<el-input-number v-model="form.unit_price" :min="0" :precision="2" style="width: 100%;" @change="onUnitPriceChange" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="总价">
|
||||
<el-input-number v-model="form.total_price" :min="0" :precision="2" style="width: 100%;" @change="onTotalPriceChange" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="商家链接">
|
||||
<el-input v-model="form.supplier_link" placeholder="商家地址链接(选填)" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="备注信息(选填)" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="图片上传">
|
||||
<el-upload
|
||||
v-model:file-list="fileList"
|
||||
:http-request="customUpload"
|
||||
:on-remove="handleRemoveImage"
|
||||
:before-upload="beforeAvatarUpload"
|
||||
accept="image/jpeg,image/png,image/gif,image/webp"
|
||||
multiple
|
||||
list-type="picture-card"
|
||||
>
|
||||
<el-icon><Plus /></el-icon>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="formDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitLoading" @click="submitForm">确认提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- ========== 详情弹窗 ========== -->
|
||||
<el-dialog v-model="detailDialogVisible" title="采购申请详情" width="700px" destroy-on-close>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="申请单号">{{ detail.request_no }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="statusTagType(detail.status)" size="small">{{ detail.status_text }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="采购物品">{{ detail.name }}</el-descriptions-item>
|
||||
<el-descriptions-item label="规格型号">{{ detail.spec_model || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="采购数量">{{ detail.quantity }}</el-descriptions-item>
|
||||
<el-descriptions-item label="采购日期">{{ detail.purchase_date }}</el-descriptions-item>
|
||||
<el-descriptions-item label="单价">{{ detail.unit_price || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="总价">{{ detail.total_price || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="申请人">{{ detail.requester_name }}</el-descriptions-item>
|
||||
<el-descriptions-item label="审批人">{{ detail.approver_name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="审批时间">{{ detail.approved_at || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="商家链接">
|
||||
<a v-if="detail.supplier_link" :href="detail.supplier_link" target="_blank" style="color: #409EFF;">
|
||||
{{ detail.supplier_link }}
|
||||
</a>
|
||||
<span v-else>-</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="2">{{ detail.remark || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="驳回原因" :span="2" v-if="detail.reject_reason">
|
||||
<span style="color: #F56C6C;">{{ detail.reject_reason }}</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<!-- 图片展示 -->
|
||||
<div v-if="detail.images && detail.images.length > 0" style="margin-top: 16px;">
|
||||
<div style="font-weight: bold; margin-bottom: 8px;">图片</div>
|
||||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||||
<el-image
|
||||
v-for="(img, idx) in detail.images"
|
||||
:key="idx"
|
||||
:src="getImageUrl(img)"
|
||||
:preview-src-list="detail.images.map(u => getImageUrl(u))"
|
||||
fit="cover"
|
||||
style="width: 100px; height: 100px; border-radius: 4px; cursor: pointer;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- ========== 驳回原因弹窗 ========== -->
|
||||
<el-dialog v-model="rejectDialogVisible" title="驳回申请" width="480px" destroy-on-close>
|
||||
<el-form label-width="80px">
|
||||
<el-form-item label="申请单号">
|
||||
<span style="font-weight: bold; color: #409EFF;">{{ currentRejectRow?.request_no }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="驳回原因" required>
|
||||
<el-input v-model="rejectReason" type="textarea" :rows="4" placeholder="请填写驳回原因(必填)" maxlength="200" show-word-limit />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="rejectDialogVisible = false">取消</el-button>
|
||||
<el-button type="danger" :loading="rejectLoading" @click="confirmReject">确认驳回</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { Refresh, Plus } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import {
|
||||
getPurchaseList, createPurchase, getPurchaseDetail,
|
||||
approvePurchase, getPurchaseApprovers, autoFillPurchase
|
||||
} from '@/api/purchase'
|
||||
import { uploadFile, deleteFile } from '@/api/common/upload'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
// --- 状态 ---
|
||||
const list = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const filterStatus = ref<number | ''>(0) // 默认筛选待审批
|
||||
const submitLoading = ref(false)
|
||||
const rejectLoading = ref(false)
|
||||
const fileList = ref<any[]>([])
|
||||
|
||||
// 驳回
|
||||
const rejectDialogVisible = ref(false)
|
||||
const currentRejectRow = ref<any>(null)
|
||||
const rejectReason = ref('')
|
||||
|
||||
// 详情
|
||||
const detailDialogVisible = ref(false)
|
||||
const detail = ref<any>({})
|
||||
|
||||
// 创建弹窗
|
||||
const formDialogVisible = ref(false)
|
||||
const dialogTitle = ref('新建采购申请')
|
||||
const formRef = ref<FormInstance>()
|
||||
const isUploading = ref(false)
|
||||
const autoFillHint = ref('')
|
||||
|
||||
// 审批人
|
||||
const approvers = ref<any[]>([])
|
||||
|
||||
// 表单
|
||||
const form = ref({
|
||||
name: '',
|
||||
spec_model: '',
|
||||
quantity: 1,
|
||||
purchase_date: '',
|
||||
supplier_link: '',
|
||||
remark: '',
|
||||
unit_price: undefined as number | undefined,
|
||||
total_price: undefined as number | undefined,
|
||||
approver_id: undefined as number | undefined,
|
||||
images: [] as string[]
|
||||
})
|
||||
|
||||
// --- 计算属性 ---
|
||||
const canApprove = computed(() => {
|
||||
return userStore.role === 'SUPER_ADMIN' || userStore.role === 'SUPERVISOR'
|
||||
})
|
||||
|
||||
// --- 工具函数 ---
|
||||
const statusTagType = (status: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: 'warning', 1: 'success', 2: 'danger', 3: 'info'
|
||||
}
|
||||
return map[status] ?? 'info'
|
||||
}
|
||||
|
||||
const getImageUrl = (url: string) => {
|
||||
if (!url) return ''
|
||||
if (url.startsWith('http')) return url
|
||||
return `/api/v1/common/files/${url}`
|
||||
}
|
||||
|
||||
const formatDate = (d: string) => d ? d.split(' ')[0] : ''
|
||||
|
||||
// --- 数据获取 ---
|
||||
const fetchData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: any = { page: page.value, limit: pageSize.value }
|
||||
if (filterStatus.value !== '') params.status = filterStatus.value
|
||||
|
||||
const res: any = await getPurchaseList(params)
|
||||
list.value = res.data?.items || []
|
||||
total.value = res.data?.total || 0
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err?.msg || '加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchApprovers = async () => {
|
||||
try {
|
||||
const res: any = await getPurchaseApprovers()
|
||||
approvers.value = res.data || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
// --- 筛选 & 分页 ---
|
||||
const handleStatusChange = () => {
|
||||
page.value = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
const handlePageChange = (p: number) => { page.value = p; fetchData() }
|
||||
const handleSizeChange = (s: number) => { pageSize.value = s; page.value = 1; fetchData() }
|
||||
|
||||
// --- 新建 ---
|
||||
const openCreateDialog = () => {
|
||||
dialogTitle.value = '新建采购申请'
|
||||
form.value = {
|
||||
name: '', spec_model: '', quantity: 1,
|
||||
purchase_date: new Date().toISOString().split('T')[0],
|
||||
supplier_link: '', remark: '',
|
||||
unit_price: undefined, total_price: undefined,
|
||||
approver_id: undefined, images: []
|
||||
}
|
||||
fileList.value = []
|
||||
autoFillHint.value = ''
|
||||
formDialogVisible.value = true
|
||||
}
|
||||
|
||||
// --- 自动补全名称/规格 ---
|
||||
let autoFillTimer: any = null
|
||||
const onNameChange = () => {
|
||||
clearTimeout(autoFillTimer)
|
||||
autoFillTimer = setTimeout(() => doAutoFill(), 500)
|
||||
}
|
||||
const onNameBlur = () => {
|
||||
clearTimeout(autoFillTimer)
|
||||
doAutoFill()
|
||||
}
|
||||
const doAutoFill = async () => {
|
||||
const kw = form.value.name.trim()
|
||||
if (!kw) { autoFillHint.value = ''; return }
|
||||
try {
|
||||
const res: any = await autoFillPurchase(kw)
|
||||
if (res.data) {
|
||||
if (!form.value.spec_model && res.data.spec_model) {
|
||||
autoFillHint.value = `已自动补全规格:${res.data.spec_model}`
|
||||
form.value.spec_model = res.data.spec_model
|
||||
} else if (!form.value.name && res.data.name) {
|
||||
autoFillHint.value = `已自动补全名称:${res.data.name}`
|
||||
form.value.name = res.data.name
|
||||
}
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
// --- 价格自动计算 ---
|
||||
const onUnitPriceChange = (val: number | undefined) => {
|
||||
if (val !== undefined && val > 0 && form.value.quantity > 0) {
|
||||
const total = +(val * form.value.quantity).toFixed(2)
|
||||
form.value.total_price = total
|
||||
}
|
||||
}
|
||||
const onTotalPriceChange = (val: number | undefined) => {
|
||||
if (val !== undefined && val > 0 && form.value.quantity > 0) {
|
||||
const unit = +(val / form.value.quantity).toFixed(4)
|
||||
form.value.unit_price = unit
|
||||
}
|
||||
}
|
||||
|
||||
// --- 上传 ---
|
||||
const beforeAvatarUpload = (rawFile: any) => {
|
||||
const isTypeValid = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp'].includes(rawFile.type)
|
||||
if (!isTypeValid) {
|
||||
ElMessage.error('仅支持 JPG/PNG/GIF/WEBP 图片')
|
||||
return false
|
||||
}
|
||||
if (rawFile.size / 1024 / 1024 > 10) {
|
||||
ElMessage.error('图片不能超过 10MB')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const customUpload = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
isUploading.value = true
|
||||
try {
|
||||
const res: any = await uploadFile(formData)
|
||||
if (res.code === 200) {
|
||||
const newUrl = res.data.url
|
||||
form.value.images!.push(newUrl)
|
||||
onSuccess(res)
|
||||
} else {
|
||||
ElMessage.error(res.msg || '上传失败')
|
||||
onError(new Error(res.msg))
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error('网络错误')
|
||||
onError(e)
|
||||
} finally {
|
||||
isUploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleRemoveImage = async (uploadFile: any) => {
|
||||
const urlToRemove = form.value.images!.find(u => getImageUrl(u) === uploadFile.url) || uploadFile.url
|
||||
form.value.images = form.value.images!.filter(u => u !== urlToRemove)
|
||||
const filename = urlToRemove.split('/').pop()
|
||||
if (filename && !urlToRemove.startsWith('http')) {
|
||||
await deleteFile(filename).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
// --- 提交 ---
|
||||
const submitForm = async () => {
|
||||
if (!form.value.name.trim()) { ElMessage.warning('请填写采购物品名称'); return }
|
||||
if (!form.value.approver_id) { ElMessage.warning('请选择审批人'); return }
|
||||
if (!form.value.purchase_date) { ElMessage.warning('请选择采购日期'); return }
|
||||
|
||||
submitLoading.value = true
|
||||
try {
|
||||
await createPurchase(form.value as any)
|
||||
ElMessage.success('提交成功,审批人将收到邮件通知')
|
||||
formDialogVisible.value = false
|
||||
await fetchData()
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err?.msg || '提交失败')
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// --- 详情 ---
|
||||
const openDetailDialog = async (row: any) => {
|
||||
try {
|
||||
const res: any = await getPurchaseDetail(row.id)
|
||||
detail.value = res.data || {}
|
||||
detailDialogVisible.value = true
|
||||
} catch (e) {
|
||||
ElMessage.error('获取详情失败')
|
||||
}
|
||||
}
|
||||
|
||||
// --- 审批操作 ---
|
||||
const handleApprove = async (row: any) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要通过采购申请「${row.request_no}」吗?`, '审批确认', {
|
||||
confirmButtonText: '确定通过', cancelButtonText: '取消', type: 'info'
|
||||
})
|
||||
} catch { return }
|
||||
|
||||
try {
|
||||
await approvePurchase(row.id, { action: 'approve' })
|
||||
ElMessage.success('已通过')
|
||||
await fetchData()
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err?.msg || '操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const openRejectDialog = (row: any) => {
|
||||
currentRejectRow.value = row
|
||||
rejectReason.value = ''
|
||||
rejectDialogVisible.value = true
|
||||
}
|
||||
|
||||
const confirmReject = async () => {
|
||||
if (!rejectReason.value.trim()) { ElMessage.warning('请填写驳回原因'); return }
|
||||
rejectLoading.value = true
|
||||
try {
|
||||
await approvePurchase(currentRejectRow.value.id, {
|
||||
action: 'reject', reject_reason: rejectReason.value
|
||||
})
|
||||
ElMessage.success('已驳回')
|
||||
rejectDialogVisible.value = false
|
||||
await fetchData()
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err?.msg || '操作失败')
|
||||
} finally {
|
||||
rejectLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// --- 初始化 ---
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
fetchApprovers()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.app-container { padding: 20px; }
|
||||
.filter-container { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user