feast_page.dart 9.6 KB

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/GetBanquetByTimeModel.dart';
import 'package:one_key/pages/feast/feast_item.dart';
import 'package:one_key/provider/feast_model.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';

import '../../constant/state.dart';
import '../../provider/user_model.dart';
import '../../res/colors.dart';

import '../../utils/event_bus.dart';
import '../../utils/screen_util.dart';
import '../../widgets/page_exception.dart';

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

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

class _FeastPageState extends State<FeastPage> {
  ScrollController controller = ScrollController();
  late FeastModel feastModel;
  // bool notDo = false;
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      // notDo =
      //     Provider.of<UserModel>(context, listen: false).user.role_name == '迎宾';
      _getBanquetByTime();
      _getBanquetBeFollow();
      // scrollController.jumpTo(scrollController.position.minScrollExtent);
    });

    bus.on("feast_home_page", (arg) {
      _getBanquetByTime();
      _getBanquetBeFollow();
    });
  }

  @override
  void dispose() {
    super.dispose();
    bus.off('feast_home_page');
  }

  /// 根据时间范围查询待跟进订单
  _getBanquetBeFollow() async {
    Map<String, String?> pramas = {
      "sid": Provider.of<UserModel>(context, listen: false).user!.sellerid,
      'type': '2'
    }; //
    bool success =  await feastModel.getBanquetBeFollow(context, pramas) ;
    if (success) {}
  }

  ///获取宴会详情
  _getBanquetByTime() async {
    DateTime now = DateTime.now();
    DateTime new7 = now.add(Duration(days: 7));
    String timeStrStart = now.year.toString() +
        "-" +
        Utils.addZeroNumber(now.month) +
        "-" +
        Utils.addZeroNumber(now.day) +
        " 00:00:00";
    String timeStrEnd = new7.year.toString() +
        "-" +
        Utils.addZeroNumber(new7.month) +
        "-" +
        Utils.addZeroNumber(new7.day) +
        " 23:59:59";
    double startDay =
        (DateTime.parse(timeStrStart).millisecondsSinceEpoch) / 1000;
    double endDay = (DateTime.parse(timeStrEnd).millisecondsSinceEpoch) / 1000;
    Map<String, String?> pramas = {
      'sid': Provider.of<UserModel>(context, listen: false).user!.sellerid,
      'rdate': startDay.floor().toString(),
      'edate': endDay.floor().toString()
    }; //
    bool success = await feastModel.getBanquetByTime(context, pramas) ;
  }

  Widget upAndDown(String image, String title, {GestureTapCallback? onTap}) {
    bool notDo = !Utils.getAuthority(context, title);

    return InkWell(
        onTap: onTap,
        child: Column(
          children: [
            Image.asset(Utils.getImgPath(image),
                width: ScreenUtil().setWidth(36 * 2)),
            VEmptyView(8),
            Text(
              title,
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(28),
                  color: title != '宴会看板' && notDo
                      ? MyColours.color_999999
                      : MyColours.color_515151),
            )
          ],
        ));
  }

  @override
  Widget build(BuildContext context) {
    feastModel = Provider.of<FeastModel>(context, listen: true);
    return Scaffold(
        backgroundColor: MyColours.color_ffffff,
        // appBar: SystemAppBar(''),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  VEmptyView(112),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      upAndDown('y_kanban', '宴会看板', onTap: () {
                        NavigatorUtil.goFeastBoardPage(context);
                      }),
                      upAndDown(
                          Utils.getAuthority(context, '新建宴会')
                              ? 'y_new'
                              : 'y_new_un',
                          '新建宴会', onTap: () {
                        if (Utils.getAuthority(context, '新建宴会')) {
                          NavigatorUtil.goFeastCreatePage(context,
                              isCreate: true);
                        }
                      }),
                      InkWell(
                          onTap: () {
                            if (Utils.getAuthority(context, '待跟进')) {
                              NavigatorUtil.goFeastFollowUpPage(context);
                            }
                          },
                          child: Stack(clipBehavior: Clip.none, children: [
                            upAndDown(
                                Utils.getAuthority(context, '待跟进')
                                    ? 'y_schedule'
                                    : 'y_schedule_un',
                                '待跟进', onTap: () {
                              if (Utils.getAuthority(context, '待跟进')) {
                                NavigatorUtil.goFeastFollowUpPage(context);
                              }
                            }),
                            feastModel.beFollowData != null &&
                                    feastModel.beFollowData!.length > 0 &&
                                    (Utils.getAuthority(context, '待跟进'))
                                ? Positioned(
                                    right: ScreenUtil().setWidth(0),
                                    bottom: ScreenUtil().setWidth(38),
                                    child: Container(
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                          borderRadius: BorderRadius.circular(
                                              ScreenUtil().setWidth(16)),
                                          color: MyColours.color_E34D59),
                                      // width: ScreenUtil().setWidth(32),
                                      height: ScreenUtil().setWidth(32),
                                      padding: EdgeInsets.symmetric(
                                          horizontal: w(4)),
                                      child: Text(
                                        '${feastModel.beFollowData!.length}',
                                        style: TextStyle(
                                            color: MyColours.color_F6F6F6,
                                            fontWeight: FontWeight.bold,
                                            fontSize: ScreenUtil().setSp(24)),
                                      ),
                                    ),
                                  )
                                : SizedBox()
                          ])),
                      upAndDown(
                          Utils.getAuthority(context, '订金管理')
                              ? 'y_money'
                              : 'y_money_un',
                          '订金管理', onTap: () {
                        if (Utils.getAuthority(context, '订金管理')) {
                          NavigatorUtil.goFeastDepositDataPage(context);
                        }
                      })
                    ],
                  ),
                  VEmptyView(102),
                  Padding(
                    padding: EdgeInsets.only(left: ScreenUtil().setWidth(48)),
                    child: Text(
                      '7天内宴会',
                      style: TextStyle(
                          color: MyColours.color_000000,
                          fontSize: ScreenUtil().setSp(28)),
                    ),
                  ),
                  VEmptyView(26),
                ],
              ),
            ),
            Expanded(child: Consumer<FeastModel>(builder: (context, model, _) {
              if (model.pageState != PageState.Success) {
                return ExceptionPage(
                  pageState: model.pageState,
                  callback: () {
                    _getBanquetByTime();
                    _getBanquetBeFollow();
                    // offset = 0;
                    // getMessage(showLoading: true);
                  },
                  emptyMsg: "还未创建宴会",
                  emptyImg: "empty_search",
                  showMsg: "加载中,请稍候...",
                );
              } else {
                return ListView.builder(
                  controller: controller,
                  padding: EdgeInsets.symmetric(
                      horizontal: ScreenUtil().setWidth(24)),
                  itemBuilder: (context, index) {
                    GetBanquetByTimeSunModel sunModel =
                        feastModel.banquetHome![index];
                    return InkWell(
                        onTap: () {
                          NavigatorUtil.goFeastDetailPage(context, sunModel.id,
                              needChange: true);
                        },
                        child: FeastItem(controller, sunModel));
                  },
                  itemCount: feastModel.banquetHome!.length,
                );
              }
            }))
          ],
        ));
  }
}