<template>
|
<slot name="form-items"></slot>
|
<slot name="description-items"></slot>
|
</template>
|
<script setup>
|
import { reactive, ref, watch, computed } from 'vue';
|
import { useDateFormat } from '@vueuse/core';
|
import sceneApi from '@/api/fysp/sceneApi';
|
expose({
|
submit
|
});
|
const props = defineProps({
|
scene: Object,
|
//工地额外信息
|
formInfo: Object,
|
//场景类型:工地
|
sceneType: {
|
type: Number,
|
default: 1
|
},
|
});
|
const emit = defineEmits([
|
'onSubmit',
|
'onCancel',
|
'update:scene',
|
'update:formInfo'
|
]);
|
const loading = ref(false);
|
const formObj = ref({});
|
const sceneObj = ref({});
|
// 创建或更新场景详情
|
function createOrupdateSubScene() {
|
loading.value = true;
|
|
if (formObj.value._timeRange && formObj.value._timeRange.length == 2) {
|
const t = formObj.value._timeRange;
|
formObj.value.csStartTime = useDateFormat(t[0], 'YYYY-MM-DD');
|
formObj.value.csEndTime = useDateFormat(t[1], 'YYYY-MM-DD');
|
}
|
return sceneApi
|
.updateSubScene(props.sceneType, formObj.value)
|
.then((res) => {
|
emit('onSubmit', formObj);
|
emit('update:formInfo', formObj);
|
return res.data;
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
}
|
|
// 更新场景
|
function updateScene() {
|
return sceneApi.updateScene(sceneObj.value).then(() => {
|
emit('update:scene', sceneObj);
|
});
|
}
|
|
function submit() {
|
updateScene();
|
return createOrupdateSubScene();
|
}
|
|
function cancel() {
|
emit('onCancel');
|
}
|
|
watch(
|
() => props.formInfo,
|
(nValue) => {
|
if (nValue) {
|
formObj.value = nValue;
|
formObj.value._timeRange = [
|
new Date(formObj.value.csStartTime),
|
new Date(formObj.value.csEndTime)
|
];
|
}
|
},
|
{ deep: false, immediate: true }
|
);
|
|
watch(
|
() => props.scene,
|
(nValue) => {
|
if (nValue) {
|
sceneObj.value = nValue;
|
}
|
},
|
{ deep: false, immediate: true }
|
);
|
</script>
|