/*
 * @Author: XianKaiQun
 * @Date: 2020-08-18 18:20:14
 * @LastEditors: ,: XianKaiQun
 * @LastEditTime: ,: 2020-10-20 11:35:56
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:receipt_package/src/view_models/private_success_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

// part 'components/list.dart';

class SuccessPage extends StatelessWidget {
  const SuccessPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) =>
          PrivateSuccessStore(context, providerContext),
      child: _PageView(),
      lazy: false,
    );
  }
}

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);
  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    // PrivateSuccessStore store = Provider.of(context);
    // final data = store.data;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('收单成功',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(
        // onInit: () => store.getData(),
        // onRefresh: () => store.getData(),
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: Wisdom.column(
              margin: EdgeInsets.symmetric(vertical: 30.pt, horizontal: 15.pt),
              children: [
                Image.asset(
                  'lib/assets/success.png',
                  package: 'receipt_package',
                  width: 60.pt,
                ),
                Text(
                  '收单成功',
                  style: TextStyle(
                    fontSize: 20.pt,
                    fontWeight: FontWeight.bold,
                    height: 3,
                  ),
                ),
              ],
            ),
          ),
          WButton(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(20.pt),
            ),
            onPressed: () => Navigator.pop(context, {
              'isRefresh': true,
            }),
            margin: EdgeInsets.all(15.pt),
            height: 45.pt,
            child: Text('继续收单'),
          ).asSliver(),
          // if (data != null)
          //   WisCard(
          //     margin: EdgeInsets.all(15.pt),
          //     padding: EdgeInsets.all(15.pt),
          //     isSliver: true,
          //     child: Column(
          //       crossAxisAlignment: CrossAxisAlignment.stretch,
          //       children: [
          //         Text(
          //           '${data.assetFullName}',
          //           style: TextStyle(
          //             fontWeight: FontWeight.bold,
          //             fontSize: 16.pt,
          //           ),
          //         ),
          //         Divider(height: 20.pt),
          //         _RowText('账单缴费', '￥${data.totalPayFee}'),
          //         _RowText('实收金额', '￥${data.receivedFee}'),
          //         if ((data.excessFee ?? 0) > 0)
          //           _RowText('超额金额', '￥${data.excessFee}'),
          //         if ((data.excessFee ?? 0) > 0)
          //           _RowText('存入预存款', '${data.feeName}'),
          //       ],
          //     ),
          //   ),
          // if (data != null)
          //   Wisdom.column(
          //     margin: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 15.pt),
          //     padding: EdgeInsets.all(10.pt),
          //     children: [
          //       _RowText('缴费人', '${data.payer}'),
          //       _RowText('支付时间', '${data.payAt}'),
          //       _RowText('缴费备注', '${data.remark}'),
          //       _RowText('收据号', () {
          //         return data.tickets
          //                 ?.where((e) => e.ticketType == 'receipt')
          //                 .toList()
          //                 .map((e) => e.ticketNo)
          //                 .join('、') ??
          //             '--';
          //       }()),
          //       _RowText('发票号', () {
          //         return data.tickets
          //                 ?.where((e) => e.ticketType == 'invoice')
          //                 .toList()
          //                 .map((e) => e.ticketNo)
          //                 .join('、') ??
          //             '--';
          //       }()),
          //     ],
          //   ).asSliver(),
        ],
      ),
    );
  }
}

class _RowText extends StatelessWidget {
  const _RowText(this.leadingText, this.valueText, {Key? key})
      : super(key: key);
  final String leadingText;
  final String valueText;
  @override
  Widget build(BuildContext context) {
    return Wisdom.row(
      padding: EdgeInsets.symmetric(vertical: 10.pt),
      children: [
        SizedBox(
          width: 80.pt,
          child: Text('$leadingText'),
        ),
        Text(
          '$valueText',
          textAlign: TextAlign.end,
        ).asExpanded(),
      ],
    );
  }
}
