/*
 * @Author: XianKaiQun
 * @Date: 2020-07-15 14:23:32
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-11-01 16:40:31
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:receipt_package/src/components/form_item.dart';
import 'package:receipt_package/src/view_models/private_submint_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

part 'components/card.dart';
part 'components/form.dart';
part 'components/pre_pay.dart';
part 'components/deposite_pay.dart';

class SubmintPage extends StatelessWidget {
  const SubmintPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) =>
          PrivateSubmintStore(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> {
  PrivateSubmintStore get store => Provider.of(context, listen: false);
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: WAppBar(
        brightness: Brightness.light,
        title: WisText('缴费录单',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
      ),
      body: WisForm(
        formKey: null,
        child: WisScrollView(
          onInit: () => store.onInit(),
          slivers: <Widget>[
            if (store.ptype == 'prePay') ...[
              _PrePayComponent(),
            ] else if (store.ptype == 'depositePay') ...[
              _DepositePayComponent(),
            ] else ...[
              _CardComponent(),
            ],
            _FormComponent(),
          ],
        ),
      ),
      bottomNavigationBar: SafeArea(
        child: Wisdom.row(
            height: 60.pt,
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 8.pt),
            children: [
              WLoadingButton(
                onPressed: () => store.submit(),
                height: 44.pt,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20.pt)),
                child: WisText(
                  '确认录单',
                  size: 18.pt,
                  bold: true,
                ),
              ).asExpanded(),
            ]),
      ),
    );
  }
}
