/*
 * @Author: XianKaiQun
 * @Date: 2020-07-08 15:52:55
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2022-12-15 10:51:40
 * @Description: 
 */
part of '../index.dart';

class _HouseListComponent extends StatelessWidget {
  const _HouseListComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<IndexStore>(context, listen: true);
    final list = store.houseList;
    final colorScheme = WTheme.of(context).colorScheme;

    ///统计
    buildStatic() {
      return SliverToBoxAdapter(
        child: Center(
          child: Container(
            margin: EdgeInsets.fromLTRB(15.pt, 15.pt, 15.pt, 0),
            height: 100.pt,
            decoration: BoxDecoration(
              image: DecorationImage(
                image:
                    AssetImage('lib/assets/bj8.png', package: 'bill_package'),
                fit: BoxFit.cover,
              ),
            ),
            child: Wisdom.column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              padding: EdgeInsets.all(20.pt),
              children: <Widget>[
                WisText(
                  '欠费统计',
                  size: 13.pt,
                  color: Colors.white,
                ),
                Consumer<IndexStore>(
                  builder: (ctx, store, child) {
                    return Expanded(
                      child: WisText(
                        store.total == null ? '' : '${store.total}',
                        size: 34.pt,
                        bold: true,
                        color: Colors.white,
                      ),
                    );
                  },
                )
              ],
            ),
          ),
        ),
      );
    }

    return Column(
      children: <Widget>[
        WisScrollView(
          key: store.houseScrollViewKey,
          controller: store.viewController,
          onInit: () => store.onInit(),
          onLoad: () => store.onLoad(),
          slivers: <Widget>[
            WSearch(
              isDark: true,
              moonlight: false,
              initValue: store.houseSearchWord ?? '',
              isControlOutside: true,
              backColor: Colors.white,
              hintText: '请输入房屋号',
              onSubmitted: (value) => store.onHouseSearchTrigger(value),
              onCancel: () => store.onHouseSearchTrigger(''),
              // onInput: (v) => store.setIsShowBuild(v),
              // onChanged: (value) => store.setHouseName(value),
            ).asSliver(),
            if (store.isShowBuild == true) ...[
              buildStatic(),
              SizedBox(height: 15.pt).asSliver(),
              WisSliverList.childBuilder(
                childCount: store.billList.length,
                builder: (context, index) {
                  final item = store.billList[index];
                  return WisCard(
                    margin: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 10.pt),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      children: <Widget>[
                        Wisdom.row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          onTap: () => store.route2list(item),
                          color: Colors.white,
                          padding: EdgeInsets.fromLTRB(0, 15.pt, 15.pt, 15.pt),
                          children: [
                            Row(
                              children: [
                                Container(
                                  height: 20.pt,
                                  width: 3.pt,
                                  color: colorScheme.primary,
                                ),
                                SizedBox(width: 12.pt),
                                WisText(
                                  '${item?.buildName}(${item?.households ?? 0}户)',
                                  size: 16.pt,
                                  bold: true,
                                  color: colorScheme.mainTitle,
                                ),
                              ],
                            ),
                            Wisdom.column(
                              margin: EdgeInsets.only(right: 15.pt),
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.end,
                              children: [
                                WisText(
                                  '￥${item?.arrearsFee ?? 0}',
                                  size: 16.pt,
                                  bold: (item?.arrearsFee ?? 0) > 0
                                      ? true
                                      : false,
                                  color: (item?.arrearsFee ?? 0) > 0
                                      ? colorScheme.red
                                      : colorScheme.minor,
                                ),
                                WisText(
                                  '欠费金额',
                                  size: 13.pt,
                                  color: colorScheme.minor,
                                ),
                              ],
                            ).asFlexible(flex: 1),
                          ],
                        ),
                      ],
                    ),
                  );
                },
              ),
            ] else if ((store.houseSearchWord != null &&
                    store.houseSearchWord != '') ||
                store.buildId != null) ...[
              SizedBox(height: 15.pt).asSliver(),
              WisSliverList.childBuilder(
                childCount: list.length,
                builder: (context, index) {
                  final item = list[index];
                  return WisCard(
                      margin: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 10.pt),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: <Widget>[
                          Wisdom(
                            onTap: () => store.route2Detail(item),
                            color: Colors.white,
                            padding: EdgeInsets.all(20.pt),
                            child: Text('${item.assetName}'),
                          ),
                        ],
                      ));
                },
              ),
            ],
          ],
        ).asExpanded(),
      ],
    );
  }
}
