Commit e7879b4f by 胡鑫

库存盘点相关开发

parent 9d5a680d
......@@ -35,6 +35,10 @@
type: Number,
default: FromPageType.MENU,
},
isView: {
type: Boolean,
default: false,
},
});
const systemFormRef = ref();
const data: { formDataProps: FormDataProps } = reactive({
......@@ -49,11 +53,107 @@
() => state.formModel,
(val) => {
emits('update:value', val);
// Update button and field states based on form state
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
},
{
deep: true,
},
);
// Update button disabled state based on form state
function updateButtonVisibility() {
const hasId = !!state.formModel.id;
const isCompletedOrCancelled = state.formModel.zt === '已完成' || state.formModel.zt === '取消';
// Find the grid component that contains the buttons
const gridComponent = data.formDataProps.schemas.find(schema => schema.component === 'Grid' && schema.children);
if (gridComponent && gridComponent.children) {
// Update each button's disabled state
gridComponent.children.forEach(child => {
if (child.list && child.list.length > 0) {
child.list.forEach(button => {
// Disable all buttons in view mode or if status is completed or cancelled
if (props.isView || isCompletedOrCancelled) {
button.componentProps.disabled = true;
button.componentProps.isShow = true;
} else if (button.label === '开始盘点') {
// Disable start inventory button in edit mode
button.componentProps.disabled = hasId;
// Always show the button
button.componentProps.isShow = true;
} else if (['确认盘点', '取消盘点'].includes(button.label)) {
// Disable these buttons in add mode
button.componentProps.disabled = !hasId;
// Always show the buttons
button.componentProps.isShow = true;
} else if (button.label === '处理盈亏') {
// Disable in add mode or when status is not completed
button.componentProps.disabled = !hasId || state.formModel.zt !== '已完成';
// Always show the button
button.componentProps.isShow = true;
}
});
}
});
}
}
// Update header field disabled state based on form state
function updateHeaderFieldDisabledState() {
const hasId = !!state.formModel.id;
const isCompletedOrCancelled = state.formModel.zt === '已完成' || state.formModel.zt === '取消';
// Find the grid component that contains the header fields
const headerGridComponent = data.formDataProps.schemas.find(schema =>
schema.component === 'Grid' &&
schema.children &&
schema.children.some(child =>
child.list &&
child.list.some(field => field.field === 'ckwz' || field.field === 'cplx' || field.field === 'cp' || field.field === 'pdrq' || field.field === 'bz')
)
);
if (headerGridComponent && headerGridComponent.children) {
// Update each header field's disabled state
headerGridComponent.children.forEach(child => {
if (child.list && child.list.length > 0) {
child.list.forEach(field => {
if (field.componentProps) {
// Disable header fields in edit mode, view mode, or if status is completed or cancelled
field.componentProps.disabled = props.isView || hasId || isCompletedOrCancelled;
}
});
}
});
}
}
// Update inventory detail fields disabled state based on form state
function updateDetailFieldDisabledState() {
const isCompletedOrCancelled = state.formModel.zt === '已完成' || state.formModel.zt === '取消';
// Find the tab component that contains the inventory detail subform
const tabComponent = data.formDataProps.schemas.find(schema => schema.component === 'Tab' && schema.children);
if (tabComponent && tabComponent.children) {
// Find the inventory detail subform
tabComponent.children.forEach(tab => {
if (tab.list && tab.list.length > 0) {
tab.list.forEach(item => {
if (item.component === 'SubForm' && item.componentProps && item.componentProps.columns) {
// Update each detail field's disabled state
item.componentProps.columns.forEach(column => {
if (column.componentProps) {
// For pdsl field, disable in view mode or if status is completed or cancelled
if (column.dataIndex === 'pdsl') {
column.componentProps.disabled = props.isView || isCompletedOrCancelled;
}
}
});
}
});
}
});
}
}
onMounted(async () => {
try {
......@@ -70,6 +170,10 @@
await loadFormEvent(formEventConfigs, state.formModel,
systemFormRef.value,
formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:加载表单
// Update button and field states after form initialization
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
} else if (props.fromPage == FromPageType.FLOW) {
emits('loadingCompleted'); //告诉系统表单已经加载完毕
// loadingCompleted后 工作流页面直接利用Ref调用setWorkFlowForm方法
......@@ -84,6 +188,10 @@
await loadFormEvent(formEventConfigs, state.formModel,
systemFormRef.value,
formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:加载表单
// Update button and field states after form initialization
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
}
} catch (error) {}
});
......@@ -116,6 +224,10 @@
await getFormDataEvent(formEventConfigs, state.formModel,
systemFormRef.value,
formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:获取表单数据
// Update button and field states after setting form data
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
} catch (error) {
}
......
......@@ -6,7 +6,7 @@
:height="1080"
v-bind="$attrs" @register="registerModal" :title="getTitle"
@ok="handleSubmit" @cancel="handleClose" >
<ModalForm ref="formRef" v-model:value="state.formModel" :fromPage="FromPageType.MENU" />
<ModalForm ref="formRef" v-model:value="state.formModel" :fromPage="FromPageType.MENU" :isView="state.isView" />
<template #footer v-if=" !state.isView">
<template v-for="(item, index) in sortBy(formButtons, 'index')" :key="item.key">
<template v-if="item.isShow">
......@@ -26,7 +26,7 @@
</template>
<script lang="ts" setup>
import { ref, computed, reactive, provide, Ref } from 'vue';
import { ref, computed, reactive, provide, Ref, onMounted, onBeforeUnmount } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { CustomButtonModalType } from '/@/enums/userEnum';
......@@ -36,7 +36,7 @@
import { formProps ,formButtons } from './config';
import ModalForm from './Form.vue';
import { FromPageType } from '/@/enums/workflowEnum';
import { sortBy } from 'lodash-es';
import { executeCurFormEvent } from '/@/utils/event/data';
......@@ -58,6 +58,24 @@
await handleInner(data);
});
// Handle postMessage event to close modal or trigger confirm button
function handlePostMessage(event) {
if (event.data && event.data.type === 'CLOSE_MODAL') {
closeModal();
} else if (event.data && event.data.type === 'TRIGGER_CONFIRM_BUTTON') {
// Trigger confirm button click event
handleSubmit();
}
}
onMounted(() => {
window.addEventListener('message', handlePostMessage);
});
onBeforeUnmount(() => {
window.removeEventListener('message', handlePostMessage);
});
const getTitle = computed(() => (state.isView ? '查看' : state.isUpdate ? '编辑' : isCopy.value ? '复制数据' : '新增'));
......
......@@ -61,6 +61,49 @@ async function handleStartInventory(_schema, formModel, formActionType) {
}
}
async function handleProfitLoss(_schema, formModel, formActionType) {
try {
const inventoryDetails = formModel.mesWarehouseInventoryRelaList || [];
if (inventoryDetails.length === 0) {
formActionType?.showMessage?.('没有盘点明细数据可处理', { type: 'warning' });
return;
}
await formActionType?.httpRequest({
requestUrl: '/ckgl/kczb/handleyk',
requestType: 'post',
data: inventoryDetails,
headers: { Authorization: localStorage.getItem('token') }
});
formActionType?.showMessage?.('盈亏处理成功!', { type: 'success' });
// Close the modal by emitting an event to parent component
if (window.parent && window.parent.postMessage) {
window.parent.postMessage({ type: 'CLOSE_MODAL' }, '*');
}
} catch (error) {
console.error('盈亏处理失败', error);
formActionType?.showMessage?.('盈亏处理失败,请重试!');
}
}
async function handleCancelInventory(_schema, formModel, formActionType) {
try {
// Update inventory status to "取消"
formModel.zt = '取消';
formActionType?.showMessage?.('盘点已取消', { type: 'success' });
// Trigger the confirm button click event to close the modal and save changes
if (window.parent && window.parent.postMessage) {
window.parent.postMessage({ type: 'TRIGGER_CONFIRM_BUTTON' }, '*');
}
} catch (error) {
console.error('取消盘点失败', error);
formActionType?.showMessage?.('取消盘点失败,请重试!');
}
}
export const searchFormSchema: FormSchema[] = [
{
field: 'pdrq',
......@@ -259,7 +302,7 @@ export const formProps: FormProps = {
],
},
dicOptions: [],
disabled: false,
disabled: true,
isShow: true,
margin: '10px',
events: { click: handleStartInventory },
......@@ -302,10 +345,10 @@ export const formProps: FormProps = {
],
},
dicOptions: [],
disabled: false,
disabled: true,
isShow: true,
margin: '10px',
events: { click: "formActionType.showMessage('确认盘点')" },
events: { click: "formModel.zt = '已完成'; formActionType.showMessage('盘点已确认,状态已更新为已完成', { type: 'success' });" },
type: 1,
event: [],
tooltipConfig: { visible: false, title: '提示文本' },
......@@ -348,7 +391,7 @@ export const formProps: FormProps = {
disabled: false,
isShow: true,
margin: '10px',
events: { click: "formActionType.showMessage('取消盘点')" },
events: { click: handleCancelInventory },
type: 1,
event: [],
tooltipConfig: { visible: false, title: '提示文本' },
......@@ -391,7 +434,7 @@ export const formProps: FormProps = {
disabled: false,
isShow: true,
margin: '10px',
events: {},
events: { click: handleProfitLoss },
modal: null,
type: 1,
event: [],
......@@ -443,7 +486,7 @@ export const formProps: FormProps = {
showSearch: true,
isMultiple: true,
clearable: false,
disabled: false,
disabled: true,
staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' },
......@@ -495,7 +538,7 @@ export const formProps: FormProps = {
showSearch: true,
isMultiple: true,
clearable: false,
disabled: false,
disabled: true,
staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' },
......@@ -540,7 +583,7 @@ export const formProps: FormProps = {
showSearch: true,
isMultiple: true,
clearable: false,
disabled: false,
disabled: true,
staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' },
......@@ -593,7 +636,7 @@ export const formProps: FormProps = {
format: 'YYYY-MM-DD HH:mm:ss',
showLabel: true,
allowClear: true,
disabled: false,
disabled: true,
required: false,
isShow: true,
rules: [],
......@@ -626,7 +669,7 @@ export const formProps: FormProps = {
suffix: '',
addonBefore: '',
addonAfter: '',
disabled: false,
disabled: true,
allowClear: false,
showLabel: true,
required: false,
......@@ -710,7 +753,7 @@ export const formProps: FormProps = {
required: false,
rules: [],
events: {},
isShow: false,
isShow: true,
tooltipConfig: { visible: false, title: '提示文本' },
itemId: '2018581306872238081',
style: { width: '100%' },
......@@ -778,7 +821,7 @@ export const formProps: FormProps = {
suffix: '',
addonBefore: '',
addonAfter: '',
disabled: false,
disabled: true,
allowClear: false,
showLabel: true,
required: false,
......@@ -806,7 +849,7 @@ export const formProps: FormProps = {
showSearch: false,
isMultiple: false,
clearable: false,
disabled: false,
disabled: true,
staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' },
......@@ -849,7 +892,7 @@ export const formProps: FormProps = {
showSearch: false,
isMultiple: false,
clearable: false,
disabled: false,
disabled: true,
staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' },
......@@ -887,7 +930,7 @@ export const formProps: FormProps = {
showSearch: false,
isMultiple: false,
clearable: false,
disabled: false,
disabled: true,
staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' },
......@@ -933,7 +976,7 @@ export const formProps: FormProps = {
suffix: '',
addonBefore: '',
addonAfter: '',
disabled: false,
disabled: true,
allowClear: false,
showLabel: true,
required: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment