/*
 * @Author: WuWei
 * @Date: 2020-05-26 17:44:27
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-06 10:44:42
 * @Description:
 */

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

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

  @override
  Widget build(BuildContext context) {
    return ParkMainContainer();
  }
}

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

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

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

    return Column(
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        /// 搜索框
        SearchInput(
          placeholder: '请输入车位名称',
          title: store.parkingSpaceId,
          onInput: (v) => store.onInputPark(v),
          onCancel: () => store.onInputPark(''),
        ),

        /// 滚动列表
        Expanded(
          child: store.parkingSpaceId == ''
              ? ListEmpty()
              : WisScrollView(
                  key: store.scorllViewKey4,
                  onInit: () => store.initParkList(),
                  onLoad: () => store.getParkList(isLoad: true),
                  slivers: <Widget>[
                    WisSliverList.childBuilder(
                      childCount: store.parkList.length,
                      padding: EdgeInsets.symmetric(vertical: 5.pt),
                      builder: (_, i) {
                        var item = store.parkList[i];
                        // 列表项
                        return InkWell(
                          onTap: () => store.route2ParkDetail(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.code ?? ''}',
                                            color: Color(0xFF333333),
                                            bold: true,
                                            size: 18.pt,
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                          ).asFlexible(flex: 1),
                                        ],
                                      ),
                                      Wisdom.row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: <Widget>[
                                          WisText(
                                            '${item.parkingLotName ?? ''}',
                                            color: Color(0xFF999999),
                                            size: 12.pt,
                                            textAlign: TextAlign.left,
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                          ).asFlexible(flex: 1),
                                        ],
                                      )
                                    ],
                                  ),
                                ).asFlexible(flex: 1),

                                /// 列表项右侧
                                InkWell(
                                  // onTap: () => store.route2ResidentDetail(item),
                                  child: Wisdom.row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: <Widget>[
                                      if (item.type != null &&
                                          store.parkType[item.type] != null)
                                        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.parkType[item.type] ?? ''}',
                                              color: const Color(0xFF2D8CF0),
                                              size: 10.pt,
                                            )
                                          ],
                                        )
                                    ],
                                  ),
                                )
                              ],
                            ),
                          ),
                        );
                      },
                    )
                  ],
                ),
        ),
      ],
    );
  }
}
