| | |
| | | import { |
| | | ref, |
| | | onMounted, |
| | | reactive, |
| | | computed, |
| | | Ref, |
| | | watch, |
| | | SetupContext, |
| | | h, |
| | | } from 'vue' |
| | | import { injectModel } from '@/libs/Provider/Provider' |
| | | import { WmsInOutStockRecordDrawer } from '../Models/WmsInOutStockRecordDrawer' |
| | | import { ElMessage } from 'element-plus' |
| | | import isEqual from 'lodash/isEqual' |
| | | import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox' |
| | | import { cloneDeep } from 'lodash' |
| | | |
| | | export const useWmsInOutStockRecordDrawer = (props: any, ctx?: any) => { |
| | | const wmsInOutStockRecordDrawer = injectModel<WmsInOutStockRecordDrawer>('wmsInOutStockRecordDrawer') |
| | | /** |
| | | * 用来对比的初始化数据 |
| | | */ |
| | | const initiateData: Ref<Record<string, any>> = ref({}) |
| | | const formData = ref<Record<string, any>>({}) |
| | | // ref |
| | | const formRef = ref() |
| | | |
| | | const disabled = ref(false) |
| | | |
| | | const current = computed(() => { |
| | | return props.row || null |
| | | }) |
| | | |
| | | const inputNumber = (attrs) => { |
| | | return ( |
| | | <el-input-number |
| | | min="1" |
| | | step="1" |
| | | precision="0" |
| | | {...attrs} |
| | | ></el-input-number> |
| | | ) |
| | | } |
| | | |
| | | const visible = computed({ |
| | | get() { |
| | | return props.modelValue |
| | | }, |
| | | set(val) { |
| | | ctx.emit('update:modelValue', val) |
| | | }, |
| | | }) |
| | | /** |
| | | * 添加的form字段 |
| | | */ |
| | | const formItems = reactive([ |
| | | { |
| | | label: '单据编号', |
| | | prop: 'orderNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入单据编号', |
| | | rules: [{required: true, message: '单据编号不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '物料名称', |
| | | prop: 'materialName', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入物料名称', |
| | | }, |
| | | { |
| | | label: '物料件号', |
| | | prop: 'materialNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入物料件号', |
| | | rules: [{required: true, message: '物料件号不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '操作类型', |
| | | prop: 'stockType', |
| | | el: 'select', |
| | | //disabled: disabled, |
| | | placeholder: '请输入操作类型', |
| | | rules: [{required: true, message: '操作类型不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '容器编号', |
| | | prop: 'containerNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入容器编号', |
| | | }, |
| | | { |
| | | label: '机型', |
| | | prop: 'materialModel', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入机型', |
| | | }, |
| | | { |
| | | label: '操作时间', |
| | | prop: 'operateTime', |
| | | type: 'datetimerange', |
| | | el: 'date-picker', |
| | | //disabled: disabled, |
| | | placeholder: '请输入操作时间', |
| | | }, |
| | | { |
| | | label: '备注', |
| | | prop: 'remark', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入备注', |
| | | }, |
| | | { |
| | | label: '物料ID', |
| | | prop: 'materialId', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入物料ID', |
| | | rules: [{required: true, message: '物料ID不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '任务号', |
| | | prop: 'taskNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入任务号', |
| | | rules: [{required: true, message: '任务号不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '起始库位', |
| | | prop: 'sourcePlace', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入起始库位', |
| | | }, |
| | | { |
| | | label: '目标库位', |
| | | prop: 'toPlace', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入目标库位', |
| | | }, |
| | | ]) |
| | | /** |
| | | * 校验是否有数据变化 |
| | | */ |
| | | const checkIsEqualObject = () => { |
| | | const data = { |
| | | formData: formData.value, |
| | | } |
| | | const check = isEqual(initiateData.value, data) |
| | | return check |
| | | } |
| | | |
| | | const onClose = (done: () => void) => { |
| | | if (visible.value) { |
| | | if (checkIsEqualObject()) { |
| | | visible.value = false |
| | | done && done() |
| | | } else { |
| | | ConfirmBox('是否保存设置?') |
| | | .then(() => { |
| | | onConfirm() |
| | | }) |
| | | .catch(() => { |
| | | visible.value = false |
| | | done && done() |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 保存 |
| | | */ |
| | | const onConfirm = async () => { |
| | | await formRef.value?.validate() |
| | | const data = { |
| | | orderNo: formData.value.orderNo, |
| | | materialName: formData.value.materialName, |
| | | materialNo: formData.value.materialNo, |
| | | stockType: formData.value.stockType, |
| | | containerNo: formData.value.containerNo, |
| | | materialModel: formData.value.materialModel, |
| | | operateTime: formData.value.operateTime, |
| | | remark: formData.value.remark, |
| | | materialId: formData.value.materialId, |
| | | taskNo: formData.value.taskNo, |
| | | sourcePlace: formData.value.sourcePlace, |
| | | toPlace: formData.value.toPlace, |
| | | } |
| | | if (!current.value) { |
| | | await wmsInOutStockRecordDrawer.addWmsInOutStockRecord(data) |
| | | } else { |
| | | const id = current.value.id |
| | | await wmsInOutStockRecordDrawer.updateWmsInOutStockRecord(id, data) |
| | | } |
| | | ElMessage.success('保存成功') |
| | | ctx.emit('confirm') |
| | | } |
| | | |
| | | const updateCheckData = () => { |
| | | initiateData.value = { |
| | | formData: { |
| | | ...formData.value, |
| | | }, |
| | | } |
| | | } |
| | | const updateFormItemOptions = (propName: string, enumData: any[]) => { |
| | | const item = formItems.find((item) => item.prop === propName) |
| | | if (item && enumData) { |
| | | item.options = enumData.map((item) => ({ |
| | | label: item.description, |
| | | value: item.value, |
| | | })) |
| | | } |
| | | } |
| | | /** |
| | | * 通用查询枚举 |
| | | */ |
| | | const commonQueryEnumForFrom = async () => { |
| | | const stockTypeEnumEnum = await wmsInOutStockRecordDrawer.getWmsEnumData({ |
| | | EnumName: 'StockTypeEnum', |
| | | }) |
| | | updateFormItemOptions('stockType', stockTypeEnumEnum) |
| | | |
| | | } |
| | | commonQueryEnumForFrom() |
| | | /** |
| | | * 弹窗打开获取详情 |
| | | */ |
| | | const onOpen = async () => { |
| | | if (current.value) { |
| | | const res = await wmsInOutStockRecordDrawer.getWmsInOutStockRecordDetail(current.value) |
| | | |
| | | formData.value = { |
| | | orderNo: res.orderNo, |
| | | materialName: res.materialName, |
| | | materialNo: res.materialNo, |
| | | stockType: res.stockType, |
| | | containerNo: res.containerNo, |
| | | materialModel: res.materialModel, |
| | | operateTime: res.operateTime, |
| | | remark: res.remark, |
| | | materialId: res.materialId, |
| | | taskNo: res.taskNo, |
| | | sourcePlace: res.sourcePlace, |
| | | toPlace: res.toPlace, |
| | | id: res.id, |
| | | } |
| | | disabled.value = true |
| | | updateCheckData() |
| | | } else { |
| | | formData.value = {} |
| | | |
| | | disabled.value = false |
| | | updateCheckData() |
| | | } |
| | | } |
| | | |
| | | watch(() => current.value, onOpen) |
| | | |
| | | return { |
| | | formItems, |
| | | formData, |
| | | visible, |
| | | formRef, |
| | | onOpen, |
| | | onClose, |
| | | onConfirm, |
| | | } |
| | | } |
| | | import { |
| | | ref, |
| | | onMounted, |
| | | reactive, |
| | | computed, |
| | | Ref, |
| | | watch, |
| | | SetupContext, |
| | | h, |
| | | } from 'vue' |
| | | import { injectModel } from '@/libs/Provider/Provider' |
| | | import { WmsInOutStockRecordDrawer } from '../Models/WmsInOutStockRecordDrawer' |
| | | import { ElMessage } from 'element-plus' |
| | | import isEqual from 'lodash/isEqual' |
| | | import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox' |
| | | import { cloneDeep } from 'lodash' |
| | | |
| | | export const useWmsInOutStockRecordDrawer = (props: any, ctx?: any) => { |
| | | const wmsInOutStockRecordDrawer = injectModel<WmsInOutStockRecordDrawer>( |
| | | 'wmsInOutStockRecordDrawer' |
| | | ) |
| | | /** |
| | | * 用来对比的初始化数据 |
| | | */ |
| | | const initiateData: Ref<Record<string, any>> = ref({}) |
| | | const formData = ref<Record<string, any>>({}) |
| | | // ref |
| | | const formRef = ref() |
| | | |
| | | const disabled = ref(false) |
| | | |
| | | const current = computed(() => { |
| | | return props.row || null |
| | | }) |
| | | |
| | | const inputNumber = (attrs) => { |
| | | return ( |
| | | <el-input-number |
| | | min="1" |
| | | step="1" |
| | | precision="0" |
| | | {...attrs} |
| | | ></el-input-number> |
| | | ) |
| | | } |
| | | |
| | | const visible = computed({ |
| | | get() { |
| | | return props.modelValue |
| | | }, |
| | | set(val) { |
| | | ctx.emit('update:modelValue', val) |
| | | }, |
| | | }) |
| | | /** |
| | | * 添加的form字段 |
| | | */ |
| | | const formItems = reactive([ |
| | | { |
| | | label: '单据编号', |
| | | prop: 'orderNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入单据编号', |
| | | rules: [{ required: true, message: '单据编号不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '物料名称', |
| | | prop: 'materialName', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入物料名称', |
| | | }, |
| | | { |
| | | label: '物料件号', |
| | | prop: 'materialNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入物料件号', |
| | | rules: [{ required: true, message: '物料件号不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '操作类型', |
| | | prop: 'stockType', |
| | | el: 'select', |
| | | //disabled: disabled, |
| | | placeholder: '请输入操作类型', |
| | | rules: [{ required: true, message: '操作类型不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '容器编号', |
| | | prop: 'containerNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入容器编号', |
| | | }, |
| | | { |
| | | label: '机型', |
| | | prop: 'materialModel', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入机型', |
| | | }, |
| | | { |
| | | label: '操作时间', |
| | | prop: 'operateTime', |
| | | type: 'datetimerange', |
| | | el: 'date-picker', |
| | | //disabled: disabled, |
| | | placeholder: '请输入操作时间', |
| | | }, |
| | | { |
| | | label: '备注', |
| | | prop: 'remark', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入备注', |
| | | }, |
| | | { |
| | | label: '物料ID', |
| | | prop: 'materialId', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入物料ID', |
| | | rules: [{ required: true, message: '物料ID不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '任务号', |
| | | prop: 'taskNo', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入任务号', |
| | | rules: [{ required: true, message: '任务号不能为空', trigger: 'blur' }], |
| | | }, |
| | | { |
| | | label: '起始库位', |
| | | prop: 'sourcePlace', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入起始库位', |
| | | }, |
| | | { |
| | | label: '目标库位', |
| | | prop: 'toPlace', |
| | | el: 'input', |
| | | //disabled: disabled, |
| | | placeholder: '请输入目标库位', |
| | | }, |
| | | ]) |
| | | /** |
| | | * 校验是否有数据变化 |
| | | */ |
| | | const checkIsEqualObject = () => { |
| | | const data = { |
| | | formData: formData.value, |
| | | } |
| | | const check = isEqual(initiateData.value, data) |
| | | return check |
| | | } |
| | | |
| | | const onClose = (done: () => void) => { |
| | | if (visible.value) { |
| | | if (checkIsEqualObject()) { |
| | | visible.value = false |
| | | done && done() |
| | | } else { |
| | | ConfirmBox('是否保存设置?') |
| | | .then(() => { |
| | | onConfirm() |
| | | }) |
| | | .catch(() => { |
| | | visible.value = false |
| | | done && done() |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 保存 |
| | | */ |
| | | const onConfirm = async () => { |
| | | await formRef.value?.validate() |
| | | const data = { |
| | | orderNo: formData.value.orderNo, |
| | | materialName: formData.value.materialName, |
| | | materialNo: formData.value.materialNo, |
| | | stockType: formData.value.stockType, |
| | | containerNo: formData.value.containerNo, |
| | | materialModel: formData.value.materialModel, |
| | | operateTime: formData.value.operateTime, |
| | | remark: formData.value.remark, |
| | | materialId: formData.value.materialId, |
| | | taskNo: formData.value.taskNo, |
| | | sourcePlace: formData.value.sourcePlace, |
| | | toPlace: formData.value.toPlace, |
| | | } |
| | | if (!current.value) { |
| | | await wmsInOutStockRecordDrawer.addWmsInOutStockRecord(data) |
| | | } else { |
| | | const id = current.value.id |
| | | await wmsInOutStockRecordDrawer.updateWmsInOutStockRecord(id, data) |
| | | } |
| | | ElMessage.success('保存成功') |
| | | ctx.emit('confirm') |
| | | } |
| | | |
| | | const updateCheckData = () => { |
| | | initiateData.value = { |
| | | formData: { |
| | | ...formData.value, |
| | | }, |
| | | } |
| | | } |
| | | const updateFormItemOptions = (propName: string, enumData: any[]) => { |
| | | const item = formItems.find((item) => item.prop === propName) |
| | | if (item && enumData) { |
| | | item.options = enumData.map((item) => ({ |
| | | label: item.description, |
| | | value: item.value, |
| | | })) |
| | | } |
| | | } |
| | | /** |
| | | * 通用查询枚举 |
| | | */ |
| | | const commonQueryEnumForFrom = async () => { |
| | | const stockTypeEnumEnum = await wmsInOutStockRecordDrawer.getWmsEnumData({ |
| | | EnumName: 'StockTypeEnum', |
| | | }) |
| | | updateFormItemOptions('stockType', stockTypeEnumEnum) |
| | | } |
| | | commonQueryEnumForFrom() |
| | | /** |
| | | * 弹窗打开获取详情 |
| | | */ |
| | | const onOpen = async () => { |
| | | if (current.value) { |
| | | const res = await wmsInOutStockRecordDrawer.getWmsInOutStockRecordDetail( |
| | | current.value |
| | | ) |
| | | |
| | | formData.value = { |
| | | orderNo: res.orderNo, |
| | | materialName: res.materialName, |
| | | materialNo: res.materialNo, |
| | | stockType: res.stockType, |
| | | containerNo: res.containerNo, |
| | | materialModel: res.materialModel, |
| | | operateTime: res.operateTime, |
| | | remark: res.remark, |
| | | materialId: res.materialId, |
| | | taskNo: res.taskNo, |
| | | sourcePlace: res.sourcePlace, |
| | | toPlace: res.toPlace, |
| | | id: res.id, |
| | | } |
| | | disabled.value = true |
| | | updateCheckData() |
| | | } else { |
| | | formData.value = {} |
| | | |
| | | disabled.value = false |
| | | updateCheckData() |
| | | } |
| | | } |
| | | |
| | | watch(() => current.value, onOpen) |
| | | |
| | | return { |
| | | formItems, |
| | | formData, |
| | | visible, |
| | | formRef, |
| | | onOpen, |
| | | onClose, |
| | | onConfirm, |
| | | } |
| | | } |