import {
|
ref,
|
onMounted,
|
reactive,
|
computed,
|
Ref,
|
watch,
|
SetupContext,
|
h,
|
} from 'vue'
|
import { injectModel } from '@/libs/Provider/Provider'
|
import { WmsMaterialTypeDrawer } from '../Models/WmsMaterialTypeDrawer'
|
import { ElMessage } from 'element-plus'
|
import isEqual from 'lodash/isEqual'
|
import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
|
import { cloneDeep } from 'lodash'
|
// 引入公共选项配置
|
import {
|
BOOLEAN_OPTIONS_AddEdit
|
} from '@/utils/commonOptionConstants';
|
|
export const useWmsMaterialTypeDrawer = (props: any, ctx?: any) => {
|
const wmsMaterialTypeDrawer = injectModel<WmsMaterialTypeDrawer>('wmsMaterialTypeDrawer')
|
/**
|
* 用来对比的初始化数据
|
*/
|
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 datePicker = (attrs) => {
|
return (
|
<el-date-picker
|
type="date"
|
format="YYYY-MM-DD HH:mm:ss"
|
formatValue="YYYY-MM-DD HH:mm:ss"
|
{...attrs}
|
></el-date-picker>
|
)
|
}
|
const inputNumber = (attrs) => {
|
return (
|
<el-input-number
|
min="1"
|
step="1"
|
precision="0"
|
{...attrs}
|
></el-input-number>
|
)
|
}
|
|
const dateTimePicker = (attrs) => {
|
return (
|
<el-date-picker
|
type="datetime"
|
format="YYYY-MM-DD HH:mm:ss"
|
formatValue="YYYY-MM-DD HH:mm:ss"
|
{...attrs}
|
></el-date-picker>
|
)
|
}
|
|
const visible = computed({
|
get() {
|
return props.modelValue
|
},
|
set(val) {
|
ctx.emit('update:modelValue', val)
|
},
|
})
|
/**
|
* 添加的form字段
|
*/
|
const formItems = reactive([
|
{
|
label: '类型描述',
|
prop: 'materialTypeDesc',
|
el: 'input',
|
//disabled: disabled,
|
placeholder: '请输入类型描述',
|
rules: [{required: true, message: '类型描述不能为空', trigger: 'blur' }],
|
},
|
{
|
label: '类型编码',
|
prop: 'materialTypeCode',
|
el: 'input',
|
//disabled: disabled,
|
placeholder: '请输入类型编码',
|
rules: [{required: true, message: '类型编码不能为空', trigger: 'blur' }],
|
},
|
{
|
label: '备注',
|
prop: 'remark',
|
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 = {
|
materialTypeDesc: formData.value.materialTypeDesc,
|
materialTypeCode: formData.value.materialTypeCode,
|
remark: formData.value.remark,
|
}
|
if (!current.value) {
|
await wmsMaterialTypeDrawer.addWmsMaterialType(data)
|
} else {
|
const id = current.value.id
|
await wmsMaterialTypeDrawer.updateWmsMaterialType(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 () => {
|
|
}
|
commonQueryEnumForFrom()
|
/**
|
* 弹窗打开获取详情
|
*/
|
const onOpen = async () => {
|
if (current.value) {
|
const res = await wmsMaterialTypeDrawer.getWmsMaterialTypeDetail(current.value)
|
|
formData.value = {
|
materialTypeDesc: res.materialTypeDesc,
|
materialTypeCode: res.materialTypeCode,
|
remark: res.remark,
|
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,
|
}
|
}
|