gaoluyang
昨天 cd8b52bdf89a4d1101f72e0ece9f4df22a3d3f7a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<script setup lang="ts">
import type { SpareMovement } from '#/api/mes/dv/spare';
import { onMounted, reactive, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Alert, Button, Form, Input, Select, Space, Table } from 'ant-design-vue';
import { getSpareMovements, movementLabels } from '#/api/mes/dv/spare';
import Action from './action.vue';
const props=defineProps<{repairId?:number;sparePartId?:number;canIssue?:boolean;repairCode?:string}>();
const rows=ref<SpareMovement[]>([]),loading=ref(false),error=ref('');
const page=ref(1),size=ref(10),total=ref(0);
const filters=reactive<{repairCode?:string;type?:number}>({type:3});
let seq=0;
const [ActionModal,actionApi]=useVbenModal({connectedComponent:Action,destroyOnClose:true});
const columns=[
 {title:'操作时间',dataIndex:'createTime',key:'createTime',width:175},
 {title:'类型',dataIndex:'type',key:'type',width:95},
 {title:'备件编码',dataIndex:'sparePartCode',width:135},
 {title:'备件名称',dataIndex:'sparePartName',width:150},
 {title:'规格型号',dataIndex:'specification',width:130},
 {title:'数量 / 单位',key:'quantity',width:110},
 {title:'已退回',dataIndex:'returnedQuantity',width:90},
 {title:'可退回',dataIndex:'returnableQuantity',width:90},
 {title:'维修单号',dataIndex:'repairCode',width:145},
 {title:'设备',dataIndex:'machineryName',width:150},
 {title:'领用人',dataIndex:'receiverName',width:110},
 {title:'操作说明',dataIndex:'remark',width:220},
 {title:'操作',key:'action',width:90,fixed:'right' as const},
];
async function load(reset=false) {
 if(reset)page.value=1;
 const current=++seq;loading.value=true;error.value='';
 try {const result=await getSpareMovements({pageNo:page.value,pageSize:size.value,...filters,repairId:props.repairId,sparePartId:props.sparePartId});
 if(current===seq){rows.value=result.list;total.value=result.total;}}
 catch {if(current===seq){rows.value=[];total.value=0;error.value='记录加载失败,请点击查询重试';}}
 finally {if(current===seq)loading.value=false;}
}
function changePage(p:{current?:number;pageSize?:number}){page.value=p.current||1;size.value=p.pageSize||10;void load();}
function issue(){actionApi.setData({type:'issue',repairId:props.repairId,repairCode:props.repairCode}).open();}
function returnPart(record:SpareMovement){actionApi.setData({type:'return',original:record}).open();}
watch(()=>[props.repairId,props.sparePartId],()=>load(true));
onMounted(()=>load());
defineExpose({refresh:()=>load(true)});
</script>
<template>
 <div class="mt-4">
  <ActionModal @success="load(true)" />
  <div class="mb-3 flex flex-wrap items-center justify-between gap-3"><h3 class="text-base font-semibold">备件领用记录</h3>
   <Button v-if="canIssue" v-access:code="['mes:dv-spare:issue']" type="primary" @click="issue">领用备件</Button>
  </div>
  <Form layout="inline" class="mb-4 flex flex-wrap gap-y-3">
   <Form.Item v-if="!repairId" label="维修单号"><Input v-model:value="filters.repairCode" allow-clear placeholder="完整维修单号" @press-enter="load(true)" /></Form.Item>
   <Form.Item label="记录类型"><Select v-model:value="filters.type" allow-clear class="w-36" :options="Object.entries(movementLabels).map(([value,label])=>({label,value:Number(value)}))" /></Form.Item>
   <Form.Item><Space><Button :loading="loading" @click="load(true)">查询</Button><Button @click="filters.repairCode=undefined;filters.type=3;load(true)">重置</Button></Space></Form.Item>
  </Form>
  <Alert v-if="error" type="error" :message="error" class="mb-3" />
  <Table :columns="columns" :data-source="rows" :loading="loading" row-key="id" :scroll="{x:1790}" :pagination="{current:page,pageSize:size,total,showSizeChanger:true}" @change="changePage">
   <template #bodyCell="{column,record}">
    <template v-if="column.key==='type'">{{ movementLabels[record.type] }}</template>
    <template v-else-if="column.key==='quantity'">{{ record.quantity }} {{ record.unit }}</template>
    <template v-else-if="column.key==='action'"><Button v-if="record.type===3 && Number(record.returnableQuantity)>0" v-access:code="['mes:dv-spare:return']" type="link" @click="returnPart(record as SpareMovement)">退回</Button><span v-else>—</span></template>
   </template>
  </Table>
 </div>
</template>