import 'package:farmer_client/models/app.dart';
import 'package:farmer_client/pages/machinery/map/widgets/detail.dart';
import 'package:farmer_client/widgets/layout/BasicPage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';

import '../../../models/entities/CardInfo.dart';
import '../../../services/homeAPI.dart';

class MachineryMapPage extends BasicPage {
  String markId = '';
  String marKm = '';
  final machineryInfoContent = Rx<CardInfo>(CardInfo()); //全部详情
  final appController = AppController.t;

  // 响应预约事件
  void handleClick() {
    // Get.toNamed("/machineryDetail");
    Get.toNamed('/orderConfirmation',
        arguments: {'item': machineryInfoContent()});
  }

  @override
  void beforeShow() {
    // TODO: implement onMounted
    super.beforeShow();
    if (Get.arguments['id'] != null) {
      EasyLoading.show(status: '数据加载中...');

      markId = Get.arguments['id'];
      marKm = Get.arguments['km'];
      print(marKm);
      getMachineryInfo(
              markId, appController.locationStr ?? '112.091892,32.690712', true)
          .then((value) {
        machineryInfoContent(CardInfo.fromJson(value));
        EasyLoading.dismiss();
      }).catchError((error) {
        EasyLoading.dismiss();
        Fluttertoast.showToast(msg: error.error['message']);
      });
    }
    print("----show----map page--------------");
  }

  @override
  void beforeHide() {
    // TODO: implement beforeHide
    super.beforeHide();
    print("-----hide---map page--------------");
  }

  @override
  Widget builder(BuildContext context) {
    naviTitle = "查看地图";
    return Obx(() => page(
        context: context,
        handleClick: handleClick,
        item: machineryInfoContent(),
        km: marKm));
  }
}
