/*
 * @Author: WuWei
 * @Date: 2020-05-26 17:44:07
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-04 10:46:53
 * @Description:
 */

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

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

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

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

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

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

    return Column(
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        /// 搜索框
        SearchInput(
          placeholder: '请输入车主姓名/车牌号',
          title: store.carKeyWord,
          onInput: (v) => store.onInputCar(v),
          onCancel: () => store.onInputCar(''),
        ),

        /// 滚动列表
        Expanded(
          child: store.fuzzyCarNo == '' && store.ownerName == ''
              ? ListEmpty()
              : WisScrollView(
                  key: store.scorllViewKey3,
                  onInit: () => store.initCarList(),
                  onLoad: () => store.getCarList(isLoad: true),
                  slivers: <Widget>[
                    WisSliverList.childBuilder(
                      childCount: store.carList.length,
                      padding: EdgeInsets.symmetric(vertical: 5.pt),
                      builder: (_, i) {
                        var item = store.carList[i];
                        // 列表项
                        return InkWell(
                          onTap: () => store.route2CarDetail(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(
                                    child: Wisdom.column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: <Widget>[
                                        Wisdom.row(
                                          margin: EdgeInsets.fromLTRB(
                                              0, 0, 0, 5.pt),
                                          children: <Widget>[
                                            WisText(
                                              '${item.cardNo ?? ''}',
                                              color: Color(0xFF333333),
                                              bold: true,
                                              size: 18.pt,
                                              maxLines: 1,
                                              overflow: TextOverflow.ellipsis,
                                            ).asFlexible(flex: 1),
                                            Wisdom.row(
                                              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)),
                                              children: <Widget>[
                                                WisText(
                                                  '${store.carType[item.type] ?? ''}',
                                                  color:
                                                      const Color(0xFF2D8CF0),
                                                  size: 10.pt,
                                                )
                                              ],
                                            )
                                          ],
                                        ),
                                        Wisdom.row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: <Widget>[
                                            WisText(
                                              '车主：${item.ownerName ?? ''}',
                                              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.ownerMobile}'),
                                          margin: EdgeInsets.fromLTRB(
                                              0, 0, 10.pt, 0),
                                          children: <Widget>[
                                            WisText(
                                              '${item.ownerMobile ?? ''}',
                                              color: Color(0xFF666666),
                                              size: 14.pt,
                                            ),
                                          ],
                                        ),
                                        Wisdom(
                                          onTap: () =>
                                              launch('tel:${item.ownerMobile}'),
                                          child: Image.asset(
                                            'lib/assets/icon_call.png',
                                            width: 20.pt,
                                            height: 20.pt,
                                            package: 'search_package',
                                          ),
                                        )
                                      ],
                                    ),
                                  )
                                ],
                              )),
                        );
                      },
                    )
                  ],
                ),
        ),
      ],
    );
  }
}
