feat(WorkOrderEdit): 添加作业周期选择功能并暴露表单数据方法

- 在基础信息组件中添加日期范围选择器
- 暴露getFormData方法供父组件获取表单数据
- 优化样式和代码结构
This commit is contained in:
liangbin 2026-01-16 13:44:25 +08:00
parent b55f605d6d
commit 7d1b906aae
2 changed files with 65 additions and 25 deletions

View File

@ -10,49 +10,83 @@
</view> </view>
<view class="FormItem"> <view class="FormItem">
<view class="FormLableBox mustBox">作业地点</view> <view class="FormLableBox mustBox">作业地点</view>
<view class="MapBox" id="tianditu-map"> <view class="MapBox" id="tianditu-map"> </view>
</view>
<view class="FormValueBox"> <view class="FormValueBox">
<u-input v-model="formData.SpecificAddress" placeholder="请输入具体楼层或区域"></u-input> <u-input v-model="formData.SpecificAddress" placeholder="请输入具体楼层或区域"></u-input>
</view> </view>
</view> </view>
<view class="FormItem">
<view class="FormLableBox mustBox">作业周期</view>
<view class="FormValueBox">
<view class="date-picker-box">
<u-input v-model="formData.period" placeholder="请选择作业周期" readonly @focus="showTimeBox = true"></u-input>
<u-button style="margin-left: 5rpx;width: 80rpx;" type="primary" size="small" @click="showTimeBox = true">选择日期</u-button>
</view>
<u-calendar :show="showTimeBox" mode="range" :minDate="minDate"
@confirm="HandlePeriodConfirm" @close="HandleCloseTimeBox" ></u-calendar>
</view>
</view>
</view> </view>
</view> </view>
</template> </template>
<script setup> <script setup>
import { ref, onMounted } from 'vue' import { ref, onMounted, defineExpose } from "vue";
// //
let mapEntity = null; let mapEntity = null;
// //
let currentMarker = null; let currentMarker = null;
const showTimeBox = ref(false); //
const minDate = ref('1900-01-01'); //
// //
const formData = ref({ const formData = ref({
ProjectName: '', // ProjectName: "", //
Location: '', // Location: "", //
SpecificAddress: '', // SpecificAddress: "", //
}) period: "", //
});
//
defineExpose({
getFormData: () => formData.value,
});
// //
onMounted(() => { onMounted(() => {
// DOM
initTiandituMap(); initTiandituMap();
}); });
// //
const HandlePeriodConfirm = (dates) => {
console.log('选中的日期范围:', dates);
if (dates && dates.length > 0) {
const startDate = dates[0];
const endDate = dates[dates.length - 1] || dates[0];
formData.value.period = `${startDate}${endDate}`;
console.log('作业周期:', formData.value.period);
}
showTimeBox.value = false;
};
//
const HandleCloseTimeBox = () => {
showTimeBox.value = false;
formData.value.period = "";
};
//
const initTiandituMap = () => { const initTiandituMap = () => {
try { try {
// 1. // 1.
const container = document.getElementById('tianditu-map'); const container = document.getElementById("tianditu-map");
if (!container) { if (!container) {
console.error('地图容器未找到'); console.error("地图容器未找到");
return; return;
} }
// 2. 12 // 2. 12
mapEntity = new T.Map('tianditu-map'); mapEntity = new T.Map("tianditu-map");
const centerPoint = new T.LngLat(116.403874, 39.914885); const centerPoint = new T.LngLat(116.403874, 39.914885);
mapEntity.centerAndZoom(centerPoint, 12); mapEntity.centerAndZoom(centerPoint, 12);
@ -61,13 +95,13 @@ const initTiandituMap = () => {
mapEntity.enableScrollWheelZoom(); mapEntity.enableScrollWheelZoom();
// 4. + // 4. +
const vecLayer = new T.TileLayer('vec_w', { key: '你的天地图Key' }); const vecLayer = new T.TileLayer("vec_w", { key: "你的天地图Key" });
const cvaLayer = new T.TileLayer('cva_w', { key: '你的天地图Key' }); const cvaLayer = new T.TileLayer("cva_w", { key: "你的天地图Key" });
const layerGroup = new T.LayerGroup([vecLayer, cvaLayer]); const layerGroup = new T.LayerGroup([vecLayer, cvaLayer]);
mapEntity.addLayer(layerGroup); mapEntity.addLayer(layerGroup);
// 5. // 5.
mapEntity.addEventListener('click', (e) => { mapEntity.addEventListener("click", (e) => {
const lng = e.lnglat.getLng(); const lng = e.lnglat.getLng();
const lat = e.lnglat.getLat(); const lat = e.lnglat.getLat();
@ -84,15 +118,14 @@ const initTiandituMap = () => {
// Location // Location
formData.value.Location = `${lng},${lat}`; formData.value.Location = `${lng},${lat}`;
console.log('标记点位置:', lng, lat); console.log("标记点位置:", lng, lat);
}); });
console.log('天地图初始化成功'); console.log("天地图初始化成功");
} catch (error) { } catch (error) {
console.error('天地图初始化失败:', error); console.error("天地图初始化失败:", error);
} }
} };
</script> </script>
@ -105,7 +138,7 @@ const initTiandituMap = () => {
} }
.mustBox::after { .mustBox::after {
content: '*'; content: "*";
color: red; color: red;
font-size: 30rpx; font-size: 30rpx;
margin-left: 10rpx; margin-left: 10rpx;
@ -133,7 +166,14 @@ const initTiandituMap = () => {
.FormValueBox { .FormValueBox {
font-size: 30rpx; font-size: 30rpx;
margin-top: 20rpx; margin-top: 20rpx;
.date-picker-box {
display: flex;
align-items: center;
gap: 20rpx;
flex: 1;
}
} }
} }
} }
</style> </style>

View File

@ -15,7 +15,7 @@
</view> </view>
</view> </view>
<view class="ContentBox"> <view class="ContentBox">
<BasicsInfo :ref="basicsInfoRef"></BasicsInfo> <BasicsInfo ref="basicsInfoRef"></BasicsInfo>
</view> </view>
<view class="FootBox" v-for="item in stepList" :key="item.id"> <view class="FootBox" v-for="item in stepList" :key="item.id">
<u-button :text="item.PrevBtnName" type="info"></u-button> <u-button :text="item.PrevBtnName" type="info"></u-button>
@ -53,7 +53,7 @@ const stepList = ref([
// //
const nextStep = () => { const nextStep = () => {
console.log(basicsInfoRef.value); console.log(basicsInfoRef.value.getFormData());
} }