feat: 基础信息弹窗新增"发起采购申请"按钮, 跳转采购管理自动预填物料+默认审批人

- material/list.vue: 弹窗头部新增"发起采购申请"按钮, 携带物料信息跳转/purchase
- purchase/index.vue: onMounted读取URL参数自动弹窗并预填物料
- purchase/index.vue: fetchDefaultApprover取当前用户上一次采购申请的审批人作为默认值
- 商家链接placeholder去掉"选填"字样
This commit is contained in:
yueli
2026-07-14 17:13:31 +08:00
parent 68fd93b457
commit 31903bdb39
2 changed files with 80 additions and 7 deletions

View File

@ -138,7 +138,7 @@
</el-col>
<el-col :span="24">
<el-form-item label="商家链接">
<el-input v-model="form.supplier_link" placeholder="商家地址链接(选填)" clearable />
<el-input v-model="form.supplier_link" placeholder="商家地址链接" clearable />
</el-form-item>
</el-col>
<el-col :span="24">
@ -235,6 +235,7 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { Refresh, Plus } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useUserStore } from '@/stores/user'
@ -372,21 +373,55 @@ const handlePageChange = (p: number) => { page.value = p; fetchData() }
const handleSizeChange = (s: number) => { pageSize.value = s; page.value = 1; fetchData() }
// --- 新建 ---
const openCreateDialog = () => {
const openCreateDialog = (prefill?: { materialId?: number; name?: string; spec?: string; unit?: string }) => {
dialogTitle.value = '新建采购申请'
form.value = {
name: '', spec_model: '', quantity: 1,
name: prefill?.name || '',
spec_model: prefill?.spec || '',
quantity: 1,
purchase_date: new Date().toISOString().split('T')[0],
supplier_link: '', remark: '',
unit_price: undefined, total_price: undefined,
approver_id: undefined, images: []
}
materialBaseId.value = null
materialOptions.value = []
autoFillHint.value = ''
if (prefill?.materialId) {
materialBaseId.value = prefill.materialId
// 预填物料选项以便显示选中状态
materialOptions.value = [{
id: prefill.materialId,
name: prefill.name || '',
spec_model: prefill.spec || ''
}]
if (prefill.spec) {
form.value.spec_model = prefill.spec
}
autoFillHint.value = `已从基础信息【${prefill.name || ''}】带入,请补充采购信息`
} else {
materialBaseId.value = null
materialOptions.value = []
autoFillHint.value = ''
}
fileList.value = []
totalPriceManuallyEdited.value = false
formDialogVisible.value = true
// 异步加载默认审批人(取当前用户上一次采购申请的审批人)
fetchDefaultApprover()
}
// 获取当前用户上一次采购申请的审批人作为默认值
const fetchDefaultApprover = async () => {
try {
const res: any = await getPurchaseList({ page: 1, limit: 1, status: undefined })
const items = res?.data?.items || []
if (items.length > 0 && items[0].approver_id) {
form.value.approver_id = items[0].approver_id
}
} catch (e) {
// 静默失败,用户可手动选择
}
}
// --- 物料搜索(分页) ---
@ -602,9 +637,22 @@ const confirmReject = async () => {
}
// --- 初始化 ---
const route = useRoute()
onMounted(() => {
fetchData()
fetchApprovers()
// 从基础信息跳转过来的参数
const query = route.query
if (query.material_id) {
openCreateDialog({
materialId: Number(query.material_id),
name: (query.name as string) || '',
spec: (query.spec as string) || '',
unit: (query.unit as string) || ''
})
}
})
</script>