/*
 * @Author       : WuWei
 * @LastEditors: wjc
 * @Date         : 2021-04-27 16:40:18
 * @LastEditTime: 2023-04-03 15:22:26
 * @FilePath     : /wisdom-huiguanjia-app/task_package/lib/src/pages/statistic/components/people.dart
 * @Description  : 任务统计-人员统计
 */
part of '../index.dart';

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

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<StatisticStore>(context, listen: false);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    return WisScrollView(
      slivers: [
        SliverToBoxAdapter(
          child: Observer(builder: (_) {
            return Column(
              children: [
                if (store.isStatShow) ...[
                  BuildAllTaskCard(),
                  BuildTaskListStat(),
                ] else ...[
                  Wisdom.row(
                      color: Color(0xFFFFFFFF),
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      margin: EdgeInsets.only(bottom: 5.pt),
                      children: <Widget>[
                        Expanded(
                          child: WSearch(
                            hintText: "输入人员姓名搜索",
                            onCancel: () => {store.onSearchEmployee('')},
                            onSubmitted: (v) => {store.onSearchEmployee(v)},
                            moonlight: false,
                            padding: EdgeInsets.symmetric(vertical: 10.pt),
                            isDark: true,
                          ),
                        )
                      ]),
                  WisCard(
                    margin:
                        EdgeInsets.only(left: 15.pt, right: 15.pt, top: 5.pt),
                    child: Wisdom.column(
                      padding: EdgeInsets.all(15.pt),
                      color: Colors.white,
                      children: [
                        Row(
                          children: [
                            WisText.c222(
                              "请先选择人员",
                              weight: FontWeight.w600,
                              size: 15.pt,
                            ),
                          ],
                        ),
                        Observer(builder: (_) {
                          return Column(
                            children: [
                              if (store.employeeList.length > 0) ...[
                                for (int i = 0;
                                    i < store.employeeList.length;
                                    i++)
                                  Wisdom.row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    margin: EdgeInsets.only(top: 10.pt),
                                    onTap: () => store.onSelectPeopleItem(i),
                                    children: [
                                      Row(
                                        children: [
                                          Observer(builder: (_) {
                                            return Wisdom(
                                              margin:
                                                  EdgeInsets.only(right: 20.pt),
                                              child: Image(
                                                image: store.employeeList[i]
                                                                .isSelect ==
                                                            null ||
                                                        store.employeeList[i]
                                                                .isSelect ==
                                                            false
                                                    ? AssetList.$dxH_png_image
                                                    : AssetList.$dxy_png_image,
                                                height: 17.pt,
                                              ),
                                            );
                                          }),
                                          Wisdom(
                                            margin:
                                                EdgeInsets.only(right: 4.pt),
                                            child: WisText.c222(
                                              "${store.employeeList[i].name}",
                                              weight: FontWeight.w600,
                                              size: 15.pt,
                                            ),
                                          )
                                        ],
                                      ),
                                      WisText.c666(
                                        "${store.employeeList[i].organName}",
                                        weight: FontWeight.w300,
                                        size: 14.pt,
                                      ).asFlexible(flex: 1),
                                    ],
                                  ),
                              ] else ...[
                                Observer(builder: (_) {
                                  return WEmptyWidget(
                                    text: Text(store.employeeName != null &&
                                            store.employeeName!.length > 0
                                        ? '搜索暂无数据'
                                        : '当前管理的部门人员为空，请先在后台添加部门人员'),
                                  );
                                }),
                              ]
                            ],
                          );
                        })
                      ],
                    ),
                  ),
                ],
                Wisdom.column(
                  padding: EdgeInsets.all(15.pt),
                  margin: EdgeInsets.only(bottom: 79.pt),
                  children: [
                    Wisdom.row(
                      margin: EdgeInsets.only(bottom: 15.pt),
                      children: [
                        WisText(
                          '统计说明',
                          size: 15.pt,
                          weight: FontWeight.w600,
                        ),
                      ],
                    ),
                    Row(
                      children: [
                        WisText(
                          '当前展示为后台为您授权的部门人员，若数据有误请联系管理员授权。',
                          size: 13.pt,
                          weight: FontWeight.w300,
                          color: colorScheme.placeholder,
                        ).asExpanded(),
                      ],
                    ),
                  ],
                ),
              ],
            );
          }),
        )
      ],
    );
  }
}
