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

class _PrePayComponent extends StatelessWidget {
  const _PrePayComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<PrivateSubmintStore>(context);

    return SliverToBoxAdapter(
      child: WisCard(
        margin: EdgeInsets.only(
          top: 15.pt,
          bottom: 10.pt,
          left: 15.pt,
          right: 15.pt,
        ),
        child: Wisdom.column(
          padding: EdgeInsets.fromLTRB(0, 15.pt, 15.pt, 5.pt),
          children: <Widget>[
            FormItemComponent(
              leadingText: '预存资产',
              must: true,
              child: TextFormField(
                controller:
                    TextEditingController(text: store.preAssetItem?.name),
                readOnly: true,
                onTap: () => store.choosePreAsset(),
                decoration: InputDecoration(
                  filled: true,
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4.pt),
                    borderSide: BorderSide.none,
                  ),
                  fillColor: colorScheme.background4,
                  hintText: '选择预存资产',
                  suffixIcon: Icon(
                    Icons.arrow_right_rounded,
                    color: colorScheme.placeholder2,
                    size: 30.pt,
                  ),
                  suffixIconConstraints: BoxConstraints(),
                ),
              ),
            ),
            FormItemComponent(
              leadingText: '预存项目',
              must: true,
              child: TextFormField(
                controller: TextEditingController(
                    text: store.preFeeChargeItem?.feeName),
                readOnly: true,
                onTap: () => store.choosePrefeeCharge(),
                decoration: InputDecoration(
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4.0.pt),
                    borderSide: BorderSide(color: Colors.white),
                  ),
                  fillColor: colorScheme.background4,
                  hintText: '选择预存项目',
                  suffixIcon: Icon(
                    Icons.arrow_right_rounded,
                    color: colorScheme.placeholder2,
                    size: 30.pt,
                  ),
                  suffixIconConstraints: BoxConstraints(),
                ),
              ),
            ),
            if (store.preFeeChargeItem?.identification != null) ...[
              if (store.preFeeChargeItem?.prepay == true) ...[
                FormItemComponent(
                  leadingText: '每月费用',
                  child: Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    color: colorScheme.background4,
                    padding: EdgeInsets.fromLTRB(15.pt, 10.pt, 5.pt, 10.pt),
                    // borderRadius: BorderRadius.circular(4.pt),
                    children: [
                      WisText(
                        '${store.preFeeChargeItem?.receivableFee != null ? store.preFeeChargeItem?.receivableFee : ''}',
                        color: colorScheme.placeholder2,
                      ),
                    ],
                  ),
                ),
                FormItemComponent(
                  leadingText: '预存金额',
                  child: Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    color: colorScheme.background4,
                    padding: EdgeInsets.fromLTRB(15.pt, 10.pt, 5.pt, 10.pt),
                    // borderRadius: BorderRadius.circular(4.pt),
                    children: [
                      WisText(
                        '${store.preFee ?? 0}',
                        color: colorScheme.placeholder2,
                      ),
                    ],
                  ),
                )
              ],
              FormItemComponent(
                must: true,
                crossAxisAlignment: CrossAxisAlignment.center,
                leadingText:
                    store.preFeeChargeItem?.prepay == true ? '预存月份' : '预存金额',
                child: TextField(
                  textAlign: TextAlign.left,
                  style: TextStyle(
                    fontSize: 15.pt,
                    color: colorScheme.primary,
                  ),
                  keyboardType: TextInputType.numberWithOptions(
                    decimal:
                        store.preFeeChargeItem.prepay == true ? false : true,
                  ),
                  decoration: InputDecoration(
                    fillColor: colorScheme.background4,
                    hintText: store.preFeeChargeItem.prepay == true
                        ? '输入预存月份'
                        : '输入预存金额',
                    hintStyle: TextStyle(
                      fontSize: 14.pt,
                      color: colorScheme.placeholder2,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                  scrollPadding: EdgeInsets.zero,
                  onChanged: (value) {
                    String trimmedValue = value.trim();
                    store.inputPrefee(trimmedValue);
                  },
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
