/*
 * @Author: ChenYaJin
 * @Date: 2022-12-15 15:21:46
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-27 15:28:38
 * @Description: 
 */
part of '../index.dart';

class _ReportPage extends StatelessWidget {
  _ReportPage({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final OverdueIndexStore store = Get.find<OverdueIndexStore>();

    _getSelectValue() {
      List _initialValue = store.communityIds;
      List<SinglePickerEntity> _selectValue = [];
      if (_initialValue.length == 0) return null;
      List tempList;
      (_initialValue).forEach((item) {
            tempList =
                store.communityList.where((v) => v['id'] == item).toList();
            _selectValue.add(SinglePickerEntity(
              name: tempList[0]['name'],
              unique: tempList[0]['id'],
            ));
          });
      return _selectValue;
    }

    return NestedScrollView(
      controller: store.outerController,
      headerSliverBuilder: (context, innerBoxIsScrolled) {
        return <Widget>[
          new _BuildSearchInput(
            title: store.searchKeyWord.value,
            onInput: (v) => store.onSearchName(v),
            onCancel: () => store.onSearchName(''),
          ).asSliver(),
          Wisdom.row(
            padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
            color: Colors.white,
            children: [
              Wisdom.row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                padding: EdgeInsets.all(8.pt),
                margin: EdgeInsets.only(right: 10.pt),
                color: colorScheme.background4,
                borderRadius: BorderRadius.circular(4.pt),
                onTap: () async {
                  final res = await WPickerUtil.multiple<SinglePickerEntity>(
                    context,
                    title: Text('选择小区'),
                    initialValue: _getSelectValue(),
                    getData: () => SinglePickerEntity.listMap2entity(
                      store.communityList,
                      'name',
                      'id',
                      enableValue: null,
                    ),
                    isSearch: true,
                  );
                  if (res != null) {
                    store.onChooseCommunityIds(
                        res.map((e) => e.unique).toList());
                  }
                },
                children: [
                  Wisdom(
                    margin: EdgeInsets.only(
                      right: 10.pt,
                    ),
                    child: Obx(() => WisText(
                          store.communityNameString.isNotEmpty
                              ? store.communityNameString.value
                              : '小区选择',
                          size: 14.pt,
                          weight: FontWeight.w400,
                          overflow: TextOverflow.ellipsis,
                          color: store.communityNameString.isNotEmpty
                              ? colorScheme.primary
                              : colorScheme.mainTitle,
                        )),
                  ).asExpanded(),
                  Image(
                    image: AssetList.$tzhxq_png_image,
                    height: 10.pt,
                  ),
                ],
              ).asExpanded(),
              Wisdom.row(
                onTap: () async {
                  final res = await WPickerUtil.single<StatusModel>(
                    context,
                    title: Text('选择状态'),
                    initialValue: store.status.value,
                    getData: () => store.getStatusEnum(),
                    isSearch: false,
                  );
                  if (res != null) {
                    store.onChooseStatus(res);
                  }
                },
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                padding: EdgeInsets.all(8.pt),
                margin: EdgeInsets.only(right: 10.pt),
                color: colorScheme.background4,
                borderRadius: BorderRadius.circular(4.pt),
                children: [
                  Wisdom(
                    margin: EdgeInsets.only(
                      right: 10.pt,
                    ),
                    child: Obx(() => WisText(
                          store.status.value.name ?? '工单状态',
                          size: 14.pt,
                          weight: FontWeight.w400,
                          color: store.status.value.name != null
                              ? colorScheme.primary
                              : colorScheme.mainTitle,
                        )),
                  ).asExpanded(),
                  Image(
                    image: AssetList.$tzhxq_png_image,
                    height: 10.pt,
                  ),
                ],
              ).asExpanded(),
              Wisdom.row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                padding: EdgeInsets.all(8.pt),
                margin: EdgeInsets.only(right: 10.pt),
                color: colorScheme.background4,
                borderRadius: BorderRadius.circular(4.pt),
                onTap: () async {
                  final res = await WPickerUtil.single<InnerSortListModel>(
                    context,
                    title: Text('选择业主分类'),
                    initialValue: store.innerSort.value,
                    getData: () => store.getInnerSortList(),
                    isSearch: false,
                  );
                  if (res != null) {
                    store.onChooseInnerSort(res);
                  }
                },
                children: [
                  Wisdom(
                      margin: EdgeInsets.only(
                        right: 10.pt,
                      ),
                      child: Obx(
                        () => WisText(
                          store.innerSort.value.name ?? '内部分类',
                          size: 14.pt,
                          weight: FontWeight.w400,
                          overflow: TextOverflow.ellipsis,
                          color: store.innerSort.value.name != null
                              ? colorScheme.primary
                              : colorScheme.mainTitle,
                        ),
                      )).asExpanded(),
                  Image(
                    image: AssetList.$tzhxq_png_image,
                    height: 10.pt,
                  ),
                ],
              ).asExpanded(),
              Wisdom.row(
                children: [
                  Wisdom(
                    onTap: () => store.onReset(),
                    padding:
                        EdgeInsets.symmetric(horizontal: 8.pt, vertical: 5.pt),
                    color: colorScheme.primary,
                    borderRadius: BorderRadius.circular(4.pt),
                    child: WisText(
                      '重置',
                      size: 13.pt,
                      weight: FontWeight.w400,
                      color: Colors.white,
                    ),
                  )
                ],
              )
            ],
          ).asSliver(),
          SliverToBoxAdapter(
            child: Obx(
              () => Wisdom(
                height: 44.pt,
                color: Colors.white,
                padding:
                    EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
                child: Wisdom.row(
                  color: Colors.white,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    CustomScrollView(
                      scrollDirection: Axis.horizontal,
                      slivers: [
                        SliverToBoxAdapter(
                          child: Wisdom.row(
                            children: [
                              for (var item in store.statisticStatus)
                                Wisdom(
                                  borderRadius: BorderRadius.circular(4.pt),
                                  color: Color(0xFFF6F7FC),
                                  padding: EdgeInsets.symmetric(
                                    horizontal: 6.pt,
                                    vertical: 5.pt,
                                  ),
                                  margin: EdgeInsets.only(right: 12.pt),
                                  onTap: () => store.filterStatus(item),
                                  child: Wisdom.rich(
                                    overflow: TextOverflow.ellipsis,
                                    children: [
                                      TextSpan(
                                        text: item['name'] as String,
                                        style: TextStyle(
                                          fontSize: 14.pt,
                                          fontWeight: FontWeight.w400,
                                          color: store.statusCode.value ==
                                                  item['code']
                                              ? colorScheme.primary
                                              : Color(0xFF616178),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                            ],
                          ),
                        ),
                      ],
                    ).asExpanded(),
                    Wisdom.row(
                      color: Colors.white,
                      padding: EdgeInsets.symmetric(vertical: 5.pt),
                      width: 65.pt,
                      onTap: () => store.toFilterPage(),
                      alignment: Alignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Text('筛选',
                            style: TextStyle(
                              fontSize: 13.pt,
                              color: store.isFilterStatus
                                  ? colorScheme.primary
                                  : colorScheme.mainTitle,
                            )),
                        Image(
                          image: store.isFilterStatus
                              ? AssetList.$filter_blue_png_image
                              : AssetList.$filter_png_image,
                          height: 20.pt,
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
        ];
      },
      body: _ListAllView(),
    );
  }
}
