/*
 * @Author: WuWei
 * @Date: 2020-05-26 17:25:46
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-04 11:20:04
 * @Description:
 */
part of '../../index.dart';

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

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

final Map houseType = {
  'dwelling': '住宅',
  'shop': '商铺',
  'virtual': '虚拟',
  'villa': '别墅',
  'office': '办公',
  'apartment': '公寓',
  'hotel': '酒店',
  'lowrent': '廉租房',
  'economic': '经适房',
};

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

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

class _HouseMainContainerState extends State<HouseMainContainer> {
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<SearchIndexStore>(context);
    return Column(
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        /// 搜索框
        SearchInput(
          placeholder: '请输入房屋名称',
          title: store.roomNo,
          onInput: (v) => store.onInputRoomNo(v),
          onCancel: () => store.onInputRoomNo(''),
        ),

        /// 滚动列表
        Expanded(
          child: store.roomNo == ''
              ? ListEmpty()
              : WisScrollView(
                  key: store.scorllViewKey2,
                  onInit: () => store.initHouseList(),
                  onLoad: () => store.getHouseList(isLoad: true),
                  // onRefresh: () => store.getHouseList(isLoad: false),
                  slivers: <Widget>[
                    WisSliverList.childBuilder(
                      childCount: store.houseList.length,
                      padding: EdgeInsets.symmetric(vertical: 5.pt),
                      builder: (_, i) {
                        var item = store.houseList[i];
                        // 列表项
                        return InkWell(
                          onTap: () => store.route2HouseDetail(item),
                          child: WisCard(
                            color: Colors.white,
                            margin: EdgeInsets.symmetric(
                                horizontal: 15.pt, vertical: 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.roomNo}',
                                            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.buildName ?? ''}/${item.unitName ?? ''}/${item.houseFloor ?? ''}',
                                            color: Color(0xFF999999),
                                            size: 12.pt,
                                            textAlign: TextAlign.left,
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                          ).asFlexible(flex: 1),
                                        ],
                                      )
                                    ],
                                  ),
                                ).asFlexible(flex: 1),

                                /// 列表项右侧
                                InkWell(
                                  child: Wisdom.row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: <Widget>[
                                      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(
                                            '${houseType[item.type] ?? ''}',
                                            color: const Color(0xFF2D8CF0),
                                            size: 10.pt,
                                          )
                                        ],
                                      )
                                    ],
                                  ),
                                )
                              ],
                            ),
                          ),
                        );
                      },
                    ),
                  ],
                ),
        ),
      ],
    );
  }
}
