37 lines
5.3 KiB
Vue
37 lines
5.3 KiB
Vue
|
|
<template>
|
|||
|
|
<el-dialog :title="mode==='receipt'?'批量确认入库':'批量到货'" :visible.sync="visible" width="min(1000px,98vw)" append-to-body :close-on-click-modal="!saving" :show-close="!saving" :close-on-press-escape="!saving">
|
|||
|
|
<p>共 {{ rows.length }} 条,逐行核对数量。成功行不再重复提交;失败行保留原因。</p>
|
|||
|
|
<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 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>
|
|||
|
|
<el-table :data="rows" border max-height="480">
|
|||
|
|
<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.materialParams || s.row.productSpec,s.row.productCode].filter(Boolean).join(' / ') }}</div></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.0001" :max="s.row.maximum" :disabled="s.row.done || saving" :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"><el-button :disabled="saving" @click="visible=false">关闭</el-button><el-button type="primary" :loading="saving" :disabled="rows.every(r=>r.done)" @click="submit">提交未成功行</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}),
|
|||
|
|
methods:{
|
|||
|
|
async open(input,mode='receipt') { this.mode=mode; this.date=this.parseTime(new Date(),'{y}-{m}-{d}'); this.commonArea=undefined; this.areas=(await optionselectArea()).data||[]; this.rows=input.filter(r=>mode==='receipt'?Number(r.inStatus)===0:Number(r.remainingQuantity)>0&&Number(r.purchaseStatus)!==5).map(r=>({...r,quantity:Number(mode==='receipt'?r.inNum:r.remainingQuantity),maximum:Number(mode==='receipt'?r.inNum:r.remainingQuantity),done:false,result:'',key:`batch-${r.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`,arrivalIdCreated:null})); if(!this.rows.length)return this.$modal.msgWarning('没有可办理的记录');this.visible=true },
|
|||
|
|
setArea(value){this.rows.filter(r=>!r.done).forEach(r=>{r.areaId=value})},
|
|||
|
|
async submit(){if(this.saving)return;this.saving=true;try{for(const row of this.rows.filter(r=>!r.done)){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(!this.date)throw new Error('请选择日期');if(!row.arrivalIdCreated){const result=await addPurchaseArrival({purchaseRequestId:row.id,arrivalQuantity:row.quantity,arrivalDate:this.date,requestKey:row.key});row.arrivalIdCreated=result.data&&result.data.id;if(!row.arrivalIdCreated)throw new Error('请刷新到货记录核对')}if(this.acceptAll){const current=((await listPurchaseArrival(row.id)).data||[]).find(a=>a.id===row.arrivalIdCreated);if(!current)throw new Error('到货记录不存在');if(Number(current.acceptanceStatus)===0)await acceptPurchaseArrival(row.arrivalIdCreated,{acceptanceStatus:1,defectiveQuantity:0});else if(Number(current.acceptanceStatus)!==1)throw new Error('该行已被拒收,请刷新核对')}}
|
|||
|
|
row.done=true;row.result=this.mode==='receipt'?'已入库':this.acceptAll?'已到货并验收':'已登记到货';
|
|||
|
|
}catch(error){row.result=error.message||'未成功,请刷新核对'}}this.$emit('changed')}finally{this.saving=false}}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</script>
|