cmvr-wms/ruoyi-ui/src/components/ReceiptDialog/Batch.vue
lixiaolong e3860a3fd9 feat(production): 优化生产任务操作权限控制与数据查询
- 添加权限检查功能,防止未授权操作
- 实现远程搜索功能优化任务选择体验
- 集成分页查询提高大数据量性能表现
- 增强批量操作界面增加搜索筛选功能
- 完善表单验证与错误处理机制
- 重构数据过滤逻辑支持多条件组合查询
2026-10-13 09:41:46 +08:00

45 lines
8.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<el-dialog :title="mode==='receipt'?'批量入库':mode==='acceptance'?'批量验收':'批量到货'" :visible.sync="visible" width="min(1000px,98vw)" append-to-body :close-on-click-modal="!saving" :show-close="!saving" :close-on-press-escape="!saving">
<el-input v-model="keyword" size="small" clearable placeholder="搜索批次、项目、物品" style="width:260px;margin-bottom:10px"/>
<el-form inline size="small">
<el-form-item v-if="mode==='receipt'" label="统一库区"><el-select v-model="commonArea" @change="setArea"><el-option v-for="a in areas" :key="a.id" :label="a.areaName" :value="a.id" /></el-select></el-form-item>
<el-form-item v-if="mode!=='acceptance'" label="日期"><el-date-picker v-model="date" type="date" value-format="yyyy-MM-dd" :clearable="false"/></el-form-item>
<el-form-item label="备注"><el-input v-model="remark" maxlength="500"/></el-form-item>
<el-form-item v-if="mode==='arrival'"><el-checkbox v-model="acceptAll">同时按全部合格验收</el-checkbox></el-form-item>
<el-form-item v-if="mode!=='acceptance'"><el-button size="small" :disabled="saving" @click="selectedRows.filter(r=>!r.arrivalIdCreated).forEach(r=>r.quantity=r.maximum)">{{ mode==='receipt'?'本次全部入库':'本次全部到齐' }}</el-button><el-button size="small" :disabled="saving" @click="selectedRows.filter(r=>!r.arrivalIdCreated).forEach(r=>r.quantity=0)">清空数量</el-button></el-form-item>
</el-form>
<el-table :data="filteredRows" border max-height="480">
<el-table-column width="45"><template slot="header"><el-checkbox :value="filteredRows.length>0&&filteredRows.every(r=>r.done||r.chosen)" @change="selectVisible"/></template><template slot-scope="s"><el-checkbox v-model="s.row.chosen" :disabled="s.row.done||saving"/></template></el-table-column>
<el-table-column label="批次 / 来源" min-width="150" show-overflow-tooltip><template slot-scope="s">{{ s.row.purchaseBatchNo || s.row.sourceNo || s.row.arrivalNo || '未分批' }}<div class="secondary">{{ s.row.supplierName }}</div></template></el-table-column>
<el-table-column label="项目 / 物品" min-width="190"><template slot-scope="s">{{ s.row.sourceProjectName || s.row.projectName }}<br>{{ s.row.productName || s.row.materialName }}<div style="color:#909399;font-size:12px">{{ [s.row.materialBrand || s.row.productBrand || s.row.brand,s.row.materialParams || s.row.productSpec || s.row.spec,s.row.unit].filter(Boolean).join(' / ') }}</div></template></el-table-column>
<el-table-column label="剩余" width="100"><template slot-scope="s">{{ s.row.maximum }} {{ s.row.unit }}</template></el-table-column>
<el-table-column v-if="mode==='acceptance'" label="不合格数量" width="145"><template slot-scope="s"><el-input-number v-model="s.row.defectiveQuantity" :precision="4" :min="0" :max="s.row.quantity" :disabled="saving||s.row.done" :controls="false" style="width:120px"/></template></el-table-column>
<el-table-column label="本次数量" width="165"><template slot-scope="s"><el-input-number v-model="s.row.quantity" :precision="4" :min="0" :max="s.row.maximum" :disabled="mode==='acceptance' || s.row.done || saving || !!s.row.arrivalIdCreated" :controls="false" style="width:140px" /></template></el-table-column>
<el-table-column v-if="mode==='receipt'" label="库区" width="165"><template slot-scope="s"><el-select v-model="s.row.areaId" :disabled="s.row.done || saving"><el-option v-for="a in areas" :key="a.id" :label="a.areaName" :value="a.id" /></el-select></template></el-table-column>
<el-table-column label="结果" min-width="180"><template slot-scope="s"><span :style="{color:s.row.done?'#218c4b':'#d27b00'}">{{ s.row.result || '待提交' }}</span></template></el-table-column>
</el-table>
<div slot="footer"><span>本次 {{ selectedRows.filter(r=>Number(r.quantity)>0).length }} 项</span><el-button :disabled="saving" @click="visible=false">关闭</el-button><el-button type="primary" :loading="saving" :disabled="!selectedRows.some(r=>Number(r.quantity)>0)" @click="submit">确认本次{{ mode==='arrival'?'到货':mode==='acceptance'?'验收':'入库' }}</el-button></div>
</el-dialog>
</template>
<script>
import { optionselectArea } from '@/api/warehouse/area'
import { getInRecord, receiveInRecord, updateInRecord, confirmInRecord } from '@/api/warehouse/inRecord'
import { addPurchaseArrival, acceptPurchaseArrival, listPurchaseArrival } from '@/api/warehouse/purchase'
export default {
data:()=>({visible:false,saving:false,mode:'receipt',rows:[],areas:[],commonArea:undefined,date:'',remark:'',acceptAll:true,keyword:''}),
watch:{keyword(){const visible=new Set(this.filteredRows);this.rows.forEach(r=>{if(!visible.has(r)&&!r.done)r.chosen=false})}},
computed:{selectedRows(){return this.rows.filter(r=>r.chosen&&!r.done)},filteredRows(){const k=this.keyword.toLowerCase();return this.rows.filter(r=>!k||[r.purchaseBatchNo,r.sourceNo,r.projectName,r.sourceProjectName,r.materialName,r.productName,r.materialBrand,r.materialParams,r.brand,r.spec,r.productBrand,r.productSpec,r.unit,r.supplierName].join(' ').toLowerCase().includes(k))}},
methods:{
async open(input,mode='receipt') { this.mode=mode; this.keyword=''; this.date=this.parseTime(new Date(),'{y}-{m}-{d}');this.remark='';this.acceptAll=true; this.commonArea=undefined; this.areas=mode==='receipt'?((await optionselectArea()).data||[]):[]; this.rows=input.filter(r=>mode==='receipt'?Number(r.inStatus)===0:Number(r.remainingQuantity)>0&&Number(r.purchaseStatus)!==5&&r.priceLocked&&!r.historical).map(r=>({...r,quantity:mode==='receipt'?Number(r.inNum):0,maximum:Number(mode==='receipt'?r.inNum:r.remainingQuantity),chosen:true,chosen:true,done:false,result:'',key:`batch-${r.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`,arrivalIdCreated:null})); if(mode==='acceptance'){this.rows=[];for(const request of [...new Map(input.map(r=>[r.id,r])).values()]){const arrivals=(await listPurchaseArrival(request.id)).data||[];for(const a of arrivals.filter(a=>Number(a.acceptanceStatus)===0))this.rows.push({...request,arrivalIdCreated:a.id,arrivalNo:a.arrivalNo,quantity:Number(a.arrivalQuantity),maximum:Number(a.arrivalQuantity),defectiveQuantity:0,done:false,result:''})}}if(!this.rows.length)return this.$modal.msgWarning('没有可办理的记录');this.visible=true },
selectVisible(value){if(this.saving)return;this.filteredRows.filter(r=>!r.done).forEach(r=>{r.chosen=value})},
setArea(value){this.selectedRows.forEach(r=>{r.areaId=value})},
async submit(){if(this.saving)return;if(!this.date)return this.$modal.msgWarning('请选择日期');const pending=this.selectedRows.filter(r=>Number(r.quantity)>0);if(!pending.length)return this.$modal.msgWarning('请填写本次实际数量');this.saving=true;try{for(const row of pending){try{
if(!(row.quantity>0))throw new Error('数量必须大于0');
if(this.mode==='receipt') {if(!row.areaId)throw new Error('请选择库区');const current=(await getInRecord(row.id)).data;if(current.receiptRoot)await receiveInRecord(row.id,{areaId:row.areaId,quantity:row.quantity,key:row.key,date:this.date,remark:this.remark});else{if(row.quantity!==Number(current.inNum))throw new Error('历史或手工入库请整条确认');if(Number(current.inStatus)===1){if(current.areaId!==row.areaId)throw new Error('该条已在其他库区入库,请核对')}else{await updateInRecord({...current,areaId:row.areaId,businessDate:this.date,remark:this.remark});await confirmInRecord(row.id)}}}
else {if(!row.arrivalIdCreated){const result=await addPurchaseArrival({purchaseRequestId:row.id,arrivalQuantity:row.quantity,arrivalDate:this.date,requestKey:row.key,remark:this.remark});row.arrivalIdCreated=result.data&&result.data.id;if(!row.arrivalIdCreated)throw new Error('请刷新到货记录核对')}if(this.mode==='acceptance'||this.acceptAll){const current=((await listPurchaseArrival(row.id)).data||[]).find(a=>a.id===row.arrivalIdCreated);if(!current)throw new Error('到货记录不存在');row.quantity=Number(current.arrivalQuantity);if(Number(current.acceptanceStatus)===0)await acceptPurchaseArrival(row.arrivalIdCreated,{acceptanceStatus:1,defectiveQuantity:this.mode==='acceptance'?Number(row.defectiveQuantity||0):0,acceptanceRemark:this.remark});else if(Number(current.acceptanceStatus)!==1)throw new Error('该行已被拒收,请刷新核对')}}
row.done=true;row.result=(this.mode==='receipt'?'已入库':this.mode==='acceptance'||this.acceptAll?'已验收':'已登记到货')+' '+row.quantity;
}catch(error){row.result=(row.arrivalIdCreated?'已登记 '+row.quantity+',':'')+(error.message||'未成功,请重试')}}this.$emit('changed')}finally{this.saving=false}}
}
}
</script>