/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2023-03-23 17:11:18
 * @LastEditTime: 2023-11-02 15:53:27
 * @Description  : Do not edit
 */
part of 'index.dart';

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);
  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  _Store get store => Provider.of(context, listen: false);

  @override
  void initState() {
    store.onInit();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        title: WisText('${store.args['appBarTitle'] ?? '收银台'}',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        actions: [
          Wisdom(
            padding: EdgeInsets.only(
              right: 15.pt,
              left: 5.pt,
            ),
            onTap: () => store.toRecord(),
            child: Image.asset(
              'lib/assets/record.png',
              height: 18.pt,
              width: 18.pt,
              package: 'bill_package',
              color: colorScheme.mainTitle,
            ),
          ).asFlexible(flex: 1),
        ],
      ),
      body: Stack(
        children: [
          Stack(
            children: [
              Image.asset(
                'lib/assets/main/bg.png',
                package: 'app_package',
                width: MediaQuery.of(context).size.width,
              ),
            ],
          ),
          Consumer<_Store>(
            builder: (ctx, store, child) {
              return Column(
                children: [
                  buildStatic(),
                  _StatisticComponent(),
                  if (store.currentTreeSelection == 'house')
                    _HouseListComponent().asExpanded(),
                  if (store.currentTreeSelection == 'car')
                    _CarListComponent().asExpanded(),
                  if (store.currentTreeSelection == 'parkingSpace')
                    _ParkListComponent().asExpanded(),
                  if (store.currentTreeSelection == 'resident')
                    _ResidentListComponent().asExpanded(),
                ],
              );
            },
          ),
        ],
      ),
    );
  }

  Widget _buildAlertDialog() {
    return AlertDialog(
      title: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          WisText(
            '系统说明',
            size: 16.pt,
            weight: FontWeight.w600,
          ),
          Wisdom(
            onTap: () => {Navigator.pop(context, false)},
            child: Icon(
              Icons.close,
              size: 22.pt,
            ),
          )
        ],
      ),
      titleTextStyle: const TextStyle(fontSize: 20, color: Colors.black),
      titlePadding: EdgeInsets.all(
        15.pt,
      ),
      contentPadding: const EdgeInsets.symmetric(horizontal: 5),
      backgroundColor: Colors.white,
      content: _buildContent(),
      actions: const [],
      elevation: 4,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.all(
          Radius.circular(20),
        ),
      ),
    );
  }

  Widget _buildContent() {
    return Container(
      width: MediaQuery.of(context).size.width * 0.8,
      child: Wisdom.column(
        padding: EdgeInsets.fromLTRB(
          15.pt,
          5.pt,
          15.pt,
          15.pt,
        ),
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              WisText(
                '切换月份：',
                size: 14.pt,
                weight: FontWeight.w600,
              ),
              WisText('统计的账期根据设置不同分别统计【本月】暨当前日期所在月份账期的相关数据，【上月】暨当前日期上月账期账单的相关数据。')
                  .asExpanded(),
            ],
          ),
          SizedBox(height: 5.pt),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              WisText(
                '应收：',
                size: 14.pt,
                weight: FontWeight.w600,
              ),
              WisText('统计账期内的所有类型的已审核账单应收之和，且包含冻结账单的应收。').asExpanded(),
            ],
          ),
          SizedBox(height: 5.pt),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              WisText(
                '实收：',
                size: 14.pt,
                weight: FontWeight.w600,
              ),
              WisText('统计账期内的所有类型的已审核账单的实收总额，包含导入账单的已收金额。').asExpanded(),
            ],
          ),
          SizedBox(height: 5.pt),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              WisText(
                '欠费：',
                size: 14.pt,
                weight: FontWeight.w600,
              ),
              WisText('统计账期内的所有类型的已审核账单欠费之和，且包含冻结账单的欠费与导入账单的欠费。').asExpanded(),
            ],
          ),
          SizedBox(height: 5.pt),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              WisText(
                '收费率：',
                size: 14.pt,
                weight: FontWeight.w600,
              ),
              WisText('统计以上的实收与应收的比例。(收费率 = 实收/应收。)').asExpanded(),
            ],
          ),
          SizedBox(height: 5.pt),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              WisText(
                '今年：',
                size: 14.pt,
                weight: FontWeight.w600,
              ),
              WisText('统计本月、上月及今年之前所有月份的实收之和与应收之和的比例。').asExpanded(),
            ],
          ),
        ],
      ),
    );
  }

  ///统计
  buildStatic() {
    return Wisdom.column(
      margin: EdgeInsets.fromLTRB(15.pt, 15.pt, 15.pt, 0),
      children: [
        Consumer<_Store>(
          builder: (ctx, store, child) {
            return Container(
              // height: 100.pt,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    Color.fromRGBO(246, 176, 103, 1),
                    Color.fromRGBO(238, 127, 58, 1),
                    Color.fromRGBO(239, 130, 66, 1),
                  ],
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                ),
                borderRadius: store.expand == true
                    ? BorderRadius.only(
                        topRight: Radius.circular(12.pt),
                        topLeft: Radius.circular(12.pt),
                      )
                    : BorderRadius.circular(12.pt),
              ),
              child: Wisdom.row(
                padding: EdgeInsets.all(15.pt),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Wisdom.column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      WisText(
                        '欠费统计${store.arrearsFeeText}',
                        size: 14.pt,
                        color: Colors.white,
                      ),
                      Consumer<_Store>(
                        builder: (ctx, store, child) {
                          return Wisdom.row(
                            crossAxisAlignment: CrossAxisAlignment.end,
                            margin: EdgeInsets.only(top: 15.pt),
                            children: [
                              Wisdom(
                                padding: EdgeInsets.only(bottom: 5.pt),
                                child: WisText(
                                  '¥',
                                  size: 18.pt,
                                  bold: true,
                                  color: Colors.white,
                                ),
                              ),
                              WisText(
                                '${store.feeStatistics?.totalArrearsFee ?? '--'}',
                                size: 34.pt,
                                bold: true,
                                color: Colors.white,
                              ),
                            ],
                          );
                        },
                      )
                    ],
                  ).asExpanded(),
                  Consumer<_Store>(
                    builder: (ctx, store, child) {
                      if (store.expand == true)
                        return Wisdom(
                          onTap: () => store.onSetExpand(false),
                          child: Image.asset(
                            'lib/assets/shrink.png',
                            package: 'bill_package',
                            width: 18.pt,
                          ),
                        );
                      else
                        return Wisdom(
                          onTap: () => store.onSetExpand(true),
                          child: Image.asset(
                            'lib/assets/expand.png',
                            package: 'bill_package',
                            width: 18.pt,
                          ),
                        );
                    },
                  ),
                ],
              ),
            );
          },
        ),
        Consumer<_Store>(
          builder: (ctx, store, child) {
            if (store.expand == true)
              return Container(
                decoration: BoxDecoration(
                    boxShadow: [
                      BoxShadow(
                        color: Color(0x08000000),
                        offset: Offset(0, 2.pt),
                        blurRadius: 10.pt,
                        spreadRadius: 2.5.pt,
                      ),
                    ],
                    borderRadius: BorderRadius.only(
                      bottomRight: Radius.circular(12.pt),
                      bottomLeft: Radius.circular(12.pt),
                    )),
                child: Wisdom.column(
                  padding: EdgeInsets.all(15.pt),
                  color: Colors.white,
                  children: [
                    Wisdom.row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        WisText(
                          '${store.statisticText}',
                          size: 14.pt,
                          color: Colors.black87,
                        ),
                        Wisdom(
                          onTap: () => store.setBillStatisticThisMonth(),
                          child: Text(
                            '切换月份',
                            style: TextStyle(
                              color: Color.fromRGBO(15, 103, 248, 1),
                              decorationColor: Color.fromRGBO(15, 103, 248, 1),
                              decoration: TextDecoration.underline,
                              fontSize: 14.pt,
                            ),
                          ),
                        ),
                      ],
                    ),
                    Wisdom.column(
                      color: Colors.grey[50],
                      borderRadius: BorderRadius.all(Radius.circular(8.pt)),
                      padding: EdgeInsets.all(5.pt),
                      margin: EdgeInsets.symmetric(vertical: 10.pt),
                      children: [
                        Wisdom.row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          padding: EdgeInsets.all(5.pt),
                          children: [
                            Wisdom(
                              margin: EdgeInsets.only(right: 10.pt),
                              child: Image.asset(
                                'lib/assets/yingshou.png',
                                package: 'bill_package',
                                width: 28.pt,
                                height: 28.pt,
                              ),
                            ),
                            WisText(
                              '应收（${store.billStatisticIsThisMonth == true ? '本期' : '上期'}）',
                            ).asExpanded(),
                            WisText(
                              '${store.feeStatistics?.receivableFee ?? '--'}',
                              size: 16.pt,
                              weight: FontWeight.w500,
                            ),
                          ],
                        ),
                        Wisdom.row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          padding: EdgeInsets.all(5.pt),
                          children: [
                            Wisdom(
                              margin: EdgeInsets.only(right: 10.pt),
                              child: Image.asset(
                                'lib/assets/shishou.png',
                                package: 'bill_package',
                                width: 28.pt,
                                height: 28.pt,
                              ),
                            ),
                            WisText(
                              '实收（${store.billStatisticIsThisMonth == true ? '本期' : '上期'}）',
                            ).asExpanded(),
                            WisText(
                              '${store.feeStatistics?.receivedFee ?? '--'}',
                              size: 16.pt,
                              weight: FontWeight.w500,
                            ),
                          ],
                        ),
                        Wisdom.row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          padding: EdgeInsets.all(5.pt),
                          children: [
                            Wisdom(
                              margin: EdgeInsets.only(right: 10.pt),
                              child: Image.asset(
                                'lib/assets/qianfei.png',
                                package: 'bill_package',
                                width: 28.pt,
                                height: 28.pt,
                              ),
                            ),
                            WisText(
                              '欠费（${store.billStatisticIsThisMonth == true ? '本期' : '上期'}）',
                            ).asExpanded(),
                            WisText(
                              '${store.feeStatistics?.arrearsFee ?? '--'}',
                              size: 16.pt,
                              weight: FontWeight.w500,
                            ),
                          ],
                        ),
                      ],
                    ),
                    Wisdom.row(
                      padding:
                          EdgeInsets.only(top: 5.pt, left: 10.pt, right: 10.pt),
                      children: [
                        Wisdom.row(
                          onTap: () => {
                            showDialog(
                              context: context,
                              builder: (ctx) => _buildAlertDialog(),
                            ),
                          },
                          children: [
                            Image.asset(
                              'lib/assets/fee_total.png',
                              package: 'bill_package',
                              width: 28.pt,
                              height: 28.pt,
                            ),
                            SizedBox(width: 10.pt),
                            WisText(
                              '收费率',
                            ),
                            SizedBox(width: 5.pt),
                            Icon(
                              Icons.info_outlined,
                              size: 13.pt,
                              color: Colors.black,
                            ),
                          ],
                        ).asExpanded(),
                        Wisdom.column(
                          width: 70.pt,
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            WisText(
                              '今年',
                            ),
                            SizedBox(height: 2.pt),
                            Wisdom.row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                WisText(
                                  '${store.feeStatistics?.collectionRate ?? '--'}',
                                  size: 20.pt,
                                  weight: FontWeight.w400,
                                ),
                                WisText(
                                  '%',
                                  size: 16.pt,
                                  weight: FontWeight.w400,
                                ),
                              ],
                            ),
                          ],
                        ),
                        SizedBox(width: 10.pt),
                        Wisdom.column(
                          width: 70.pt,
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            WisText(
                              '${store.billStatisticIsThisMonth == true ? '本期' : '上期'}',
                            ),
                            SizedBox(height: 2.pt),
                            Wisdom.row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                WisText(
                                  '${store.feeStatistics?.monthCollectionRate ?? '--'}',
                                  size: 20.pt,
                                  weight: FontWeight.w400,
                                  overflow: TextOverflow.ellipsis,
                                ),
                                WisText(
                                  '%',
                                  size: 16.pt,
                                  weight: FontWeight.w400,
                                ),
                              ],
                            ),
                          ],
                        )
                      ],
                    ),
                  ],
                ),
              );
            else
              return SizedBox(height: 0);
          },
        ),
      ],
    );
  }
}
