/*
 * @Author: WuXiangNan
 * @Date: 2021-04-20 16:13:35
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-02-03 10:13:53
 * @FilePath: /wisdom-huiguanjia-app/business_package/lib/src/pages/data/data.dart
 * @Description: 数据
 */

part of '../index.dart';

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

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

class __DataPageViewState extends State<_DataPageView> {
  BusinessStore get businessStore =>
      Provider.of<BusinessStore>(context, listen: false);
  String domain = '';

  @override
  void initState() {
    super.initState();
    businessStore.getData();
    switch (businessStore.dataType) {
      case 'day':
        domain = '日';
        break;
      case 'month':
        domain = '月';
        break;
      case 'year':
        domain = '年';
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    BusinessStore businessStore = Provider.of<BusinessStore>(context);
    final colorScheme = WTheme.of(context).colorScheme;

    return ListView(
      children: [
        Wisdom(
          child: Wisdom.row(
            margin: EdgeInsets.fromLTRB(15.pt, 10.pt, 15.pt, 10.pt),
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              WisText(
                '数据统计截止日期：',
                color: colorScheme.minor,
              ),
              WisText(
                // 最早可查询的数据均为上一天
                businessStore.dataType == 'day'
                    ? DateFormat("yyyy-MM-dd")
                        .format(DateTime.now().add(Duration(days: -1)))
                    :
                    // businessStore.dataType == 'month' ?
                    DateFormat("yyyy-MM").format(DateTime(DateTime.now().year,
                        DateTime.now().month - 1, DateTime.now().day)),
                // :
                // DateFormat("yyyy-MM-dd").format(DateTime.now()),
                color: colorScheme.primary,
              )
            ],
          ),
        ),
        // 绘服务数据
        Wisdom(
          child: Wisdom.column(
            // height: 200.pt,
            color: Colors.white,
            padding: EdgeInsets.all(15.pt),
            margin: EdgeInsets.only(bottom: 10.pt),
            children: [
              _buildTitle('绘服务数据'),
              Wisdom.row(
                margin: EdgeInsets.symmetric(vertical: 10.pt),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Wisdom(
                    width: 108.pt,
                    height: 98.pt,
                    color: Color(0xFFF5F7F9),
                    child: Wisdom.column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image(
                          image: AssetList.$yh_png_image,
                          height: 30,
                          width: 30,
                        ),
                        Wisdom.column(
                          margin: EdgeInsets.only(top: 10),
                          children: [
                            WisText(
                              '关注用户',
                              color: colorScheme.minor,
                              size: 14.pt,
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            WisText(
                              '${businessStore.platformData.onUsers}',
                              bold: true,
                              size: 13.pt,
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                  Wisdom(
                    width: 108.pt,
                    height: 98.pt,
                    color: Color(0xFFF5F7F9),
                    child: Wisdom.column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image(
                          image: AssetList.$zhh_png_image,
                          height: 30,
                          width: 30,
                        ),
                        Wisdom.column(
                          margin: EdgeInsets.only(top: 10),
                          children: [
                            WisText(
                              '关注住户',
                              color: colorScheme.minor,
                              size: 14.pt,
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            WisText(
                              '${businessStore.platformData.onHouseholds}',
                              bold: true,
                              size: 13.pt,
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                  Wisdom(
                    width: 108.pt,
                    height: 98.pt,
                    color: Color(0xFFF5F7F9),
                    child: Wisdom.column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image(
                          image: AssetList.$hsh_png_image,
                          height: 30,
                          width: 30,
                        ),
                        Wisdom.column(
                          margin: EdgeInsets.only(top: 10),
                          children: [
                            WisText(
                              '关注户数',
                              color: colorScheme.minor,
                              size: 14.pt,
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            Wisdom.row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  WisText(
                                    '${businessStore.platformData.onHouses}',
                                    bold: true,
                                    size: 13.pt,
                                  ),
                                  // WisText(
                                  //   '(34.1%)',
                                  //   bold: true,
                                  //   size: 13.pt,
                                  //   color: Color(0XFF27CEAC),
                                  // ),
                                ])
                          ],
                        )
                      ],
                    ),
                  ),
                ],
              ),

              // 折线图
              if (businessStore.dataType != 'year')
                Wisdom.column(
                  children: [
                    _buildPlatformChartTagRow(),
                    // Wisdom(
                    //   height: 200,
                    //   // width: 300,
                    //   child: CustomAxisTickFormatters.withSampleData(
                    //       businessStore.platformDataLineChartLine,
                    //       businessStore.dataType),
                    // )
                  ],
                )
            ],
          ),
        ),
        // 收费数据
        Wisdom(
          child: Wisdom.column(
            // height: 200.pt,
            color: Colors.white,
            padding: EdgeInsets.all(15.pt),
            margin: EdgeInsets.only(bottom: 10.pt),
            children: [
              _buildTitle('收费数据'),
              Wisdom.row(
                margin: EdgeInsets.symmetric(vertical: 10.pt),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Wisdom.row(
                    width: 169.pt,
                    height: 64.pt,
                    color: Color(0xFFF5F7F9),
                    children: [
                      Wisdom(
                        margin: EdgeInsets.symmetric(horizontal: 15.pt),
                        child: Image(
                          image: AssetList.$drsk_png_image,
                          height: 30,
                        ),
                      ),
                      Wisdom.column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          WisText(
                            '${businessStore.billData.incomeCount}',
                            size: 14.pt,
                            bold: true,
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          WisText(
                            '当$domain收款(笔)',
                            size: 13.pt,
                            color: colorScheme.minor,
                          )
                        ],
                      )
                    ],
                  ),
                  Wisdom.row(
                    width: 169.pt,
                    height: 64.pt,
                    color: Color(0xFFF5F7F9),
                    children: [
                      Wisdom(
                        margin: EdgeInsets.symmetric(horizontal: 15.pt),
                        child: Image(
                          image: AssetList.$drskje_png_image,
                          height: 30,
                        ),
                      ),
                      Wisdom.column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          WisText(
                            '${businessStore.billData.incomeAmount}',
                            size: 14.pt,
                            bold: true,
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          WisText(
                            '当$domain收款金额',
                            size: 13.pt,
                            color: colorScheme.minor,
                          )
                        ],
                      )
                    ],
                  ),
                ],
              ),
              Wisdom.row(
                margin: EdgeInsets.only(bottom: 10.pt),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Wisdom.row(
                    width: 169.pt,
                    height: 64.pt,
                    color: Color(0xFFF5F7F9),
                    children: [
                      Wisdom(
                        margin: EdgeInsets.symmetric(horizontal: 15.pt),
                        child: Image(
                          image: AssetList.$zssk_png_image,
                          height: 30,
                        ),
                      ),
                      Wisdom.column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Wisdom.row(
                            children: [
                              WisText(
                                '${businessStore.billData.incomeOnlineCount}',
                                size: 14.pt,
                                bold: true,
                              ),
                              // WisText(
                              //   '(80.3%)',
                              //   size: 14.pt,
                              //   bold: true,
                              //   color: colorScheme.green,
                              // ),
                            ],
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          WisText(
                            '线上收款(笔)',
                            size: 13.pt,
                            color: colorScheme.minor,
                          )
                        ],
                      )
                    ],
                  ),
                  Wisdom.row(
                    width: 169.pt,
                    height: 64.pt,
                    color: Color(0xFFF5F7F9),
                    children: [
                      Wisdom(
                        margin: EdgeInsets.symmetric(horizontal: 15.pt),
                        child: Image(
                          image: AssetList.$xsskje_png_image,
                          height: 30,
                        ),
                      ),
                      Wisdom.column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Wisdom.column(
                            // width: 150.pt,
                            children: [
                              WisText(
                                '${businessStore.billData.incomeOnlineAmount}',
                                size: 14.pt,
                                bold: true,
                              ),
                              // WisText(
                              //   '(81.1%)',
                              //   size: 14.pt,
                              //   bold: true,
                              //   color: colorScheme.green,
                              // ),
                            ],
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          WisText(
                            '线上收款金额',
                            size: 13.pt,
                            color: colorScheme.minor,
                          )
                        ],
                      )
                    ],
                  ),
                ],
              ),
              _buildBillChartTagRow(),
              // // 收款折线图
              // if (businessStore.dataType == 'day')
              //   Wisdom(
              //     height: 200,
              //     // width: 300,
              //     child: CustomAxisTickFormatters.withSampleData(
              //         businessStore.platformDataLineChart,
              //         businessStore.dataType),
              //   )
              // else
              //   // 收款柱状图
              //   Wisdom(
              //     height: 200,
              //     // width: 300,
              //     child: BarCharts.withSampleData(
              //         businessStore.billDataLineChartLine),
              //   ),
              Wisdom(
                alignment: Alignment.centerLeft,
                child: WisText(
                  '单位：万元',
                  color: colorScheme.minor,
                ),
              ),
              Wisdom(
                margin: EdgeInsets.only(top: 10.pt),
                // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                child: Wisdom.row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    // Wisdom(
                    //   height: 160,
                    //   width: 136,
                    //   alignment: Alignment.bottomLeft,
                    //   child: HiddenTicksAndLabelsAxis.withSampleData(
                    //       businessStore.projectData.historyArrearsAmount,
                    //       businessStore.projectData.arrearsAmount),
                    // ),
                    Wisdom.column(
                      height: 160,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        _buildArrearsCard(
                            '当月回收历史欠费',
                            businessStore.billData.historicalArrearsAmount
                                .toString(),
                            '清欠率',
                            '${(businessStore.billData.historicalArrearsAmount! / businessStore.projectData.historyArrearsAmount! * 100).toStringAsFixed(2)}%'),
                        _buildArrearsCard(
                            '当月回收本年欠费',
                            businessStore.billData.arrearsAmount.toString(),
                            '收缴率',
                            '${(businessStore.billData.arrearsAmount! / businessStore.projectData.arrearsAmount! * 100).toStringAsFixed(2)}%'),
                      ],
                    )
                  ],
                ),
                // Wisdom.column(
                //   height: 180,
                //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //   children: [
                //     _buildArrearsCard(
                //         '当月回收历史欠费', '1000234.45', '清欠率', '12.4%'),
                //     _buildArrearsCard('当月回收本年欠费', '1234.45', '收缴率', '12.4%'),
                //   ],
                // )
              )
            ],
          ),
        ),
        // 客户服务数据
        Wisdom(
          child: Wisdom.column(
            // height: 200.pt,
            color: Colors.white,
            padding: EdgeInsets.all(15.pt),
            margin: EdgeInsets.only(bottom: 10.pt),
            children: [
              _buildTitle('客户服务员数据'),
              Divider(
                height: 20.pt,
              ),
              ..._buildReport(),
              Divider(height: 20.pt),
              ..._buildRepair(),
              Divider(height: 20.pt),
              _buildTitle('当$domain报事报修解决比例'),
              // 进度条图
              _buildLineProgress(),
              Divider(height: 20.pt),
              _buildTitle('当$domain数据来源'),
              // 饼图 比例图
              Wisdom.row(
                width: MediaQuery.of(context).size.width,
                children: [
                  // Wisdom(
                  //   height: 150,
                  //   width: 150,
                  //   child: PieCharts(businessStore.serveData.source),
                  // ),
                  Wisdom(
                    child: Wisdom.column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      height: 150,
                      children: [
                        // _buildPieLabel(
                        //     Color(0xFF2D8CF0),
                        //     '绘服务：${businessStore.serveData.source.hfwEventsCount}',
                        //     '45%'),
                        // _buildPieLabel(
                        //     Color(0xFF54E2EB),
                        //     '客服工作台：${businessStore.serveData.source.adminEventsCount}',
                        //     '30%'),
                        // _buildPieLabel(
                        //     Color(0xFFFFE13D),
                        //     '绘管家手机端：${businessStore.serveData.source.hgjEventsCount}',
                        //     '15%'),
                        // _buildPieLabel(
                        //     Color(0xFFFF583D),
                        //     '企业客服中心：${businessStore.serveData.source.centreEventsCount}',
                        //     '10%'),
                        ..._sortDataSource()
                      ],
                    ),
                  ).asExpanded()
                ],
              ),
              Divider(height: 20.pt),
              _buildTitle('本年度服务评价'),
              // 评分星星图
              Wisdom.row(
                margin: EdgeInsets.symmetric(vertical: 10.pt),
                children: [
                  ..._buildGradeStart(
                      double.parse(
                          '${businessStore.serveData.serviceEvaluationAvgScore ?? 0}'),
                      5),
                  WisText(
                    '${businessStore.serveData.serviceEvaluationAvgScore}/5',
                    color: colorScheme.primary,
                  ),
                  WisText(
                    ' (共${businessStore.serveData.serviceEvaluationCount}条)',
                    color: Color(0xFF999999),
                  ),
                ],
              ),

              _buildRowList('当$domain服务动态',
                  '共发布1${businessStore.serveData.serviceNewsCount}条，获得${businessStore.serveData.serviceNewsUpCount}个赞'),
              _buildRowList('当$domain通知公告',
                  '共发布${businessStore.serveData.noticeCount}条，${businessStore.serveData.noticeReadCount}次阅读'),
              Divider(height: 20.pt),
              _buildTitle('本年度业主评分'),
              // 评分星星图
              Wisdom.row(
                margin: EdgeInsets.symmetric(vertical: 10.pt),
                children: [
                  ..._buildGradeStart(
                      double.parse(
                          '${businessStore.serveData.ownerAvgScore ?? 0}'),
                      5),
                  WisText(
                    '${businessStore.serveData.ownerAvgScore}/5',
                    color: colorScheme.primary,
                  ),
                  WisText(
                    ' (共1${businessStore.serveData.ownerScoreCount}条)',
                    color: Color(0xFF999999),
                  ),
                ],
              ),
              Wisdom.row(
                color: Color(0xFFF5F7F9),
                height: 72.pt,
                margin: EdgeInsets.symmetric(vertical: 10),
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  _buildColumnList(
                      '保洁', '${businessStore.serveData.cleanOwnerAvgScore}'),
                  _buildColumnList(
                      '秩序', '${businessStore.serveData.orderOwnerAvgScore}'),
                  _buildColumnList(
                      '设备', '${businessStore.serveData.deviceOwnerAvgScore}'),
                  _buildColumnList(
                      '绿化', '${businessStore.serveData.greenOwnerAvgScore}'),
                  _buildColumnList('智能化',
                      '${businessStore.serveData.intelligentOwnerAvgScore}'),
                ],
              )
            ],
          ),
        ),
        // 智能设备数据
        Wisdom(
          child: Wisdom.column(
            color: Colors.white,
            padding: EdgeInsets.all(15.pt),
            margin: EdgeInsets.only(bottom: 10.pt),
            children: [
              _buildTitle('智能设备数据'),
              Divider(height: 20.pt),
              _buildRowList('智能门禁',
                  '${businessStore.hardwareData.intelligentDoorControlCount}台',
                  bold: true),
              _buildRowList('出入次数',
                  '${businessStore.hardwareData.intelligentDoorControl?.doorAccessCount}'),
              _buildRowList('访客人次',
                  '${businessStore.hardwareData.intelligentDoorControl?.doorAccessVisitorCount}'),
              _buildRowList('在线设备',
                  '${businessStore.hardwareData.intelligentDoorControl?.onlineDoorDeviceCount}'),
              _buildRowList('离线设备',
                  '${businessStore.hardwareData.intelligentDoorControl?.offlineDoorDeviceCount}'),
              Divider(height: 20.pt),
              _buildRowList(
                  '智能车场', '${businessStore.hardwareData.intelligentParkCount}个',
                  bold: true),
              _buildRowList('出入车场',
                  '${businessStore.hardwareData.intelligentPark?.parkAccessCount}'),
              _buildRowList('临时缴费',
                  '${businessStore.hardwareData.intelligentPark?.parkTemPay}'),
              Divider(height: 20.pt),
              _buildRowList('智能电表',
                  '${businessStore.hardwareData.intelligentElectricMeterCount}块',
                  bold: true),
              _buildRowList('充值次数',
                  '${businessStore.hardwareData.intelligentElectricMeter?.electricMeterRechargeTimes}'),
              _buildRowList('充值金额',
                  '${businessStore.hardwareData.intelligentElectricMeter?.electricMeterRechargeAmount}'),
              _buildRowList('电表余量',
                  '${businessStore.hardwareData.intelligentElectricMeter?.electricMeterMargin}'),
              _buildRowList('充值余额',
                  '${businessStore.hardwareData.intelligentElectricMeter?.electricMeterRechargeBalance}'),
              _buildRowList('欠费表数',
                  '${businessStore.hardwareData.intelligentElectricMeter?.electricMeterArrearsDegree}'),
              _buildRowList('欠费金额',
                  '${businessStore.hardwareData.intelligentElectricMeter?.electricMeterArrearsAmount}'),
            ],
          ),
        ),
      ],
    );
  }

  bool isShowUsers = true;
  bool isShowHouses = true;
  bool isShowHouseHolds = true;
  _buildPlatformChartTagRow() {
    var tagWidth = (MediaQuery.of(context).size.width - 50.pt) / 3;
    var tagHeight = 20.pt;
    var tagMargin = EdgeInsets.symmetric(horizontal: 3.pt);
    Color hiddenColor = Color(0xFF666666);
    return Wisdom.row(
      mainAxisAlignment: MainAxisAlignment.center,
      margin: EdgeInsets.symmetric(vertical: 10.pt),
      children: [
        Wisdom(
          height: tagHeight,
          width: tagWidth,
          margin: tagMargin,
          onTap: () {
            setState(() {
              isShowUsers = !isShowUsers;
            });
            businessStore.hiddenOrShowPlatformLine('onUsers', isShowUsers);
          },
          child: _buildChartTag(
              '新增关注用户', isShowUsers ? Color(0xFF47A7FF) : hiddenColor),
        ),
        Wisdom(
          height: tagHeight,
          width: tagWidth,
          margin: tagMargin,
          onTap: () {
            setState(() {
              isShowHouses = !isShowHouses;
            });
            businessStore.hiddenOrShowPlatformLine('onHouses', isShowHouses);
          },
          child: _buildChartTag(
              '新增关注住户', isShowHouses ? Color(0xFF54E2EB) : hiddenColor),
        ),
        Wisdom(
          height: tagHeight,
          width: tagWidth,
          margin: tagMargin,
          onTap: () {
            setState(() {
              isShowHouseHolds = !isShowHouseHolds;
            });
            businessStore.hiddenOrShowPlatformLine(
                'onHouseHolds', isShowHouseHolds);
          },
          child: _buildChartTag(
              '新增关注户数', isShowHouseHolds ? Color(0xFFFF7059) : hiddenColor),
        ),
      ],
    );
  }

  bool isShowIncomeCount = true;
  bool isShowIncomeCountOnline = true;
  _buildBillChartTagRow() {
    var tagWidth = (MediaQuery.of(context).size.width - 50.pt) / 3;
    var tagHeight = 20.pt;
    var tagMargin = EdgeInsets.symmetric(horizontal: 3.pt);
    Color hiddenColor = Color(0xFF666666);
    return Wisdom.row(
      mainAxisAlignment: MainAxisAlignment.end,
      margin: EdgeInsets.symmetric(vertical: 10.pt),
      children: [
        Wisdom(
          height: tagHeight,
          width: tagWidth,
          margin: tagMargin,
          onTap: () {
            setState(() {
              isShowIncomeCount = !isShowIncomeCount;
            });
            businessStore.hiddenOrShowBillLine(
                'IncomeCount', isShowIncomeCount);
          },
          child: _buildChartTag(
              '收款金额', isShowIncomeCount ? Color(0xFF47A7FF) : hiddenColor),
        ),
        Wisdom(
          height: tagHeight,
          width: tagWidth,
          margin: tagMargin,
          onTap: () {
            setState(() {
              isShowIncomeCountOnline = !isShowIncomeCountOnline;
            });
            businessStore.hiddenOrShowBillLine(
                'IncomeCountOnline', isShowIncomeCountOnline);
          },
          child: _buildChartTag('线上收款金额',
              isShowIncomeCountOnline ? Color(0xFF54E2EB) : hiddenColor),
        ),
        WisText(
          '单位：万元',
          color: Colors.grey,
          size: 12.pt,
        )
      ],
    );
  }

  _buildChartTag(String title, Color color) {
    return WTag(
      child: Wisdom.row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Wisdom(
            margin: EdgeInsets.only(right: 5.pt),
            height: 5.pt,
            width: 13.pt,
            color: color,
          ),
          WisText(
            title,
            color: Colors.black,
            size: 12.pt,
          )
        ],
      ),
      color: color,
    );
  }

  _buildTitle(String title) {
    return Wisdom(
      // margin: EdgeInsets.only(bottom: 10),
      alignment: Alignment.centerLeft,
      child: WisText(
        title,
        size: 15.pt,
        bold: true,
      ),
    );
  }

  _buildRowList(String str1, String str2, {bool bold = false}) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom.row(
      margin: EdgeInsets.only(bottom: 10),
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        WisText(
          str1,
          size: 15.pt,
          color: bold ? colorScheme.mainTitle : colorScheme.minor,
          bold: bold,
        ),
        WisText(
          str2,
          size: 15.pt,
          color: bold ? colorScheme.mainTitle : colorScheme.minor,
          bold: bold,
        ),
      ],
    );
  }

  _buildColumnList(String str1, String str2) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom.column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        WisText(
          str1,
          size: 12.pt,
          color: colorScheme.minor,
        ),
        SizedBox(height: 5),
        WisText(
          str2,
          size: 13.pt,
          bold: true,
        ),
      ],
    );
  }

  // 评分五角星
  List<Widget> _buildGradeStart(double score, int total) {
    List<Widget> _list = [];
    for (var i = 0; i < total; i++) {
      double factor = (score - i);
      if (factor >= 1) {
        factor = 1.0;
      } else if (factor < 0) {
        factor = 0;
      }
      var _st = Wisdom.stack(
        margin: EdgeInsets.only(right: 8.pt),
        children: <Widget>[
          Image(
            image: AssetList.$hxxk_icon_png_image,
            height: 15.pt,
          ),
          ClipRect(
              child: Align(
            alignment: Alignment.topLeft,
            widthFactor: factor,
            child: Image(
              image: AssetList.$hx_icon_png_image,
              height: 15.pt,
            ),
          ))
        ],
      );
      _list.add(_st);
    }
    return _list;
  }

  // 饼图标注
  _buildPieLabel(Color pieColor, String pieLabel, String piePercent) {
    return Wisdom.row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Wisdom.row(
          children: [
            Wisdom(
              height: 10.pt,
              width: 10.pt,
              color: pieColor,
              margin: EdgeInsets.only(right: 10.pt),
            ),
            WisText(pieLabel),
          ],
        ),
        WisText(piePercent)
      ],
    );
  }

  // 收费数据欠费卡片
  _buildArrearsCard(
      String leftTitle, String leftData, String rightTitle, String rightData) {
    return Wisdom(
      padding: EdgeInsets.all(10),
      border: Border.all(color: Color(0xFF7CB4EE), width: 0.5),
      color: Color.fromARGB(30, 124, 180, 238),
      child: Wisdom.row(
        children: [
          Wisdom.column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            height: 50,
            children: [
              WisText(
                leftTitle,
                color: Colors.black,
              ),
              Wisdom.row(
                children: [
                  WisText(
                    leftData,
                    color: Color(0xFF25B41C),
                  ),
                  WisText(
                    '(元)',
                    color: Color(0xFF7CB4EE),
                  )
                ],
              )
            ],
          ),
          Wisdom(
            height: 50,
            child: VerticalDivider(
              width: 25.pt,
              color: Color(0xFFA6CBF3),
              thickness: 1.pt,
              indent: 1.pt,
              endIndent: 1.pt,
            ),
          ),
          Wisdom.column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            height: 50,
            children: [
              WisText(
                rightTitle,
              ),
              WisText(
                rightData,
                color: Color(0xFF2D8CF0),
              )
            ],
          )
        ],
      ),
    );
  }

  // 进度条
  _buildLineProgress() {
    return Wisdom.column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Wisdom(
          height: 10.0,
          margin: EdgeInsets.only(top: 20.pt, left: 40),
          width: 300,
          child: ClipRRect(
            //圆角大小
            borderRadius: BorderRadius.all(Radius.circular(4)),
            child: Container(
              height: 16,
              //层叠到一起的进度
              child: Stack(
                children: [
                  //背景
                  Positioned.fill(
                    child: Container(
                      height: 16,
                      color: Color(0xFFE8E8E8),
                    ),
                  ),
                  //进度
                  ClipRect(
                    //对齐
                    child: Align(
                      //裁剪比例
                      widthFactor:
                          businessStore.serveData.solveRatio as double? ?? 0,
                      child: Container(
                        height: 16,
                        //背景装饰
                        decoration: BoxDecoration(
                          //线性渐变
                          gradient: LinearGradient(colors: [
                            Color(0xFF2D8CF0),
                            Color(0xFF51E2EB),
                          ]),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        Wisdom(
          // color: Color(0XFFFF495E),
          width: 300 * double.parse(businessStore.serveData.solveRatio ?? '0'),
          margin: EdgeInsets.only(left: 40),
          height: 16,
          border: Border(
              right: BorderSide(
            color: Color(0xFF51E2EB),
            width: 0.5,
          )),
        ),
        Wisdom.row(
          // color: Color(0XFFFF495E),
          width: 300 * double.parse(businessStore.serveData.solveRatio ?? '0') +
              80,
          minWidth: 50,
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            BubbleWidget(
              80.0,
              40.0,
              Color(0XFF0F67F8).withOpacity(0.7),
              BubbleArrowDirection.top,
              child: Text(
                '${double.parse(businessStore.serveData.solveRatio ?? '0') * 100}%',
                style: TextStyle(color: Colors.white, fontSize: 14.0),
              ),
            ),
          ],
        )
      ],
    );
  }

  List<Widget> _sortDataSource() {
    int totalCount = businessStore.serveData.source!.hfwEventsCount! +
        businessStore.serveData.source!.adminEventsCount! +
        businessStore.serveData.source!.centreEventsCount! +
        businessStore.serveData.source!.hgjEventsCount!;
    var list = [];
    list.addAll([
      {
        'color': Color(0xFF2D8CF0),
        'text': '绘服务：',
        'count': businessStore.serveData.source!.hfwEventsCount,
        'precent':
            '${(businessStore.serveData.source!.hfwEventsCount! / totalCount * 100).toStringAsFixed(2)}%'
      },
      {
        'color': Color(0xFF54E2EB),
        'text': '客服工作台：',
        'count': businessStore.serveData.source!.adminEventsCount,
        'precent':
            '${(businessStore.serveData.source!.adminEventsCount! / totalCount * 100).toStringAsFixed(2)}%'
      },
      {
        'color': Color(0xFFFFE13D),
        'text': '绘管家手机端：',
        'count': businessStore.serveData.source!.hgjEventsCount,
        'precent':
            '${(businessStore.serveData.source!.hgjEventsCount! / totalCount * 100).toStringAsFixed(2)}%'
      },
      {
        'color': Color(0xFFFF583D),
        'text': '企业客服中心：',
        'count': businessStore.serveData.source!.centreEventsCount,
        'precent':
            '${(businessStore.serveData.source!.centreEventsCount! / totalCount * 100).toStringAsFixed(2)}%'
      },
    ]);
    // 排序 从大到小
    for (var i = 1; i < list.length; i++) {
      for (var j = 0; j < list.length - i; j++) {
        if (list[j]['count'] < list[j + 1]['count']) {
          var temp = {};
          temp = list[j];
          list[j] = list[j + 1];
          list[j + 1] = temp;
        }
      }
    }

    List<Widget> widgetList = [];
    list.forEach((data) {
      widgetList.add(
        _buildPieLabel(
            data['color'], '${data['text']}${data['count']}', data['precent']),
      );
    });
    return widgetList;
  }

  List<Widget> _buildReport() {
    List<Widget> widgetList = [
      _buildTitle('当$domain报事'),
      SizedBox(height: 10),
    ];
    businessStore.serveData.report?.forEach((data) {
      widgetList.add(
        _buildRowList(data.eventName!, '${data.eventCount ?? 0}件'),
      );
    });
    return widgetList;
  }

  List<Widget> _buildRepair() {
    List<Widget> widgetList = [
      _buildTitle('当$domain报修'),
      SizedBox(height: 10),
    ];
    businessStore.serveData.repair?.forEach((data) {
      widgetList.add(
        _buildRowList(data.eventName!, '${data.eventCount ?? 0}件'),
      );
    });
    return widgetList;
  }
}
