/*
 * @Author: XianKaiQun
 * @Date: 2020-07-29 09:44:51
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-05-12 17:03:31
 * @Description: 
 */
part of '../index.dart';

///巡检
class _PollingComponent extends StatelessWidget {
  const _PollingComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateRepairStore>(context);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final theme = Theme.of(context);
    final textTheme = theme.textTheme;
    return ColoredBox(
      color: Colors.white,
      child: WisScrollView(
        onInit: () => store.getPollingPlans(),
        onRefresh: () => store.getPollingPlans(),
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: AspectRatio(
              aspectRatio: 1,
              child: Wisdom.column(
                alignment: Alignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Wisdom(
                    onTap: () => Route2business.scan2page(
                      context: context,
                      scene: ScanScene.pqc,
                    ),
                    borderRadius: BorderRadius.circular(56.pt),
                    child: Image.asset(
                      'lib/assets/qrscan.png',
                      width: 112.pt,
                      height: 112.pt,
                      package: 'qrcode_package',
                    ),
                  ),
                  SizedBox(height: 22.pt),
                  Text(
                    '扫描设备二维码',
                    style: TextStyle(color: colorScheme.minor),
                  ),
                ],
              ),
            ),
          ),
          if (store.pollingPlans.length != 0)
            WisSliverList.childBuilder(
              childCount: store.pollingPlans.length,
              padding: EdgeInsets.all(15.pt),
              builder: (_, i) {
                final item = store.pollingPlans[i];
                final planInfoList = store.pollingPlans[i].planInfoList ?? [];
                return Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    ExpansionTile(
                      title: Row(
                        children: <Widget>[
                          WisText(
                            (item.location ?? '') == '' ? '其他' : item.location!,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            weight: FontWeight.normal,
                            color: colorScheme.text,
                          ).asExpanded(),
                          Text(
                            '(${item.count ?? 0})',
                            style: textTheme.bodySmall!.copyWith(
                              color: colorScheme.danger,
                            ),
                          ),
                        ],
                      ),
                      children: <Widget>[
                        for (var index = 0;
                            index < planInfoList.length;
                            index++)
                          WisCell(
                            onTap: () => store.route2detail(
                              planInfoList[index].equipmentId,
                            ),
                            topDivider: WisCellDivider.fill,
                            color: colorScheme.background,
                            padding: EdgeInsets.all(10.pt),
                            title: Text.rich(
                              TextSpan(
                                text:
                                    '${planInfoList[index].equipmentName ?? ''}',
                                children: [
                                  TextSpan(
                                    text:
                                        '(剩余${planInfoList[index].date ?? 0}天)',
                                    style: TextStyle(
                                      color: colorScheme.danger,
                                    ),
                                  )
                                ],
                              ),
                            ),
                            trailing: Row(
                              children: <Widget>[
                                Text('详情'),
                                Icon(Icons.chevron_right),
                              ],
                            ),
                          ),
                      ],
                    ),
                    Divider(),
                  ],
                );
              },
            ),
        ],
      ),
    );
  }
}
