/*
 * @Author: XianKaiQun
 * @Date: 2020-07-15 11:26:26
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-08-19 09:44:19
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:receipt_package/src/models/deposit_detail.dart';
import 'package:receipt_package/src/view_models/private_deposit_detail_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class DepositDetailPage extends StatelessWidget {
  const DepositDetailPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) =>
          PrivateDepositDetailStore(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> {
  Map<String, String> imageMap = {
    'house': 'lib/assets/build.png',
    'car': 'lib/assets/car.png',
    'parkingSpace': 'lib/assets/park.png',
  };
  @override
  Widget build(BuildContext context) {
    PrivateDepositDetailStore store = Provider.of(context);

    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    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.getList(),
        onRefresh: () => store.getList(),
        slivers: <Widget>[
          for (DepositDetailModel item in store.list ?? [])
            WisCard(
              isSliver: true,
              margin: EdgeInsets.fromLTRB(15.pt, 10.pt, 15.pt, 0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Wisdom.row(
                    padding: EdgeInsets.all(15.pt),
                    children: [
                      Image.asset(
                        imageMap[item.chargeSubject!]!,
                        package: 'receipt_package',
                        width: 20.pt,
                      ),
                      Text(
                        ' ' + item.assetFullName!,
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 16.pt,
                        ),
                      ).asExpanded(),
                    ],
                  ),
                  Divider(),
                  if (item.generalPrepayFee != null) ...[
                    Wisdom.row(
                      padding: EdgeInsets.all(15.pt),
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('通用预存款余额'),
                        Text(
                          '￥${item.generalPrepayFee}',
                          style: TextStyle(color: Color(0XFFFF495E)),
                        ),
                      ],
                    ),
                    Divider(),
                  ],
                  if (item.specialPrepayFee != null) ...[
                    Wisdom.row(
                      padding: EdgeInsets.all(10.pt),
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('专项预存款余额'),
                        Text(
                          '￥${item.specialPrepayFee}',
                          style: TextStyle(color: Color(0XFFFF495E)),
                        ),
                      ],
                    ),
                    Divider(),
                  ],
                  if (item.specialPrePayInfos?.length != 0) ...[
                    Wisdom.column(
                      margin: EdgeInsets.all(10.pt),
                      color: colorScheme.background,
                      children: ListTile.divideTiles(
                        context: context,
                        tiles: [
                          for (var child in item.specialPrePayInfos!)
                            Wisdom.row(
                              padding: EdgeInsets.all(10.pt),
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text('${child.feeName}'),
                                Text('￥${child.fee}'),
                              ],
                            ),
                        ],
                      ).toList(),
                    ),
                    Divider(),
                  ],
                  if (item.customizePrepayFee != null) ...[
                    Wisdom.row(
                      padding: EdgeInsets.all(10.pt),
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('自定义预存款余额'),
                        Text(
                          '￥${item.customizePrepayFee}',
                          style: TextStyle(color: Color(0XFFFF495E)),
                        ),
                      ],
                    ),
                    Divider(),
                  ],
                  if (item.customizePrePayInfos?.length != 0)
                    Wisdom.column(
                      margin: EdgeInsets.all(10.pt),
                      color: colorScheme.background,
                      children: ListTile.divideTiles(
                        context: context,
                        tiles: [
                          for (var child in item.customizePrePayInfos!)
                            Wisdom.row(
                              padding: EdgeInsets.all(10.pt),
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text('${child.feeName}'),
                                Text('￥${child.fee}'),
                              ],
                            ),
                        ],
                      ).toList(),
                    ),
                ],
              ),
            ),
        ],
      ),
    );
  }
}
