|
@@ -1,13 +1,283 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
+import { AlertController } from '@ionic/angular';
|
|
|
+
|
|
|
+interface FarmField {
|
|
|
+ id: string;
|
|
|
+ name: string;
|
|
|
+ area: number;
|
|
|
+ location: string;
|
|
|
+ currentCrop: string;
|
|
|
+ daysPlanted: number;
|
|
|
+ status?: '需灌溉' | '需施肥' | '需防治' | '正常';
|
|
|
+ nextTask?: string;
|
|
|
+ soilType?: string;
|
|
|
+}
|
|
|
+
|
|
|
+interface FarmTask {
|
|
|
+ id: string;
|
|
|
+ fieldId: string;
|
|
|
+ fieldName: string;
|
|
|
+ name: string;
|
|
|
+ type: 'irrigation' | 'fertilization' | 'pestControl' | 'harvest';
|
|
|
+ dueDate: Date;
|
|
|
+ notes?: string;
|
|
|
+ urgent: boolean;
|
|
|
+ completed: boolean;
|
|
|
+}
|
|
|
+
|
|
|
+interface GrowthRecord {
|
|
|
+ id: string;
|
|
|
+ fieldId: string;
|
|
|
+ fieldName: string;
|
|
|
+ date: Date;
|
|
|
+ activity: string;
|
|
|
+ notes: string;
|
|
|
+ images?: string[];
|
|
|
+}
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab3',
|
|
|
- templateUrl: 'tab3.page.html',
|
|
|
- styleUrls: ['tab3.page.scss'],
|
|
|
+ templateUrl: './tab3.page.html',
|
|
|
+ styleUrls: ['./tab3.page.scss'],
|
|
|
standalone: false,
|
|
|
})
|
|
|
-export class Tab3Page {
|
|
|
+export class Tab3Page implements OnInit {
|
|
|
+ fields: FarmField[] = [
|
|
|
+ {
|
|
|
+ id: '1',
|
|
|
+ name: '北区小麦田',
|
|
|
+ area: 5.2,
|
|
|
+ location: '农场北侧',
|
|
|
+ currentCrop: '冬小麦',
|
|
|
+ daysPlanted: 45,
|
|
|
+ status: '需施肥',
|
|
|
+ nextTask: '明日追肥',
|
|
|
+ soilType: '粘壤土'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: '2',
|
|
|
+ name: '南区玉米地',
|
|
|
+ area: 3.8,
|
|
|
+ location: '农场南侧',
|
|
|
+ currentCrop: '春玉米',
|
|
|
+ daysPlanted: 22,
|
|
|
+ status: '正常',
|
|
|
+ nextTask: '下周除草',
|
|
|
+ soilType: '砂壤土'
|
|
|
+ }
|
|
|
+ ];
|
|
|
|
|
|
- constructor() {}
|
|
|
+ tasks: FarmTask[] = [
|
|
|
+ {
|
|
|
+ id: '1',
|
|
|
+ fieldId: '1',
|
|
|
+ fieldName: '北区小麦田',
|
|
|
+ name: '追施氮肥',
|
|
|
+ type: 'fertilization',
|
|
|
+ dueDate: new Date(new Date().setDate(new Date().getDate() + 1)),
|
|
|
+ urgent: true,
|
|
|
+ completed: false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: '2',
|
|
|
+ fieldId: '2',
|
|
|
+ fieldName: '南区玉米地',
|
|
|
+ name: '除草作业',
|
|
|
+ type: 'pestControl',
|
|
|
+ dueDate: new Date(new Date().setDate(new Date().getDate() + 7)),
|
|
|
+ urgent: false,
|
|
|
+ completed: false
|
|
|
+ }
|
|
|
+ ];
|
|
|
|
|
|
-}
|
|
|
+ records: GrowthRecord[] = [
|
|
|
+ {
|
|
|
+ id: '1',
|
|
|
+ fieldId: '1',
|
|
|
+ fieldName: '北区小麦田',
|
|
|
+ date: new Date(new Date().setDate(new Date().getDate() - 3)),
|
|
|
+ activity: '病虫害检查',
|
|
|
+ notes: '发现少量蚜虫,已喷施防治',
|
|
|
+ images: [
|
|
|
+ 'assets/images/wheat-pest1.jpg',
|
|
|
+ 'assets/images/wheat-pest2.jpg'
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: '2',
|
|
|
+ fieldId: '2',
|
|
|
+ fieldName: '南区玉米地',
|
|
|
+ date: new Date(new Date().setDate(new Date().getDate() - 5)),
|
|
|
+ activity: '追肥',
|
|
|
+ notes: '施用复合肥20kg/亩'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ showFieldForm = false;
|
|
|
+ editingField: FarmField | null = null;
|
|
|
+ fieldForm: FormGroup;
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private fb: FormBuilder,
|
|
|
+ private alertCtrl: AlertController
|
|
|
+ ) {
|
|
|
+ this.fieldForm = this.fb.group({
|
|
|
+ name: ['', Validators.required],
|
|
|
+ area: ['', [Validators.required, Validators.min(0.1)]],
|
|
|
+ location: [''],
|
|
|
+ currentCrop: ['冬小麦', Validators.required],
|
|
|
+ soilType: ['粘壤土']
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {}
|
|
|
+
|
|
|
+ get totalArea(): number {
|
|
|
+ return this.fields.reduce((sum, field) => sum + field.area, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ get pendingTasks(): number {
|
|
|
+ return this.tasks.filter(t => !t.completed).length;
|
|
|
+ }
|
|
|
+
|
|
|
+ get recentTasks(): FarmTask[] {
|
|
|
+ return this.tasks
|
|
|
+ .filter(t => !t.completed)
|
|
|
+ .sort((a, b) => a.dueDate.getTime() - b.dueDate.getTime())
|
|
|
+ .slice(0, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ get recentRecords(): GrowthRecord[] {
|
|
|
+ return [...this.records]
|
|
|
+ .sort((a, b) => b.date.getTime() - a.date.getTime())
|
|
|
+ .slice(0, 4);
|
|
|
+ }
|
|
|
+
|
|
|
+ getCropImage(crop: string): string {
|
|
|
+ const cropImages: {[key: string]: string} = {
|
|
|
+ '冬小麦': 'assets/images/wheat-icon.png',
|
|
|
+ '春玉米': 'assets/images/corn-icon.png',
|
|
|
+ '水稻': 'assets/images/rice-icon.png',
|
|
|
+ '大豆': 'assets/images/soybean-icon.png'
|
|
|
+ };
|
|
|
+ return cropImages[crop] || 'assets/images/crop-default.png';
|
|
|
+ }
|
|
|
+
|
|
|
+ getStatusColor(status: string): string {
|
|
|
+ const statusColors: {[key: string]: string} = {
|
|
|
+ '需灌溉': 'primary',
|
|
|
+ '需施肥': 'warning',
|
|
|
+ '需防治': 'danger',
|
|
|
+ '正常': 'success'
|
|
|
+ };
|
|
|
+ return statusColors[status] || 'medium';
|
|
|
+ }
|
|
|
+
|
|
|
+ getTaskIcon(type: string): string {
|
|
|
+ const taskIcons: {[key: string]: string} = {
|
|
|
+ 'irrigation': 'water',
|
|
|
+ 'fertilization': 'nutrition',
|
|
|
+ 'pestControl': 'bug',
|
|
|
+ 'harvest': 'leaf'
|
|
|
+ };
|
|
|
+ return taskIcons[type] || 'alert-circle';
|
|
|
+ }
|
|
|
+
|
|
|
+ getTaskColor(type: string): string {
|
|
|
+ const taskColors: {[key: string]: string} = {
|
|
|
+ 'irrigation': 'primary',
|
|
|
+ 'fertilization': 'warning',
|
|
|
+ 'pestControl': 'danger',
|
|
|
+ 'harvest': 'success'
|
|
|
+ };
|
|
|
+ return taskColors[type] || 'medium';
|
|
|
+ }
|
|
|
+
|
|
|
+ toggleFieldForm() {
|
|
|
+ this.showFieldForm = !this.showFieldForm;
|
|
|
+ if (!this.showFieldForm) {
|
|
|
+ this.editingField = null;
|
|
|
+ this.fieldForm.reset({
|
|
|
+ currentCrop: '冬小麦',
|
|
|
+ soilType: '粘壤土'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ editField(field: FarmField) {
|
|
|
+ this.editingField = field;
|
|
|
+ this.fieldForm.patchValue({
|
|
|
+ name: field.name,
|
|
|
+ area: field.area,
|
|
|
+ location: field.location,
|
|
|
+ currentCrop: field.currentCrop,
|
|
|
+ soilType: field.soilType
|
|
|
+ });
|
|
|
+ this.showFieldForm = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ saveField() {
|
|
|
+ if (this.fieldForm.invalid) return;
|
|
|
+
|
|
|
+ const fieldData = this.fieldForm.value;
|
|
|
+
|
|
|
+ if (this.editingField) {
|
|
|
+ // 更新现有农田
|
|
|
+ const index = this.fields.findIndex(f => f.id === this.editingField?.id);
|
|
|
+ if (index >= 0) {
|
|
|
+ this.fields[index] = {
|
|
|
+ ...this.fields[index],
|
|
|
+ ...fieldData
|
|
|
+ };
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 添加新农田
|
|
|
+ this.fields.push({
|
|
|
+ id: Date.now().toString(),
|
|
|
+ daysPlanted: 0,
|
|
|
+ status: '正常',
|
|
|
+ ...fieldData
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ this.cancelEdit();
|
|
|
+ }
|
|
|
+
|
|
|
+ cancelEdit() {
|
|
|
+ this.showFieldForm = false;
|
|
|
+ this.editingField = null;
|
|
|
+ this.fieldForm.reset({
|
|
|
+ currentCrop: '冬小麦',
|
|
|
+ soilType: '粘壤土'
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async deleteField(fieldId: string) {
|
|
|
+ const alert = await this.alertCtrl.create({
|
|
|
+ header: '确认删除',
|
|
|
+ message: '确定要删除这个农田地块吗?相关记录也将被删除',
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '取消',
|
|
|
+ role: 'cancel'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '删除',
|
|
|
+ handler: () => {
|
|
|
+ this.fields = this.fields.filter(f => f.id !== fieldId);
|
|
|
+ this.tasks = this.tasks.filter(t => t.fieldId !== fieldId);
|
|
|
+ this.records = this.records.filter(r => r.fieldId !== fieldId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ viewTaskDetail(task: FarmTask) {
|
|
|
+ console.log('查看任务详情:', task);
|
|
|
+ // 实际应导航到任务详情页
|
|
|
+ }
|
|
|
+}
|