/*
 * @Author: ChenYaJin
 * @Date: 2023-04-12 15:25:48
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-08-08 10:00:24
 * @Description: 异常排名列表
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'package:task_package/src/view_models/work_statistic_store.dart';
import './rank_tip.dart';

class AbnormalRankComponent extends GetView<WorkStatisticStore> {
  @override
  Widget build(BuildContext context) {
    final WorkStatisticStore store = Get.find<WorkStatisticStore>();
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    return WisScrollView(
      key: store.workScrViewKey,
      controller: store.outerController,
      onInit: () => store.updateRankList(isLoad: false),
      onRefresh: () => store.updateRankList(isLoad: false),
      onLoad: () => store.updateRankList(isLoad: true),
      emptyWidget: SliverToBoxAdapter(
        child: Wisdom.column(
          mainAxisAlignment: MainAxisAlignment.center,
          margin: EdgeInsets.only(bottom: 10.pt),
          padding: EdgeInsets.symmetric(vertical: 15.pt),
          // border: Border(top: BorderSide(color: Color(0xffe6e6e6))),
          color: Colors.white,
          children: [
            WEmptyWidget(
              text: Text('空空如也~~'),
            ),
          ],
        ),
      ),
      slivers: <Widget>[
        SliverToBoxAdapter(
          child: Obx(
            () => Wisdom.column(
              children: [
                RankTipComponent(),
                for (var item in (store.isPoint.value
                    ? store.pointList
                    : store.areaRankList))
                  WisCard(
                    margin:
                        EdgeInsets.symmetric(vertical: 5.pt, horizontal: 15.pt),
                    padding: EdgeInsets.symmetric(
                        horizontal: 10.pt, vertical: 10.pt),
                    onTap: () => store.onToAbnormalList(item),
                    child: Column(
                      children: [
                        Wisdom.row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          margin: EdgeInsets.only(bottom: 8.pt),
                          children: [
                            Wisdom.row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  '排名：${item.abnormalRank ?? ''}',
                                  style: TextStyle(
                                    color: colorScheme.mainTitle,
                                    fontSize: 16.pt,
                                    fontWeight: FontWeight.w500,
                                  ),
                                ),
                              ],
                            ),
                            Wisdom.row(
                              children: [
                                Icon(
                                  Icons.arrow_forward_ios,
                                  size: 14.pt,
                                  color: colorScheme.grey,
                                ),
                              ],
                            ),
                          ],
                        ),
                        Wisdom.row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          mainAxisSize: MainAxisSize.max,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Wisdom.column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              padding: EdgeInsets.symmetric(horizontal: 5.pt),
                              border: Border(
                                right: BorderSide(
                                  color: Color(0xffE6E6E6),
                                  width: 0.5.pt,
                                ),
                              ),
                              children: [
                                WisText(
                                  '所属小区',
                                  color: colorScheme.minor,
                                  size: 13.pt,
                                  weight: FontWeight.w300,
                                ),
                                WisText(
                                  '${item.communityName ?? '--'}',
                                  size: 14.pt,
                                ),
                              ],
                            ).asExpanded(),
                            Wisdom.column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              padding: EdgeInsets.symmetric(horizontal: 5.pt),
                              border: Border(
                                right: BorderSide(
                                  color: Color(0xffE6E6E6),
                                  width: 0.5.pt,
                                ),
                              ),
                              children: [
                                WisText(
                                  '区域位置',
                                  color: colorScheme.minor,
                                  size: 13.pt,
                                  weight: FontWeight.w300,
                                ),
                                WisText(
                                  '${item.communityAreaName ?? '--'}',
                                  size: 14.pt,
                                ),
                              ],
                            ).asExpanded(),
                            Wisdom.column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              padding: EdgeInsets.symmetric(horizontal: 5.pt),
                              children: [
                                WisText(
                                  '异常总数',
                                  color: colorScheme.minor,
                                  size: 13.pt,
                                  weight: FontWeight.w300,
                                ),
                                WisText(
                                  '${item.resultAbnormalCount ?? '--'}',
                                  size: 16.pt,
                                  color: colorScheme.red,
                                  weight: FontWeight.w400,
                                ),
                              ],
                            ).asExpanded(),
                          ],
                        ),
                      ],
                    ),
                  ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}
