import 'package:farmer_client/models/entities/CardInfo.dart';
import 'package:farmer_client/widgets/layout/BasicPage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../services/homeAPI.dart';
import 'widgets/detail.dart';

class MachineryDetailPage extends BasicPage {
  String markId = '';
  String marKm = '';
  final machineryInfoContent = Rx<CardInfo>(CardInfo());//全部详情
  final machineryListBanner = Rx<List<BannerImageList>>([]);//banner轮播
  final machineryListContent= Rx<List<ContentImageList>>([]);//图文详情
  // 响应预约事件
  void handleClick() {
    Get.toNamed('/orderConfirmation',arguments: {'item':machineryInfoContent()});
  }


  @override
  void beforeShow() {
    // TODO: implement onMounted
    super.beforeShow();
    if (Get.arguments['id'] != null) {
     markId = Get.arguments['id'];
     marKm = Get.arguments['km'];
     print(marKm);
      getMachineryInfo(markId, '122.08400000000002,37.421998333333335', true).then((value) {
        machineryInfoContent(CardInfo.fromJson(value));
        machineryListBanner(machineryInfoContent().imagesList!);
        machineryListContent(machineryInfoContent().contentList!);

      });

    }
    print("----show----detail page--------------");
  }

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

  @override
  Widget builder(BuildContext context) {
    naviTitle = "查看详情";
    return Obx(()=>page(context: context, handleClick: handleClick,km:marKm,item:machineryInfoContent.value,bnnerItem:machineryListBanner.value,contentItem:machineryListContent.value));
  }
}
