/*
 * @Author: WuWei
 * @Date: 2020-07-15 14:52:09
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-30 15:47:59
 * @Description:
 */
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../view_models/private_detail_model.dart';

class AcceptPage extends StatelessWidget {
  const AcceptPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => RepairDetailStore(context),
      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;
    final store = Provider.of<RepairDetailStore>(context, listen: true);
    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(
        slivers: <Widget>[
          SliverToBoxAdapter(
              child: Wisdom.column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              WisCard(
                elevation: 0,
                margin: EdgeInsets.symmetric(horizontal: 15.pt),
                child: Wisdom.row(
                  onTap: () => store.showChooseperson(),
                  height: 54.pt,
                  padding: EdgeInsets.symmetric(horizontal: 15.pt),
                  color: Colors.white,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    WFormTile(
                      required: true,
                      leading: Text(
                        '维修师傅',
                        style: TextStyle(
                            fontSize: 15.pt, fontWeight: FontWeight.w400),
                      ),
                    ),
                    Wisdom.row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      padding: EdgeInsets.only(left: 30.pt),
                      children: <Widget>[
                        if (store.dealPerson?.name == null)
                          Text(
                            '请选择',
                            style: TextStyle(
                                fontSize: 15.pt, color: colorScheme.grey),
                            textAlign: TextAlign.left,
                          )
                        else
                          Text(
                            '${store.dealPerson?.name ?? ''} ${store.dealPerson?.positionName ?? ''}',
                            style: TextStyle(
                              fontSize: 15.pt,
                              fontWeight: FontWeight.w700,
                            ),
                            textAlign: TextAlign.left,
                          ),
                        Container(
                          // padding: EdgeInsets.only(right: 15.pt),
                          alignment: Alignment.centerRight,
                          child: Icon(Icons.chevron_right,
                              color: Color(0xff656565)),
                        ).asExpanded()
                      ],
                    ).asExpanded()
                  ],
                ),
              ),
              WisCard(
                color: Colors.white,
                padding: EdgeInsets.only(top: 15.pt),
                margin: EdgeInsets.symmetric(vertical: 15.pt),
                elevation: 0,
                shape: BeveledRectangleBorder(),
                child: Wisdom.column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Wisdom(
                      padding: EdgeInsets.only(left: 15.pt),
                      child: Text(
                        '备注',
                        style: TextStyle(
                          fontSize: 15.pt,
                          color: Color(0xff222222),
                        ),
                      ),
                    ),
                    Wisdom(
                      padding: EdgeInsets.only(bottom: 12.pt, left: 6.pt),
                      child: TextFormField(
                        initialValue: store.remark,
                        style: TextStyle(fontWeight: FontWeight.bold),
                        onChanged: (v) => store.remarkChange(v),
                        scrollPadding: EdgeInsets.zero,
                        decoration: InputDecoration(
                          fillColor: Colors.white,
                          contentPadding: EdgeInsets.all(9.pt),
                          hintText: '请输入备注，请勿重复报修',
                        ),
                        minLines: 5,
                        maxLines: 5,
                        maxLength: 256,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          )),
          SliverToBoxAdapter(
            child: Wisdom.column(
              padding: EdgeInsets.symmetric(horizontal: 15.pt),
              children: [
                WLoadingWrapper(
                  action: () => store.putAccept(),
                  size: 44.pt,
                  builder: (_, method, child) {
                    return Wisdom(
                      height: 44.pt,
                      borderRadius: BorderRadius.all(Radius.circular(4.pt)),
                      onTap: method,
                      color: colorScheme.primary,
                      alignment: Alignment.center,
                      child: child,
                    );
                  },
                  child: Wisdom(
                    height: 44.pt,
                    borderRadius: BorderRadius.all(Radius.circular(4.pt)),
                    alignment: Alignment.center,
                    child: Text(
                      '确认受理',
                      style: TextStyle(color: Colors.white, fontSize: 16.pt),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
