ADD: Utm Convert
FIX: Features data not saving and not loading
This commit is contained in:
@@ -47,7 +47,6 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const mapKey = 'web.79abbab4970e401781f434da3e41cfa6';
|
||||
const serviceKey = 'service.11d860f52c434bd29e5f84d0a0a41108';
|
||||
const mapRef = ref();
|
||||
|
||||
const transactions = ref([]);
|
||||
const stockData = ref({});
|
||||
@@ -118,6 +117,7 @@ onBeforeMount(async () => {
|
||||
if (route.name === 'edit-belonging') {
|
||||
editMode.value = true;
|
||||
belonging.value = await BelongingService.getBelonging(route.params.belongingId);
|
||||
featuresValues.value = extractFeaturesValues(belonging.value.features);
|
||||
transactions.value = await TransactionService.getTransactionsByBelongingId(route.params.belongingId);
|
||||
stockData.value = await TransactionService.getStockByBelongingId(route.params.belongingId);
|
||||
mainImageUrlsWithData.value = fillImagesArray(belonging.value?.mainImageUrls || []);
|
||||
@@ -126,6 +126,67 @@ onBeforeMount(async () => {
|
||||
});
|
||||
const showTransactionDialog = ref(false);
|
||||
|
||||
import { UTMtoLatLon, LatLontoUTM } from '@/utm';
|
||||
|
||||
const easting = ref();
|
||||
const northing = ref();
|
||||
const zone = ref();
|
||||
const lat = ref();
|
||||
const long = ref();
|
||||
|
||||
const convertUTMtoLatLng = () => {
|
||||
if (easting.value && northing.value && zone.value) {
|
||||
try {
|
||||
const result = UTMtoLatLon(
|
||||
Number(easting.value),
|
||||
Number(northing.value),
|
||||
Number(zone.value),
|
||||
'N' // Change to 'S' if in Southern Hemisphere
|
||||
);
|
||||
lat.value = result.latitude;
|
||||
long.value = result.longitude;
|
||||
console.log(lat.value, long.value);
|
||||
searchLocation(lat.value, long.value);
|
||||
} catch (error) {
|
||||
console.error('Error converting UTM to Lat/Lng:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Watch nationalGeoCode to split and convert to Lat/Lng
|
||||
watch(
|
||||
() => belonging.value.nationalGeoCode,
|
||||
(newCode) => {
|
||||
if (newCode && newCode.length === 15) {
|
||||
easting.value = newCode.substring(0, 6); // First 6 digits for easting
|
||||
northing.value = newCode.substring(6, 13); // Next 6 digits for northing
|
||||
zone.value = newCode.substring(13, 15); // Last 2 digits for zone
|
||||
// Convert to Lat/Lng after splitting
|
||||
convertUTMtoLatLng();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const mapRef = ref();
|
||||
|
||||
const searchLocation = (lat, lon) => {
|
||||
if (mapRef.value) {
|
||||
mapRef.value.searchByCoordinates(lat, lon);
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => belonging.value.category,
|
||||
(newCategory) => {
|
||||
if (editMode.value && newCategory) {
|
||||
selectedCategory.value = categories.value.find((x) => x._id === newCategory);
|
||||
if (selectedCategory.value) {
|
||||
features.value = selectedCategory.value.features;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const fillImagesArray = (imageUrls) => {
|
||||
const images = [];
|
||||
for (let url of imageUrls) {
|
||||
@@ -161,12 +222,36 @@ const handleSelectCategory = ($event) => {
|
||||
}
|
||||
};
|
||||
|
||||
const extractFeatures = (featuresValues) => {
|
||||
const features = [];
|
||||
|
||||
for (const [key, value] of Object.entries(featuresValues)) {
|
||||
features.push({
|
||||
definition: key,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
return features;
|
||||
};
|
||||
|
||||
const extractFeaturesValues = (features) => {
|
||||
const featuresValues = {};
|
||||
|
||||
for (let feature of features) {
|
||||
featuresValues[feature.definition] = feature.value;
|
||||
}
|
||||
|
||||
return featuresValues;
|
||||
};
|
||||
|
||||
const saveBelonging = async () => {
|
||||
let status = 'failed';
|
||||
console.log(belonging);
|
||||
if (belonging?.value._id?.trim()) {
|
||||
belonging.value.mainImageUrls = mainImageUrlsWithData.value.map((x) => x.url);
|
||||
belonging.value.documentUrls = documentUrlsWithData.value.map((x) => x.url);
|
||||
belonging.value.features = extractFeatures(featuresValues.value);
|
||||
status = await BelongingService.updateBelonging(belonging.value._id, belonging.value);
|
||||
} else {
|
||||
status = await BelongingService.createBelonging(belonging.value);
|
||||
@@ -181,23 +266,6 @@ const saveBelonging = async () => {
|
||||
await router.push('/belonging/list-belongings');
|
||||
};
|
||||
|
||||
watch(
|
||||
() => mapRef.value?.state.map,
|
||||
(nv, ol) => {
|
||||
if (ol) return;
|
||||
setTimeout(() => {
|
||||
mapRef.value?.state.map?.setMapType('standard-night');
|
||||
if (mapRef.value?.state.mapType) mapRef.value.state.mapType = 'standard-night';
|
||||
}, 2000);
|
||||
setTimeout(() => {
|
||||
mapRef.value?.search({
|
||||
term: 'ولی عصر',
|
||||
coords: [51.36281969540723, 35.69672648316882]
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
);
|
||||
|
||||
const filters = ref({
|
||||
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
|
||||
type: { value: null, matchMode: FilterMatchMode.EQUALS },
|
||||
@@ -336,7 +404,7 @@ const formatDate = (dateString) => {
|
||||
</div>
|
||||
<div class="my-10">
|
||||
<label class="text-lg"> موقعیت دارایی </label>
|
||||
<MapComponent v-model="belonging.location.coordinates" />
|
||||
<MapComponent ref="mapRef" v-model="belonging.location.coordinates" />
|
||||
<!-- <MapIrComponent />-->
|
||||
</div>
|
||||
|
||||
@@ -447,6 +515,11 @@ const formatDate = (dateString) => {
|
||||
<label class="text-lg"> برچسب ها </label>
|
||||
<KiwiChips v-model="belonging.tags" class="w-full" placeholder="مثلا: زمین، ملک، کیانپارس..." />
|
||||
</div>
|
||||
|
||||
<div class="my-8">
|
||||
<label class="text-lg"> شناسه ملی جغرافیایی </label>
|
||||
<InputText v-model="belonging.nationalGeoCode" class="w-full" placeholder="شناسه 14 رقمی سند" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user