| | |
| | | <script setup lang="ts"> |
| | | import type { VxeGridProps } from '#/adapter/vxe-table'; |
| | | |
| | | import { computed, ref } from 'vue'; |
| | | |
| | | import { useVbenDrawer } from '@vben/common-ui'; |
| | | import { useVbenDrawer, useVbenModal } from '@vben/common-ui'; |
| | | import { DictEnum } from '@vben/constants'; |
| | | import { $t } from '@vben/locales'; |
| | | import { addFullName, cloneDeep, getPopupContainer } from '@vben/utils'; |
| | | |
| | | import { message } from 'ant-design-vue'; |
| | | |
| | | import { useVbenForm } from '#/adapter/form'; |
| | | import { addSpareInout, getSpareInout, updateSpareInout } from '#/api/eims/spare-inout'; |
| | | import { getDeptTree, userList } from '#/api/system/user'; |
| | | import { renderDict } from '#/utils/render'; |
| | | import CodeInput from '#/views/eims/components/code-input.vue'; |
| | | import spareModal from '#/views/eims/components/spare-modal.vue'; |
| | | |
| | | import { drawerSchema } from './data'; |
| | | import CodeInput from '#/views/eims/components/code-input.vue'; |
| | | import SelectSpareTable from './select-spare-table.vue'; |
| | | |
| | | const emit = defineEmits<{ reload: [] }>(); |
| | | |
| | | /** |
| | | * 出库单选择的备件数据 |
| | | */ |
| | | const outSpareList = ref([]); |
| | | const selectSpareTable = ref(); |
| | | |
| | | const outCol: VxeGridProps['columns'] = [ |
| | | { |
| | | field: 'action', |
| | | slots: { default: 'action' }, |
| | | title: '删除', |
| | | width: 60 |
| | | }, |
| | | { |
| | | title: '备件名称', |
| | | field: 'name', |
| | | width: 180 |
| | | }, |
| | | { |
| | | title: '备件编码', |
| | | field: 'code', |
| | | width: 120 |
| | | }, |
| | | { |
| | | title: '备件型号', |
| | | field: 'modelNo', |
| | | width: 100 |
| | | }, |
| | | { |
| | | title: '计量单位', |
| | | field: 'unit', |
| | | slots: { |
| | | default: ({ row }) => { |
| | | if (!row.unit || row.unit === '') { |
| | | return ''; |
| | | } |
| | | return renderDict(row.unit, DictEnum.EIMS_SPARE_UNIT); |
| | | } |
| | | }, |
| | | width: 80 |
| | | }, |
| | | |
| | | { |
| | | title: '实际库存', |
| | | field: 'actualStock', |
| | | width: 100 |
| | | }, |
| | | { |
| | | title: '数量', |
| | | field: 'quantity', |
| | | editRender: { |
| | | name: 'input' |
| | | }, |
| | | width: 80 |
| | | }, |
| | | { |
| | | title: '参考价', |
| | | field: 'referPrice', |
| | | width: 90 |
| | | } |
| | | ]; |
| | | |
| | | const isUpdate = ref(false); |
| | | const title = computed(() => { |
| | |
| | | drawerApi.drawerLoading(true); |
| | | const { id } = drawerApi.getData() as { id?: number | string }; |
| | | isUpdate.value = !!id; |
| | | outSpareList.value = []; |
| | | // 初始化 |
| | | await setupDeptSelect(); |
| | | // 更新 && 赋值 |
| | | if (isUpdate.value && id) { |
| | | const record = await getSpareInout(id); |
| | | await formApi.setValues(record); |
| | | // 更新出库单的备件明细 |
| | | outSpareList.value = record?.spareList; |
| | | if (isUpdate.value && record.chargeDept) { |
| | | await setupUserOptions(record.chargeDept); |
| | | } |
| | | } |
| | | |
| | | drawerApi.drawerLoading(false); |
| | |
| | | /** 根据部门ID加载用户 */ |
| | | await setupUserOptions(deptId); |
| | | /** 变化后需要重新选择用户 */ |
| | | formModel.operatorId = undefined; |
| | | formModel.chargeUser = undefined; |
| | | }, |
| | | placeholder: '请选择', |
| | | showSearch: true, |
| | |
| | | } |
| | | ]); |
| | | } |
| | | |
| | | async function handleConfirm() { |
| | | try { |
| | | drawerApi.drawerLoading(true); |
| | |
| | | if (!valid) { |
| | | return; |
| | | } |
| | | const selectSpareList = selectSpareTable.value.tableData(); |
| | | // 检测是否输入出库数量 |
| | | const eList = selectSpareList.filter((item: any) => !item.quantity || item.quantity <= 0 || item.quantity > item.actualStock); |
| | | if (selectSpareList.length<= 0 ||eList.length > 0) { |
| | | message.error('出库数量为空或大于库存,请检查!'); |
| | | return false; |
| | | } |
| | | const data = cloneDeep(await formApi.getValues()); |
| | | data.spareList = selectSpareList; |
| | | await (isUpdate.value ? updateSpareInout(data) : addSpareInout(data)); |
| | | emit('reload'); |
| | | await handleCancel(); |
| | |
| | | drawerApi.close(); |
| | | await formApi.resetForm(); |
| | | } |
| | | |
| | | // 备件modal |
| | | const [SpareModal, spareModalApi] = useVbenModal({ |
| | | connectedComponent: spareModal, |
| | | draggable: true, |
| | | title: '选择备件' |
| | | }); |
| | | |
| | | function handleSpareModal() { |
| | | spareModalApi.setData({}); |
| | | spareModalApi.open(); |
| | | } |
| | | |
| | | /** |
| | | * 选择的备件 |
| | | * @param spareList |
| | | */ |
| | | function selectSpare(spareList: any) { |
| | | outSpareList.value = spareList; |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <BasicDrawer :close-on-click-modal="false" :title="title" class="w-[600px]"> |
| | | <BasicDrawer :close-on-click-modal="false" :title="title" class="w-[1000px]"> |
| | | <BasicForm> |
| | | <template #orderCode="slotProps"> |
| | | <CodeInput v-bind="slotProps" :disabled="isUpdate" prefix="CK" /> |
| | | </template> |
| | | |
| | | <template #openSpare="slotProps"> |
| | | <a-button type="primary" v-bind="slotProps" :disabled="isUpdate" @click.stop="handleSpareModal">添加备件</a-button> |
| | | </template> |
| | | |
| | | <template #outSpareList> |
| | | <SelectSpareTable ref="selectSpareTable" :columns="outCol" :data="outSpareList" :is-update="isUpdate" /> |
| | | </template> |
| | | </BasicForm> |
| | | <SpareModal class="w-[1200px]" @update-select="selectSpare" /> |
| | | </BasicDrawer> |
| | | </template> |