| | |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="记录名称:" prop="recordName"> |
| | | <el-input v-model.trim="state.form.recordName" :readonly="state.title =='查看'" placeholder="文件名称"></el-input> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="材料名称:" prop="materialId"> |
| | | <el-select v-model="state.form.materialId" placeholder="请选择" :disabled="state.title =='查看'" clearable @change="getInventory()"> |
| | | <el-option |
| | | v-for="item in state.materialList" |
| | | :key="item.id" |
| | | :label="item.materialName" |
| | | :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-button |
| | | type="primary" |
| | | plain |
| | | @click="openAdd('add',{})" |
| | | >新增材料</el-button> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <el-form-item label="库存数量:"> |
| | | <el-input v-model.trim="state.originInventory" readonly placeholder="库存数量"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="材料清单:" prop="warehousingRecordDetails"> |
| | | <el-button |
| | |
| | | /> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="名称" prop="name" align="center"> |
| | | <el-table-column label="出入库" prop="recordType" align="center"> |
| | | <template #default="scope"> |
| | | <el-select clearable v-model="scope.row.recordType" :disabled="state.title =='查看'" filterable placeholder="出入库" style="width: 100%" @change="checkRemain(scope)"> |
| | | <el-option :key="1" label="入库" :value="1"/> |
| | | <el-option :key="2" label="出库" :value="2"/> |
| | | </el-select> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="规格" prop="specification" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim="scope.row.name" |
| | | size="large" |
| | | v-model.trim="scope.row.specification" |
| | | type="textarea" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | readonly |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="入库-单位" prop="enterCompany" align="center"> |
| | | <el-table-column label="单位" prop="materialUnit" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim="scope.row.enterCompany" |
| | | size="large" |
| | | v-model.trim="scope.row.materialUnit" |
| | | type="textarea" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | readonly |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="入库数量" prop="enterNum" align="center"> |
| | | <el-table-column label="数量" prop="num" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim.number="scope.row.enterNum" |
| | | size="large" |
| | | v-model.trim.number="scope.row.num" |
| | | type="number" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | @input="checkRemain(scope)" |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="入库-入库经手人" prop="enterPerson" align="center"> |
| | | <el-table-column label="经手人" prop="createBy" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim="scope.row.enterPerson" |
| | | size="large" |
| | | type="textarea" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="出库-出库单位" prop="outboundCompany" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim="scope.row.outboundCompany" |
| | | size="large" |
| | | type="textarea" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="出库-出库数量" prop="outboundNum" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim.number="scope.row.outboundNum" |
| | | size="large" |
| | | type="number" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="出库-出库经手人" prop="outboundPerson" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim="scope.row.outboundPerson" |
| | | size="large" |
| | | type="textarea" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | > |
| | | </el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="库存数量" prop="amount" align="center"> |
| | | <template #default="scope"> |
| | | <el-input |
| | | v-model.trim.number="scope.row.amount" |
| | | size="large" |
| | | type="number" |
| | | style="width: 100%;" |
| | | clearable |
| | | :readonly="state.title =='查看'" |
| | | > |
| | | </el-input> |
| | | <el-select clearable v-model="scope.row.createBy" :disabled="state.title =='查看'" filterable placeholder="经手人" style="width: 100%"> |
| | | <el-option |
| | | v-for="item in state.userList" |
| | | :key="item.userId" |
| | | :label="item.name" |
| | | :value="item.name" |
| | | /> |
| | | </el-select> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="备注" prop="remark" align="center"> |
| | |
| | | <el-button type="primary" @click="onSubmit" size="default" v-preReClick>确认</el-button> |
| | | </span> |
| | | </template> |
| | | <edit-dialog ref="dialogRef" @getList="getMaterials"></edit-dialog> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | <script setup> |
| | | import {reactive, ref, toRefs, defineEmits, nextTick, onMounted} from 'vue' |
| | | import editDialog from '@/views/work/procurementPlatform/materialMng/components/editDialog.vue' |
| | | import {ElMessage} from "element-plus"; |
| | | import {getToken} from "@/utils/auth"; |
| | | import { |
| | | updateMaintenanceEvaluate, |
| | | getMaintenanceEvaluateDetail |
| | | } from "@/api/infrastructureMng/ledger"; |
| | | |
| | | import {listUser} from "@/api/system/user"; |
| | | import {getWarehousingRecordDetail, updateWarehousingRecord} from "@/api/outsourcingCooperate/outsourcingCooperate"; |
| | | |
| | | import {getMaterialList} from "@/api/outsourcingCooperate/outsourcingCooperate"; |
| | | import useUserStore from "@/store/modules/user"; |
| | | const emit = defineEmits(["getList"]); |
| | | const dialogVisible = ref(false) |
| | | const superRef = ref() |
| | | const dialogRef = ref(); |
| | | const checkList = (rule, value, callback) => { |
| | | if (state.form.warehousingRecordDetails.length == 0) { |
| | | callback(new Error('材料清单不可为空')) |
| | |
| | | callback() |
| | | } |
| | | } |
| | | const userStore = useUserStore() |
| | | const state = reactive({ |
| | | title: '', |
| | | form: { |
| | | id: null, |
| | | companyId: null, |
| | | materialId: null, |
| | | recordName: '', |
| | | inventory: null, |
| | | warehousingRecordDetails: [], |
| | | delDetails: [] |
| | | }, |
| | | oldDeviceList: [], |
| | | formRules:{ |
| | | companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }], |
| | | recordName: [{ required: true, message: '请填写记录名称', trigger: 'blur' }], |
| | | materialId: [{ required: true, message: '请选择材料', trigger: 'blur' }], |
| | | warehousingRecordDetails: [{ required: true, validator: checkList, trigger: 'blur' }], |
| | | }, |
| | | isAdmin: false, |
| | | companyList: [] |
| | | companyList: [], |
| | | userList: [], |
| | | isOverNum: false, |
| | | originInventory: 0 |
| | | }) |
| | | onMounted(() => { |
| | | |
| | |
| | | if(isAdmin){ |
| | | state.companyList = companyList |
| | | } |
| | | await getUserList() |
| | | await getMaterials(companyId) |
| | | state.title = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' |
| | | state.form.companyId = companyId |
| | | if(state.title == '编辑'||state.title == '查看'){ |
| | |
| | | dialogVisible.value = true |
| | | } |
| | | |
| | | const openAdd = (type, value) => { |
| | | dialogRef.value.openDialog(type, value, state.form.companyId, state.isAdmin, state.companyList ); |
| | | } |
| | | |
| | | const calculateInventoryExcludingCurrent = (currentRow) => { |
| | | if(!state.form.materialId) return 0 |
| | | let inventory = state.materialList.find(i=>i.id == state.form.materialId)?.inventory || 0; |
| | | if(Array.isArray(state.form.warehousingRecordDetails) && state.form.warehousingRecordDetails.length>0){ |
| | | for(let i of state.form.warehousingRecordDetails){ |
| | | if(i === currentRow) continue |
| | | if(i.recordType == 1 && i.num){ |
| | | inventory = inventory + Number(i.num); |
| | | } |
| | | if(i.recordType == 2 && i.num){ |
| | | inventory = inventory - Number(i.num); |
| | | } |
| | | } |
| | | } |
| | | return inventory; |
| | | } |
| | | |
| | | const calculateInventory = () => { |
| | | if(state.form.materialId){ |
| | | let inventory = state.materialList.find(i=>i.id == state.form.materialId)?.inventory || 0 |
| | | if(Array.isArray(state.form.warehousingRecordDetails) && state.form.warehousingRecordDetails.length>0){ |
| | | for(let i of state.form.warehousingRecordDetails){ |
| | | if(i.recordType == 1 && i.num){ |
| | | inventory = inventory + Number(i.num) |
| | | } |
| | | if(i.recordType == 2 && i.num){ |
| | | inventory = inventory - Number(i.num) |
| | | } |
| | | } |
| | | } |
| | | state.originInventory = inventory |
| | | if(inventory < 0){ |
| | | ElMessage.warning('库存不足,无法出库') |
| | | } |
| | | }else{ |
| | | state.originInventory = 0 |
| | | } |
| | | } |
| | | |
| | | const checkRemain = (scope) => { |
| | | if (scope.row.recordType === 2 && scope.row.num !== null && scope.row.num !== '') { |
| | | const availableInventory = calculateInventoryExcludingCurrent(scope.row); |
| | | const inputNum = Number(scope.row.num); |
| | | if (inputNum > availableInventory) { |
| | | ElMessage.warning(`出库数量不能大于当前库存,当前可用库存为:${availableInventory}`); |
| | | scope.row.num = availableInventory; |
| | | } |
| | | calculateInventory(); |
| | | } else { |
| | | calculateInventory(); |
| | | } |
| | | } |
| | | |
| | | const getMaterials = async (companyId)=>{ |
| | | const queryParams = { |
| | | pageNum: 1, |
| | | pageSize: 999, |
| | | companyId: companyId |
| | | } |
| | | const res = await getMaterialList(queryParams) |
| | | if (res.code == 200) { |
| | | state.materialList = res.data.list?res.data.list:[] |
| | | } else { |
| | | ElMessage.warning(res.message) |
| | | } |
| | | } |
| | | |
| | | const getInventory = ()=>{ |
| | | state.form.warehousingRecordDetails = state.form.warehousingRecordDetails.map(i=>{ |
| | | return { |
| | | ...i, |
| | | specification: state.materialList.find(i=>i.id == state.form.materialId)?.specification, |
| | | materialUnit: state.materialList.find(i=>i.id == state.form.materialId)?.materialUnit |
| | | } |
| | | }) |
| | | calculateInventory() |
| | | } |
| | | |
| | | const addLine = () => { |
| | | const obj = { |
| | | id: null, |
| | | recordId: null, |
| | | boardingTime: '', |
| | | name: '', |
| | | enterCompany: '', |
| | | enterNum: null, |
| | | enterPerson: '', |
| | | outboundCompany: '', |
| | | outboundNum: null, |
| | | outboundPerson: '', |
| | | amount: null, |
| | | recordType: null, |
| | | specification: state.materialList.find(i=>i.id == state.form.materialId)?.specification || '', |
| | | materialUnit: state.materialList.find(i=>i.id == state.form.materialId)?.materialUnit || '', |
| | | num: null, |
| | | createBy: userStore.name || null, |
| | | remark: '' |
| | | } |
| | | state.form.warehousingRecordDetails.push(obj); |
| | | state.form.warehousingRecordDetails.push(obj) |
| | | calculateInventory() |
| | | } |
| | | |
| | | const handleDelete = (i) =>{ |
| | | state.form.warehousingRecordDetails = state.form.warehousingRecordDetails.filter((item,index) => index != i) |
| | | calculateInventory() |
| | | } |
| | | |
| | | const onSubmit = async () => { |
| | | const valid = await superRef.value.validate(); |
| | | if(valid){ |
| | | const data = JSON.parse(JSON.stringify(state.form)) |
| | | console.log(data,'return') |
| | | // return |
| | | data.recordName = state.materialList.find(i=>i.id == state.form.materialId)?.materialName |
| | | data.inventory = state.originInventory |
| | | data.delDetails = state.oldDeviceList.filter(i =>!data.warehousingRecordDetails.some(item=>item.id == i.id)).map(i=>i.id) |
| | | if(state.title == '新增'){ |
| | | delete data.id |
| | |
| | | id: item.id, |
| | | recordId: item.recordId, |
| | | boardingTime: item.boardingTime, |
| | | name: item.name, |
| | | enterCompany: item.enterCompany, |
| | | enterNum: item.enterNum, |
| | | enterPerson: item.enterPerson, |
| | | outboundCompany: item.outboundCompany, |
| | | outboundNum: item.outboundNum, |
| | | outboundPerson: item.outboundPerson, |
| | | amount: item.amount, |
| | | recordType: item.recordType, |
| | | specification: item.specification, |
| | | materialUnit: item.materialUnit, |
| | | num: item.num, |
| | | createBy: item.createBy, |
| | | remark: item.remark |
| | | } |
| | | }) |
| | |
| | | } |
| | | |
| | | const getDeptList = async ()=>{ |
| | | // state.form.establishmentId = null |
| | | // state.form.processId = null |
| | | // state.form.approvalId = null |
| | | // await getUserList(state.form.companyId) |
| | | state.form.materialId = null |
| | | await getMaterials(state.form.companyId) |
| | | } |
| | | |
| | | const getUserList = async (companyId)=> { |
| | | const res = await listUser({pageIndex: 1,pageSize: 999,companyId: companyId}) |
| | | const getUserList = async ()=> { |
| | | const res = await listUser({pageIndex: 1,pageSize: 999}) |
| | | if(res.code == 200){ |
| | | state.userList = res.data.list?res.data.list.map(item=>{ |
| | | const user = item.id |
| | |
| | | state.form = { |
| | | id: null, |
| | | companyId: null, |
| | | materialId: null, |
| | | recordName: '', |
| | | inventory: null, |
| | | warehousingRecordDetails: [], |
| | | delDetails: [] |
| | | } |