|
@@ -35,7 +35,7 @@
|
|
<div class="box-content">
|
|
<div class="box-content">
|
|
<div class="create-title">
|
|
<div class="create-title">
|
|
<img class="title-icon" src="@/assets/img/home/create-icon.png" alt="" />
|
|
<img class="title-icon" src="@/assets/img/home/create-icon.png" alt="" />
|
|
- {{ isClient ? '新增用户' : '创建农场' }}
|
|
|
|
|
|
+ {{ isClient ? "新增用户" : "创建农场" }}
|
|
</div>
|
|
</div>
|
|
<div class="create-content">
|
|
<div class="create-content">
|
|
<div class="create-from">
|
|
<div class="create-from">
|
|
@@ -57,28 +57,43 @@
|
|
<div class="draw-btn" @click="toSubPage">点击勾选地块</div>
|
|
<div class="draw-btn" @click="toSubPage">点击勾选地块</div>
|
|
</div>
|
|
</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- <el-form-item label="农场面积" prop="area">
|
|
|
|
|
|
+ <el-form-item label="农场面积" prop="mianji">
|
|
<div class="area-box">
|
|
<div class="area-box">
|
|
<el-input
|
|
<el-input
|
|
placeholder="勾选地块获得农场面积"
|
|
placeholder="勾选地块获得农场面积"
|
|
- v-model="ruleForm.area"
|
|
|
|
|
|
+ v-model="ruleForm.mianji"
|
|
autocomplete="off"
|
|
autocomplete="off"
|
|
- style="width: fit-content;"
|
|
|
|
|
|
+ style="width: fit-content"
|
|
/>
|
|
/>
|
|
<div class="unit">亩</div>
|
|
<div class="unit">亩</div>
|
|
</div>
|
|
</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- <el-form-item label="种植作物" prop="phenologyId">
|
|
|
|
|
|
+ <el-form-item label="种植作物" prop="speciesItem">
|
|
<div class="select-wrap">
|
|
<div class="select-wrap">
|
|
- <el-select @change="changeSpecie" class="select-item" v-model="ruleForm.speciesItem" placeholder="作物类型">
|
|
|
|
- <el-option v-for="(item, index) in specieList" :key="index" :label="item.name" :value="{value: item.id, ...item}" />
|
|
|
|
|
|
+ <el-select
|
|
|
|
+ @change="changeSpecie"
|
|
|
|
+ class="select-item"
|
|
|
|
+ v-model="ruleForm.speciesItem"
|
|
|
|
+ placeholder="作物类型"
|
|
|
|
+ >
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="(item, index) in specieList"
|
|
|
|
+ :key="index"
|
|
|
|
+ :label="item.name"
|
|
|
|
+ :value="{ value: item.id, ...item }"
|
|
|
|
+ />
|
|
</el-select>
|
|
</el-select>
|
|
<el-select
|
|
<el-select
|
|
v-model="ruleForm.phenologyId"
|
|
v-model="ruleForm.phenologyId"
|
|
placeholder="物候期"
|
|
placeholder="物候期"
|
|
class="period-select select-item"
|
|
class="period-select select-item"
|
|
>
|
|
>
|
|
- <el-option v-for="(item, index) in phenologyList" :key="index" :label="item.name" :value="item.id" />
|
|
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="(item, index) in phenologyList"
|
|
|
|
+ :key="index"
|
|
|
|
+ :label="item.name"
|
|
|
|
+ :value="item.id"
|
|
|
|
+ />
|
|
</el-select>
|
|
</el-select>
|
|
</div>
|
|
</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
@@ -93,7 +108,9 @@
|
|
</div>
|
|
</div>
|
|
<div class="create-btn">
|
|
<div class="create-btn">
|
|
<div class="btn-item sencond-btn" @click="resetForm(ruleFormRef)">取消</div>
|
|
<div class="btn-item sencond-btn" @click="resetForm(ruleFormRef)">取消</div>
|
|
- <div class="btn-item primary-btn" @click="submitForm(ruleFormRef)">{{ isClient ? '添加' : '立即创建' }}</div>
|
|
|
|
|
|
+ <div class="btn-item primary-btn" @click="submitForm(ruleFormRef)">
|
|
|
|
+ {{ isClient ? "添加" : "立即创建" }}
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -107,11 +124,13 @@
|
|
import customHeader from "@/components/customHeader.vue";
|
|
import customHeader from "@/components/customHeader.vue";
|
|
import IndexMap from "./map/index.js";
|
|
import IndexMap from "./map/index.js";
|
|
import { useRoute, useRouter } from "vue-router";
|
|
import { useRoute, useRouter } from "vue-router";
|
|
-import { mapLocation } from "./map/index.js"
|
|
|
|
|
|
+import { mapLocation } from "./map/index.js";
|
|
import { onMounted, ref, reactive, watch, onActivated } from "vue";
|
|
import { onMounted, ref, reactive, watch, onActivated } from "vue";
|
|
import { useStore } from "vuex";
|
|
import { useStore } from "vuex";
|
|
import { convertPointToArray } from "@/utils/index";
|
|
import { convertPointToArray } from "@/utils/index";
|
|
import { ElMessage } from "element-plus";
|
|
import { ElMessage } from "element-plus";
|
|
|
|
+import { transformFromGCJToWGS, transformFromWGSToGCJ } from "@/utils/WSCoordinate.js";
|
|
|
|
+
|
|
const route = useRoute();
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
const store = useStore();
|
|
const store = useStore();
|
|
@@ -119,28 +138,35 @@ const store = useStore();
|
|
const indexMap = new IndexMap();
|
|
const indexMap = new IndexMap();
|
|
const mapContainer = ref(null);
|
|
const mapContainer = ref(null);
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
- centerPoint.value = store.state.home.miniUserLocationPoint
|
|
|
|
|
|
+ centerPoint.value = store.state.home.miniUserLocationPoint;
|
|
|
|
+ const arr = convertPointToArray(centerPoint.value);
|
|
|
|
+ getLocationName(`${arr[1]},${arr[0]}`);
|
|
indexMap.initMap(centerPoint.value, mapContainer.value);
|
|
indexMap.initMap(centerPoint.value, mapContainer.value);
|
|
- const arr = convertPointToArray(centerPoint.value)
|
|
|
|
- getLocationName(`${arr[1]},${arr[0]}`)
|
|
|
|
|
|
|
|
- getSpecieList()
|
|
|
|
|
|
+ getSpecieList();
|
|
});
|
|
});
|
|
|
|
|
|
-const polygonArr = ref(null)
|
|
|
|
|
|
+const polygonArr = ref(null);
|
|
const isClient = ref(false);
|
|
const isClient = ref(false);
|
|
onActivated(() => {
|
|
onActivated(() => {
|
|
if (route.query.type) {
|
|
if (route.query.type) {
|
|
isClient.value = true;
|
|
isClient.value = true;
|
|
}
|
|
}
|
|
|
|
+ if (route.query.isFromHome) {
|
|
|
|
+ centerPoint.value = store.state.home.miniUserLocationPoint;
|
|
|
|
+ const arr = convertPointToArray(centerPoint.value);
|
|
|
|
+ getLocationName(`${arr[1]},${arr[0]}`);
|
|
|
|
+ indexMap.setMapPosition(arr);
|
|
|
|
+ }
|
|
|
|
+ indexMap.clearLayer();
|
|
// 绘制勾画范围
|
|
// 绘制勾画范围
|
|
- const polygonData = store.state.home.polygonData
|
|
|
|
|
|
+ const polygonData = store.state.home.polygonData;
|
|
if (polygonData) {
|
|
if (polygonData) {
|
|
- indexMap.setAreaGeometry(polygonData?.geometryArr)
|
|
|
|
- polygonArr.value = polygonData.geometryArr
|
|
|
|
- ruleForm.area = polygonData.area
|
|
|
|
|
|
+ indexMap.setAreaGeometry(polygonData?.geometryArr);
|
|
|
|
+ polygonArr.value = polygonData.geometryArr;
|
|
|
|
+ ruleForm.mianji = polygonData.mianji;
|
|
}
|
|
}
|
|
-})
|
|
|
|
|
|
+});
|
|
|
|
|
|
// 搜索
|
|
// 搜索
|
|
const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
|
|
const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
|
|
@@ -181,25 +207,26 @@ const remoteMethod = async (keyword) => {
|
|
|
|
|
|
const handleSearchRes = (v) => {
|
|
const handleSearchRes = (v) => {
|
|
const parts = v.value.split(",");
|
|
const parts = v.value.split(",");
|
|
- const coordinateArray = [parseFloat(parts[1]), parseFloat(parts[0])];
|
|
|
|
|
|
+ let { latitude, longitude } = transformFromGCJToWGS(parseFloat(parts[0]), parseFloat(parts[1]));
|
|
|
|
+ const coordinateArray = [longitude, latitude];
|
|
indexMap.setMapPosition(coordinateArray);
|
|
indexMap.setMapPosition(coordinateArray);
|
|
- centerPoint.value = `POINT (${coordinateArray[0]} ${coordinateArray[1]})`
|
|
|
|
|
|
+ centerPoint.value = `POINT (${coordinateArray[0]} ${coordinateArray[1]})`;
|
|
ruleForm.address = v.item?.title || v.item?.address;
|
|
ruleForm.address = v.item?.title || v.item?.address;
|
|
- pointAddress.value = v.item?.province + v.item?.city + v.item?.district
|
|
|
|
|
|
+ pointAddress.value = v.item?.province + v.item?.city + v.item?.district;
|
|
};
|
|
};
|
|
|
|
|
|
// 表单
|
|
// 表单
|
|
const ruleFormRef = ref(null);
|
|
const ruleFormRef = ref(null);
|
|
const ruleForm = reactive({
|
|
const ruleForm = reactive({
|
|
address: "",
|
|
address: "",
|
|
- area: "",
|
|
|
|
- speciesItem: "",
|
|
|
|
|
|
+ mianji: "",
|
|
|
|
+ speciesItem: null,
|
|
phenologyId: "",
|
|
phenologyId: "",
|
|
name: "",
|
|
name: "",
|
|
});
|
|
});
|
|
const rules = reactive({
|
|
const rules = reactive({
|
|
address: [{ required: true, message: "请选择农场位置", trigger: "blur" }],
|
|
address: [{ required: true, message: "请选择农场位置", trigger: "blur" }],
|
|
- area: [{ required: true, message: "请勾选地块获得农场面积", trigger: "blur" }],
|
|
|
|
|
|
+ mianji: [{ required: true, message: "请勾选地块获得农场面积", trigger: "blur" }],
|
|
speciesItem: [{ required: true, message: "请选择品类", trigger: "blur" }],
|
|
speciesItem: [{ required: true, message: "请选择品类", trigger: "blur" }],
|
|
phenologyId: [{ required: true, message: "请选择物候期", trigger: "blur" }],
|
|
phenologyId: [{ required: true, message: "请选择物候期", trigger: "blur" }],
|
|
name: [{ required: true, message: "请输入您的农场名称", trigger: "blur" }],
|
|
name: [{ required: true, message: "请输入您的农场名称", trigger: "blur" }],
|
|
@@ -214,13 +241,15 @@ const submitForm = (formEl) => {
|
|
wkt: centerPoint.value,
|
|
wkt: centerPoint.value,
|
|
speciesId: ruleForm.speciesItem?.id,
|
|
speciesId: ruleForm.speciesItem?.id,
|
|
containerId: ruleForm.speciesItem?.defaultContainerId,
|
|
containerId: ruleForm.speciesItem?.defaultContainerId,
|
|
- // geom: polygonArr.value
|
|
|
|
- }
|
|
|
|
|
|
+ geom: polygonArr.value,
|
|
|
|
+ };
|
|
VE_API.farm.saveFarm(params).then((res) => {
|
|
VE_API.farm.saveFarm(params).then((res) => {
|
|
- console.log('code', res.code);
|
|
|
|
- ElMessage.success("创建成功")
|
|
|
|
- router.replace('/home?reload=true')
|
|
|
|
- })
|
|
|
|
|
|
+ ElMessage.success("创建成功");
|
|
|
|
+ // 重置表单
|
|
|
|
+ ruleFormRef.value.resetFields();
|
|
|
|
+ store.commit("home/SET_FARM_POLYGON", null);
|
|
|
|
+ router.replace("/home?reload=true");
|
|
|
|
+ });
|
|
console.log("submit!", params);
|
|
console.log("submit!", params);
|
|
} else {
|
|
} else {
|
|
console.log("error submit!");
|
|
console.log("error submit!");
|
|
@@ -231,56 +260,60 @@ const submitForm = (formEl) => {
|
|
const resetForm = (formEl) => {
|
|
const resetForm = (formEl) => {
|
|
if (!formEl) return;
|
|
if (!formEl) return;
|
|
formEl.resetFields();
|
|
formEl.resetFields();
|
|
|
|
+ store.commit("home/SET_FARM_POLYGON", null);
|
|
router.go(-1);
|
|
router.go(-1);
|
|
};
|
|
};
|
|
|
|
|
|
-const centerPoint = ref(null)
|
|
|
|
|
|
+const centerPoint = ref(null);
|
|
|
|
|
|
function toSubPage() {
|
|
function toSubPage() {
|
|
- router.push(`/edit_map?mapCenter=${centerPoint.value}&pointName=${ruleForm.address}&pointAddress=${pointAddress.value}`);
|
|
|
|
|
|
+ router.push(
|
|
|
|
+ `/edit_map?mapCenter=${centerPoint.value}&pointName=${ruleForm.address}&pointAddress=${pointAddress.value}`
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
-const pointAddress = ref(null)
|
|
|
|
|
|
+const pointAddress = ref(null);
|
|
function getLocationName(location) {
|
|
function getLocationName(location) {
|
|
const params = {
|
|
const params = {
|
|
- key: MAP_KEY,
|
|
|
|
- location,
|
|
|
|
- };
|
|
|
|
- VE_API.old_mini_map.location(params).then(({ result }) => {
|
|
|
|
- // locationVal.value = result.formatted_addresses.recommend;
|
|
|
|
- const add = result.formatted_addresses?.recommend
|
|
|
|
- ? result.formatted_addresses.recommend
|
|
|
|
- : result.address + "";
|
|
|
|
- ruleForm.address = add
|
|
|
|
- pointAddress.value = result.address
|
|
|
|
- });
|
|
|
|
|
|
+ key: MAP_KEY,
|
|
|
|
+ location,
|
|
|
|
+ };
|
|
|
|
+ VE_API.old_mini_map.location(params).then(({ result }) => {
|
|
|
|
+ // locationVal.value = result.formatted_addresses.recommend;
|
|
|
|
+ const add = result.formatted_addresses?.recommend ? result.formatted_addresses.recommend : result.address + "";
|
|
|
|
+ ruleForm.address = add;
|
|
|
|
+ pointAddress.value = result.address;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
-watch(() => mapLocation.data,(newValue, oldValue) => {
|
|
|
|
- if (newValue) {
|
|
|
|
- centerPoint.value = `POINT (${newValue[0]} ${newValue[1]})`
|
|
|
|
- getLocationName(`${newValue[1]},${newValue[0]}`)
|
|
|
|
|
|
+watch(
|
|
|
|
+ () => mapLocation.data,
|
|
|
|
+ (newValue, oldValue) => {
|
|
|
|
+ if (newValue) {
|
|
|
|
+ let { latitude, longitude } = transformFromWGSToGCJ(newValue[1], newValue[0]);
|
|
|
|
+ centerPoint.value = `POINT (${newValue[0]} ${newValue[1]})`;
|
|
|
|
+ getLocationName(`${latitude},${longitude}`);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-})
|
|
|
|
|
|
+);
|
|
|
|
|
|
-const specieList = ref([])
|
|
|
|
|
|
+const specieList = ref([]);
|
|
|
|
|
|
function getSpecieList() {
|
|
function getSpecieList() {
|
|
- VE_API.farm.fetchSpecieList().then(({data}) => {
|
|
|
|
- specieList.value = data
|
|
|
|
- })
|
|
|
|
|
|
+ VE_API.farm.fetchSpecieList().then(({ data }) => {
|
|
|
|
+ specieList.value = data;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
function changeSpecie(v) {
|
|
function changeSpecie(v) {
|
|
- getPhenology(v.defaultContainerId)
|
|
|
|
|
|
+ getPhenology(v.defaultContainerId);
|
|
}
|
|
}
|
|
|
|
|
|
-const phenologyList = ref([])
|
|
|
|
|
|
+const phenologyList = ref([]);
|
|
function getPhenology(containerId) {
|
|
function getPhenology(containerId) {
|
|
- VE_API.farm.fetchPhenologyList({containerId}).then(({data}) => {
|
|
|
|
- console.log('getPhenology', data);
|
|
|
|
- phenologyList.value = data
|
|
|
|
- })
|
|
|
|
|
|
+ VE_API.farm.fetchPhenologyList({ containerId }).then(({ data }) => {
|
|
|
|
+ phenologyList.value = data;
|
|
|
|
+ });
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|