/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2023-10-27 10:21:34
 * @LastEditTime: 2023-12-01 16:37:31
 * @Description  : 预存款
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../../models/prefee_detail.dart';
import '../../stores/pre_fee_store.dart';

class PreFeeIndexPage extends StatelessWidget {
  const PreFeeIndexPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return _PageView();
  }
}

class _PageView extends StatefulWidget {
  const _PageView({Key? key}) : super(key: key);

  @override
  State<_PageView> createState() => __PageViewState();
}

class __PageViewState extends State<_PageView> {
  void dispose() {
    Get.delete<PreFeeIndexStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final PreFeeIndexStore store = Get.isRegistered<PreFeeIndexStore>()
        ? Get.find<PreFeeIndexStore>()
        : Get.put(PreFeeIndexStore());
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      backgroundColor: Color(0xFFF8F8F8),
      appBar: WAppBar(
        title: WisText(
          '预存款信息',
          color: colorScheme.mainTitle,
          weight: FontWeight.w600,
          size: 18.pt,
        ),
        brightness: Brightness.light,
        backgroundColor: Colors.white,
      ),
      body: WisScrollView(
        key: store.scrollViewKey,
        onInit: () => store.onInitData(),
        slivers: [
          SliverToBoxAdapter(
            child: Column(
              children: [
                Wisdom.column(
                  padding:
                      EdgeInsets.symmetric(horizontal: 15.pt, vertical: 15.pt),
                  children: [
                    GradientCard(
                      child: Wisdom.row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        padding: EdgeInsets.all(15.pt),
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              WisText(
                                '可用余额',
                                size: 14.pt,
                                bold: true,
                                color: Colors.white,
                              ),
                              SizedBox(height: 15.pt),
                              Obx(() {
                                return WisText(
                                  '￥${store.detail.value.totalFee ?? 0}',
                                  size: 23.pt,
                                  bold: true,
                                  color: Colors.white,
                                );
                              }),
                            ],
                          ),
                          Column(
                            children: [
                              Wisdom(
                                onTap: () => store.toRecord('prePayPay'),
                                margin: EdgeInsets.only(
                                  top: 10.pt,
                                ),
                                padding: EdgeInsets.symmetric(
                                  horizontal: 15.pt,
                                  vertical: 8.pt,
                                ),
                                border: Border.all(
                                  color: Colors.white,
                                ),
                                borderRadius: BorderRadius.circular(20.pt),
                                child: WisText(
                                  '收支记录',
                                  color: Colors.white,
                                ),
                              ),
                              // Wisdom(
                              //   onTap: () => store.toRecord('billPay'),
                              //   margin: EdgeInsets.only(
                              //     top: 10.pt,
                              //   ),
                              //   padding: EdgeInsets.symmetric(
                              //     horizontal: 15.pt,
                              //     vertical: 8.pt,
                              //   ),
                              //   border: Border.all(
                              //     color: Colors.white,
                              //   ),
                              //   borderRadius: BorderRadius.circular(20.pt),
                              //   child: WisText(
                              //     '抵扣记录',
                              //     color: Colors.white,
                              //   ),
                              // ),
                            ],
                          ),
                        ],
                      ),
                      gradient: LinearGradient(
                        colors: [Color(0xFF7FCF7D), Color(0xFF599A5E)],
                        begin: Alignment.centerLeft,
                        end: Alignment.centerRight,
                      ),
                    ),
                  ],
                ),
                Obx(() {
                  return Column(
                    children: [
                      for (ItemOfPreFeeDetailModel asset in store.feeList)
                        WisCard(
                          margin: EdgeInsets.fromLTRB(
                            15.pt,0, 15.pt,
                            10.pt,
                          ),
                          padding: EdgeInsets.all(15.pt),
                          child: Wisdom.column(
                            children: [
                              Wisdom.row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  WisText(
                                    asset.assetName ?? '',
                                    size: 15.pt,
                                    bold: true,
                                    color: colorScheme.minor,
                                  ),
                                  WisText('￥${asset.fee ?? 0}'),
                                ],
                              ),
                              SizedBox(height: 15.pt),
                              WisCard(
                                color: colorScheme.background4,
                                padding: EdgeInsets.fromLTRB(
                                    15.pt, 5.pt, 15.pt, 15.pt),
                                child: Column(children: [
                                  for (var item in asset.feeList ?? [])
                                    Wisdom.row(
                                      margin: EdgeInsets.only(top: 10.pt),
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        WisText(
                                          '${item?.feeName}',
                                          size: 15.pt,
                                          color: colorScheme.minor,
                                        ),
                                        WisText(
                                          '￥${item?.fee ?? 0}',
                                          size: 15.pt,
                                          color: colorScheme.mainTitle,
                                        ),
                                      ],
                                    ),
                                ]),
                              ),
                            ],
                          ),
                        ),
                    ],
                  );
                })
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: Wisdom.row(
        padding: EdgeInsets.symmetric(horizontal: 15.pt),
        color: Colors.white,
        children: [
          SafeArea(
            child: WLoadingButton(
              color: Color(0xff7FCF7D),
              height: 44.pt,
              margin: EdgeInsets.only(top: 8.pt, bottom: 8.pt, left: 10.pt),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
              ),
              onPressed: () => store.toSubmit(),
              child: WisText(
                "预存款缴费",
                size: 20.pt,
                color: Colors.white,
              ),
            ),
          ).asExpanded(),
        ],
      ),
    );
  }
}
