/*
 * @Author: ChenYaJin
 * @Date: 2023-08-08 10:04:37
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-08-16 16:03:41
 * @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';

class DateAbnormalListComponent 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.calendarAbnormalScrollViewListKey,
      controller: store.outerController,
      onInit: () => store.updateRankList(isLoad: false),
      onRefresh: () => store.refreshCalendarData(),
      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: [
                for (var item in store.calendarAbnormalList)
                  WisCard(
                    margin:
                        EdgeInsets.symmetric(vertical: 5.pt, horizontal: 15.pt),
                    padding: EdgeInsets.symmetric(
                        horizontal: 10.pt, vertical: 10.pt),
                    onTap: () => store.onToAbnormalDetail(item),
                    child: Column(
                      children: [
                        Wisdom.column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          margin: EdgeInsets.only(bottom: 8.pt),
                          children: [
                            Wisdom.row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                WisText(
                                  '${item.relationName ?? ''}',
                                  size: 16.pt,
                                  weight: FontWeight.bold,
                                  overflow: TextOverflow.ellipsis,
                                ).asExpanded(),
                              ],
                            ),
                            Wisdom.row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              padding: EdgeInsets.symmetric(vertical: 8.pt),
                              children: [
                                Wisdom.column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Wisdom.row(
                                      margin: EdgeInsets.only(bottom: 5.pt),
                                      children: [
                                        WisText(
                                          '所属小区：',
                                          color: colorScheme.minor,
                                        ),
                                        WisText(
                                          '${item.communityName ?? '--'}',
                                          size: 14.pt,
                                        ),
                                      ],
                                    ),
                                    Wisdom.row(
                                      children: [
                                        WisText(
                                          '所属区域：',
                                          color: colorScheme.minor,
                                        ),
                                        WisText(
                                          '${item.communityAreaName ?? '--'}',
                                          size: 14.pt,
                                        ),
                                      ],
                                    ),
                                  ],
                                ).asExpanded(),
                                if (item.resultAbnormal == true &&
                                    item.status == 'untreated') ...[
                                  Wisdom(
                                    onTap: () => store.onToAbnormalDetail(item),
                                    child: WTag(
                                      child: Text(
                                        '处理',
                                        style: TextStyle(
                                          fontSize: 14.pt,
                                        ),
                                      ),
                                      padding: EdgeInsets.symmetric(
                                          horizontal: 10.pt, vertical: 2.pt),
                                      color: colorScheme.blue,
                                      margin: EdgeInsets.only(right: 10.pt),
                                    ),
                                  ),
                                ] else
                                  SizedBox()
                              ],
                            ),
                            Wisdom.row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              border: Border(
                                top: BorderSide(
                                  color: Color(0xffE6E6E6),
                                  width: 0.5.pt,
                                ),
                              ),
                              padding: EdgeInsets.only(top: 8.pt),
                              children: [
                                Wisdom.row(
                                  children: [
                                    WisText(
                                      '操作时间：',
                                      color: colorScheme.minor,
                                    ),
                                    WisText(
                                      '${item.createdAt ?? '--'}',
                                      size: 14.pt,
                                    ),
                                  ],
                                ).asExpanded(),
                                Wisdom.row(
                                  padding:
                                      EdgeInsets.symmetric(horizontal: 5.pt),
                                  children: [
                                    WisText(
                                      '执行人：',
                                      color: colorScheme.minor,
                                      size: 13.pt,
                                      weight: FontWeight.w300,
                                    ),
                                    WisText(
                                      '${item.createdByName ?? '--'}',
                                      size: 14.pt,
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}
