<template>
|
<div>
|
<el-dialog
|
v-model="isShow"
|
:title="operationType === 'frozen' ? '冻结库存' : '解冻库存'"
|
width="800"
|
@close="closeModal"
|
>
|
<el-form label-width="140px" :model="formState" ref="formRef">
|
<el-form-item
|
:label="operationType === 'frozen' ? '冻结数量:' : '解冻数量:'"
|
prop="lockedQuantity"
|
>
|
<el-input-number v-model="formState.lockedQuantity" :step="1" :min="1" precision="0" style="width: 100%" :max="maxCount" />
|
</el-form-item>
|
</el-form>
|
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="handleSubmit">确认</el-button>
|
<el-button @click="closeModal">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import {ref, computed, getCurrentInstance} from "vue";
|
import {frozenStockInventory, thawStockInventory} from "@/api/inventoryManagement/stockInventory.js";
|
import {frozenStockUninventory, thawStockUninventory} from "@/api/inventoryManagement/stockUninventory.js";
|
|
const props = defineProps({
|
visible: {
|
type: Boolean,
|
required: true,
|
},
|
|
operationType: {
|
type: String,
|
required: true,
|
default: 'frozen',
|
},
|
|
type: {
|
type: String,
|
required: true,
|
default: 'qualified',
|
},
|
|
record: {
|
type: Object,
|
default: () => {},
|
}
|
});
|
|
const emit = defineEmits(['update:visible', 'completed']);
|
|
// 响应式数据(替代选项式的 data)
|
const formState = ref({
|
lockedQuantity: 0,
|
});
|
|
const isShow = computed({
|
get() {
|
return props.visible;
|
},
|
set(val) {
|
emit('update:visible', val);
|
},
|
});
|
|
|
let { proxy } = getCurrentInstance()
|
|
const closeModal = () => {
|
// 重置表单数据
|
formState.value = {
|
lockedQuantity: undefined
|
};
|
isShow.value = false;
|
};
|
|
const maxCount = computed(() => {
|
// 冻结库存最大数量为未解冻数量
|
if (props.operationType === 'frozen') {
|
return props.record.unLockedQuantity
|
}
|
// 解冻库存最大数量为已冻结数量
|
return props.record.lockedQuantity
|
})
|
|
const handleSubmit = () => {
|
proxy.$refs["formRef"].validate(valid => {
|
if (valid) {
|
const data = Object.assign({id: props.record.id}, formState.value);
|
if (props.type === 'qualified') {
|
// 冻结
|
if (props.operationType === 'frozen') {
|
frozenStockInventory(data).then(res => {
|
if (res.code === 200) {
|
// 关闭模态框
|
isShow.value = false;
|
// 告知父组件已完成
|
emit('completed');
|
proxy.$modal.msgSuccess("提交成功");
|
} else {
|
proxy.$modal.msgError(res.msg);
|
}
|
})
|
} else {
|
thawStockInventory(data).then(res => {
|
if (res.code === 200) {
|
// 关闭模态框
|
isShow.value = false;
|
// 告知父组件已完成
|
emit('completed');
|
proxy.$modal.msgSuccess("提交成功");
|
} else {
|
proxy.$modal.msgError(res.msg);
|
}
|
})
|
}
|
} else {
|
if (props.operationType === 'frozen') {
|
frozenStockUninventory(data).then(res => {
|
if (res.code === 200) {
|
// 关闭模态框
|
isShow.value = false;
|
// 告知父组件已完成
|
emit('completed');
|
proxy.$modal.msgSuccess("提交成功");
|
} else {
|
proxy.$modal.msgError(res.msg);
|
}
|
})
|
} else {
|
thawStockUninventory(data).then(res => {
|
if (res.code === 200) {
|
// 关闭模态框
|
isShow.value = false;
|
// 告知父组件已完成
|
emit('completed');
|
proxy.$modal.msgSuccess("提交成功");
|
} else {
|
proxy.$modal.msgError(res.msg);
|
}
|
})
|
}
|
}
|
}
|
})
|
};
|
|
onMounted(() => {
|
formState.value.lockedQuantity = maxCount.value;
|
})
|
|
defineExpose({
|
closeModal,
|
handleSubmit,
|
isShow,
|
});
|
</script>
|