Commit e7879b4f by 胡鑫

库存盘点相关开发

parent 9d5a680d
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
type: Number, type: Number,
default: FromPageType.MENU, default: FromPageType.MENU,
}, },
isView: {
type: Boolean,
default: false,
},
}); });
const systemFormRef = ref(); const systemFormRef = ref();
const data: { formDataProps: FormDataProps } = reactive({ const data: { formDataProps: FormDataProps } = reactive({
...@@ -49,11 +53,107 @@ ...@@ -49,11 +53,107 @@
() => state.formModel, () => state.formModel,
(val) => { (val) => {
emits('update:value', val); emits('update:value', val);
// Update button and field states based on form state
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
}, },
{ {
deep: true, 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 () => { onMounted(async () => {
try { try {
...@@ -70,6 +170,10 @@ ...@@ -70,6 +170,10 @@
await loadFormEvent(formEventConfigs, state.formModel, await loadFormEvent(formEventConfigs, state.formModel,
systemFormRef.value, systemFormRef.value,
formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:加载表单 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) { } else if (props.fromPage == FromPageType.FLOW) {
emits('loadingCompleted'); //告诉系统表单已经加载完毕 emits('loadingCompleted'); //告诉系统表单已经加载完毕
// loadingCompleted后 工作流页面直接利用Ref调用setWorkFlowForm方法 // loadingCompleted后 工作流页面直接利用Ref调用setWorkFlowForm方法
...@@ -84,6 +188,10 @@ ...@@ -84,6 +188,10 @@
await loadFormEvent(formEventConfigs, state.formModel, await loadFormEvent(formEventConfigs, state.formModel,
systemFormRef.value, systemFormRef.value,
formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:加载表单 formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:加载表单
// Update button and field states after form initialization
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
} }
} catch (error) {} } catch (error) {}
}); });
...@@ -116,6 +224,10 @@ ...@@ -116,6 +224,10 @@
await getFormDataEvent(formEventConfigs, state.formModel, await getFormDataEvent(formEventConfigs, state.formModel,
systemFormRef.value, systemFormRef.value,
formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:获取表单数据 formProps.schemas, true, state.formInfo.formName,state.formInfo.formId); //表单事件:获取表单数据
// Update button and field states after setting form data
updateButtonVisibility();
updateHeaderFieldDisabledState();
updateDetailFieldDisabledState();
} catch (error) { } catch (error) {
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
:height="1080" :height="1080"
v-bind="$attrs" @register="registerModal" :title="getTitle" v-bind="$attrs" @register="registerModal" :title="getTitle"
@ok="handleSubmit" @cancel="handleClose" > @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 #footer v-if=" !state.isView">
<template v-for="(item, index) in sortBy(formButtons, 'index')" :key="item.key"> <template v-for="(item, index) in sortBy(formButtons, 'index')" :key="item.key">
<template v-if="item.isShow"> <template v-if="item.isShow">
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
</template> </template>
<script lang="ts" setup> <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 { BasicModal, useModalInner } from '/@/components/Modal';
import { CustomButtonModalType } from '/@/enums/userEnum'; import { CustomButtonModalType } from '/@/enums/userEnum';
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
import { formProps ,formButtons } from './config'; import { formProps ,formButtons } from './config';
import ModalForm from './Form.vue'; import ModalForm from './Form.vue';
import { FromPageType } from '/@/enums/workflowEnum'; import { FromPageType } from '/@/enums/workflowEnum';
import { sortBy } from 'lodash-es'; import { sortBy } from 'lodash-es';
import { executeCurFormEvent } from '/@/utils/event/data'; import { executeCurFormEvent } from '/@/utils/event/data';
...@@ -58,6 +58,24 @@ ...@@ -58,6 +58,24 @@
await handleInner(data); 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 ? '复制数据' : '新增')); const getTitle = computed(() => (state.isView ? '查看' : state.isUpdate ? '编辑' : isCopy.value ? '复制数据' : '新增'));
......
...@@ -61,6 +61,49 @@ async function handleStartInventory(_schema, formModel, formActionType) { ...@@ -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[] = [ export const searchFormSchema: FormSchema[] = [
{ {
field: 'pdrq', field: 'pdrq',
...@@ -259,7 +302,7 @@ export const formProps: FormProps = { ...@@ -259,7 +302,7 @@ export const formProps: FormProps = {
], ],
}, },
dicOptions: [], dicOptions: [],
disabled: false, disabled: true,
isShow: true, isShow: true,
margin: '10px', margin: '10px',
events: { click: handleStartInventory }, events: { click: handleStartInventory },
...@@ -302,10 +345,10 @@ export const formProps: FormProps = { ...@@ -302,10 +345,10 @@ export const formProps: FormProps = {
], ],
}, },
dicOptions: [], dicOptions: [],
disabled: false, disabled: true,
isShow: true, isShow: true,
margin: '10px', margin: '10px',
events: { click: "formActionType.showMessage('确认盘点')" }, events: { click: "formModel.zt = '已完成'; formActionType.showMessage('盘点已确认,状态已更新为已完成', { type: 'success' });" },
type: 1, type: 1,
event: [], event: [],
tooltipConfig: { visible: false, title: '提示文本' }, tooltipConfig: { visible: false, title: '提示文本' },
...@@ -348,7 +391,7 @@ export const formProps: FormProps = { ...@@ -348,7 +391,7 @@ export const formProps: FormProps = {
disabled: false, disabled: false,
isShow: true, isShow: true,
margin: '10px', margin: '10px',
events: { click: "formActionType.showMessage('取消盘点')" }, events: { click: handleCancelInventory },
type: 1, type: 1,
event: [], event: [],
tooltipConfig: { visible: false, title: '提示文本' }, tooltipConfig: { visible: false, title: '提示文本' },
...@@ -391,7 +434,7 @@ export const formProps: FormProps = { ...@@ -391,7 +434,7 @@ export const formProps: FormProps = {
disabled: false, disabled: false,
isShow: true, isShow: true,
margin: '10px', margin: '10px',
events: {}, events: { click: handleProfitLoss },
modal: null, modal: null,
type: 1, type: 1,
event: [], event: [],
...@@ -443,7 +486,7 @@ export const formProps: FormProps = { ...@@ -443,7 +486,7 @@ export const formProps: FormProps = {
showSearch: true, showSearch: true,
isMultiple: true, isMultiple: true,
clearable: false, clearable: false,
disabled: false, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -495,7 +538,7 @@ export const formProps: FormProps = { ...@@ -495,7 +538,7 @@ export const formProps: FormProps = {
showSearch: true, showSearch: true,
isMultiple: true, isMultiple: true,
clearable: false, clearable: false,
disabled: false, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -540,7 +583,7 @@ export const formProps: FormProps = { ...@@ -540,7 +583,7 @@ export const formProps: FormProps = {
showSearch: true, showSearch: true,
isMultiple: true, isMultiple: true,
clearable: false, clearable: false,
disabled: false, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -593,7 +636,7 @@ export const formProps: FormProps = { ...@@ -593,7 +636,7 @@ export const formProps: FormProps = {
format: 'YYYY-MM-DD HH:mm:ss', format: 'YYYY-MM-DD HH:mm:ss',
showLabel: true, showLabel: true,
allowClear: true, allowClear: true,
disabled: false, disabled: true,
required: false, required: false,
isShow: true, isShow: true,
rules: [], rules: [],
...@@ -626,7 +669,7 @@ export const formProps: FormProps = { ...@@ -626,7 +669,7 @@ export const formProps: FormProps = {
suffix: '', suffix: '',
addonBefore: '', addonBefore: '',
addonAfter: '', addonAfter: '',
disabled: false, disabled: true,
allowClear: false, allowClear: false,
showLabel: true, showLabel: true,
required: false, required: false,
...@@ -710,7 +753,7 @@ export const formProps: FormProps = { ...@@ -710,7 +753,7 @@ export const formProps: FormProps = {
required: false, required: false,
rules: [], rules: [],
events: {}, events: {},
isShow: false, isShow: true,
tooltipConfig: { visible: false, title: '提示文本' }, tooltipConfig: { visible: false, title: '提示文本' },
itemId: '2018581306872238081', itemId: '2018581306872238081',
style: { width: '100%' }, style: { width: '100%' },
...@@ -778,7 +821,7 @@ export const formProps: FormProps = { ...@@ -778,7 +821,7 @@ export const formProps: FormProps = {
suffix: '', suffix: '',
addonBefore: '', addonBefore: '',
addonAfter: '', addonAfter: '',
disabled: false, disabled: true,
allowClear: false, allowClear: false,
showLabel: true, showLabel: true,
required: false, required: false,
...@@ -806,7 +849,7 @@ export const formProps: FormProps = { ...@@ -806,7 +849,7 @@ export const formProps: FormProps = {
showSearch: false, showSearch: false,
isMultiple: false, isMultiple: false,
clearable: false, clearable: false,
disabled: false, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -849,7 +892,7 @@ export const formProps: FormProps = { ...@@ -849,7 +892,7 @@ export const formProps: FormProps = {
showSearch: false, showSearch: false,
isMultiple: false, isMultiple: false,
clearable: false, clearable: false,
disabled: false, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -887,7 +930,7 @@ export const formProps: FormProps = { ...@@ -887,7 +930,7 @@ export const formProps: FormProps = {
showSearch: false, showSearch: false,
isMultiple: false, isMultiple: false,
clearable: false, clearable: false,
disabled: false, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -933,7 +976,7 @@ export const formProps: FormProps = { ...@@ -933,7 +976,7 @@ export const formProps: FormProps = {
suffix: '', suffix: '',
addonBefore: '', addonBefore: '',
addonAfter: '', addonAfter: '',
disabled: false, disabled: true,
allowClear: false, allowClear: false,
showLabel: true, showLabel: true,
required: false, 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