import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:worker_client/models/app.dart';
import 'package:worker_client/widgets/GradientButton.dart';
import 'package:worker_client/widgets/MyCell/index.dart';
import 'package:worker_client/widgets/layout/BasicPage.dart';
import '/widgets/MyDialog.dart' as modal;

class Main extends BasicPage {
  Main({Key? key}) : super(key: key) {
    tabIndex = 2;
    naviTitle = '我的';
  }
  AppController store = AppController.t;
  GetStorage box = GetStorage();

  void loginOut() {
    modal.showAlert(
        title: '提示',
        message: '确定要退出登陆吗？',
        onConfirm: () {
          box.remove('token');
          Get.offNamed('/login');
          return true;
        },
        onCancel: () => true);
  }

  void goMachinery() {
    Get.toNamed('/machineryList');
  }

  void goWallet() {
    //钱包页面
    // Get.toNamed('/bankList');
  }
  void goBankPage() {
    // if (store.user().isOrgManager==true) {
      Get.toNamed('/bankList');
    // }
  }

  @override
  Widget builder(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(color: Colors.white),
      child: ListView(
        children: [
          Stack(
            children: [
              Positioned(
                top: 0,
                child: Container(
                  width: 375.w,
                  height: 187.5.w,
                  decoration: const BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage("images/main/userBgi.png"),
                      fit: BoxFit.cover,
                    ),
                  ),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        margin: EdgeInsets.fromLTRB(40.w, 0, 10.w, 0),
                        child: store.user().avatar != null
                            ? Container(
                                clipBehavior: Clip.hardEdge,
                                decoration: BoxDecoration(
                                    borderRadius: BorderRadius.all(
                                        Radius.circular(31.5.w))),
                                child: Image.network(
                                  store.user().avatar.toString(),
                                  width: 63.w,
                                  height: 63.w,
                                ),
                              )
                            : Image.asset(
                                'images/main/defaultAvatar.png',
                                width: 63.w,
                                height: 63.w,
                              ),
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            store.user().nickName != null
                                ? store.user().nickName.toString()
                                : '',
                            style: TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.w500,
                                fontSize: 17.sp,
                                letterSpacing: 2,
                                shadows: [
                                  BoxShadow(
                                      color: const Color(0x66000000),
                                      offset: Offset(0, 1.w),
                                      blurRadius: 0)
                                ]),
                          ),
                          Container(
                            margin: EdgeInsets.fromLTRB(0, 19.h, 0, 0),
                            child: Text(
                              store.user().nickName != null
                                  ? store.user().phone.toString()
                                  : '',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.w500,
                                  fontSize: 17.sp,
                                  letterSpacing: 2,
                                  shadows: [
                                    BoxShadow(
                                        color: const Color(0x66000000),
                                        offset: Offset(0, 1.w),
                                        blurRadius: 0)
                                  ]),
                            ),
                          )
                        ],
                      )
                    ],
                  ),
                ),
              ),
              Positioned(
                right: 0,
                top: 0,
                child: Container(
                  decoration: const BoxDecoration(color: Color(0xb2000000)),
                  child: Text(
                    '该账号归${store.user().userName != null ? store.user().nickName.toString() : ''}所属',
                    style: TextStyle(color: Colors.white, fontSize: 12.sp),
                  ),
                ),
              ),
              Column(
                children: [
                  Container(
                    margin: EdgeInsets.fromLTRB(15.w, 187.5.w - 15.h, 15.w, 0),
                    height: 101.h,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(20.w)),
                        boxShadow: [
                          BoxShadow(
                            color: const Color(0x14000000),
                            offset: const Offset(0, 0),
                            blurRadius: 22.w,
                          ),
                        ]),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        GestureDetector(
                          onTap: () {
                            goMachinery();
                          },
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Image.asset(
                                'images/main/machinery.png',
                                width: 30.w,
                              ),
                              Text(
                                '我的农机',
                                style: TextStyle(
                                    fontSize: 17.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Color(0xFF333333)),
                              )
                            ],
                          ),
                        ),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Image.asset(
                              'images/main/wallet.png',
                              width: 30.w,
                            ),
                            Text(
                              '我的钱包',
                              style: TextStyle(
                                  fontSize: 17.sp,
                                  fontWeight: FontWeight.bold,
                                  color: Color(0xFF333333)),
                            )
                          ],
                        ),
                        GestureDetector(
                          onTap: () {
                            goBankPage();
                          },
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Image.asset(
                                'images/main/bankCard.png',
                                width: 30.w,
                              ),
                              Text(
                                '我的银行卡',
                                style: TextStyle(
                                    fontSize: 17.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Color(0xFF333333)),
                              )
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 15.h, 0, 0),
                    padding:
                        EdgeInsets.symmetric(horizontal: 15.w, vertical: 0),
                    child: Column(
                      children: [
                        MyCell(
                          head: Image.asset(
                            'images/main/account.png',
                            width: 19.w,
                          ),
                          body: Text(
                            '账号与安全',
                            style: TextStyle(
                              fontSize: 17.sp,
                              color: Color(0xff333333),
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                          action: Image.asset(
                            'images/main/goto.png',
                            width: 10.w,
                          ),
                          onClick: () {},
                        ),
                        MyCell(
                          head: Image.asset(
                            'images/main/aboutUs.png',
                            width: 19.w,
                          ),
                          body: Text(
                            '关于我们',
                            style: TextStyle(
                                fontSize: 17.sp,
                                fontWeight: FontWeight.bold,
                                color: Color(0xff333333)),
                          ),
                          action: Image.asset(
                            'images/main/goto.png',
                            width: 10.w,
                          ),
                          onClick: () {},
                        ),
                        MyCell(
                          head: Image.asset(
                            'images/main/update.png',
                            width: 19.w,
                          ),
                          body: Text(
                            '用户协议及隐私政策',
                            style: TextStyle(
                                fontSize: 17.sp,
                                fontWeight: FontWeight.bold,
                                color: Color(0xff333333)),
                          ),
                          action: Image.asset(
                            'images/main/goto.png',
                            width: 10.w,
                          ),
                          onClick: () {},
                        ),
                        MyCell(
                          head: Image.asset(
                            'images/main/Feedback.png',
                            width: 19.w,
                          ),
                          body: Text(
                            '意见反馈',
                            style: TextStyle(
                                fontSize: 17.sp,
                                fontWeight: FontWeight.bold,
                                color: Color(0xff333333)),
                          ),
                          action: Image.asset(
                            'images/main/goto.png',
                            width: 10.w,
                          ),
                          onClick: () {},
                        ),
                        Container(
                            height: 45.5.h,
                            width: 345.w,
                            margin: EdgeInsets.only(top: 30.h, bottom: 30.h),
                            child: GradientButton(
                                colors: const [
                                  Color(0xFFF8F8F8),
                                  Color(0xFFF8F8F8)
                                ],
                                borderRadius:
                                    BorderRadius.all(Radius.circular(24.5.w)),
                                onPressed: () {
                                  loginOut();
                                },
                                child: Text(
                                  "退出登陆",
                                  style: TextStyle(
                                    fontSize: 20.sp,
                                    fontWeight: FontWeight.bold,
                                    color: const Color(0xFF333333),
                                  ),
                                )))
                      ],
                    ),
                  ),
                ],
              )
            ],
          )
        ],
      ),
    );
  }
}
