cmvr-wms/ruoyi-ui-vue3/src/components/PurchaseSheet/Lookup.vue
lixiaolong 5bdeceafd7 feat(auth): 添加认证cookie名称配置并优化表单布局
- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称
- 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配
- 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配
- 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名
- 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试
- 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token
- 调整系统角色授权用户页面的表单布局和表格样式类名
- 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
2026-10-15 11:30:55 +08:00

72 lines
8.1 KiB
Vue

<template>
<business-list-page class="purchase-lookup">
<template #header>
<el-form inline size="small">
<query-toolbar :active-count="$filterCount([!unbatched?query.supplierId:null])">
<el-form-item label="物品"><el-input v-model="query.materialName" clearable placeholder="名称、品牌、规格" @keyup.enter="search"/></el-form-item>
<el-form-item label="项目"><el-select v-model="query.projectId" clearable filterable :disabled="!!projectId"><el-option v-for="p in projects" :key="p.id" :value="p.id" :label="p.projectName"/></el-select></el-form-item>
<el-form-item v-if="!unbatched" label="批次"><el-input v-model="query.purchaseBatchNo" clearable @keyup.enter="search"/></el-form-item>
<template #actions><el-form-item><el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button><el-button @click="reset">重置</el-button><el-button icon="el-icon-refresh" :loading="loading" @click="load">刷新</el-button></el-form-item></template>
<template #business><el-button v-if="(unbatched) && ($can(['warehouse:purchase:add','warehouse:purchase:manage']))" type="primary" plain icon="el-icon-plus" @click="$emit('create')" >新增未组批</el-button></template>
<template v-if="!unbatched" #advanced><el-form-item label="供应商"><supplier-picker :show-manage="false" v-model="query.supplierId"/></el-form-item></template>
</query-toolbar>
</el-form>
<div v-if="unbatched" class="list-actions"><el-button type="primary" plain size="small" :disabled="!selected.length||saving" @click="prepare(selected)" v-if="$canAll([['warehouse:purchase:add','warehouse:purchase:manage'],['warehouse:purchase:edit','warehouse:purchase:manage']])">组批</el-button><el-button size="small" :disabled="!selected.length||saving" @click="$emit('edit',selected)" v-if="$can(['warehouse:purchase:edit','warehouse:purchase:manage'])">编辑</el-button><el-button size="small" type="danger" plain :disabled="!selected.length||saving" @click="remove(selected)" v-if="$can(['warehouse:purchase:remove','warehouse:purchase:manage'])">删除</el-button><span v-if="selected.length">已选 {{ selected.length }} 项</span><el-button v-if="selected.length" link @click="clearSelection">清空选择</el-button></div>
</template>
<template #default="{tableHeight}"><business-table :height="tableHeight" ref="table" row-key="id" :data="rows" v-loading="loading" size="small" @selection-change="selectionChanged" @row-dblclick="open">
<el-table-column v-if="unbatched" type="selection" width="45" :reserve-selection="true" :selectable="canPrepare"/>
<el-table-column label="物品 / 规格" min-width="220"><template #default="s"><item-summary :name="s.row.materialName" :brand="s.row.materialBrand" :spec="s.row.materialParams" :unit="s.row.unit" /></template></el-table-column>
<el-table-column prop="projectName" label="项目" min-width="130" show-overflow-tooltip/>
<el-table-column v-if="!unbatched" prop="purchaseBatchNo" label="批次" min-width="140" show-overflow-tooltip/>
<el-table-column v-if="!unbatched" prop="supplierName" label="供应商" min-width="120" show-overflow-tooltip/>
<el-table-column label="数量" width="95" show-overflow-tooltip><template #default="s">{{ s.row.quantity }} {{ s.row.unit }}</template></el-table-column>
<el-table-column label="单价" width="100" align="right" show-overflow-tooltip><template #default="s">{{ s.row.finalUnitPrice==null?'待报价':s.row.finalUnitPrice }}</template></el-table-column>
<el-table-column v-if="!unbatched" label="进度" width="150" align="center" show-overflow-tooltip><template #default="s">已验收 {{ s.row.acceptedQuantity||0 }} / 未到 {{ s.row.remainingQuantity||0 }}</template></el-table-column>
<el-table-column :formatter="(row,column,value)=>$dateTime(value)" v-else prop="createTime" label="创建时间" width="170" show-overflow-tooltip/>
<el-table-column label="操作" width="160" fixed="right" align="center" class-name="business-operation-cell"><template #default="s"><el-button v-if="s.row.purchaseBatchId" link type="primary" @click="open(s.row)">打开清单</el-button><template v-else-if="canPrepare(s.row)"><el-button link type="primary" @click="$emit('edit',[s.row])" v-if="$can(['warehouse:purchase:edit','warehouse:purchase:manage'])">编辑</el-button><el-button link type="primary" @click="prepare([s.row])" v-if="$canAll([['warehouse:purchase:add','warehouse:purchase:manage'],['warehouse:purchase:edit','warehouse:purchase:manage']])">组批</el-button><el-button link type="primary" @click="remove([s.row])" v-if="$can(['warehouse:purchase:remove','warehouse:purchase:manage'])">删除</el-button></template><span v-else>归档记录</span></template></el-table-column>
</business-table></template>
<template #footer><pagination :total="total" v-model:page="query.pageNum" v-model:limit="query.pageSize" @pagination="load"/></template>
<template #dialogs><group-dialog ref="group" @prepared="prepared" /></template>
</business-list-page>
</template>
<script>
import { defineAsyncComponent } from 'vue'
import {listPurchase,getUnbatchedSheet,savePurchaseSheet,newPurchaseSheetSubmissionKey} from '@/api/warehouse/purchase'
import GroupDialog from './GroupDialog.vue'
import {projectOptions} from '@/api/project/project'
export default {
props:{projectId:Number,unbatched:Boolean,embedded:Boolean},
components:{GroupDialog,SupplierPicker:defineAsyncComponent(()=>import('@/components/SupplierPicker'))},
data(){return {query:{pageNum:1,pageSize:20,materialName:'',purchaseBatchNo:'',projectId:this.projectId,supplierId:null,productionTaskId:Number(this.$route.query.productionTaskId)||undefined},rows:[],projects:[],total:0,selected:[],loading:false,saving:false}},
watch:{unbatched(){this.clearSelection();this.search()},projectId(id){this.query.projectId=id;this.clearSelection();this.search()},'$route.fullPath'(){if(!this.embedded){this.applyRoute();this.clearSelection();this.search()}}},
created(){projectOptions('',true).then(r=>this.projects=r.data||[]);this.applyRoute();this.load()},
methods:{
canPrepare(r){return !r.purchaseBatchId&&!r.priceLocked&&!r.historical&&Number(r.purchaseStatus)!==5&&Number(r.acceptedQuantity||0)<=0&&Number(r.pendingArrivalQuantity||0)<=0},
applyRoute(){if(this.embedded)return;this.query.productionTaskId=Number(this.$route.query.productionTaskId)||undefined;this.query.materialName=this.$route.query.materialName||'';this.query.requestNo=this.$route.query.requestNo||undefined},
selectionChanged(rows){this.selected=rows},clearSelection(){if(this.$refs.table)this.$refs.table.clearSelection();this.selected=[]},
async load(){const seq=this._sequence=(this._sequence||0)+1;this.loading=true;try{const r=await listPurchase({...this.query,unbatched:this.unbatched});if(seq===this._sequence){this.rows=r.rows||[];this.total=r.total||0}}finally{if(seq===this._sequence)this.loading=false}},
search(){this.query.pageNum=1;this.load()},
reset(){this.clearSelection();this.query={pageNum:1,pageSize:20,projectId:this.projectId};this.load()},
open(row){if(row.purchaseBatchId)this.$emit('open',row);else if(this.canPrepare(row))this.$emit('edit',[row])},
prepare(rows){if(this.saving||!rows.length)return;this.$refs.group.open(rows)},
prepared(sheet){this.clearSelection();this.$emit('prepared',sheet)},
async remove(rows){
if(this.saving)return
try{await this.$modal.confirm('确认删除这 '+rows.length+' 条未组批明细?')}catch(_){return}
this.saving=true
try{
const ids=rows.map(r=>r.id).sort((a,b)=>a-b).join(',')
if(this._deleteSubmission?.ids!==ids){
const sheet=(await getUnbatchedSheet(rows.map(r=>r.id))).data
this._deleteSubmission={ids,payload:{...sheet,submissionKey:newPurchaseSheetSubmissionKey(),rows:[],deletedIds:sheet.rows.map(r=>r.id)}}
}
await savePurchaseSheet(this._deleteSubmission.payload)
this._deleteSubmission=null;this.clearSelection();await this.load();this.$modal.msgSuccess('已删除')
}catch{/* Keep the original delete payload/key to recover a lost response safely. */}
finally{this.saving=false}
}
}
}
</script>
<style scoped>.secondary{color:var(--el-text-color-secondary);font-size:12px}.purchase-lookup{display:flex;flex-direction:column;flex:1;min-height:0}</style>