feast_otherset_manage_page.dart 7.98 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/otherset_model.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';

import '../../../constant/state.dart';
import '../../../provider/feast_model.dart';
import '../../../res/colors.dart';
import '../../../utils/dialog_util.dart';
import '../../../utils/event_bus.dart';
import '../../../utils/screen_util.dart';
import '../../../utils/utils.dart';
import '../../../widgets/h_empty_view.dart';
import '../../../widgets/page_exception.dart';
import '../../../widgets/round_button.dart';
import '../../../widgets/system_app_bar.dart';

/**
 * 其他配置管理
 */

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

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

class _FeastOthersetManagePageState extends State<FeastOthersetManagePage> {
  FeastModel feastModel;
  @override
  void initState() {
    super.initState();
    Utils.changeStatusColor(color: MyColours.color_438E93);
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _getOthersetList();
      // scrollController.jumpTo(scrollController.position.minScrollExtent);
    });
    bus.on("feast_otherset_list", (arg) {
      _getOthersetList();
    });
  }

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

  ///获取其他配置
  Future<bool> _getOthersetList({bool isShowLoading = true}) async {
    await feastModel.getOthersetList(context, isShowLoading: isShowLoading);
  }

  Widget buildFeastTypeHeader() {
    return RoundButton(
      onPressed: () async {
        NavigatorUtil.goFeastOthersetManageEditPage(context);
      },
      text: '添加一项',
      fontSize: 32,
      isBold: false,
      height: h(32),
      width: w(80),
      margin: EdgeInsets.only(top: w(18), bottom: w(4)),
      textColor: MyColours.color_438E93,
      gradientStart: MyColours.color_ffffff,
      gradientEnd: MyColours.color_ffffff,
      borderColor: MyColours.color_438E93,
      radius: r(6),
    );
  }

  Widget buildFeastTypeItem(OthersetSunModel model, int index) {
    return Container(
      height: h(48),
      margin: EdgeInsets.only(top: w(12)),
      decoration: BoxDecoration(
          border: Border(
              bottom:
                  BorderSide(width: w(0.5), color: MyColours.color_E7E7E7))),
      child: Row(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                model.otherName,
                style: TextStyle(
                    fontSize: font(16), color: MyColours.color_E6000000),
              ),
              VEmptyView(12),
              Text(
                '${model.price}元/${model.spec}  ${model.bargaining == '1' ? '可议价' : '不可议价'}',
                style: TextStyle(
                    fontSize: font(12), color: MyColours.color_999999),
              )
            ],
          ),
          Spacer(),
          InkWell(
              onTap: () {
                NavigatorUtil.goFeastOthersetManageEditPage(context,
                    isNew: false, othersetSunModel: model);
              },
              child: Text(
                '修改',
                style: TextStyle(
                    decoration: TextDecoration.underline,
                    fontSize: font(16),
                    color: MyColours.color_438E93),
              )),
          HEmptyView(32),
          InkWell(
              onTap: () {
                //已经传到服务器,弹提醒窗口,是否删除
                //修改之前有内容,则弹框
                DialogUtil.cupertinoAlertDialogFeast(context,
                    rTitle: '删除',
                    title: "是否确认删除",
                    content: model.otherName, lCallback: () {
                  print("取消");
                }, rCallback: () async {
                  print("确定");
                  Map<String, String> pramas = {'id': model.id};
                  bool success =
                      await feastModel.delOthersetList(context, pramas);
                  if (success) {
                    Utils.showToast('删除成功');
                    _getOthersetList(isShowLoading: true);
                  }
                });
              },
              child: Image.asset(
                Utils.getImgPath('f_delete_red'),
                width: w(32),
                height: w(32),
              )),
          HEmptyView(32),
        ],
      ),
    );
  }

  Widget _callButton(
      {GestureTapCallback onPress,
      content,
      hasLeftBorder = true,
      isSelect = false}) {
    return InkWell(
      onTap: onPress,
      child: Container(
        height: h(48),
        decoration: BoxDecoration(
            color: isSelect ? MyColours.color_438E93 : MyColours.color_ffffff,
            border: Border(
                bottom: BorderSide(
                    color: MyColours.color_438E93,
                    width: ScreenUtil().setWidth(2)),
                top: BorderSide(
                    color: MyColours.color_438E93,
                    width: ScreenUtil().setWidth(2)),
                left: hasLeftBorder
                    ? BorderSide(
                        color: MyColours.color_438E93,
                        width: ScreenUtil().setWidth(2))
                    : BorderSide.none,
                right: BorderSide(
                    color: MyColours.color_438E93,
                    width: ScreenUtil().setWidth(2)))),
        child: Align(
          alignment: Alignment.center,
          child: Text(
            content,
            style: TextStyle(
                color:
                    isSelect ? MyColours.color_F6F6F6 : MyColours.color_438E93,
                fontSize: ScreenUtil().setSp(36)),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    feastModel = Provider.of<FeastModel>(context, listen: true);
    return Scaffold(
      backgroundColor: MyColours.color_ffffff,
      resizeToAvoidBottomInset: false,

        /// 这里必须禁止重绘
      appBar: SystemAppBar(
        '其他配置管理',
        needWhite: true,
        bgColor: MyColours.color_438E93,
        titleColor: MyColours.color_F6F6F6,
        onTap: () {
          Navigator.pop(context);
        },
      ),
      body: NestedScrollView(
          // controller: _scrollViewController,
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
            pinned: true,
            floating: false,
            leading: null,
            backgroundColor: MyColours.color_ffffff,
            expandedHeight: ScreenUtil().setWidth(56 * 2),
            automaticallyImplyLeading: false,
            title: buildFeastTypeHeader(),
            // flexibleSpace: FlexibleSpaceBar(
            //     collapseMode: CollapseMode.pin,
            //     title: buildFeastTypeHeader())
          )
        ];
      }, body: Consumer<FeastModel>(builder: (context, model, _) {
        if (model.pageStateOther != PageState.Success) {
          return ExceptionPage(
            pageState: model.pageStateOther,
            callback: () {
              _getOthersetList();
            },
            emptyMsg: "暂时没有配置哦",
            emptyImg: "empty_search",
            showMsg: "加载中,请稍后...",
          );
        } else {
          return ListView.builder(
              itemCount: feastModel.otherData.length,
              padding: EdgeInsets.only(left: w(16)),
              itemBuilder: (BuildContext context, int index) {
                OthersetSunModel sunModel = feastModel.otherData[index];
                return buildFeastTypeItem(sunModel, index);
                // 'LED大屏', '1100元/次  不可议价'
              });
        }
      })),
    );
  }
}