import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:liftmanager/common/common.dart';
import 'package:liftmanager/internal/heavy/heavy_router.dart';
import 'package:liftmanager/internal/heavy/model/heavy_item.dart';
import 'package:liftmanager/internal/project/project_router.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/widgets/click_item.dart';
import 'package:liftmanager/widgets/my_button.dart';
import 'package:oktoast/oktoast.dart';

class HeavyDetailPage extends StatefulWidget {
  HeavyDetailPage(this.projectId, this.projectStatus);

  final String projectId;
  final String projectStatus;

  @override
  State<StatefulWidget> createState() {
    return HeavyDetailState();
  }
}

class HeavyDetailState extends State<HeavyDetailPage> {
  HeavyItem item = HeavyItem();

  @override
  void initState() {
    super.initState();
    getDetail();
  }

  ///获取大修详情
  getDetail() {
    ApiService(context: context).heavyProjectDetail(widget.projectId,
        onSuccess: (data) {
      if (data != null) {
        setState(() {
          item = data;
        });
      }
    }, onError: (code, msg) {
      showToast(msg);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: "大修详情",
      ),
      body: SafeArea(
        child: Column(
          children: <Widget>[
            Expanded(
              flex: 1,
              child: defaultTargetPlatform == TargetPlatform.iOS
                  ? FormKeyboardActions(child: _buildBody())
                  : SingleChildScrollView(child: _buildBody()),
            )
          ],
        ),
      ),
    );
  }

  _buildBody() {
    if (item == null) {
      return Container();
    }
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
//        ClickItem(
//          title: "大修状态",
//          content: "${item?.projectName}",
//        ),
        ClickItem(
          title: "项目名称",
          content: "${item?.projectName}",
        ),
        ClickItem(
          title: "项目用途",
          content: "${Constant.projectUsageText[item?.projectUsage]}",
        ),
        ClickItem(
          title: "项目地址",
          content: "${item?.address}",
        ),
        ClickItem(
          title: "项目台量",
          content: "${item?.actualNum}",
        ),
        ClickItem(
          title: "行政区域",
          content: "${item?.province}-${item?.city}-${item?.district}",
        ),
        ClickItem(
          title: "区域",
          content: "${item?.areaName}",
        ),
        ClickItem(
          title: "区域主管",
          content: "${item?.areaDirector}",
        ),
        ClickItem(
          title: "文员",
          content: "${item?.clerkName}",
        ),
        ClickItem(
          title: "大修开始时间",
          content: "${item?.startDate}",
        ),

        ClickItem(
          title: "大修结束时间",
          content: "${item?.endDate}",
        ),

        ClickItem(
          title: "备注",
          content: "",
        ),

        ClickItem(title: "甲方公司", content: "${item?.companyName}"),
        ClickItem(title: "甲方联系人", content: "${item?.companyContact}"),
        ClickItem(title: "甲方联系人电话", content: "${item?.telephone}"),
        ClickItem(
          title: "人员信息",
          content: "查看",
          onTap: () {
            NavigatorUtils.push(context,
                "${ProjectRouter.projectUsersPage}?id=${widget.projectId}&type=0");
          },
        ),
//        ClickItem(
//          title: "电梯列表",
//          content: "${item?.telephone}",
//          onTap: (){
//            NavigatorUtils.push(context, HeavyRouter.heavyLiftListPage + "?id=${widget.projectId}");
//          },
//        ),
        Offstage(
            offstage: widget.projectStatus != "2",
            child: Container(
                padding: EdgeInsets.all(30),
                child: MyButton(
                  onPressed: () {
                    NavigatorUtils.push(context,
                        "${HeavyRouter.heavySignPage}?id=${widget.projectId}");
                  },
                  text: "签到管理",
                )))
      ],
    );
  }
}
