Files
geg-gas-web/src/views/dayPlan/Demand/components/createForm.vue

233 lines
7.9 KiB
Vue
Raw Normal View History

2026-01-16 17:28:00 +08:00
<template>
<a-spin :spinning="spinning" tip="加载中...">
2026-01-22 17:31:32 +08:00
<div class="page-bg-wrap formViewStyle pdcss">
<div class="top-toolbar" >
<a-button style="margin-right: 10px" @click="close">
<slot name="icon"><close-outlined /></slot>关闭
</a-button>
2026-01-23 13:31:05 +08:00
<template v-if="pageType=='edit'||pageType=='update' || !pageType ">
2026-01-23 11:20:27 +08:00
<a-button style="margin-right: 10px" type="primary" @click="checkBtn('save')">
2026-01-22 17:31:32 +08:00
<slot name="icon"><save-outlined /></slot>保存
</a-button>
2026-01-23 11:20:27 +08:00
<a-button style="margin-right: 10px" @click="checkBtn('submit')">
2026-01-22 17:31:32 +08:00
<slot name="icon"><send-outlined /></slot>保存并提交
</a-button>
</template>
</div>
2026-01-23 11:20:27 +08:00
<Card :title="title" :bordered="false" v-if="pageType=='compare'&&titleNew">
<basicForm :formObj="formStateNew" :changeList="diffResultList" :list="dataListNew" :disable="true"></basicForm>
</Card>
<Card :title="title" :bordered="false" v-if="title">
<basicForm ref="formRef" :formObj="formState" :list="dataList" :disable="pageType=='view' || pageType=='compare'"></basicForm>
</Card>
2026-01-22 17:31:32 +08:00
2026-01-16 17:28:00 +08:00
</div>
</a-spin>
</template>
<script lang="ts" setup>
import { Card } from 'ant-design-vue';
import { useRouter } from 'vue-router';
import { FromPageType, RecordType } from '/@/enums/workflowEnum';
import { ref, computed, onMounted, onBeforeMount, nextTick, defineAsyncComponent, reactive, defineComponent, watch} from 'vue';
2026-01-22 17:31:32 +08:00
import { SendOutlined, SaveOutlined, CloseOutlined, } from '@ant-design/icons-vue';
2026-01-16 17:28:00 +08:00
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
import useEventBus from '/@/hooks/event/useEventBus';
import type { Rule } from 'ant-design-vue/es/form';
import { getDictionary } from '/@/api/sales/Customer';
import { useModal } from '/@/components/Modal';
2026-01-23 11:20:27 +08:00
import { addLngPngDemand, submitLngPngDemand,getLngPngDemand,getLngPngDemandUpdate,getLngPngDemandCompare } from '/@/api/dayPlan/Demand';
2026-01-16 17:28:00 +08:00
import dayjs from 'dayjs';
import { getAppEnvConfig } from '/@/utils/env';
import { message } from 'ant-design-vue';
import { useUserStore } from '/@/store/modules/user';
import basicForm from './basicForm.vue'
const userStore = useUserStore();
const userInfo = userStore.getUserInfo;
const formRef = ref();
const { bus, FORM_LIST_MODIFIED } = useEventBus();
const router = useRouter();
2026-01-23 11:20:27 +08:00
const { currentRoute } = router
2026-01-16 17:28:00 +08:00
const tabStore = useMultipleTabStore();
const formProps = ref(null);
const pageId = ref(currentRoute.value.query?.id)
2026-01-23 11:20:27 +08:00
const pageType = ref(currentRoute.value.query?.type)
2026-01-16 17:28:00 +08:00
const spinning = ref(false);
const { notification } = useMessage();
const { t } = useI18n();
const formState = reactive({
2026-01-22 17:31:32 +08:00
datePlan: null
2026-01-16 17:28:00 +08:00
});
2026-01-23 11:20:27 +08:00
const formStateNew = reactive({})
2026-01-16 17:28:00 +08:00
const [register, { openModal:openModal}] = useModal();
2026-01-22 17:31:32 +08:00
const title = ref('管道气需求')
2026-01-23 11:20:27 +08:00
const titleNew = ref('')
const dataListNew = ref([])
2026-01-16 17:28:00 +08:00
const basicFormRef = ref()
2026-01-23 11:20:27 +08:00
const diffResultList = ref([])
const dataList = ref([])
2026-01-16 17:28:00 +08:00
onMounted(() => {
if (pageId.value) {
2026-01-23 11:20:27 +08:00
if (pageType.value=='compare') {
getCompareInfo(pageId.value)
return
}
2026-01-16 17:28:00 +08:00
getInfo(pageId.value)
}
});
2026-01-23 11:20:27 +08:00
async function getCompareInfo(id) {
spinning.value = true
try {
let data = await getLngPngDemandCompare(id) || {}
spinning.value = false
diffResultList.value = data.diffResultList || []
let obj = changeData(data.oldBean || {})
Object.assign(formState, {...obj.params})
Object.assign(dataList.value, obj.list || [])
title.value = formState.verNo? ('版本V'+ formState.verNo) : ''
let obj1 = changeData(data.newBean || {})
Object.assign(formStateNew, {...obj1.params})
Object.assign(dataListNew.value, obj1.list || [])
titleNew.value = formStateNew.verNo ? ('版本V'+ formStateNew.verNo) : ''
} catch (error) {
console.log(error,'error555555')
spinning.value = false
}
}
2026-01-16 17:28:00 +08:00
async function getInfo(id) {
spinning.value = true
try {
2026-01-23 11:20:27 +08:00
let data = {}
if (pageType.value == 'update') {
data = await getLngPngDemandUpdate(id)
} else {
data = await getLngPngDemand(id)
}
spinning.value = false
let obj = changeData(data)
Object.assign(formState, {...obj.params})
Object.assign(dataList.value, obj.list || [{}])
2026-01-16 17:28:00 +08:00
} catch (error) {
console.log(error, 'error')
spinning.value = false
}
}
2026-01-22 17:31:32 +08:00
const changeData = (obj) => {
2026-01-23 11:20:27 +08:00
let arr = obj.lngPngDemandPurList || []
2026-01-22 17:31:32 +08:00
obj.datePlan = obj.datePlan ? dayjs(obj.datePlan) : null
obj.qtyContractM3 = Number(obj.qtyContractM3)/10000
obj.qtyPlanM3 = Number(obj.qtyPlanM3)/10000
obj.qtyDemandM3 = Number(obj.qtyDemandM3)/10000
obj.qtySalesM3 = Number(obj.qtySalesM3)/10000
2026-01-23 11:20:27 +08:00
arr.length && arr.forEach(v => {
2026-01-22 17:31:32 +08:00
v.qtyDemandM3 = Number(v.qtyDemandM3)/10000
v.qtySalesM3 = Number(v.qtySalesM3)/10000
2026-01-16 17:28:00 +08:00
2026-01-22 17:31:32 +08:00
v.qtyDemandM3 = Number(v.qtyDemandM3) ? Number(v.qtyDemandM3).toFixed(5) : ''
v.qtySalesM3 = Number(v.qtySalesM3) ? Number(v.qtySalesM3).toFixed(5) : ''
});
obj.qtyContractM3 = Number(obj.qtyContractM3) ? Number(obj.qtyContractM3).toFixed(5) : ''
obj.qtyPlanM3 = Number(obj.qtyPlanM3) ? Number(obj.qtyPlanM3).toFixed(5) : ''
obj.qtyDemandM3 = Number(obj.qtyDemandM3) ? Number(obj.qtyDemandM3).toFixed(5) : ''
obj.qtySalesM3 = Number(obj.qtySalesM3) ? Number(obj.qtySalesM3).toFixed(5) : ''
return {
list : arr,
params: obj
}
}
2026-01-16 17:28:00 +08:00
function close() {
tabStore.closeTab(currentRoute.value, router);
}
async function checkBtn(type) {
try {
2026-01-22 17:31:32 +08:00
const data = await formRef.value.getFormValue();
let arr = JSON.parse(JSON.stringify(data.list))
arr.forEach(v=> {
v.qtyDemandM3 = Number(v.qtyDemandM3)*10000
v.qtySalesM3 = Number(v.qtySalesM3)*10000
})
let obj = {
...data.formInfo,
datePlan: dayjs(data.formInfo.datePlan).format('YYYY-MM-DD HH:mm:ss'),
qtyContractM3: Number(data.formInfo.qtyContractM3)*10000,
qtyPlanM3: Number(data.formInfo.qtyPlanM3)*10000,
qtyDemandM3: Number(data.formInfo.qtyDemandM3)*10000,
qtySalesM3: Number(data.formInfo.qtySalesM3)*10000,
lngPngDemandPurList:arr
2026-01-16 17:28:00 +08:00
}
2026-01-22 17:31:32 +08:00
spinning.value = true;
let request = ''
request = type == 'save'? addLngPngDemand : submitLngPngDemand
await request(obj)
2026-01-16 17:28:00 +08:00
spinning.value = false;
notification.success({
message: 'Tip',
2026-01-22 17:31:32 +08:00
description: type == 'save' ? '保存成功':'已提交'
2026-01-16 17:28:00 +08:00
}); //提示消息
setTimeout(() => {
bus.emit(FORM_LIST_MODIFIED, {});
close();
}, 500);
2026-01-22 17:31:32 +08:00
} catch (errorInfo) {
spinning.value = false;
errorInfo?.errorFields?.length && notification.warning({
message: 'Tip',
description: '请完善信息'
});
2026-01-16 17:28:00 +08:00
}
2026-01-22 17:31:32 +08:00
}
2026-01-16 17:28:00 +08:00
</script>
<style lang="less" scoped>
.page-bg-wrap {
background-color: #fff;
}
.top-toolbar {
min-height: 44px;
margin-bottom: 12px;
border-bottom: 1px solid #eee;
}
2026-01-22 17:31:32 +08:00
.pdcss {
padding:0px 12px 6px 12px !important;
}
2026-01-16 17:28:00 +08:00
.dot {
margin-right: 10px;
display: flex;
align-items: center;
i{
padding: 5px;
font-style: normal;
}
span{
width: 10px !important;
height: 10px !important;
border-radius: 50%;
background: red;
display: block;
}
}
</style>