/*
 * @Author: WuWei
 * @Date: 2020-05-26 17:38:49
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-04 10:44:36
 * @Description:
 */

part of '../../index.dart';

class _TabResidentComponent extends StatelessWidget {
  const _TabResidentComponent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => SearchIndexStore(context),
      child: MainContainer(),
    );
  }
}

class MainContainer extends StatefulWidget {
  MainContainer({Key? key}) : super(key: key);

  @override
  _MainContainerState createState() => _MainContainerState();
}

class _MainContainerState extends State<MainContainer> {
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<SearchIndexStore>(context);

    return Column(
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        /// 搜索框
        SearchInput(
          placeholder: '请输入住户姓名/手机号',
          title: store.residentKeyWord,
          onInput: (v) => store.onInputResident(v),
          onCancel: () => store.onInputResident(''),
        ),

        /// 滚动列表
        Expanded(
          child: store.residentname == '' && store.residentMobile == ''
              ? ListEmpty()
              : WisScrollView(
                  key: store.scorllViewKey1,
                  onInit: () => store.initResidentList(),
                  onLoad: () => store.getResidentList(isLoad: true),
                  slivers: <Widget>[
                    WisSliverList.childBuilder(
                      childCount: store.residentList.length,
                      padding: EdgeInsets.symmetric(vertical: 5.pt),
                      builder: (_, i) {
                        var item = store.residentList[i];
                        // 列表项
                        return InkWell(
                          onTap: () => store.route2ResidentDetail(item),
                          borderRadius: BorderRadius.circular(6.pt),
                          child: WisCard(
                              color: Colors.white,
                              margin: EdgeInsets.symmetric(
                                  horizontal: 15.pt, vertical: 5.pt),
                              shadowColor: Color(0x40000000),
                              elevation: 5.pt,
                              child: Wisdom.row(
                                minHeight: 62.pt,
                                padding: EdgeInsets.fromLTRB(
                                    15.pt, 10.pt, 15.pt, 10.pt),
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: <Widget>[
                                  /// 列表项左侧
                                  Wisdom(
                                    margin: EdgeInsets.only(right: 10.pt),
                                    child: Wisdom.column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: <Widget>[
                                        Wisdom.row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          margin: EdgeInsets.fromLTRB(
                                              0, 0, 0, 5.pt),
                                          children: <Widget>[
                                            WisText(
                                              '${item.name ?? ''}',
                                              color: Color(0xFF333333),
                                              bold: true,
                                              size: 18.pt,
                                              maxLines: 1,
                                              overflow: TextOverflow.ellipsis,
                                            ).asFlexible(flex: 1),
                                            Wisdom(
                                              margin: EdgeInsets.fromLTRB(
                                                  10.pt, 0, 0, 0),
                                              padding: EdgeInsets.fromLTRB(
                                                  5.pt, 1.pt, 5.pt, 1.pt),
                                              borderRadius:
                                                  BorderRadius.circular(8.5.pt),
                                              border: Border.all(
                                                  width: 1.pt,
                                                  color:
                                                      const Color(0xFF2D8CF0)),
                                              child: WisText(
                                                '${item.identity ?? ''}',
                                                color: const Color(0xFF2D8CF0),
                                                size: 10.pt,
                                              ),
                                            )
                                          ],
                                        ),
                                        Wisdom.row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: <Widget>[
                                            WisText(
                                              '${item.buildName ?? ''}/${item.unitName ?? ''}/${item.roomNo ?? ''}',
                                              color: Color(0xFF999999),
                                              size: 12.pt,
                                              textAlign: TextAlign.left,
                                            ),
                                          ],
                                        )
                                      ],
                                    ),
                                  ).asFlexible(flex: 1),

                                  /// 列表项右侧
                                  InkWell(
                                    // onTap: () => store.route2ResidentDetail(item),
                                    child: Wisdom.row(
                                      children: <Widget>[
                                        Wisdom.row(
                                          onTap: () =>
                                              launch('tel:${item.mobile}'),
                                          margin: EdgeInsets.fromLTRB(
                                              0, 0, 10.pt, 0),
                                          children: <Widget>[
                                            WisText(
                                              '${item.mobile ?? ''}',
                                              color: Color(0xFF666666),
                                              size: 14.pt,
                                            ),
                                          ],
                                        ),
                                        Wisdom(
                                          onTap: () =>
                                              launch('tel:${item.mobile}'),
                                          child: Image.asset(
                                            'lib/assets/icon_call.png',
                                            width: 20.pt,
                                            height: 20.pt,
                                            package: 'search_package',
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ],
                              )),
                        );
                      },
                    )
                  ],
                ),
        ),
      ],
    );
  }
}
