
import 'package:flutter/material.dart';
import 'package:twong/config/style.dart';
import 'package:twong/router/base.dart';

import 'package:twong/utils/index.dart';
import 'package:twong/widgets/app_bar.dart';

class PromotionPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _PromotionState();
  }
}

class _PromotionState extends State<PromotionPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: DColors.back,
      appBar: DAppBar("推广中心", actions: [
        InkWell(
          onTap: () => Navigator.pushNamed(context, RouteNames.cashRecord),
          child: Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(right: 12.px),
            child: Text("提现记录", style: TextStyle(color: Colors.white)),
          ),
        )
      ]),
      body: SafeArea(
        child: Container(
          child: ListView(
            physics: ClampingScrollPhysics(),
            children: [
              Container(
                height: MediaQuery.of(context).size.height,
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    Positioned(child: _buildHeader(), top: 0),
                    Positioned(child: Container(
                      width: 120.px,
                      decoration: BoxDecoration(
                          color: DColors.back,
                          borderRadius: BorderRadius.circular(30.px)
                      ),
                      padding: EdgeInsets.only(left: 9.px, right: 9.px),
                      child: FlatButton(
                        onPressed: () {
                          Navigator.pushNamed(context, RouteNames.cashDraw);
                        },
                        color: DColors.Main,
                        shape: StadiumBorder(),
                        child: Text("立即提现", style: TextStyle(color: Colors.white)),
                      ),
                    ), top: 126.px),
                    Positioned(child: Container(
                      width: MediaQuery.of(context).size.width,
                      child: _buildMenus(),
                    ), top: 160.px, left: 0)
                  ],
                ),
              ),
            ],
          ),
        )
      ),
    );
  }

  Widget _buildHeader() {
    return Container(
      color: DColors.Main,
      height: 146.px,
      width: MediaQuery.of(context).size.width,
      padding: EdgeInsets.only(left: 12.px, right: 12.px, top: 12.px),
      child: Column(
        children: [
          Container(
            child: Column(
              children: [
                Text("当前佣金", style: TextStyle(color: Colors.white)),
                Text(Utils.formatRMB(Cache.user.brokerage_price), style:
                TextStyle(fontSize: 36.px, color: Colors.white))
              ],
            ),
          ),
          Spacer(),
          Container(
            margin: EdgeInsets.only(bottom: 6.px),
            child: Row(
              children: [
                Column(
                  children: [
                    Text("昨日收益", style: TextStyle(color: Colors.white)),
                    Text("0.00", style: TextStyle(color: Colors.white)),
                  ],
                ),
                Spacer(),
                Column(
                  children: [
                    Text("累计提现", style: TextStyle(color: Colors.white)),
                    Text("0.00", style: TextStyle(color: Colors.white)),
                  ],
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _buildMenus() {
    return Container(
      margin: EdgeInsets.only(left: 12.px, right: 12.px, top: 12.px),
      child: Column(
        children: [
          Row(
            children: [
              Expanded(child: InkWell(
                onTap: () {
                  Navigator.pushNamed(context, RouteNames.promotionPoster);
                },
                child: Container(
                    height: 86.px,
                    padding: EdgeInsets.all(6.px),
                    margin: EdgeInsets.only(right: 6.px, bottom: 12.px),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(6.px)
                    ),
                    child: Column(
                      children: [
                        Icon(Icons.padding),
                        Text("推广名片")
                      ],
                    )
                ),
              )),
              Expanded(child: InkWell(
                onTap: () {
                  Navigator.pushNamed(context, RouteNames.promotionSpread);
                },
                child: Container(
                    height: 86.px,
                    padding: EdgeInsets.all(6.px),
                    margin: EdgeInsets.only(left: 6.px, bottom: 12.px),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(6.px)
                    ),
                    child: Column(
                      children: [
                        Icon(Icons.padding),
                        Text("推广人统计")
                      ],
                    )
                ),
              )),
            ],
          ),
          Row(
            children: [
              Expanded(child: InkWell(
                onTap: () {
                  Navigator.pushNamed(context, RouteNames.promotionRecord);
                },
                child: Container(
                    height: 86.px,
                    padding: EdgeInsets.all(6.px),
                    margin: EdgeInsets.only(right: 6.px),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(6.px)
                    ),
                    child: Column(
                      children: [
                        Icon(Icons.padding),
                        Text("佣金记录")
                      ],
                    )
                ),
              )),
              Expanded(child: InkWell(
                onTap: () {
                  Navigator.pushNamed(context, RouteNames.promotionOrder);
                },
                child: Container(
                    height: 86.px,
                    padding: EdgeInsets.all(6.px),
                    margin: EdgeInsets.only(left: 6.px),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(6.px)
                    ),
                    child: Column(
                      children: [
                        Icon(Icons.padding),
                        Text("推广人订单")
                      ],
                    )
                ),
              )),
            ],
          )
        ],
      ),
    );
  }
}