<template>
|
<div class="notice">
|
<el-dialog
|
v-model="dialogVisible"
|
:title="title"
|
width="50%"
|
:before-close="handleClose"
|
:close-on-press-escape="false"
|
:close-on-click-modal="false"
|
>
|
<el-form :model="state.form" size="default" ref="busRef" :rules="state.rules" >
|
<el-row :gutter="24">
|
<el-col :span="24">
|
<el-form-item label="企业名称:" prop="companyId" v-if="state.isAdmin">
|
<el-select v-model="state.form.companyId" placeholder="请选择" filterable clearable style="width: 100%" :disabled="title == '查看' || title == '编辑' || !state.isAdmin" @change="selectValueCom">
|
<el-option
|
v-for="item in state.companyList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="24">
|
<el-form-item label="申购单名称:" prop="applyName" >
|
<el-input :disabled="title === '查看'" v-model="state.form.applyName" placeholder="请输入"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="12">
|
<el-form-item label="申请部门:" prop="deptId" >
|
<el-select
|
:disabled="title === '查看'"
|
v-model="state.form.deptId"
|
placeholder="请选择部门"
|
style="width: 240px"
|
>
|
<el-option
|
v-for="item in state.deptList"
|
:key="item.deptId"
|
:label="item.deptName"
|
:value="item.deptId"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="申请日期:" prop="applyTime" >
|
<el-date-picker
|
:disabled="title === '查看'"
|
v-model="state.form.applyTime"
|
type="date"
|
placeholder="请选择日期"
|
style="width: 100%"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="12">
|
<el-form-item label="申请理由:" prop="applyReason" >
|
<el-input :disabled="title === '查看'" :rows="2" type="textarea" v-model="state.form.applyReason" placeholder="请输入"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="申请人:" prop="applyUser" >
|
<el-select clearable v-model="state.form.applyUser" :disabled="title =='查看'" filterable style="width: 100%">
|
<el-option
|
v-for="item in state.peopleList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="12">
|
<el-form-item label="直属部门领导:" prop="deptUser" >
|
<el-select clearable v-model="state.form.deptUser" :disabled="title =='查看'" filterable style="width: 100%">
|
<el-option
|
v-for="item in state.peopleList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="财务部:" prop="financeUser" >
|
<el-select clearable v-model="state.form.financeUser" :disabled="title =='查看'" filterable style="width: 100%">
|
<el-option
|
v-for="item in state.peopleList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="24">
|
<div style="display: flex;align-items: center;margin-bottom: 10px">
|
<span style="font-size: 15px;font-weight: 700;" >采购计划:</span>
|
<el-button
|
:disabled="title === '查看'"
|
type="primary"
|
@click="addTableData"
|
style="margin-left: 20px"
|
>新增</el-button>
|
</div>
|
<el-table
|
ref="tableRef"
|
:data="state.form.purchaseApplyPlans"
|
show-summary
|
:summary-method="getSummaries"
|
style="margin-bottom: 10px"
|
:border="true"
|
|
>
|
<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
|
<el-table-column label="品名" prop="name" align="center" width="150">
|
<template #default="{row,$index}">
|
<el-form-item :prop="'purchaseApplyPlans.' + '[' + $index + ']' + '.name'" :rules="state.rules.name">
|
<el-input style="margin-top: 10px" :disabled="title === '查看'" :rows="2" type="textarea" v-model="row.name" placeholder="请输入"></el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="型号规格" prop="model" align="center" width="150">
|
<template #default="{row,$index}">
|
<el-form-item :prop="'purchaseApplyPlans.' + '[' + $index + ']' + '.model'" :rules="state.rules.model">
|
<el-input style="margin-top: 10px" :disabled="title === '查看'" :rows="2" type="textarea" v-model="row.model" placeholder="请输入"></el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="建议供应商" prop="supplier" align="center" width="150">
|
<template #default="{row,$index}">
|
<el-form-item :prop="'purchaseApplyPlans.' + '[' + $index + ']' + '.supplier'" :rules="state.rules.supplier">
|
<el-input style="margin-top: 10px" :disabled="title === '查看'" :rows="2" type="textarea" v-model="row.supplier" placeholder="请输入"></el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="数量" prop="amount" align="center" width="150">
|
<template #default="{row,$index}">
|
<el-form-item :prop="'purchaseApplyPlans.' + '[' + $index + ']' + '.amount'" :rules="state.rules.amount">
|
<el-input
|
:disabled="title === '查看'"
|
v-model.trim.number="row.amount"
|
placeholder="请输入"
|
@input="debouncedUpdate"
|
@blur="handleBlur(row, 'amount')"
|
>
|
</el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="预计单价" prop="money" align="center" width="150">
|
<template #default="{row,$index}">
|
<el-form-item :prop="'purchaseApplyPlans.' + '[' + $index + ']' + '.money'" :rules="state.rules.money">
|
<el-input
|
:disabled="title === '查看'"
|
v-model="row.money"
|
placeholder="请输入"
|
@change="debouncedUpdate"
|
@input="row.money= row.money.replace(/[^\d.]/g, '') .replace(/\.+/g, '.').replace(/^\./, '0.').replace(/^(\d*\.?\d{0,2}).*/, '$1')"
|
@blur="handleBlur(row, 'money')"
|
>
|
</el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="分类" prop="solutions" align="center" width="150">
|
<template #default="{row,$index}">
|
<el-form-item :prop="'purchaseApplyPlans.' + '[' + $index + ']' + '.type'" :rules="state.rules.type">
|
<el-input style="margin-top: 10px" :disabled="title === '查看'" :rows="2" type="textarea" v-model="row.type" placeholder="请输入"></el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" v-if="title !== '查看'" >
|
<template #default="scope">
|
<el-button link type="danger" @click="delTableData(scope.row)" >删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer v-if="title !== '查看'">
|
<span class="dialog-footer">
|
<el-button @click="handleClose" size="default">取 消</el-button>
|
<el-button type="primary" @click="onSubmit" size="default" v-preReClick>确认</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
<script setup>
|
import {computed, onMounted, reactive, ref, toRefs} from 'vue'
|
import Cookies from "js-cookie";
|
import {getCompany} from "@/api/onlineEducation/company";
|
import {ElMessage} from "element-plus";
|
import {getUser} from "@/api/onlineEducation/user";
|
import {getDept, getObject, getObjectPage} from "@/api/qualityObjectives/object";
|
import {addTable, editTable, getTargetById} from "@/api/qualityObjectives/table";
|
import {addNeedDiscren, editNeedDiscren} from "@/api/need/need";
|
import {debounce} from "@/utils";
|
import {addApply, editApply} from "@/api/procurementPlatform/procurementPlatform";
|
|
const dialogVisible = ref(false);
|
const title = ref("");
|
const busRef = ref();
|
const length = ref()
|
const selectPopperClass = "max-width-select";
|
const emit = defineEmits(["getList"]);
|
const dataRef = ref();
|
const tableRef = ref();
|
const state = reactive({
|
form: {
|
id: '',
|
companyId: null,
|
deptId: null,
|
applyName: '',
|
applyTime: null,
|
applyReason: null,
|
applyUser: null,
|
deptUser: null,
|
financeUser: '',
|
purchaseApplyPlans:[],
|
},
|
rules: {
|
companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
|
deptId: [{ required: true, message: '请选择部门', trigger: 'blur' }],
|
applyName: [{ required: true, message: '请输入申购单名称', trigger: 'blur' }],
|
applyTime: [{ required: true, message: '请选择申请日期', trigger: 'blur' }],
|
applyReason: [{ required: true, message: '请输入申请理由', trigger: 'blur' }],
|
applyUser: [{ required: true, message: '请选择申请人', trigger: 'blur' }],
|
deptUser: [{ required: true, message: '请选择直属部门领导', trigger: 'blur' }],
|
financeUser: [{ required: true, message: '请选择财务部人员', trigger: 'blur' }],
|
name: [{required: true, message: "", trigger: "blur"}],
|
model: [{required: true, message: "", trigger: "blur"}],
|
supplier: [{required: true, message: "", trigger: "blur"}],
|
amount: [{required: true, message: "", trigger: "blur"}],
|
money: [{required: true, message: "", trigger: "blur"}],
|
type: [{required: true, message: "", trigger: "blur"}],
|
},
|
peopleList: [],
|
isAdmin: false,
|
companyList: [],
|
deptList: [],
|
})
|
|
onMounted(() => {
|
|
|
});
|
|
|
const openDialog = async (type, value,companyList) => {
|
const userInfo = JSON.parse(Cookies.get('userInfo'))
|
state.isAdmin = userInfo.userType === 0;
|
state.form.companyName = userInfo.companyName
|
state.form.companyId = userInfo.companyId
|
if(state.isAdmin){
|
state.form.companyId = value.companyId
|
state.form.companyName = value.companyName
|
state.companyList = companyList
|
}
|
title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
|
if(type === 'edit' || type === 'review') {
|
state.form = JSON.parse(JSON.stringify(value));
|
if(state.isAdmin){
|
state.form.companyId = value.companyId
|
state.form.companyName = value.companyName
|
}
|
}
|
await getDeptList()
|
await getPeopleList()
|
dialogVisible.value = true;
|
}
|
|
const getDeptList = async () => {
|
if(state.isAdmin && (state.form.companyId == 0 || state.form.companyId == null)){
|
return
|
}
|
const param = {
|
pageNum: 1,
|
pageSize: 999,
|
companyId: state.form.companyId
|
}
|
const res = await getDept(param)
|
if(res.code === 200){
|
state.deptList = res.data
|
}
|
}
|
const onSubmit = async () => {
|
|
const valid = await busRef.value.validate();
|
if(valid){
|
if(title.value === '新增'){
|
console.log('sta',state.form)
|
const {id, ...data} = JSON.parse(JSON.stringify(state.form))
|
const res = await addApply(data)
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '新增成功'
|
});
|
}else{
|
ElMessage.warning(res.message)
|
}
|
emit("getList")
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
}else if(title.value === '编辑'){
|
state.form.purchaseApplyPlans.forEach(item => {
|
item.applyId = state.form.id
|
})
|
const {...data} = JSON.parse(JSON.stringify(state.form))
|
const res = await editApply(data)
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '编辑成功'
|
});
|
}else{
|
ElMessage.warning(res.message)
|
}
|
emit("getList")
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
}
|
}
|
}
|
|
const handleClose = () => {
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
emit("getList")
|
|
}
|
const reset = () => {
|
state.form = {
|
id: '',
|
companyId: null,
|
deptId: null,
|
year: '',
|
fictionId: null,
|
checkId: null,
|
ratifyId: null,
|
fictionTime: null,
|
frequency: '',
|
purchaseApplyPlans:[],
|
}
|
state.deptList = []
|
state.peopleList = []
|
state.companyList = []
|
}
|
const getPeopleList = async ()=> {
|
if(state.isAdmin && (state.form.companyId == 0 || state.form.companyId == null)){
|
return
|
}
|
const queryParams = {
|
pageNum: 1,
|
pageSize: 9999,
|
companyId: state.form.companyId
|
}
|
const res = await getUser(queryParams)
|
if(res.code == 200){
|
state.peopleList = res.data.list?res.data.list:[]
|
}else{
|
ElMessage.warning(res.message)
|
}
|
};
|
|
|
|
const selectValueCom = (val) => {
|
state.form.applyUser = null
|
state.form.deptUser = null
|
state.form.financeUser = null
|
state.form.deptId = null
|
state.companyList.forEach(item => {
|
if(item.name === val){
|
state.form.companyId = item.id
|
}
|
})
|
getDeptList()
|
getPeopleList()
|
}
|
|
const handleChangeNum = (value) => {
|
if (!/^\d+$/.test(value)) { // 验证是否为数字
|
ElMessage.warning('只能输入数字')
|
state.form.year = '' // 重置选择,避免非法值被添加到options中
|
} else if (!state.yearList.some(option => option.label === value)) { // 确保不是已存在的选项
|
state.yearList.push({ value, label: value }); // 添加新选项(这里简单地将值和标签设为相同)
|
}
|
}
|
// const addTableData = () => {
|
// state.form.purchaseApplyPlans.push({})
|
// }
|
// const delTableData = (val) => {
|
// state.form.purchaseApplyPlans = state.form.purchaseApplyPlans.filter(item=> item != val)
|
// }
|
|
|
const summaryData = computed(() => {
|
return state.form.purchaseApplyPlans.reduce((acc, row) => {
|
const money = Number(row.money) || 0
|
const quantity = Number(row.amount) || 0
|
acc.money += money
|
acc.amount += quantity
|
return acc
|
}, {
|
money: 0,
|
amount: 0,
|
})
|
})
|
// 格式化货币显示
|
const formatCurrency = (value) => {
|
return '¥' + (Number(value) || 0).toFixed(2)
|
}
|
// 自定义合计行方法
|
const getSummaries = ({ columns }) => {
|
const sums = []
|
const data = summaryData.value
|
columns.forEach((column, index) => {
|
if (index === 0) {
|
sums[index] = `合计`
|
return
|
}
|
switch (column.property) {
|
case 'money':
|
sums[index] = `${formatCurrency(data.money)}`
|
break
|
case 'amount':
|
sums[index] = data.amount
|
break
|
default:
|
sums[index] = ''
|
}
|
})
|
|
return sums
|
}
|
// 防抖更新 - 防止频繁触发重计算
|
const debouncedUpdate = debounce(() => {
|
// 强制更新表格布局
|
tableRef.value?.doLayout()
|
}, 300)
|
|
// 输入框失去焦点时的处理
|
const handleBlur = (row, field) => {
|
row[field] = Number(row[field]) || 0
|
debouncedUpdate()
|
}
|
// 添加新行
|
const addTableData = () => {
|
state.form.purchaseApplyPlans.push({
|
money: null,
|
amount: null
|
})
|
|
debouncedUpdate()
|
}
|
// 删除行
|
const delTableData = (index) => {
|
state.form.purchaseApplyPlans.splice(index, 1)
|
debouncedUpdate()
|
}
|
|
|
defineExpose({
|
openDialog
|
});
|
|
</script>
|
|
<style scoped lang="scss">
|
.notice{
|
:deep(.el-form .el-form-item__label) {
|
font-size: 15px;
|
}
|
.file {
|
display: flex;
|
flex-direction: column;
|
align-items: flex-start;
|
}
|
}
|
</style>
|