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/project/model/project_list_entity.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:oktoast/oktoast.dart';

class ProjectDetailPage extends StatefulWidget {
  ProjectDetailPage(this.id);

  final String id;

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

class ProjectDetailPageState extends State<ProjectDetailPage> {
  bool _hasData = false;
  ProjectListItem item;

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

  ///获取项目详情
  _getProjectDetail() {
    ApiService(context: context).projectDetail(widget.id, onSuccess: (data) {
      if (data != null) {
        _hasData = true;
        item = data;
        setState(() {});
      }
    }, 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: _hasData
                  ? defaultTargetPlatform == TargetPlatform.iOS
                      ? FormKeyboardActions(child: _buildBody())
                      : SingleChildScrollView(child: _buildBody())
                  : Center(
                      child: Text("正在加载..."),
                    ),
            )
          ],
        ),
      ),
    );
  }

  _buildBody() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        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: "${item?.companyName}",
        ),
        ClickItem(
          title: "甲方联系人",
          content: "${item?.companyContact}",
        ),
        ClickItem(
          title: "甲方联系人电话",
          content: "${item?.telephone}",
        ),
        ClickItem(
          title: "维保人员",
          content: "",
          onTap: (){
            NavigatorUtils.push(context, "${ProjectRouter.projectUsersPage}?id=${widget.id}&type=0");
          },
        )
      ],
    );
  }
}
