/*
 * @Author: XianKaiQun
 * @Date: 2020-08-17 17:01:06
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-11-01 16:36:42
 * @Description: 
 */
part of '../index.dart';

class _CardComponent extends StatelessWidget {
  const _CardComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateSubmintStore>(context);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
//final theme = Theme.of(context);
//final textTheme = theme.textTheme;
    return SliverToBoxAdapter(
      child: WisCard(
        margin: EdgeInsets.all(15.pt),
        padding: EdgeInsets.all(10.pt),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Row(
              children: [
                Wisdom.row(
                  margin: EdgeInsets.only(right: 10.pt),
                  gradient: LinearGradient(
                    colors: [
                      Color(0x99F99B1A),
                      const Color(0xFFF99B1A),
                    ],
                  ),
                  mainAxisAlignment: MainAxisAlignment.center,
                  padding: EdgeInsets.fromLTRB(0, 10.pt, 0, 10.pt),
                  borderRadius: BorderRadius.circular(4.pt),
                  children: [
                    WisText(
                      '账单:',
                      color: Colors.white,
                    ),
                    SizedBox(width: 5.pt),
                    WisText(
                      '${store.payFee != null ? store.payFee : 0}',
                      color: Colors.white,
                    ),
                  ],
                ).asFlexible(flex: 1),
                Wisdom.row(
                  gradient: LinearGradient(
                    colors: [
                      Color(0x9927CEAC),
                      const Color(0xFF27CEAC),
                    ],
                  ),
                  margin: EdgeInsets.only(right: 10.pt),
                  color: colorScheme.background4,
                  mainAxisAlignment: MainAxisAlignment.center,
                  padding: EdgeInsets.fromLTRB(0, 10.pt, 0, 10.pt),
                  borderRadius: BorderRadius.circular(4.pt),
                  children: [
                    WisText(
                      '预存款:',
                      color: Colors.white,
                    ),
                    SizedBox(width: 5.pt),
                    WisText(
                      '${store.preFee != null ? store.preFee : 0}',
                      color: Colors.white,
                    ),
                  ],
                ).asFlexible(flex: 1),
                Wisdom.row(
                  gradient: LinearGradient(
                    colors: [
                      Color(0x990F67F8),
                      const Color(0xFF0F67F8),
                    ],
                  ),
                  color: colorScheme.background4,
                  padding: EdgeInsets.fromLTRB(0, 10.pt, 0, 10.pt),
                  mainAxisAlignment: MainAxisAlignment.center,
                  borderRadius: BorderRadius.circular(4.pt),
                  children: [
                    WisText(
                      '押金:',
                      color: Colors.white,
                    ),
                    SizedBox(width: 5.pt),
                    WisText(
                      '${store.depositeFee != null ? store.depositeFee : 0}',
                      color: Colors.white,
                    ),
                  ],
                ).asFlexible(flex: 1),
              ],
            ),
            Divider(height: 20.pt),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text.rich(
                  TextSpan(
                    text: '总计：',
                    children: [
                      TextSpan(
                        text: '￥${store.total ?? 0}',
                        style: TextStyle(
                            color: colorScheme.danger,
                            fontWeight: FontWeight.bold,
                            fontSize: 15.pt),
                      ),
                    ],
                  ),
                ),
                // Wisdom(
                //   onTap: () => store.isAdvanceChange(),
                //   child: Text(
                //     store.isAdvance ? '取消超额缴纳' : '超额缴纳',
                //     style: TextStyle(color: colorScheme.primary),
                //   ),
                // ),
              ],
            ),
            if (store.isAdvance) ...[
              Divider(height: 20.pt),
              Wisdom.row(
                crossAxisAlignment: CrossAxisAlignment.center,
                padding: EdgeInsets.only(bottom: 10.pt),
                children: [
                  Wisdom(
                    padding: EdgeInsets.only(
                        bottom: double.tryParse(store.totalValueText) == null ||
                                store.totalPrePayFee == 0
                            ? 20.pt
                            : 0),
                    width: 80.pt,
                    child: WisText(
                      '实收金额',
                      size: 15.pt,
                    ),
                  ),
                  TextFormField(
                    autovalidateMode: AutovalidateMode.always,
                    validator: (value) {
                      if (double.tryParse(value!) == null) {
                        return '请输入正确金额';
                      } else if (store.totalPrePayFee == 0) {
                        return '超额缴费实收金额必须大于总金额';
                      }
                      return null;
                    },
                    onChanged: (v) => store.totalValueChange(v),
                  ).asExpanded(),
                ],
              ),
              // FormItemComponent(
              //   crossAxisAlignment: CrossAxisAlignment.start,
              //   leadingText: '实收金额',
              //   child: TextFormField(
              //     autovalidateMode: AutovalidateMode.always,
              //     validator: (value) {
              //       if (double.tryParse(value) == null) {
              //         return '请输入正确金额';
              //       } else if (store.totalPrePayFee == 0) {
              //         return '超额缴费实收金额必须大于总金额';
              //       }
              //       return null;
              //     },
              //     onChanged: (v) => store.totalValueChange(v),
              //   ),
              // ),
              FormItemComponent(
                leadingText: '超额金额',
                child: Wisdom(
                  padding: EdgeInsets.all(10.pt),
                  child: Text(
                    '￥${store.totalPrePayFee}',
                    style: TextStyle(
                      fontSize: 15.pt,
                    ),
                  ),
                ),
              ),
              FormItemComponent(
                leadingText: '预存款项目',
                child: TextFormField(
                  controller: TextEditingController(text: store.advanceText),
                  maxLines: 4,
                  minLines: 1,
                  readOnly: true,
                  onTap: () => store.advancePicker(),
                  decoration: InputDecoration(
                    suffixIcon: Icon(Icons.chevron_right),
                    suffixIconConstraints: BoxConstraints(),
                  ),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
