Commit 2f19a30fdec2ffa17248b4cdc9c9e7d41f0b97c0

Authored by wdn127929
1 parent 302c89bb

菜品管理ok

  1 +import 'package:json_annotation/json_annotation.dart';
  2 +
  3 +part 'cookbook_category_model.g.dart';
  4 +
  5 +@JsonSerializable()
  6 +class CookbookCategoryModel extends Object {
  7 + @JsonKey(name: 'ret')
  8 + int ret;
  9 +
  10 + @JsonKey(name: 'data')
  11 + List<CookbookCategorySunModel> data;
  12 +
  13 + @JsonKey(name: 'msg')
  14 + String msg;
  15 +
  16 + CookbookCategoryModel(
  17 + this.ret,
  18 + this.data,
  19 + this.msg,
  20 + );
  21 +
  22 + factory CookbookCategoryModel.fromJson(Map<String, dynamic> srcJson) =>
  23 + _$CookbookCategoryModelFromJson(srcJson);
  24 +
  25 + Map<String, dynamic> toJson() => _$CookbookCategoryModelToJson(this);
  26 +}
  27 +
  28 +@JsonSerializable()
  29 +class CookbookCategorySunModel extends Object {
  30 + @JsonKey(name: 'id')
  31 + String id;
  32 +
  33 + @JsonKey(name: 'sellerid')
  34 + String sellerid;
  35 +
  36 + @JsonKey(name: 'class_name')
  37 + String className;
  38 +
  39 + @JsonKey(name: 'order')
  40 + String order;
  41 +
  42 + @JsonKey(name: 'status')
  43 + String status;
  44 +
  45 + @JsonKey(name: 'class_type')
  46 + String classType;
  47 +
  48 + CookbookCategorySunModel(
  49 + this.id,
  50 + this.sellerid,
  51 + this.className,
  52 + this.order,
  53 + this.status,
  54 + this.classType,
  55 + );
  56 +
  57 + factory CookbookCategorySunModel.fromJson(Map<String, dynamic> srcJson) =>
  58 + _$CookbookCategorySunModelFromJson(srcJson);
  59 +
  60 + Map<String, dynamic> toJson() => _$CookbookCategorySunModelToJson(this);
  61 +}
  1 +// GENERATED CODE - DO NOT MODIFY BY HAND
  2 +
  3 +part of 'cookbook_category_model.dart';
  4 +
  5 +// **************************************************************************
  6 +// JsonSerializableGenerator
  7 +// **************************************************************************
  8 +
  9 +CookbookCategoryModel _$CookbookCategoryModelFromJson(
  10 + Map<String, dynamic> json) {
  11 + return CookbookCategoryModel(
  12 + json['ret'] as int,
  13 + (json['data'][0] as List)
  14 + ?.map((e) => e == null
  15 + ? null
  16 + : CookbookCategorySunModel.fromJson(e as Map<String, dynamic>))
  17 + ?.toList(),
  18 + json['msg'] as String,
  19 + );
  20 +}
  21 +
  22 +Map<String, dynamic> _$CookbookCategoryModelToJson(
  23 + CookbookCategoryModel instance) =>
  24 + <String, dynamic>{
  25 + 'ret': instance.ret,
  26 + 'data': instance.data,
  27 + 'msg': instance.msg,
  28 + };
  29 +
  30 +CookbookCategorySunModel _$CookbookCategorySunModelFromJson(
  31 + Map<String, dynamic> json) {
  32 + return CookbookCategorySunModel(
  33 + json['id'] as String,
  34 + json['sellerid'] as String,
  35 + json['class_name'] as String,
  36 + json['order'] as String,
  37 + json['status'] as String,
  38 + json['class_type'] as String,
  39 + );
  40 +}
  41 +
  42 +Map<String, dynamic> _$CookbookCategorySunModelToJson(
  43 + CookbookCategorySunModel instance) =>
  44 + <String, dynamic>{
  45 + 'id': instance.id,
  46 + 'sellerid': instance.sellerid,
  47 + 'class_name': instance.className,
  48 + 'order': instance.order,
  49 + 'status': instance.status,
  50 + 'class_type': instance.classType,
  51 + };
  1 +import 'package:json_annotation/json_annotation.dart';
  2 +
  3 +part 'cookbook_spec_model.g.dart';
  4 +
  5 +@JsonSerializable()
  6 +class CookbookSpecModel extends Object {
  7 + @JsonKey(name: 'ret')
  8 + int ret;
  9 +
  10 + @JsonKey(name: 'data')
  11 + List<CookbookSpecSunModel> data;
  12 +
  13 + @JsonKey(name: 'msg')
  14 + String msg;
  15 +
  16 + CookbookSpecModel(
  17 + this.ret,
  18 + this.data,
  19 + this.msg,
  20 + );
  21 +
  22 + factory CookbookSpecModel.fromJson(Map<String, dynamic> srcJson) =>
  23 + _$CookbookSpecModelFromJson(srcJson);
  24 +
  25 + Map<String, dynamic> toJson() => _$CookbookSpecModelToJson(this);
  26 +}
  27 +
  28 +@JsonSerializable()
  29 +class CookbookSpecSunModel extends Object {
  30 + @JsonKey(name: 'id')
  31 + String id;
  32 +
  33 + @JsonKey(name: 'sellerid')
  34 + String sellerid;
  35 +
  36 + @JsonKey(name: 'name')
  37 + String name;
  38 +
  39 + @JsonKey(name: 'cdate')
  40 + String cdate;
  41 +
  42 + CookbookSpecSunModel(
  43 + this.id,
  44 + this.sellerid,
  45 + this.name,
  46 + this.cdate,
  47 + );
  48 +
  49 + factory CookbookSpecSunModel.fromJson(Map<String, dynamic> srcJson) =>
  50 + _$CookbookSpecSunModelFromJson(srcJson);
  51 +
  52 + Map<String, dynamic> toJson() => _$CookbookSpecSunModelToJson(this);
  53 +}
  1 +// GENERATED CODE - DO NOT MODIFY BY HAND
  2 +
  3 +part of 'cookbook_spec_model.dart';
  4 +
  5 +// **************************************************************************
  6 +// JsonSerializableGenerator
  7 +// **************************************************************************
  8 +
  9 +CookbookSpecModel _$CookbookSpecModelFromJson(Map<String, dynamic> json) {
  10 + return CookbookSpecModel(
  11 + json['ret'] as int,
  12 + (json['data'][0] as List)
  13 + ?.map((e) => e == null
  14 + ? null
  15 + : CookbookSpecSunModel.fromJson(e as Map<String, dynamic>))
  16 + ?.toList(),
  17 + json['msg'] as String,
  18 + );
  19 +}
  20 +
  21 +Map<String, dynamic> _$CookbookSpecModelToJson(CookbookSpecModel instance) =>
  22 + <String, dynamic>{
  23 + 'ret': instance.ret,
  24 + 'data': instance.data,
  25 + 'msg': instance.msg,
  26 + };
  27 +
  28 +CookbookSpecSunModel _$CookbookSpecSunModelFromJson(Map<String, dynamic> json) {
  29 + return CookbookSpecSunModel(
  30 + json['id'] as String,
  31 + json['sellerid'] as String,
  32 + json['name'] as String,
  33 + json['cdate'] as String,
  34 + );
  35 +}
  36 +
  37 +Map<String, dynamic> _$CookbookSpecSunModelToJson(
  38 + CookbookSpecSunModel instance) =>
  39 + <String, dynamic>{
  40 + 'id': instance.id,
  41 + 'sellerid': instance.sellerid,
  42 + 'name': instance.name,
  43 + 'cdate': instance.cdate,
  44 + };
@@ -141,5 +141,14 @@ class HttpUrl { @@ -141,5 +141,14 @@ class HttpUrl {
141 "?service=App.Seller.SetTableClass"; // 添加/修改包间分类 141 "?service=App.Seller.SetTableClass"; // 添加/修改包间分类
142 static const String get_cookbook_by_class = 142 static const String get_cookbook_by_class =
143 "?service=App.Cookbook.GetCookbookByClass"; //分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传 143 "?service=App.Cookbook.GetCookbookByClass"; //分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传
  144 + static const String get_cookbook_by_seller_id =
  145 + "?service=App.Cookbook.GetCookbookClassBySellerId"; //获取商家所有菜品分类
  146 + static const String del_cookbook_by_id =
  147 + "?service=App.Cookbook.DelCookbookClassById"; //删除菜品分类
  148 + static const String add_cookbook_class =
  149 + "?service=App.Cookbook.AddCookbookClass"; //添加菜品分类信息
  150 + static const String add_cookbook = "?service=App.Cookbook.AddCookbook"; //添加菜品
  151 + static const String get_spec_by_sellerid =
  152 + "?service=App.Cookbook.GetSpecBySellerid"; //获取商家计价单位
144 153
145 } 154 }
  1 +import 'dart:io';
  2 +
  3 +import 'package:amap_map_fluttify/amap_map_fluttify.dart';
  4 +import 'package:cached_network_image/cached_network_image.dart';
  5 +import 'package:flutter/material.dart';
  6 +import 'package:flutter_native_image/flutter_native_image.dart';
  7 +import 'package:flutter_screenutil/screenutil.dart';
  8 +import 'package:image_picker/image_picker.dart';
  9 +import 'package:one_key/models/upload_img_model.dart';
  10 +import 'package:one_key/provider/menu_provider.dart';
  11 +import 'package:one_key/provider/upload_img_provider.dart';
  12 +import 'package:one_key/provider/user_model.dart';
  13 +import 'package:one_key/res/colors.dart';
  14 +import 'package:one_key/utils/dialog_util.dart';
  15 +import 'package:one_key/utils/event_bus.dart';
  16 +import 'package:one_key/utils/upload_image_util.dart';
  17 +import 'package:one_key/utils/utils.dart';
  18 +import 'package:one_key/widgets/MyDivider.dart';
  19 +import 'package:one_key/widgets/h_empty_view.dart';
  20 +import 'package:one_key/widgets/round_button.dart';
  21 +import 'package:one_key/widgets/system_app_bar.dart';
  22 +import 'package:one_key/widgets/v_empty_view.dart';
  23 +import 'package:permission_handler/permission_handler.dart';
  24 +import 'package:provider/provider.dart';
  25 +
  26 +/**
  27 + *
  28 + * 添加菜品页面
  29 + */
  30 +class MenuAddDishesPage extends StatefulWidget {
  31 + MenuAddDishesPage({Key key}) : super(key: key);
  32 +
  33 + @override
  34 + _MenuAddDishesPageState createState() => _MenuAddDishesPageState();
  35 +}
  36 +
  37 +class _MenuAddDishesPageState extends State<MenuAddDishesPage> {
  38 + bool swichState = true;
  39 + TextEditingController _nameController = TextEditingController();
  40 + TextEditingController _priceController = TextEditingController();
  41 +
  42 + FocusNode _nameFocusNode = FocusNode();
  43 + FocusNode _priceFocusNode = FocusNode();
  44 + final picker = ImagePicker();
  45 + UploadImageProvider uploadImageProvider;
  46 + MenuManageProvider menuManageProvider;
  47 + List<String> categoryStrList = [];
  48 + String categoryStr = '请选择';
  49 + List<String> specStrList = [];
  50 + String specStr = '请选择';
  51 + @override
  52 + void initState() {
  53 + super.initState();
  54 +
  55 + WidgetsBinding.instance.addPostFrameCallback((_) {
  56 + uploadImageProvider.dish.process = 0.01;
  57 + uploadImageProvider.dish.qiniuUrl = '';
  58 + uploadImageProvider.notifyListeners();
  59 +
  60 + _getQiniuInfo();
  61 + _getCookbookBySellerId(showLoading: false);
  62 + _getSpecBySellerid();
  63 + });
  64 + }
  65 +
  66 + ///计价方式
  67 + _getSpecBySellerid({bool showLoading = false}) async {
  68 + Map<String, String> params = {
  69 + "sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
  70 + };
  71 + await menuManageProvider.getSpecBySellerid(context, params,
  72 + showLoading: showLoading);
  73 + if (menuManageProvider.specSunModel.length > 0) {
  74 + specStrList = [];
  75 + menuManageProvider.specSunModel.forEach((element) {
  76 + specStrList.add(element.name);
  77 + });
  78 + }
  79 + }
  80 +
  81 + ///添加菜品
  82 + _addCookbook({bool showLoading = true}) async {
  83 + if (_nameController.text.trim().length == 0) {
  84 + Utils.showToast('请输入菜品名称');
  85 + return;
  86 + }
  87 + if (_priceController.text.trim().length == 0) {
  88 + Utils.showToast('请输入菜品价格');
  89 + return;
  90 + }
  91 + if (categoryStr == "请选择") {
  92 + Utils.showToast('请选择菜品分类');
  93 + return;
  94 + }
  95 + if (specStr == "请选择") {
  96 + Utils.showToast('请选择计价方式');
  97 + return;
  98 + }
  99 + String cid = '';
  100 + // String unit = '';
  101 + menuManageProvider.categorySunModel.forEach((element) {
  102 + if (element.className == categoryStr) {
  103 + cid = element.id;
  104 + }
  105 + });
  106 + // menuManageProvider.specSunModel.forEach((element) {
  107 + // if (element.name == specStr) {
  108 + // unit = element.id;
  109 + // }
  110 + // });
  111 + Map<String, String> params = {
  112 + "sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
  113 + 'cid': cid,
  114 + 'unit': specStr,
  115 + 'name': _nameController.text,
  116 + 'status': swichState ? '1' : '0',
  117 + 'price': _priceController.text
  118 + };
  119 + if (uploadImageProvider.dish.qiniuUrl != null &&
  120 + uploadImageProvider.dish.qiniuUrl != '') {
  121 + params['image'] = uploadImageProvider.dish.qiniuUrl;
  122 + }
  123 + bool sucess = await menuManageProvider.addCookbook(context, params,
  124 + showLoading: showLoading);
  125 + if (sucess) {
  126 + EventBus().emit('menu_manage_page');
  127 + Navigator.of(context).pop();
  128 + }
  129 + }
  130 +
  131 + ///获取分类数据
  132 + _getCookbookBySellerId({bool showLoading = true}) async {
  133 + Map<String, String> params = {
  134 + "SellerId": Provider.of<UserModel>(context, listen: false).user.sellerid,
  135 + };
  136 + await menuManageProvider.getCookbookClassBySellerId(context, params,
  137 + showLoading: showLoading);
  138 + if (menuManageProvider.categorySunModel.length > 0) {
  139 + categoryStrList = [];
  140 + menuManageProvider.categorySunModel.forEach((element) {
  141 + if (element.className != '10道必点菜') {
  142 + categoryStrList.add(element.className);
  143 + }
  144 + });
  145 + }
  146 + }
  147 +
  148 + ///获取七牛云token
  149 + ///
  150 + _getQiniuInfo() async {
  151 + await uploadImageProvider.getQiniuInfo(context, {});
  152 + }
  153 +
  154 + ///输入框
  155 + Widget _textfield(
  156 + String title,
  157 + String hintText,
  158 + TextEditingController editingController,
  159 + FocusNode focusNode,
  160 + String subTitle,
  161 + {bool needStar = true,
  162 + TextInputType inputType = TextInputType.number}) {
  163 + return Container(
  164 + child: Row(
  165 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
  166 + children: [
  167 + Container(
  168 + child: Text(
  169 + title,
  170 + style: TextStyle(
  171 + color: MyColours.color_333333,
  172 + fontWeight: FontWeight.bold,
  173 + fontSize: ScreenUtil().setSp(34)),
  174 + ),
  175 + ),
  176 + HEmptyView(20),
  177 + needStar
  178 + ? Container(
  179 + child: Text(
  180 + '*',
  181 + style: TextStyle(
  182 + color: MyColours.color_199095,
  183 + fontWeight: FontWeight.bold,
  184 + ),
  185 + ),
  186 + )
  187 + : SizedBox(),
  188 + // Spacer(),
  189 + Expanded(
  190 + child: Container(
  191 + // height: ScreenUtil().setHeight(120),
  192 + padding: EdgeInsets.only(
  193 + left: ScreenUtil().setWidth(20),
  194 + right: ScreenUtil().setWidth(10),
  195 + top: ScreenUtil().setWidth(8)),
  196 + child: TextField(
  197 + controller: editingController,
  198 + textAlign: TextAlign.right,
  199 + // textAlignVertical: TextAlignVertical.bottom,
  200 + maxLines: 1,
  201 + inputFormatters: [],
  202 +
  203 + // //光标颜色
  204 + // cursorColor:
  205 + // widget.isSelect ? Colors.white : MyColours.color_199095,
  206 + //输入文本的样式
  207 + style: TextStyle(
  208 + fontSize: ScreenUtil().setSp(32),
  209 + ),
  210 + focusNode: focusNode,
  211 + decoration: InputDecoration(
  212 + border: OutlineInputBorder(borderSide: BorderSide.none),
  213 + hintText: hintText,
  214 + hintStyle: TextStyle(
  215 + color: MyColours.color_999999,
  216 + fontSize: ScreenUtil().setSp(32),
  217 + ),
  218 + enabledBorder: new UnderlineInputBorder(
  219 + borderSide: BorderSide.none,
  220 + ),
  221 + focusedBorder: new UnderlineInputBorder(
  222 + borderSide: BorderSide.none,
  223 + ),
  224 + contentPadding: EdgeInsets.zero,
  225 + ),
  226 + onChanged: (value) {},
  227 + onEditingComplete: () {
  228 + FocusScope.of(context)
  229 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  230 + },
  231 + keyboardType: inputType,
  232 + )),
  233 + ),
  234 + Container(
  235 + child: Text(
  236 + subTitle,
  237 + style: TextStyle(
  238 + color: MyColours.color_333333,
  239 + fontWeight: FontWeight.bold,
  240 + fontSize: ScreenUtil().setSp(32)),
  241 + ),
  242 + ),
  243 + ],
  244 + ),
  245 + );
  246 + }
  247 +
  248 + ///选择
  249 + Widget _select(String title, String hintText, VoidCallback callback,
  250 + {bool needStar = true}) {
  251 + return InkWell(
  252 + onTap: callback,
  253 + child: Container(
  254 + padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(40)),
  255 + child: Row(
  256 + crossAxisAlignment: CrossAxisAlignment.center,
  257 + mainAxisAlignment: MainAxisAlignment.center,
  258 + children: [
  259 + Container(
  260 + child: Text(
  261 + title,
  262 + style: TextStyle(
  263 + color: MyColours.color_333333,
  264 + fontWeight: FontWeight.bold,
  265 + fontSize: ScreenUtil().setSp(34)),
  266 + ),
  267 + ),
  268 + HEmptyView(20),
  269 + needStar
  270 + ? Container(
  271 + child: Text(
  272 + '*',
  273 + style: TextStyle(
  274 + color: MyColours.color_199095,
  275 + fontWeight: FontWeight.bold,
  276 + ),
  277 + ),
  278 + )
  279 + : SizedBox(),
  280 + Spacer(),
  281 + Text(hintText,
  282 + style: TextStyle(
  283 + color: hintText == '请选择'
  284 + ? MyColours.color_999999
  285 + : MyColours.color_333333,
  286 + fontWeight:
  287 + hintText == '请选择' ? FontWeight.normal : FontWeight.bold,
  288 + fontSize: ScreenUtil().setSp(32),
  289 + )),
  290 + HEmptyView(20),
  291 + Image.asset(
  292 + Utils.getImgPath('arr_right_gray'),
  293 + width: ScreenUtil().setWidth(12),
  294 + height: ScreenUtil().setWidth(22),
  295 + )
  296 + ],
  297 + ),
  298 + ),
  299 + );
  300 + }
  301 +
  302 + // 当前的任务状态
  303 + ///#相机拍照,单图选择
  304 + _getFromPictureOrCamera(imageSource) async {
  305 + final pickedFile = await picker.getImage(source: imageSource);
  306 + File compressedFile = await FlutterNativeImage.compressImage(
  307 + pickedFile.path,
  308 + quality: 50,
  309 + percentage: 50);
  310 + setState(() {
  311 + if (pickedFile != null) {
  312 + UploadImgModel imgModel = UploadImgModel();
  313 + imgModel.file = compressedFile;
  314 + imgModel.process = 0.01;
  315 + uploadImageProvider.dish = imgModel;
  316 + } else {
  317 + print('No image selected.');
  318 + }
  319 + });
  320 + if (pickedFile != null) {
  321 + uploadImageProvider.dish.process = 0.01;
  322 + uploadImageProvider.dish.qiniuUrl = null;
  323 +
  324 + UploadImageUtil().startUploadOnly(
  325 + context, File(pickedFile.path), 3, true, uploadImageProvider);
  326 + }
  327 + }
  328 +
  329 + @override
  330 + Widget build(BuildContext context) {
  331 + uploadImageProvider =
  332 + Provider.of<UploadImageProvider>(context, listen: true);
  333 + menuManageProvider = Provider.of<MenuManageProvider>(context, listen: true);
  334 + return Material(
  335 + child: InkWell(
  336 + onTap: () {
  337 + FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
  338 + },
  339 + child: Scaffold(
  340 + appBar: SystemAppBar('添加菜品', onTap: () {
  341 + Navigator.pop(context);
  342 + }),
  343 + body: Column(children: [
  344 + Expanded(
  345 + child: SingleChildScrollView(
  346 + child: Column(
  347 + children: [
  348 + InkWell(
  349 + onTap: () {
  350 + DialogUtil.openImageModalBottomSheet(context,
  351 + lCallback: () {
  352 + Utils.getPickPermission(context, () {
  353 + _getFromPictureOrCamera(ImageSource.camera);
  354 + Navigator.pop(context);
  355 + }, Permission.camera);
  356 + }, rCallback: () {
  357 + Utils.getPickPermission(context, () {
  358 + _getFromPictureOrCamera(ImageSource.gallery);
  359 + // _getFromPictureOrCamera(ImageSource.gallery);
  360 + Navigator.pop(context);
  361 + },
  362 + Platform.isAndroid
  363 + ? Permission.storage
  364 + : Permission.photos);
  365 + });
  366 + },
  367 + child: Stack(children: [
  368 + uploadImageProvider.dish.file == null
  369 + ? uploadImageProvider.dish.qiniuUrl != null &&
  370 + uploadImageProvider.dish.qiniuUrl !=
  371 + ''
  372 + ? CachedNetworkImage(
  373 + imageUrl:
  374 + uploadImageProvider.dish.qiniuUrl,
  375 + fit: BoxFit.cover,
  376 + width: double.infinity,
  377 + height: ScreenUtil().setWidth(400),
  378 + )
  379 + : Container(
  380 + width: double.infinity,
  381 + height: ScreenUtil().setWidth(400),
  382 + color:
  383 + Color.fromRGBO(235, 234, 239, 1),
  384 + child: Column(
  385 + mainAxisAlignment:
  386 + MainAxisAlignment.center,
  387 + children: [
  388 + Container(
  389 + padding: EdgeInsets.all(
  390 + ScreenUtil().setWidth(34)),
  391 + decoration: BoxDecoration(
  392 + shape: BoxShape.circle,
  393 + border: Border.all(
  394 + width: ScreenUtil()
  395 + .setWidth(2),
  396 + color: MyColours
  397 + .color_c1c1c1,
  398 + )),
  399 + child: Image.asset(
  400 + Utils.getImgPath(
  401 + 'take-picture'),
  402 + width: ScreenUtil()
  403 + .setWidth(80)),
  404 + ),
  405 + VEmptyView(20),
  406 + Text(
  407 + '+菜谱效果图',
  408 + style: TextStyle(
  409 + fontSize:
  410 + ScreenUtil().setSp(30),
  411 + color:
  412 + MyColours.color_999999),
  413 + )
  414 + ],
  415 + ),
  416 + )
  417 + : Image.file(
  418 + uploadImageProvider.dish.file,
  419 + fit: BoxFit.cover,
  420 + width: double.infinity,
  421 + height: ScreenUtil().setWidth(400),
  422 + ),
  423 + (uploadImageProvider.dish.file != null) &&
  424 + uploadImageProvider.dish.process != 1 &&
  425 + uploadImageProvider.dish.process != 0.01
  426 + ? Container(
  427 + width: double.infinity,
  428 + height: ScreenUtil().setWidth(400),
  429 + child: Center(
  430 + child: Text('上传中...',
  431 + style: TextStyle(
  432 + color: MyColours.color_999999)),
  433 + ),
  434 + )
  435 + : Container(),
  436 + ])),
  437 + InkWell(
  438 + onTap: () {
  439 + setState(() {
  440 + swichState = !swichState;
  441 + });
  442 + },
  443 + child: Padding(
  444 + padding: EdgeInsets.symmetric(
  445 + horizontal: ScreenUtil().setWidth(40),
  446 + vertical: ScreenUtil().setWidth(40),
  447 + ),
  448 + child: Row(
  449 + mainAxisAlignment:
  450 + MainAxisAlignment.spaceBetween,
  451 + children: [
  452 + Column(
  453 + crossAxisAlignment:
  454 + CrossAxisAlignment.start,
  455 + children: [
  456 + // Container(
  457 + // child: Text(
  458 + // swichState ? '启用' : '停用',
  459 + // style: TextStyle(
  460 + // color: MyColours.color_333333,
  461 + // fontWeight: FontWeight.bold,
  462 + // fontSize: ScreenUtil().setSp(34)),
  463 + // ),
  464 + // ),
  465 + // VEmptyView(40),
  466 + Container(
  467 + child: Text(
  468 + swichState
  469 + ? '商品已上架,在所有点餐设备上显示'
  470 + : '商品已下架',
  471 + style: TextStyle(
  472 + color: MyColours.color_666666,
  473 + fontSize: ScreenUtil().setSp(24)),
  474 + ),
  475 + ),
  476 + ],
  477 + ),
  478 + Image.asset(
  479 + swichState
  480 + ? Utils.getImgPath('swich_on')
  481 + : Utils.getImgPath('swich_off'),
  482 + width: ScreenUtil().setWidth(122),
  483 + height: ScreenUtil().setWidth(82),
  484 + )
  485 + ],
  486 + )),
  487 + ),
  488 + MyDivider(
  489 + double.infinity,
  490 + ScreenUtil().setWidth(20),
  491 + color: Color.fromRGBO(235, 234, 239, 1),
  492 + ),
  493 + Container(
  494 + height: ScreenUtil().setWidth(2),
  495 + color: MyColours.color_efefef,
  496 + margin: EdgeInsets.only(
  497 + left: ScreenUtil().setWidth(40),
  498 + right: ScreenUtil().setWidth(40)),
  499 + ),
  500 + Padding(
  501 + padding: EdgeInsets.symmetric(
  502 + horizontal: ScreenUtil().setWidth(40),
  503 + ),
  504 + child: _textfield('菜品名称', '请输入菜品名称',
  505 + _nameController, _nameFocusNode, '',
  506 + inputType: TextInputType.text)),
  507 + VEmptyView(10),
  508 + Container(
  509 + height: ScreenUtil().setWidth(2),
  510 + color: MyColours.color_efefef,
  511 + margin: EdgeInsets.only(
  512 + left: ScreenUtil().setWidth(40),
  513 + right: ScreenUtil().setWidth(40)),
  514 + ),
  515 + VEmptyView(10),
  516 + Padding(
  517 + padding: EdgeInsets.symmetric(
  518 + horizontal: ScreenUtil().setWidth(40),
  519 + ),
  520 + child: _textfield('菜品价格', '请输入菜品价格',
  521 + _priceController, _priceFocusNode, '元')),
  522 + VEmptyView(10),
  523 + Container(
  524 + height: ScreenUtil().setWidth(2),
  525 + color: MyColours.color_efefef,
  526 + margin: EdgeInsets.only(
  527 + left: ScreenUtil().setWidth(40),
  528 + right: ScreenUtil().setWidth(40)),
  529 + ),
  530 + VEmptyView(10),
  531 + Padding(
  532 + padding: EdgeInsets.symmetric(
  533 + horizontal: ScreenUtil().setWidth(40),
  534 + ),
  535 + child: _select('菜品分类', categoryStr, () {
  536 + FocusScope.of(context)
  537 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  538 + DialogUtil.showSelectCusmanDialog(
  539 + context, categoryStrList, (value) {
  540 + if (value != null) {
  541 + setState(() {
  542 + categoryStr = categoryStrList[value.first];
  543 + });
  544 + }
  545 + }, selecteds: [
  546 + categoryStrList.indexOf(categoryStr)
  547 + ]).then((value) {});
  548 + })),
  549 + VEmptyView(10),
  550 + Container(
  551 + height: ScreenUtil().setWidth(2),
  552 + color: MyColours.color_efefef,
  553 + margin: EdgeInsets.only(
  554 + left: ScreenUtil().setWidth(40),
  555 + right: ScreenUtil().setWidth(40))),
  556 + VEmptyView(10),
  557 + Padding(
  558 + padding: EdgeInsets.symmetric(
  559 + horizontal: ScreenUtil().setWidth(40),
  560 + ),
  561 + child: _select('计价方式', specStr, () {
  562 + FocusScope.of(context)
  563 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  564 + DialogUtil.showSelectCusmanDialog(
  565 + context, specStrList, (value) {
  566 + if (value != null) {
  567 + setState(() {
  568 + specStr = specStrList[value.first];
  569 + });
  570 + }
  571 + }, selecteds: [specStrList.indexOf(specStr)])
  572 + .then((value) {});
  573 + })),
  574 + VEmptyView(10),
  575 + ],
  576 + ),
  577 + )),
  578 + Padding(
  579 + padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(40), 0,
  580 + ScreenUtil().setWidth(40), ScreenUtil().setWidth(40)),
  581 + child: RoundButton(
  582 + onPressed: () async {
  583 + FocusScope.of(context)
  584 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  585 + _addCookbook();
  586 + },
  587 + text: '保存',
  588 + fontSize: 34,
  589 + isBold: false,
  590 + height: ScreenUtil().setWidth(80),
  591 + width: double.infinity,
  592 + radius: ScreenUtil().setWidth(10),
  593 + ))
  594 + ]))));
  595 + }
  596 +}
  1 +import 'package:flutter/material.dart';
  2 +import 'package:flutter_screenutil/screenutil.dart';
  3 +import 'package:one_key/constant/state.dart';
  4 +import 'package:one_key/models/cookbook_category_model.dart';
  5 +import 'package:one_key/pages/notebook/statistics_page.dart';
  6 +import 'package:one_key/provider/menu_provider.dart';
  7 +import 'package:one_key/provider/user_model.dart';
  8 +import 'package:one_key/res/colors.dart';
  9 +import 'package:one_key/utils/dialog_util.dart';
  10 +import 'package:one_key/utils/event_bus.dart';
  11 +import 'package:one_key/utils/utils.dart';
  12 +import 'package:one_key/widgets/MyDivider.dart';
  13 +import 'package:one_key/widgets/h_empty_view.dart';
  14 +import 'package:one_key/widgets/page_exception.dart';
  15 +import 'package:one_key/widgets/system_app_bar.dart';
  16 +import 'package:provider/provider.dart';
  17 +
  18 +class MenuCategoryPage extends StatefulWidget {
  19 + MenuCategoryPage({Key key}) : super(key: key);
  20 +
  21 + @override
  22 + _MenuCategoryPageState createState() => _MenuCategoryPageState();
  23 +}
  24 +
  25 +class _MenuCategoryPageState extends State<MenuCategoryPage> {
  26 + MenuManageProvider menuManageProvider;
  27 + @override
  28 + void initState() {
  29 + super.initState();
  30 + WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  31 + _getCookbookBySellerId(showLoading: false);
  32 + });
  33 + }
  34 +
  35 + ///添加菜品分类
  36 + _addCookbookClass(String name, {bool showLoading = true}) async {
  37 + Map<String, String> params = {
  38 + "sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
  39 + 'class_name': name
  40 + };
  41 +
  42 + bool sucess = await menuManageProvider.addCookbookClass(context, params,
  43 + showLoading: showLoading);
  44 + if (sucess) {
  45 + _getCookbookBySellerId(showLoading: false);
  46 + }
  47 + }
  48 +
  49 + ///获取分类数据
  50 + _getCookbookBySellerId({bool showLoading = true}) async {
  51 + Map<String, String> params = {
  52 + "SellerId": Provider.of<UserModel>(context, listen: false).user.sellerid,
  53 + };
  54 +
  55 + await menuManageProvider.getCookbookClassBySellerId(context, params,
  56 + showLoading: showLoading);
  57 + }
  58 +
  59 + //删除分类数据
  60 + _delCookbookById(String idstr, {bool showLoading = true}) async {
  61 + Map<String, String> params = {
  62 + "id": idstr,
  63 + };
  64 +
  65 + bool success = await menuManageProvider
  66 + .delCookbookClassById(context, params, showLoading: showLoading);
  67 + if (success) {
  68 + EventBus().emit('menu_manage_page');
  69 + //删除成功
  70 + _getCookbookBySellerId(showLoading: false);
  71 + }
  72 + }
  73 +
  74 + ///表头
  75 + Widget _tableItem(CookbookCategorySunModel model, int index,
  76 + TableItemType type, IntCallback callback) {
  77 + return InkWell(
  78 + onTap: () {
  79 + callback(index);
  80 + },
  81 + child: Container(
  82 + padding: EdgeInsets.only(left: ScreenUtil().setWidth(30)),
  83 + height: ScreenUtil().setWidth(130),
  84 + color: type == TableItemType.TableItemTypeHeader
  85 + ? Color.fromRGBO(235, 234, 239, 1)
  86 + : MyColours.color_fefefe,
  87 + child: Row(
  88 + children: [
  89 + Container(
  90 + width: ScreenUtil().setWidth(85 * 2),
  91 + height: double.infinity,
  92 + child: Row(
  93 + children: [
  94 + /*** 发版注释
  95 + Image.asset(
  96 + Utils.getImgPath(model.select ? 'select' : 'unselect'),
  97 + width: ScreenUtil().setWidth(34),
  98 + height: ScreenUtil().setWidth(34),
  99 + ),
  100 + */
  101 + // HEmptyView(20),
  102 + Expanded(
  103 + child: Text(
  104 + type == TableItemType.TableItemTypeHeader
  105 + ? '序号'
  106 + : '${index + 1}',
  107 + textAlign: TextAlign.center,
  108 + style: TextStyle(
  109 + fontSize: ScreenUtil().setSp(28),
  110 + color: MyColours.color_333333),
  111 + )),
  112 + HEmptyView(30),
  113 + ],
  114 + ),
  115 + ),
  116 + Expanded(
  117 + child: Container(
  118 + alignment: Alignment.center,
  119 + width: ScreenUtil().setWidth(87 * 2),
  120 + height: double.infinity,
  121 + child: Text(
  122 + type == TableItemType.TableItemTypeHeader
  123 + ? '分类名称'
  124 + : model.className,
  125 + style: TextStyle(
  126 + fontSize: ScreenUtil().setSp(28),
  127 + color: MyColours.color_333333),
  128 + ))),
  129 + Container(
  130 + alignment: Alignment.center,
  131 + width: ScreenUtil().setWidth(116 * 2),
  132 + height: double.infinity,
  133 + child: Text(
  134 + type == TableItemType.TableItemTypeHeader
  135 + ? '操作'
  136 + : model.className == '10道必点菜'
  137 + ? ''
  138 + : '删除',
  139 + style: TextStyle(
  140 + fontSize: ScreenUtil().setSp(28),
  141 + color: MyColours.color_333333),
  142 + )),
  143 + ],
  144 + ),
  145 + ),
  146 + );
  147 + }
  148 +
  149 + @override
  150 + Widget build(BuildContext context) {
  151 + menuManageProvider = Provider.of<MenuManageProvider>(context, listen: true);
  152 + return Scaffold(
  153 + appBar: SystemAppBar(
  154 + '分类管理',
  155 + onTap: () {
  156 + Navigator.pop(context);
  157 + },
  158 + rightImgName: '添加分类',
  159 + onTapRight: () {
  160 + //
  161 + DialogUtil.textfeildAlertDialog(context,
  162 + title: '添加分类', content: '输入分类名称', rCallback: (name) {
  163 + _addCookbookClass(name, showLoading: true);
  164 + });
  165 + },
  166 + ),
  167 + body: Consumer<MenuManageProvider>(builder: (context, model, _) {
  168 + if (model.pageStateCategory != PageState.Success) {
  169 + return ExceptionPage(
  170 + pageState: model.pageStateCategory,
  171 + callback: () {
  172 + // offset = 0;
  173 + // getMessage(showLoading: true);
  174 + // _couponNetworkData();
  175 + _getCookbookBySellerId(showLoading: true);
  176 + },
  177 + emptyMsg: "菜品分类是空哒,快点击右上角添加分类吧",
  178 + emptyImg: "empty_search",
  179 + showMsg: "加载中,请稍后...",
  180 + );
  181 + } else {
  182 + return Column(
  183 + children: [
  184 + //表头
  185 + _tableItem(model.categorySunModel[0], 0,
  186 + TableItemType.TableItemTypeHeader, (index) {}),
  187 + Expanded(
  188 + child: ListView.builder(
  189 + itemCount: model.categorySunModel.length,
  190 + itemBuilder: (BuildContext context, int index) {
  191 + return Column(children: [
  192 + _tableItem(model.categorySunModel[index], index,
  193 + TableItemType.TableItemTypeBody, (index) {
  194 + if (model.categorySunModel[index].className !=
  195 + '10道必点菜') {
  196 + DialogUtil.cupertinoAlertDialog(context,
  197 + title: '',
  198 + content: '删除后,该分类下所有菜品都将删除', rCallback: () {
  199 + _delCookbookById(
  200 + model.categorySunModel[index].id);
  201 + });
  202 + }
  203 + }),
  204 + Padding(
  205 + padding: EdgeInsets.symmetric(
  206 + horizontal: ScreenUtil().setWidth(40)),
  207 + child: MyDivider(
  208 + double.infinity, ScreenUtil().setWidth(2),
  209 + color: MyColours.color_f5f5f5))
  210 + ]);
  211 + })),
  212 + ],
  213 + );
  214 + }
  215 + }));
  216 + }
  217 +}
@@ -34,16 +34,27 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -34,16 +34,27 @@ class _MenuManagePageState extends State<MenuManagePage> {
34 void initState() { 34 void initState() {
35 super.initState(); 35 super.initState();
36 WidgetsBinding.instance.addPostFrameCallback((timeStamp) { 36 WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
37 - _getCookbookByClass(); 37 + _getCookbookByClass(showLoading: false);
38 }); 38 });
  39 + EventBus().on('menu_manage_page', (arg) {
  40 + _getCookbookByClass(showLoading: false);
  41 + });
  42 + }
  43 +
  44 + @override
  45 + void dispose() {
  46 + // TODO: implement dispose
  47 + super.dispose();
  48 + EventBus().off('menu_manage_page');
39 } 49 }
40 50
41 - _getCookbookByClass() async { 51 + _getCookbookByClass({bool showLoading = true}) async {
42 Map<String, String> params = { 52 Map<String, String> params = {
43 "sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid, 53 "sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
44 }; 54 };
45 55
46 - await menuManageProvider.getCookbookByClass(context, params); 56 + await menuManageProvider.getCookbookByClass(context, params,
  57 + showLoading: showLoading);
47 } 58 }
48 59
49 @override 60 @override
@@ -72,6 +83,7 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -72,6 +83,7 @@ class _MenuManagePageState extends State<MenuManagePage> {
72 // offset = 0; 83 // offset = 0;
73 // getMessage(showLoading: true); 84 // getMessage(showLoading: true);
74 // _couponNetworkData(); 85 // _couponNetworkData();
  86 + _getCookbookByClass(showLoading: true);
75 }, 87 },
76 emptyMsg: "菜品是空哒,快点击分类管理添加分类和菜品吧", 88 emptyMsg: "菜品是空哒,快点击分类管理添加分类和菜品吧",
77 emptyImg: "empty_search", 89 emptyImg: "empty_search",
@@ -325,15 +337,8 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -325,15 +337,8 @@ class _MenuManagePageState extends State<MenuManagePage> {
325 ScreenUtil().setWidth(40)), 337 ScreenUtil().setWidth(40)),
326 child: RoundButton( 338 child: RoundButton(
327 onPressed: () async { 339 onPressed: () async {
328 - bool needRefresh =  
329 - await NavigatorUtil.goCouponEditPage(  
330 - context);  
331 - print(needRefresh);  
332 - if (needRefresh != null && needRefresh) {  
333 - //刷新页面数据  
334 - // _controller.callRefresh();  
335 - // _couponNetworkData();  
336 - } 340 + await NavigatorUtil.goMenuAddDishesPage(
  341 + context);
337 }, 342 },
338 text: '添加\n菜品', 343 text: '添加\n菜品',
339 fontSize: 26, 344 fontSize: 26,
@@ -351,7 +356,8 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -351,7 +356,8 @@ class _MenuManagePageState extends State<MenuManagePage> {
351 child: RoundButton( 356 child: RoundButton(
352 onPressed: () async { 357 onPressed: () async {
353 bool needRefresh = 358 bool needRefresh =
354 - await NavigatorUtil.goCouponEditPage(context); 359 + await NavigatorUtil.goMenuCategoryPage(
  360 + context);
355 print(needRefresh); 361 print(needRefresh);
356 if (needRefresh != null && needRefresh) { 362 if (needRefresh != null && needRefresh) {
357 //刷新页面数据 363 //刷新页面数据
@@ -2,7 +2,9 @@ import 'package:flutter/material.dart'; @@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
2 import 'package:one_key/constant/constant.dart'; 2 import 'package:one_key/constant/constant.dart';
3 import 'package:one_key/constant/error.dart'; 3 import 'package:one_key/constant/error.dart';
4 import 'package:one_key/constant/state.dart'; 4 import 'package:one_key/constant/state.dart';
  5 +import 'package:one_key/models/cookbook_category_model.dart';
5 import 'package:one_key/models/cookbook_model.dart'; 6 import 'package:one_key/models/cookbook_model.dart';
  7 +import 'package:one_key/models/cookbook_spec_model.dart';
6 import 'package:one_key/net/base_resp.dart'; 8 import 'package:one_key/net/base_resp.dart';
7 import 'package:one_key/net/dio_util.dart'; 9 import 'package:one_key/net/dio_util.dart';
8 import 'package:one_key/net/http_url.dart'; 10 import 'package:one_key/net/http_url.dart';
@@ -10,14 +12,39 @@ import 'package:one_key/utils/utils.dart'; @@ -10,14 +12,39 @@ import 'package:one_key/utils/utils.dart';
10 12
11 class MenuManageProvider extends ChangeNotifier { 13 class MenuManageProvider extends ChangeNotifier {
12 PageState pageState = PageState.Loading; 14 PageState pageState = PageState.Loading;
  15 + PageState pageStateCategory = PageState.Loading;
13 List<MenuModel> menuModel; //菜品数据 16 List<MenuModel> menuModel; //菜品数据
  17 + List<CookbookCategorySunModel> categorySunModel; //菜品分类数据
  18 + List<CookbookSpecSunModel> specSunModel; //计价单位
  19 + /// 获取商家计价单位
  20 + getSpecBySellerid(BuildContext context, Map<String, String> params,
  21 + {showLoading = false}) async {
  22 + BaseResp<dynamic> baseResp = await DioUtil()
  23 + .request<dynamic>(context, Method.get, HttpUrl.get_spec_by_sellerid,
  24 + data: params, showLoading: showLoading)
  25 + .catchError((error) {
  26 + print(error.toString());
  27 + });
  28 + specSunModel = [];
  29 + if (baseResp != null && baseResp.code == Constant.status_success) {
  30 + if (baseResp.data is List) {
  31 + if (baseResp.data.length > 0) {
  32 + specSunModel = CookbookSpecModel.fromJson(baseResp.responseData).data;
  33 + }
  34 + } else {}
  35 + } else {
  36 + Utils.showToast(baseResp.msg ?? "");
  37 + }
  38 + notifyListeners();
  39 + }
14 40
15 ///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传 41 ///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传
16 42
17 - getCookbookByClass(BuildContext context, Map<String, String> params) async { 43 + getCookbookByClass(BuildContext context, Map<String, String> params,
  44 + {showLoading = false}) async {
18 BaseResp<dynamic> baseResp = await DioUtil() 45 BaseResp<dynamic> baseResp = await DioUtil()
19 .request<dynamic>(context, Method.get, HttpUrl.get_cookbook_by_class, 46 .request<dynamic>(context, Method.get, HttpUrl.get_cookbook_by_class,
20 - data: params, showLoading: false) 47 + data: params, showLoading: showLoading)
21 .catchError((error) { 48 .catchError((error) {
22 print(error.toString()); 49 print(error.toString());
23 if (error is MyError) { 50 if (error is MyError) {
@@ -54,4 +81,113 @@ class MenuManageProvider extends ChangeNotifier { @@ -54,4 +81,113 @@ class MenuManageProvider extends ChangeNotifier {
54 } 81 }
55 notifyListeners(); 82 notifyListeners();
56 } 83 }
  84 +
  85 + ///获取商家所有菜品分类
  86 + getCookbookClassBySellerId(BuildContext context, Map<String, String> params,
  87 + {showLoading = false}) async {
  88 + BaseResp<dynamic> baseResp = await DioUtil()
  89 + .request<dynamic>(
  90 + context, Method.get, HttpUrl.get_cookbook_by_seller_id,
  91 + data: params, showLoading: showLoading)
  92 + .catchError((error) {
  93 + print(error.toString());
  94 + if (error is MyError) {
  95 + switch (error.type) {
  96 + case 1:
  97 + pageStateCategory = PageState.ConnectivityError;
  98 + break;
  99 + case 2:
  100 + pageStateCategory = PageState.ConnectivityTimeOut;
  101 + break;
  102 + default:
  103 + pageStateCategory = PageState.ConnectivityError;
  104 + break;
  105 + }
  106 + }
  107 + notifyListeners();
  108 + });
  109 + categorySunModel = [];
  110 + if (baseResp != null && baseResp.code == Constant.status_success) {
  111 + if (baseResp.data is List) {
  112 + if (baseResp.data.length == 0) {
  113 + pageStateCategory = PageState.Empty;
  114 + } else {
  115 + categorySunModel =
  116 + CookbookCategoryModel.fromJson(baseResp.responseData).data;
  117 + pageStateCategory = PageState.Success;
  118 + }
  119 + } else {
  120 + pageStateCategory = PageState.Empty;
  121 + }
  122 + } else {
  123 + Utils.showToast(baseResp.msg ?? "");
  124 + pageStateCategory = PageState.ConnectivityError;
  125 + }
  126 + notifyListeners();
  127 + }
  128 +
  129 + ///删除菜品分类
  130 +
  131 + Future<bool> delCookbookClassById(
  132 + BuildContext context, Map<String, String> params,
  133 + {showLoading = false}) async {
  134 + BaseResp<dynamic> baseResp = await DioUtil()
  135 + .request<dynamic>(context, Method.get, HttpUrl.del_cookbook_by_id,
  136 + data: params, showLoading: showLoading)
  137 + .catchError((error) {
  138 + print(error.toString());
  139 + });
  140 +
  141 + if (baseResp != null && baseResp.code == Constant.status_success) {
  142 + if (baseResp.data['succ'] == 1) {
  143 + return true;
  144 + }
  145 + } else {
  146 + Utils.showToast(baseResp.msg ?? "");
  147 + }
  148 + return false;
  149 + }
  150 +
  151 + ///添加菜品
  152 +
  153 + Future<bool> addCookbook(BuildContext context, Map<String, String> params,
  154 + {showLoading = false}) async {
  155 + BaseResp<dynamic> baseResp = await DioUtil()
  156 + .request<dynamic>(context, Method.get, HttpUrl.add_cookbook,
  157 + data: params, showLoading: showLoading)
  158 + .catchError((error) {
  159 + print(error.toString());
  160 + });
  161 +
  162 + if (baseResp != null && baseResp.code == Constant.status_success) {
  163 + if (baseResp.data['data'] != '') {
  164 + return true;
  165 + }
  166 + } else {
  167 + Utils.showToast(baseResp.msg ?? "");
  168 + }
  169 + return false;
  170 + }
  171 +
  172 + ///添加菜品分类信息
  173 +
  174 + Future<bool> addCookbookClass(
  175 + BuildContext context, Map<String, String> params,
  176 + {showLoading = false}) async {
  177 + BaseResp<dynamic> baseResp = await DioUtil()
  178 + .request<dynamic>(context, Method.get, HttpUrl.add_cookbook_class,
  179 + data: params, showLoading: showLoading)
  180 + .catchError((error) {
  181 + print(error.toString());
  182 + });
  183 +
  184 + if (baseResp != null && baseResp.code == Constant.status_success) {
  185 + if (baseResp.data['data'] != '') {
  186 + return true;
  187 + }
  188 + } else {
  189 + Utils.showToast(baseResp.msg ?? "");
  190 + }
  191 + return false;
  192 + }
57 } 193 }
@@ -18,6 +18,7 @@ class UploadImageProvider extends ChangeNotifier { @@ -18,6 +18,7 @@ class UploadImageProvider extends ChangeNotifier {
18 UploadImgModel touxiang = UploadImgModel(); //头像 18 UploadImgModel touxiang = UploadImgModel(); //头像
19 UploadImgModel erweima = UploadImgModel(); //二维码 19 UploadImgModel erweima = UploadImgModel(); //二维码
20 UploadImgModel mentou = UploadImgModel(); //店铺信息----门头照片 20 UploadImgModel mentou = UploadImgModel(); //店铺信息----门头照片
  21 + UploadImgModel dish = UploadImgModel(); //菜品
21 double imgSizeTouxiang = 64; 22 double imgSizeTouxiang = 64;
22 double imgSizeErweima = 22; 23 double imgSizeErweima = 22;
23 double imgSizeMenTou = 64; 24 double imgSizeMenTou = 64;
@@ -28,6 +29,7 @@ class UploadImageProvider extends ChangeNotifier { @@ -28,6 +29,7 @@ class UploadImageProvider extends ChangeNotifier {
28 UploadImageProvider() { 29 UploadImageProvider() {
29 touxiang.process = 0.01; 30 touxiang.process = 0.01;
30 erweima.process = 0.01; 31 erweima.process = 0.01;
  32 + dish.process = 0.01;
31 } 33 }
32 34
33 /// 获取七牛上传token信息 35 /// 获取七牛上传token信息
@@ -405,4 +405,18 @@ class NavigatorUtil { @@ -405,4 +405,18 @@ class NavigatorUtil {
405 {replace = false}) { 405 {replace = false}) {
406 return _navigateTo(context, "${Routes.menu_manage_page}", replace: replace); 406 return _navigateTo(context, "${Routes.menu_manage_page}", replace: replace);
407 } 407 }
  408 +
  409 + /// 菜单分类管理
  410 + static Future<dynamic> goMenuCategoryPage(BuildContext context,
  411 + {replace = false}) {
  412 + return _navigateTo(context, "${Routes.menu_category_page}",
  413 + replace: replace);
  414 + }
  415 +
  416 + /// 添加菜品页面
  417 + static Future<dynamic> goMenuAddDishesPage(BuildContext context,
  418 + {replace = false}) {
  419 + return _navigateTo(context, "${Routes.menu_add_dishes_page}",
  420 + replace: replace);
  421 + }
408 } 422 }
@@ -37,6 +37,8 @@ import 'package:one_key/pages/message/message_order_menu.dart'; @@ -37,6 +37,8 @@ import 'package:one_key/pages/message/message_order_menu.dart';
37 import 'package:one_key/pages/my/base_info.dart'; 37 import 'package:one_key/pages/my/base_info.dart';
38 import 'package:one_key/pages/my/book_time_set.dart'; 38 import 'package:one_key/pages/my/book_time_set.dart';
39 import 'package:one_key/pages/my/contant_page.dart'; 39 import 'package:one_key/pages/my/contant_page.dart';
  40 +import 'package:one_key/pages/my/menu_type/menu_add_dishes_page.dart';
  41 +import 'package:one_key/pages/my/menu_type/menu_category_page.dart';
40 import 'package:one_key/pages/my/menu_type/menu_manage_page.dart'; 42 import 'package:one_key/pages/my/menu_type/menu_manage_page.dart';
41 import 'package:one_key/pages/my/my_integral_page.dart'; 43 import 'package:one_key/pages/my/my_integral_page.dart';
42 import 'package:one_key/pages/my/receive_orders_time_set.dart'; 44 import 'package:one_key/pages/my/receive_orders_time_set.dart';
@@ -628,3 +630,25 @@ var menuManagePageHandle = new Handler( @@ -628,3 +630,25 @@ var menuManagePageHandle = new Handler(
628 // return ChangeNotifierProvider<UploadImageProvider>( 630 // return ChangeNotifierProvider<UploadImageProvider>(
629 // create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage()); 631 // create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage());
630 }); 632 });
  633 +
  634 +///菜单分类管理页面
  635 +var menuCategoryPageHandle = new Handler(
  636 + handlerFunc: (BuildContext context, Map<dynamic, List<Object>> params) {
  637 + // SmsInfoData data = SmsInfoData.fromJson(json.decode(
  638 + // FluroConvertUtils.fluroCnParamsDecode(params["smsInfoData"].first)));
  639 + return ChangeNotifierProvider<MenuManageProvider>(
  640 + create: (_) => MenuManageProvider(), child: MenuCategoryPage());
  641 + // return ChangeNotifierProvider<UploadImageProvider>(
  642 + // create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage());
  643 +});
  644 +
  645 +///添加菜品
  646 +var menuAddDishesPageHandle = new Handler(
  647 + handlerFunc: (BuildContext context, Map<dynamic, List<Object>> params) {
  648 + // SmsInfoData data = SmsInfoData.fromJson(json.decode(
  649 + // FluroConvertUtils.fluroCnParamsDecode(params["smsInfoData"].first)));
  650 + return ChangeNotifierProvider<MenuManageProvider>(
  651 + create: (_) => MenuManageProvider(), child: MenuAddDishesPage());
  652 + // return ChangeNotifierProvider<UploadImageProvider>(
  653 + // create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage());
  654 +});
@@ -56,6 +56,8 @@ class Routes { @@ -56,6 +56,8 @@ class Routes {
56 static String room_type_select_table_page = 56 static String room_type_select_table_page =
57 "/room_type_select_table_page"; //包间管理中桌位选择页面 57 "/room_type_select_table_page"; //包间管理中桌位选择页面
58 static String menu_manage_page = "/menu_manage_page"; //菜单管理页面 58 static String menu_manage_page = "/menu_manage_page"; //菜单管理页面
  59 + static String menu_category_page = "/menu_category_page"; //菜单分类管理
  60 + static String menu_add_dishes_page = "/menu_add_dishes_page"; //添加菜品页面
59 61
60 static void configureRoutes(FluroRouter router) { 62 static void configureRoutes(FluroRouter router) {
61 router.notFoundHandler = new Handler( 63 router.notFoundHandler = new Handler(
@@ -119,5 +121,7 @@ class Routes { @@ -119,5 +121,7 @@ class Routes {
119 router.define(room_type_select_table_page, 121 router.define(room_type_select_table_page,
120 handler: roomTypeSelectTablePageHandler); 122 handler: roomTypeSelectTablePageHandler);
121 router.define(menu_manage_page, handler: menuManagePageHandle); 123 router.define(menu_manage_page, handler: menuManagePageHandle);
  124 + router.define(menu_category_page, handler: menuCategoryPageHandle);
  125 + router.define(menu_add_dishes_page, handler: menuAddDishesPageHandle);
122 } 126 }
123 } 127 }
@@ -4,6 +4,7 @@ import 'dart:ui'; @@ -4,6 +4,7 @@ import 'dart:ui';
4 import 'package:common_utils/common_utils.dart'; 4 import 'package:common_utils/common_utils.dart';
5 import 'package:flutter/cupertino.dart'; 5 import 'package:flutter/cupertino.dart';
6 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
  7 +import 'package:flutter/services.dart';
7 import 'package:flutter_picker/flutter_picker.dart'; 8 import 'package:flutter_picker/flutter_picker.dart';
8 import 'package:flutter_screenutil/flutter_screenutil.dart'; 9 import 'package:flutter_screenutil/flutter_screenutil.dart';
9 import 'package:one_key/constant/constant.dart'; 10 import 'package:one_key/constant/constant.dart';
@@ -13,6 +14,7 @@ import 'package:one_key/pages/message/message_dialog_item.dart'; @@ -13,6 +14,7 @@ import 'package:one_key/pages/message/message_dialog_item.dart';
13 import 'package:one_key/provider/message_dialog_model.dart'; 14 import 'package:one_key/provider/message_dialog_model.dart';
14 import 'package:one_key/provider/table_manager_model.dart'; 15 import 'package:one_key/provider/table_manager_model.dart';
15 import 'package:one_key/res/colors.dart'; 16 import 'package:one_key/res/colors.dart';
  17 +import 'package:one_key/utils/NumLengthInputFormatter.dart';
16 import 'package:one_key/utils/misc.dart'; 18 import 'package:one_key/utils/misc.dart';
17 import 'package:one_key/route/navigator_util.dart'; 19 import 'package:one_key/route/navigator_util.dart';
18 import 'package:one_key/utils/utils.dart'; 20 import 'package:one_key/utils/utils.dart';
@@ -31,6 +33,86 @@ typedef CustomCallBack = void Function(Object object); @@ -31,6 +33,86 @@ typedef CustomCallBack = void Function(Object object);
31 typedef CustomCallBackMap = void Function(Map<String, String> object); 33 typedef CustomCallBackMap = void Function(Map<String, String> object);
32 34
33 class DialogUtil { 35 class DialogUtil {
  36 + ///添加图片UI弹出
  37 + static openImageModalBottomSheet(context,
  38 + {VoidCallback lCallback, VoidCallback rCallback}) async {
  39 + final option = await showModalBottomSheet(
  40 + context: context,
  41 + backgroundColor: Colors.transparent,
  42 + isDismissible: false,
  43 + builder: (BuildContext context) {
  44 + return Container(
  45 + // height: ScreenUtil().setWidth(180 * 2),
  46 + decoration: BoxDecoration(
  47 + color: MyColours.color_ffffff,
  48 + borderRadius: BorderRadius.only(
  49 + topLeft: Radius.circular(ScreenUtil().setWidth(24)),
  50 + topRight: Radius.circular(ScreenUtil().setWidth(24)))),
  51 + child: Column(
  52 + mainAxisSize: MainAxisSize.min,
  53 + children: <Widget>[
  54 + InkWell(
  55 + onTap: lCallback,
  56 + child: Container(
  57 + width: double.infinity,
  58 + height: ScreenUtil().setWidth(58 * 2),
  59 + child: Center(
  60 + child: Text(
  61 + '拍摄',
  62 + style: TextStyle(
  63 + fontSize: ScreenUtil().setSp(32),
  64 + color: MyColours.color_353535,
  65 + fontWeight: FontWeight.bold),
  66 + ),
  67 + )),
  68 + ),
  69 + MyDivider(
  70 + double.infinity,
  71 + ScreenUtil().setWidth(2),
  72 + color: MyColours.color_EEEEEE,
  73 + ),
  74 + InkWell(
  75 + onTap: rCallback,
  76 + child: Container(
  77 + width: double.infinity,
  78 + height: ScreenUtil().setWidth(58 * 2),
  79 + child: Center(
  80 + child: Text(
  81 + '从相册选择',
  82 + style: TextStyle(
  83 + fontSize: ScreenUtil().setSp(32),
  84 + color: MyColours.color_353535,
  85 + fontWeight: FontWeight.bold),
  86 + ),
  87 + )),
  88 + ),
  89 + MyDivider(
  90 + double.infinity,
  91 + ScreenUtil().setWidth(10),
  92 + color: MyColours.color_EEEEEE,
  93 + ),
  94 + InkWell(
  95 + onTap: () {
  96 + Navigator.pop(context, '取消');
  97 + },
  98 + child: Container(
  99 + width: double.infinity,
  100 + height: ScreenUtil().setWidth(58 * 2),
  101 + child: Center(
  102 + child: Text(
  103 + '取消',
  104 + style: TextStyle(
  105 + fontSize: ScreenUtil().setSp(32),
  106 + color: MyColours.color_353535,
  107 + fontWeight: FontWeight.bold),
  108 + ),
  109 + )))
  110 + ],
  111 + ),
  112 + );
  113 + });
  114 + }
  115 +
34 static Future openCreateAreaDialog(BuildContext context, 116 static Future openCreateAreaDialog(BuildContext context,
35 {CustomCallBack onTap}) async { 117 {CustomCallBack onTap}) async {
36 TextEditingController controller = TextEditingController(); 118 TextEditingController controller = TextEditingController();
@@ -1915,11 +1997,13 @@ class DialogUtil { @@ -1915,11 +1997,13 @@ class DialogUtil {
1915 context: context, 1997 context: context,
1916 builder: (context) { 1998 builder: (context) {
1917 return CupertinoAlertDialog( 1999 return CupertinoAlertDialog(
1918 - title: Text(title,  
1919 - style: TextStyle(  
1920 - fontWeight: FontWeight.bold,  
1921 - fontSize: ScreenUtil().setSp(30),  
1922 - color: MyColours.color_353535)), 2000 + title: title != ''
  2001 + ? Text(title,
  2002 + style: TextStyle(
  2003 + fontWeight: FontWeight.bold,
  2004 + fontSize: ScreenUtil().setSp(30),
  2005 + color: MyColours.color_353535))
  2006 + : SizedBox(),
1923 content: Text(content, 2007 content: Text(content,
1924 style: TextStyle( 2008 style: TextStyle(
1925 fontSize: ScreenUtil().setSp(30), 2009 fontSize: ScreenUtil().setSp(30),
@@ -1950,4 +2034,93 @@ class DialogUtil { @@ -1950,4 +2034,93 @@ class DialogUtil {
1950 }, 2034 },
1951 ); 2035 );
1952 } 2036 }
  2037 +
  2038 +//输入弹框
  2039 + static Future textfeildAlertDialog(BuildContext context,
  2040 + {String title = "标题",
  2041 + String content = "内容",
  2042 + String lTitle = "取消",
  2043 + String rTitle = "确定",
  2044 + VoidCallback lCallback,
  2045 + CustomCallBack rCallback}) {
  2046 + String name = '';
  2047 + showCupertinoDialog(
  2048 + context: context,
  2049 + builder: (context) {
  2050 + return CupertinoAlertDialog(
  2051 + title: title != ''
  2052 + ? Text(title,
  2053 + style: TextStyle(
  2054 + fontWeight: FontWeight.bold,
  2055 + fontSize: ScreenUtil().setSp(30),
  2056 + color: MyColours.color_353535))
  2057 + : SizedBox(),
  2058 + content: Material(
  2059 + color: Colors.transparent,
  2060 + child: TextField(
  2061 + maxLines: 1,
  2062 + // //光标颜色
  2063 + // cursorColor:
  2064 + // widget.isSelect ? Colors.white : MyColours.color_199095,
  2065 + //输入文本的样式
  2066 + inputFormatters: [
  2067 + LengthLimitingTextInputFormatter(10),
  2068 + ],
  2069 + textAlignVertical: TextAlignVertical.bottom,
  2070 + textAlign: TextAlign.center,
  2071 + style: TextStyle(
  2072 + fontSize: ScreenUtil().setSp(28),
  2073 + ),
  2074 + decoration: InputDecoration(
  2075 + border: OutlineInputBorder(borderSide: BorderSide.none),
  2076 + hintText: content,
  2077 + hintStyle: TextStyle(
  2078 + color: MyColours.color_999999,
  2079 + fontSize: ScreenUtil().setSp(28),
  2080 + ),
  2081 + enabledBorder: new UnderlineInputBorder(
  2082 + borderSide: BorderSide.none,
  2083 + ),
  2084 + focusedBorder: new UnderlineInputBorder(
  2085 + borderSide: BorderSide.none,
  2086 + ),
  2087 + ),
  2088 + onChanged: (value) {
  2089 + name = value;
  2090 + },
  2091 + onEditingComplete: () {
  2092 + FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
  2093 + },
  2094 + keyboardType: TextInputType.text,
  2095 + )),
  2096 + actions: [
  2097 + CupertinoDialogAction(
  2098 + child: Text(lTitle,
  2099 + style: TextStyle(
  2100 + fontSize: ScreenUtil().setSp(34),
  2101 + color: MyColours.color_666666)),
  2102 + onPressed: () {
  2103 + Navigator.of(context).pop();
  2104 + lCallback();
  2105 + },
  2106 + ),
  2107 + CupertinoDialogAction(
  2108 + child: Text(rTitle,
  2109 + style: TextStyle(
  2110 + fontSize: ScreenUtil().setSp(34),
  2111 + color: MyColours.color_199095)),
  2112 + onPressed: () {
  2113 + if (name == '' || name.trim().length == 0) {
  2114 + Utils.showToast('请输入分类名称');
  2115 + return;
  2116 + }
  2117 + Navigator.of(context).pop();
  2118 + rCallback(name);
  2119 + },
  2120 + ),
  2121 + ],
  2122 + );
  2123 + },
  2124 + );
  2125 + }
1953 } 2126 }
@@ -183,6 +183,9 @@ class UploadImageUtil { @@ -183,6 +183,9 @@ class UploadImageUtil {
183 } else if (index == 2) { 183 } else if (index == 2) {
184 //2 门头 184 //2 门头
185 uploadImageProvider.mentou.process = percent; 185 uploadImageProvider.mentou.process = percent;
  186 + } else if (index == 3) {
  187 + //3 菜品
  188 + uploadImageProvider.dish.process = percent;
186 } else { 189 } else {
187 //1 二维码 190 //1 二维码
188 uploadImageProvider.erweima.process = percent; 191 uploadImageProvider.erweima.process = percent;
@@ -232,11 +235,16 @@ class UploadImageUtil { @@ -232,11 +235,16 @@ class UploadImageUtil {
232 uploadImageProvider.erweima.qiniuUrl = imgUrl; 235 uploadImageProvider.erweima.qiniuUrl = imgUrl;
233 uploadImageProvider.erweima.file = null; 236 uploadImageProvider.erweima.file = null;
234 uploadImageProvider.notifyListeners(); 237 uploadImageProvider.notifyListeners();
235 - }else if (index == 2) { 238 + } else if (index == 2) {
236 uploadImageProvider.mentou.process = 1; 239 uploadImageProvider.mentou.process = 1;
237 uploadImageProvider.mentou.qiniuUrl = imgUrl; 240 uploadImageProvider.mentou.qiniuUrl = imgUrl;
238 uploadImageProvider.mentou.file = null; 241 uploadImageProvider.mentou.file = null;
239 uploadImageProvider.notifyListeners(); 242 uploadImageProvider.notifyListeners();
  243 + } else if (index == 3) {
  244 + uploadImageProvider.dish.process = 1;
  245 + uploadImageProvider.dish.qiniuUrl = imgUrl;
  246 + uploadImageProvider.dish.file = null;
  247 + uploadImageProvider.notifyListeners();
240 } 248 }
241 }) 249 })
242 ..catchError((dynamic error) { 250 ..catchError((dynamic error) {