plan_dish_sun_page.dart 6.97 KB
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/personnel_manage_model.dart';
import 'package:one_key/pages/coupon/coupon_item_f.dart';
import 'package:one_key/pages/my/plan_dish/plan_dish_item.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/provider/personnel_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/widgets/page_exception.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';

import '../../../provider/plan_dish_provider.dart';
import '../../../utils/dialog_util.dart';

class PlanDishSunPage extends StatefulWidget {
  final int index;
  PlanDishSunPage({Key key, this.index}) : super(key: key);

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

class _PlanDishSunPageState extends State<PlanDishSunPage> {
  EasyRefreshController _controller = EasyRefreshController();
  PlanDishProvider planDishProvider;
  List<PersonnelManageSunModel> authUserLists = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((_) {
      // if (widget.index == 0) {
      //   planDishProvider.pageState = PageState.Loading;
      // } else if (widget.index == 1) {
      //   planDishProvider.pageStateStore = PageState.Loading;
      // } else if (widget.index == 2) {
      //   planDishProvider.pageStateMine = PageState.Loading;
      // }
      // couponProvider.notifyListeners();
      // _couponNetworkData(widget.index, isShowLoading: false);

      // bus.on("refresh_coupon_list_f", (arg) {
      //   _couponNetworkData(widget.index);
      // });
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  ///获取优惠券列表数据
  // _couponNetworkData(int index, {bool isShowLoading = true}) async {
  //   Map<String, String> params = {
  //     "uid": Provider.of<UserModel>(context, listen: false).user.openid,
  //     // 'is_time': '0'
  //     "is_type": index.toString()
  //   };
  //   await couponProvider.getCustomerActivity(context, params, index,
  //       isShowLoading: isShowLoading);
  // }

  ///修改活动信息
  // _setCustomerActivity(int index) async {
  //   Map<String, String> params = {
  //     "id": couponProvider.couponList[index].id,
  //     "status": couponProvider.couponList[index].isOpenBool ? '1' : '0',
  //   };
  //   bool isSuccess = await couponProvider.setCustomerActivity(context, params,
  //       isShowLoading: false);
  //   print(isSuccess);
  //   _couponNetworkData(widget.index, isShowLoading: false);
  //   // if (isSuccess) {
  //   //   couponProvider.notifyListeners();
  //   // } else {
  //   //   couponProvider.couponList[index].isOpenBool =
  //   //       !couponProvider.couponList[index].isOpenBool;
  //   //   couponProvider.notifyListeners();
  //   // }
  // }

  @override
  Widget build(BuildContext context) {
    planDishProvider = Provider.of<PlanDishProvider>(context, listen: true);
    PageState pageState;
    if (widget.index == 0) {
      pageState = planDishProvider.pageState;
    } else if (widget.index == 1) {
      pageState = planDishProvider.pageStateStore;
    } else if (widget.index == 2) {
      pageState = planDishProvider.pageStateMine;
    }
    return Container(
      child: Consumer<CouponProvider>(builder: (context, model, _) {
        if (pageState != PageState.Success) {
          return ExceptionPage(
            pageState: pageState,
            callback: () {
              // offset = 0;
              // getMessage(showLoading: true);
              // _couponNetworkData(widget.index);
            },
            emptyMsg: "暂时没有列表信息哦,",
            emptyImg: "empty_search",
            showMsg: "加载中,请稍后...",
            needEmpty: true,
          );
        } else {
          return EasyRefresh.custom(
            controller: _controller,
            shrinkWrap: true,
            slivers: [
              SliverList(
                delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                  return PlanDishItem(
                    // from: 'quan',
                    // couponSonModel: couponProvider.couponList[index],
                    // showBtn: true,
                    onPressedDel: () {
                      //弹框确认是否删除
                      DialogUtil.cupertinoAlertDialog(context,
                          title: "",
                          content: "确定要将该排菜删除吗?删除后将无法再次使用该排菜。",
                          rTitle: "确定", rCallback: () {
                        // Navigator.pop(context);
                        // _delGuestInfocDay(model.cday[index].id);
                      });
                    },
                    onPressedReUse: () {
                      NavigatorUtil.goFinalPlanDishPage(context);
                    },
                  );
                }, childCount: 10),
              ),
              // SliverList(
              //   delegate: SliverChildBuilderDelegate(
              //       (BuildContext context, int index) {
              //     return Column(
              //       children: [
              //         InkWell(
              //             onTap: () {
              //               NavigatorUtil.goCouponHistoryPage(context);
              //             },
              //             child: RichText(
              //                 text: TextSpan(
              //                     style: TextStyle(
              //                       fontSize: ScreenUtil().setSp(28),
              //                     ),
              //                     children: [
              //                   TextSpan(
              //                       text: '没有更多了,',
              //                       style: TextStyle(
              //                           color: MyColours.color_000000)),
              //                   TextSpan(
              //                       text: '查看过期优惠券',
              //                       style: TextStyle(
              //                           color: MyColours.color_438E93)),
              //                 ]))),
              //         VEmptyView(80)
              //       ],
              //     );
              //   }, childCount: 1),
              // )
            ],
            // onRefresh: () async {
            //   // offset = 0;
            //   // getMessage(showLoading: false);
            // },
            // onLoad: () async {
            //   // offset++;
            //   // getMessage(showLoading: false);
            // },
          );
        }
      }),
    );
  }
}