/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2022-10-09 16:07:52
 * @LastEditTime: 2024-04-08 10:25:23
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:statistics_package/src/view_models/filter_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../../assets.gen.dart';

///
///
///
///
///
//***以下为模板代码谨慎修改***

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

  @override
  State<FilterPage> createState() => _FilterPageState();
}

class _FilterPageState extends State<FilterPage> {
   final StatisticFilterStore _store =
        Get.isRegistered() ? Get.find() : Get.put(StatisticFilterStore());
  @override
  void dispose() {
    Get.delete<StatisticFilterStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('房管动态筛选',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(onInit: () => _store.getCompanyTree(), slivers: [
        SliverToBoxAdapter(
          child: WisCard(
            margin: EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
            color: Colors.white,
            padding: EdgeInsets.all(5.pt),
            child: Wisdom.row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              padding: EdgeInsets.symmetric(
                horizontal: 15.pt,
                vertical: 20.pt,
              ),
              children: [
                Wisdom.row(children: [
                  Image(
                    image: AssetList.$company_png_image,
                    width: 18.pt,
                    height: 15.pt,
                  ),
                  SizedBox(width: 5.pt),
                  WisText(
                    '${_store.appGlobalStore.currentUserinfo?.entName ?? '--'}',
                    weight: FontWeight.w600,
                  ),
                ]),
                Obx(() {
                  return Wisdom.row(
                      onTap: () => _store.allCheckCommunitys(),
                      children: [
                        WisText(
                          '全选',
                          color: colorScheme.placeholder,
                        ),
                        SizedBox(width: 5.pt),
                        if (_store.isAllChecked.value) ...[
                          Image(
                            image: AssetList.$multi_checked_png_image,
                            width: 15.pt,
                            height: 15.pt,
                          ),
                        ] else ...[
                          Image(
                            image: AssetList.$multi_check_png_image,
                            width: 15.pt,
                            height: 15.pt,
                          ),
                        ]
                      ]);
                })
              ],
            ),
          ),
        ),
        SliverToBoxAdapter(
          child: Obx(() {
            return WisCard(
              margin: EdgeInsets.symmetric(horizontal: 15.pt),
              color: Colors.white,
              padding: EdgeInsets.all(5.pt),
              child: Wisdom.column(
                children: [
                    for (int i = 0; i < _store.communityTree.length; i++)
                      WisExpansionTile(
                        initiallyExpanded: false,
                        title: Wisdom.row(
                          height: 53.5.pt,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Wisdom(
                                  borderRadius: BorderRadius.circular(4.pt),
                                  width: 3.pt,
                                  height: 15.pt,
                                  color: colorScheme.primary,
                                ),
                                SizedBox(width: 5.pt),
                                WisText(
                                  '${_store.communityTree.length > 0 ? _store.communityTree[i].companyName : ''}',
                                  size: 14.pt,
                                  weight: FontWeight.w600,
                                  color: colorScheme.mainTitle,
                                  overflow: TextOverflow.ellipsis,
                                ).asExpanded(),
                              ],
                            ).asExpanded(),
                            Row(
                              children: [
                                WisText(
                                  '已选',
                                  size: 14.pt,
                                  color: colorScheme.placeholder,
                                ),
                                SizedBox(width: 5.pt),
                                WisText(
                                  '${_store.allCheckedCommunityCount.length > 0 ?_store.allCheckedCommunityCount[i] ?? 0 : 0}',
                                  color: Color(0XFFFF495E),
                                ),
                              ],
                            ),
                          ],
                        ),
                        expandTitle: Wisdom.row(
                          height: 53.5.pt,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Wisdom(
                                  borderRadius: BorderRadius.circular(4.pt),
                                  width: 3.pt,
                                  height: 15.pt,
                                  color: colorScheme.primary,
                                ),
                                SizedBox(width: 5.pt),
                                WisText(
                                  '${_store.communityTree[i].companyName}',
                                  size: 14.pt,
                                  weight: FontWeight.w600,
                                  color: colorScheme.mainTitle,
                                  overflow: TextOverflow.ellipsis,
                                ).asExpanded(),
                              ],
                            ).asExpanded(),
                            Row(
                              children: [
                                WisText(
                                  '已选',
                                  size: 14.pt,
                                  color: colorScheme.placeholder,
                                ),
                                SizedBox(width: 5.pt),
                                WisText(
                                  '${_store.allCheckedCommunityCount[i] ?? 0}',
                                  color: Color(0XFFFF495E),
                                ),
                              ],
                            )
                          ],
                        ),
                        children: [
                          Wisdom.row(
                            padding: EdgeInsets.all(15.pt),
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              WisText('子公司下全部小区'),
                              Obx(() {
                                return Wisdom.row(
                                    onTap: () =>
                                        _store.allCheckCompanyCommunitys(i),
                                    children: [
                                      WisText(
                                        '全选',
                                        color: colorScheme.placeholder,
                                      ),
                                      SizedBox(width: 5.pt),
                                      if (_store.isAllCheckedCommunitys
                                          .contains(i)) ...[
                                        Image(
                                          image: AssetList
                                              .$multi_checked_png_image,
                                          width: 15.pt,
                                          height: 15.pt,
                                        ),
                                      ] else ...[
                                        Image(
                                          image:
                                              AssetList.$multi_check_png_image,
                                          width: 15.pt,
                                          height: 15.pt,
                                        ),
                                      ]
                                    ]);
                              })
                            ],
                          ),
                          for (var community
                              in _store.communityTree[i].communities!)
                            Obx(() {
                              return Wisdom.row(
                                onTap: () =>
                                    _store.checkCommunitys(community, i),
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                margin: EdgeInsets.symmetric(horizontal: 15.pt),
                                padding: EdgeInsets.symmetric(vertical: 15.pt),
                                border: Border(
                                  bottom: BorderSide(
                                    color: colorScheme.divider,
                                  ),
                                ),
                                children: [
                                  WisText('${community.communityName}'),
                                  if (_store.communityIds
                                      .contains(community.communityId)) ...[
                                    Image(
                                      image: AssetList.$checked_png_image,
                                      width: 15.pt,
                                      height: 15.pt,
                                    ),
                                  ] else ...[
                                    Image(
                                      image: AssetList.$check_png_image,
                                      width: 15.pt,
                                      height: 15.pt,
                                    ),
                                  ]
                                ],
                              );
                            })
                        ],
                      ),
                ],
              ),
            );
          }),
        ),
      ]),
      bottomNavigationBar: Wisdom.row(
          color: Colors.white,
          height: 80.pt,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 18.pt),
          onTap: () => _store.toStatisticsPage(),
          children: [
            Wisdom(
              height: 44.pt,
              color: colorScheme.primary,
              borderRadius: BorderRadius.circular(25.pt),
              child: Center(
                child: WisText(
                  '确定',
                  size: 16.pt,
                  color: Colors.white,
                ),
              ),
            ).asExpanded(),
          ]),
    );
  }
}
