|
@@ -84,6 +84,7 @@ import farmHeader from "@/components/farmHeader.vue";
|
|
|
import farmCalendarPopup from "@/components/popup/farmCalendarPopup.vue";
|
|
import farmCalendarPopup from "@/components/popup/farmCalendarPopup.vue";
|
|
|
import surveyAskPopup from "@/components/popup/surveyAskPopup.vue";
|
|
import surveyAskPopup from "@/components/popup/surveyAskPopup.vue";
|
|
|
import { useI18n } from "@/i18n";
|
|
import { useI18n } from "@/i18n";
|
|
|
|
|
+import { convertPointToArray } from "@/utils/index";
|
|
|
import wx from "weixin-js-sdk";
|
|
import wx from "weixin-js-sdk";
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
const { t } = useI18n();
|
|
@@ -102,8 +103,11 @@ const formatDateYMD = (date = new Date()) =>
|
|
|
|
|
|
|
|
const filterDate = ref(formatDateYMD());
|
|
const filterDate = ref(formatDateYMD());
|
|
|
|
|
|
|
|
-/** 假数据:后续可替换为接口;status: pending 待执行 / completed 已完成 */
|
|
|
|
|
-const taskList = ref([
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 假数据模板:wkt 相对中心点偏移(经度、纬度)
|
|
|
|
|
+ * 后续可替换为接口,接口返回绝对坐标时可去掉 offset
|
|
|
|
|
+ */
|
|
|
|
|
+const TASK_MOCK_TEMPLATE = [
|
|
|
{
|
|
{
|
|
|
id: 1,
|
|
id: 1,
|
|
|
status: "pending",
|
|
status: "pending",
|
|
@@ -117,7 +121,7 @@ const taskList = ref([
|
|
|
areaCode: "A-01 / 分区一",
|
|
areaCode: "A-01 / 分区一",
|
|
|
farmName: "喷施杀菌剂",
|
|
farmName: "喷施杀菌剂",
|
|
|
executeDate: "08/06",
|
|
executeDate: "08/06",
|
|
|
- wkt: "POINT(113.612409 23.587036)",
|
|
|
|
|
|
|
+ offset: [-0.0018, 0.0012],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
id: 2,
|
|
id: 2,
|
|
@@ -132,7 +136,7 @@ const taskList = ref([
|
|
|
areaCode: "B-03 / 分区二",
|
|
areaCode: "B-03 / 分区二",
|
|
|
farmName: "叶面追肥",
|
|
farmName: "叶面追肥",
|
|
|
executeDate: "08/06",
|
|
executeDate: "08/06",
|
|
|
- wkt: "POINT(113.615809 23.586636)",
|
|
|
|
|
|
|
+ offset: [0.0016, 0.0008],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
id: 3,
|
|
id: 3,
|
|
@@ -147,7 +151,7 @@ const taskList = ref([
|
|
|
areaCode: "C-02 / 分区三",
|
|
areaCode: "C-02 / 分区三",
|
|
|
farmName: "灌溉补水",
|
|
farmName: "灌溉补水",
|
|
|
executeDate: "08/06",
|
|
executeDate: "08/06",
|
|
|
- wkt: "POINT(113.613609 23.584436)",
|
|
|
|
|
|
|
+ offset: [-0.0006, -0.0014],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
id: 4,
|
|
id: 4,
|
|
@@ -163,7 +167,7 @@ const taskList = ref([
|
|
|
areaCode: "D-05 / 全园",
|
|
areaCode: "D-05 / 全园",
|
|
|
farmName: "病虫害巡查",
|
|
farmName: "病虫害巡查",
|
|
|
executeDate: "08/05",
|
|
executeDate: "08/05",
|
|
|
- wkt: "POINT(113.614209 23.585836)",
|
|
|
|
|
|
|
+ offset: [0.0004, -0.0003],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
id: 5,
|
|
id: 5,
|
|
@@ -178,7 +182,7 @@ const taskList = ref([
|
|
|
areaCode: "A-02 / 分区一",
|
|
areaCode: "A-02 / 分区一",
|
|
|
farmName: "修剪整枝",
|
|
farmName: "修剪整枝",
|
|
|
executeDate: "08/04",
|
|
executeDate: "08/04",
|
|
|
- wkt: "POINT(113.611809 23.586236)",
|
|
|
|
|
|
|
+ offset: [-0.0024, 0.0004],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
id: 6,
|
|
id: 6,
|
|
@@ -193,7 +197,7 @@ const taskList = ref([
|
|
|
areaCode: "B-01 / 分区二",
|
|
areaCode: "B-01 / 分区二",
|
|
|
farmName: "除草松土",
|
|
farmName: "除草松土",
|
|
|
executeDate: "08/03",
|
|
executeDate: "08/03",
|
|
|
- wkt: "POINT(113.616209 23.584936)",
|
|
|
|
|
|
|
+ offset: [0.002, -0.0009],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
id: 7,
|
|
id: 7,
|
|
@@ -208,10 +212,28 @@ const taskList = ref([
|
|
|
areaCode: "C-01 / 分区三",
|
|
areaCode: "C-01 / 分区三",
|
|
|
farmName: "防风加固",
|
|
farmName: "防风加固",
|
|
|
executeDate: "08/02",
|
|
executeDate: "08/02",
|
|
|
- wkt: "POINT(113.613109 23.587436)",
|
|
|
|
|
|
|
+ offset: [-0.0011, 0.0016],
|
|
|
},
|
|
},
|
|
|
-]);
|
|
|
|
|
|
|
+];
|
|
|
|
|
|
|
|
|
|
+/** 假数据:后续可替换为接口;status: pending 待执行 / completed 已完成 */
|
|
|
|
|
+const taskList = ref([]);
|
|
|
|
|
+
|
|
|
|
|
+/** 根据中心点生成附近任务点位 */
|
|
|
|
|
+const buildTaskListNearCenter = (centerWkt) => {
|
|
|
|
|
+ const coord = convertPointToArray(centerWkt);
|
|
|
|
|
+ const lng = Number(coord?.[0]);
|
|
|
|
|
+ const lat = Number(coord?.[1]);
|
|
|
|
|
+ if (!Number.isFinite(lng) || !Number.isFinite(lat)) return [];
|
|
|
|
|
+ return TASK_MOCK_TEMPLATE.map((item) => {
|
|
|
|
|
+ const [dx = 0, dy = 0] = item.offset || [];
|
|
|
|
|
+ const { offset, ...rest } = item;
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...rest,
|
|
|
|
|
+ wkt: `POINT(${lng + dx} ${lat + dy})`,
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
const activeTab = ref("pending");
|
|
const activeTab = ref("pending");
|
|
|
const pendingCount = computed(() => taskList.value.filter((item) => item.status === "pending").length);
|
|
const pendingCount = computed(() => taskList.value.filter((item) => item.status === "pending").length);
|
|
|
const completedCount = computed(() => taskList.value.filter((item) => item.status === "completed").length);
|
|
const completedCount = computed(() => taskList.value.filter((item) => item.status === "completed").length);
|
|
@@ -221,9 +243,10 @@ const handleTabChange = (key) => {
|
|
|
if (activeTab.value === key) return;
|
|
if (activeTab.value === key) return;
|
|
|
activeTab.value = key;
|
|
activeTab.value = key;
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
|
- if (indexMap.kmap) {
|
|
|
|
|
- indexMap.initData(getMapMarkerList(), "farmName", "wkt");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!indexMap.kmap) return;
|
|
|
|
|
+ indexMap.initData(getMapMarkerList(), "farmName", "wkt");
|
|
|
|
|
+ // 切换 tab 后仍保持用户选中农场为中心
|
|
|
|
|
+ indexMap.setMapPosition(mapPoint.value || resolveMapPoint());
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -274,28 +297,78 @@ const handleSurveyConfirm = () => {
|
|
|
|
|
|
|
|
const mapPoint = ref(null);
|
|
const mapPoint = ref(null);
|
|
|
|
|
|
|
|
|
|
+const DEFAULT_MAP_POINT = "POINT(113.6142086995688 23.585836479509055)";
|
|
|
|
|
+const ENTRY_FARM_DATA_KEY = "ENTRY_FARM_DATA";
|
|
|
|
|
+const MAP_POINT_STORAGE_KEY = "GROWTH_REPORT_MAP_POINT";
|
|
|
|
|
+
|
|
|
|
|
+const isPointWkt = (value) => typeof value === "string" && /^POINT\s*\(/i.test(value.trim());
|
|
|
|
|
+
|
|
|
|
|
+/** 与长势报告 / 农情档案一致:优先用户选中点位 */
|
|
|
|
|
+const resolveMapPoint = () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const entry = JSON.parse(localStorage.getItem(ENTRY_FARM_DATA_KEY) || "null");
|
|
|
|
|
+ if (isPointWkt(entry?.point)) return entry.point.trim();
|
|
|
|
|
+ if (Array.isArray(entry?.coordinate) && entry.coordinate.length === 2) {
|
|
|
|
|
+ return `POINT(${entry.coordinate[0]} ${entry.coordinate[1]})`;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // ignore
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const growthPoint = localStorage.getItem(MAP_POINT_STORAGE_KEY);
|
|
|
|
|
+ if (isPointWkt(growthPoint)) return growthPoint.trim();
|
|
|
|
|
+
|
|
|
|
|
+ const selectedPoint = localStorage.getItem("selectedFarmPoint");
|
|
|
|
|
+ if (isPointWkt(selectedPoint)) return selectedPoint.trim();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const farm = JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
|
|
|
|
|
+ const wkt = farm.wkt || farm.geom_wkt || farm.farm_location;
|
|
|
|
|
+ if (isPointWkt(wkt)) return wkt.trim();
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // ignore
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const userPoint = store.state.home.miniUserLocationPoint;
|
|
|
|
|
+ if (isPointWkt(userPoint)) return userPoint.trim();
|
|
|
|
|
+
|
|
|
|
|
+ return DEFAULT_MAP_POINT;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const getMapMarkerList = () => displayTaskList.value.filter((item) => item.wkt);
|
|
const getMapMarkerList = () => displayTaskList.value.filter((item) => item.wkt);
|
|
|
|
|
|
|
|
|
|
+const initWorkMap = () => {
|
|
|
|
|
+ if (!mapContainer.value) return;
|
|
|
|
|
+ mapPoint.value = resolveMapPoint();
|
|
|
|
|
+ // 假数据点位落在用户选中中心附近
|
|
|
|
|
+ taskList.value = buildTaskListNearCenter(mapPoint.value);
|
|
|
|
|
+ if (!indexMap.kmap) {
|
|
|
|
|
+ indexMap.initMap(mapPoint.value, mapContainer.value, true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ indexMap.setMapPosition(mapPoint.value);
|
|
|
|
|
+ indexMap.kmap.map?.updateSize?.();
|
|
|
|
|
+ }
|
|
|
|
|
+ indexMap.initData(getMapMarkerList(), "farmName", "wkt");
|
|
|
|
|
+ indexMap.setMapPosition(mapPoint.value);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
- mapPoint.value = store.state.home.miniUserLocationPoint || "POINT(113.614209 23.585836)";
|
|
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
|
- if (mapContainer.value) {
|
|
|
|
|
- indexMap.initMap(mapPoint.value, mapContainer.value, true);
|
|
|
|
|
- indexMap.initData(getMapMarkerList(), "farmName", "wkt");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ initWorkMap();
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
onActivated(() => {
|
|
onActivated(() => {
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
|
if (!indexMap.kmap) {
|
|
if (!indexMap.kmap) {
|
|
|
- if (mapContainer.value) {
|
|
|
|
|
- mapPoint.value = store.state.home.miniUserLocationPoint || "POINT(113.614209 23.585836)";
|
|
|
|
|
- indexMap.initMap(mapPoint.value, mapContainer.value, true);
|
|
|
|
|
- indexMap.initData(getMapMarkerList(), "farmName", "wkt");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ initWorkMap();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ mapPoint.value = resolveMapPoint();
|
|
|
|
|
+ taskList.value = buildTaskListNearCenter(mapPoint.value);
|
|
|
|
|
+ indexMap.setMapPosition(mapPoint.value);
|
|
|
|
|
+ indexMap.initData(getMapMarkerList(), "farmName", "wkt");
|
|
|
|
|
+ indexMap.setMapPosition(mapPoint.value);
|
|
|
if (mapContainer.value && indexMap.kmap.map) {
|
|
if (mapContainer.value && indexMap.kmap.map) {
|
|
|
const checkAndUpdateSize = () => {
|
|
const checkAndUpdateSize = () => {
|
|
|
const container = mapContainer.value;
|
|
const container = mapContainer.value;
|