/*
 * @Author: XianKaiQun
 * @Date: 2020-09-16 10:12:34
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-06 11:30:57
 * @Description: 
 */
part of '../index.dart';

class _TableComponent extends StatelessWidget {
  const _TableComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    final store = Provider.of<PrivateDetailStore>(context);

    return Wisdom.column(
      color: colorScheme.background4,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Wisdom.row(
          padding: EdgeInsets.symmetric(horizontal: 15.pt),
          margin: EdgeInsets.only(bottom: 5.pt),
          children: [
            Wisdom.row(
              children: [
                Wisdom(
                  height: 20.pt,
                  width: 3.pt,
                  color: colorScheme.primary,
                  margin: EdgeInsets.only(
                    right: 10.pt,
                    left: 10.pt,
                  ),
                  borderRadius: BorderRadius.circular(4.pt),
                ),
                WisText(
                  '抄表记录',
                  color: colorScheme.mainTitle,
                  weight: FontWeight.w600,
                  size: 15.pt,
                ),
              ],
            ),
          ],
        ),
        if (store.list.length == 0)
          Container(
            alignment: Alignment.center,
            child: WEmptyWidget(
              text: Text('空空如也~'),
            ),
            height: 300.pt,
          )
        else
          WisScrollView(
            slivers: <Widget>[
              WisSliverList.childBuilder(
                childCount: store.list.length,
                builder: (context, index) {
                  final item = store.list[index];
                  return WisCard(
                    color: Colors.white,
                    margin:
                        EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
                    padding: EdgeInsets.all(15.pt),
                    child: Wisdom.column(
                      children: [
                        Wisdom.row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          margin: EdgeInsets.only(bottom: 15.pt),
                          children: [
                            Text.rich(
                              TextSpan(
                                children: [
                                  WidgetSpan(
                                    alignment: PlaceholderAlignment.middle,
                                    child: Image(
                                      image: AssetList.$date_png_image,
                                      width: 22.pt,
                                      height: 22.pt,
                                    ),
                                  ),
                                  TextSpan(
                                    text: ' ${item.readerDate ?? ''}',
                                    style: TextStyle(
                                      fontSize: 16.pt,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                ],
                              ),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ).nestExpanded(),
                            WisText(
                              '${item.readerName ?? '--'}',
                              color: colorScheme.grey,
                            )
                          ],
                        ),
                        Wisdom.row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            Wisdom.column(
                              height: 56.pt,
                              width: 99.pt,
                              color: colorScheme.background4,
                              borderRadius: BorderRadius.circular(8.pt),
                              margin: EdgeInsets.symmetric(horizontal: 5.pt),
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                WisText('${item.transcribeAmount ?? ''}'),
                                Wisdom(
                                  margin: EdgeInsets.only(top: 3.pt),
                                  child: WisText(
                                    '抄表读数',
                                    color: colorScheme.grey,
                                    size: 12.pt,
                                  ),
                                ),
                              ],
                            ).asFlexible(flex: 1),
                            Wisdom.column(
                              height: 56.pt,
                              width: 99.pt,
                              color: colorScheme.background4,
                              borderRadius: BorderRadius.circular(5.pt),
                              margin: EdgeInsets.symmetric(horizontal: 8.pt),
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                WisText('${item.actualAmount ?? ''}'),
                                Wisdom(
                                  margin: EdgeInsets.only(top: 3.pt),
                                  child: WisText(
                                    '实际行度',
                                    color: colorScheme.grey,
                                    size: 12.pt,
                                  ),
                                ),
                              ],
                            ).asFlexible(flex: 1),
                            Wisdom.column(
                              height: 56.pt,
                              width: 99.pt,
                              color: colorScheme.background4,
                              borderRadius: BorderRadius.circular(8.pt),
                              margin: EdgeInsets.symmetric(horizontal: 5.pt),
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                WisText('${item.chargeAmount ?? ''}'),
                                Wisdom(
                                  margin: EdgeInsets.only(top: 3.pt),
                                  child: WisText(
                                    '计费行度',
                                    color: colorScheme.grey,
                                    size: 12.pt,
                                  ),
                                ),
                              ],
                            ).asFlexible(flex: 1),
                          ],
                        ),
                       if(index == 0) ...[
                         Wisdom.row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          margin: EdgeInsets.only(top: 10.pt),
                          children: [
                            WButton(
                              onPressed: () => store.cancelMeterRead(item),
                              color:  colorScheme.red,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(20.pt),
                              ),
                              child: WisText('撤销抄表'),
                            )
                          ],
                        )
                       ]
                      ],
                    ),
                  );
                },
              ),
            ],
          ).asExpanded(),
      ],
    ).nestExpanded();
  }
}

// _BlockDetail(num readNumber, String name) async {
//   return Wisdom.column(
//     height: 55.pt,
//     width: 99.pt,
//     color: colorScheme.background4,
//     borderRadius: BorderRadius.circular(8.pt),
//     margin: EdgeInsets.symmetric(vertical: 15.pt),
//     mainAxisAlignment: MainAxisAlignment.center,
//     crossAxisAlignment: CrossAxisAlignment.center,
//     children: [
//       WisText('${readNumber ?? '--'}'),
//       WisText('${name ?? '--'}', color: colorScheme.minor),
//     ],
//   );
// }
