Commit 2f19a30fdec2ffa17248b4cdc9c9e7d41f0b97c0

Authored by wdn127929
1 parent 302c89bb

菜品管理ok

import 'package:json_annotation/json_annotation.dart';
part 'cookbook_category_model.g.dart';
@JsonSerializable()
class CookbookCategoryModel extends Object {
@JsonKey(name: 'ret')
int ret;
@JsonKey(name: 'data')
List<CookbookCategorySunModel> data;
@JsonKey(name: 'msg')
String msg;
CookbookCategoryModel(
this.ret,
this.data,
this.msg,
);
factory CookbookCategoryModel.fromJson(Map<String, dynamic> srcJson) =>
_$CookbookCategoryModelFromJson(srcJson);
Map<String, dynamic> toJson() => _$CookbookCategoryModelToJson(this);
}
@JsonSerializable()
class CookbookCategorySunModel extends Object {
@JsonKey(name: 'id')
String id;
@JsonKey(name: 'sellerid')
String sellerid;
@JsonKey(name: 'class_name')
String className;
@JsonKey(name: 'order')
String order;
@JsonKey(name: 'status')
String status;
@JsonKey(name: 'class_type')
String classType;
CookbookCategorySunModel(
this.id,
this.sellerid,
this.className,
this.order,
this.status,
this.classType,
);
factory CookbookCategorySunModel.fromJson(Map<String, dynamic> srcJson) =>
_$CookbookCategorySunModelFromJson(srcJson);
Map<String, dynamic> toJson() => _$CookbookCategorySunModelToJson(this);
}
... ...
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'cookbook_category_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
CookbookCategoryModel _$CookbookCategoryModelFromJson(
Map<String, dynamic> json) {
return CookbookCategoryModel(
json['ret'] as int,
(json['data'][0] as List)
?.map((e) => e == null
? null
: CookbookCategorySunModel.fromJson(e as Map<String, dynamic>))
?.toList(),
json['msg'] as String,
);
}
Map<String, dynamic> _$CookbookCategoryModelToJson(
CookbookCategoryModel instance) =>
<String, dynamic>{
'ret': instance.ret,
'data': instance.data,
'msg': instance.msg,
};
CookbookCategorySunModel _$CookbookCategorySunModelFromJson(
Map<String, dynamic> json) {
return CookbookCategorySunModel(
json['id'] as String,
json['sellerid'] as String,
json['class_name'] as String,
json['order'] as String,
json['status'] as String,
json['class_type'] as String,
);
}
Map<String, dynamic> _$CookbookCategorySunModelToJson(
CookbookCategorySunModel instance) =>
<String, dynamic>{
'id': instance.id,
'sellerid': instance.sellerid,
'class_name': instance.className,
'order': instance.order,
'status': instance.status,
'class_type': instance.classType,
};
... ...
import 'package:json_annotation/json_annotation.dart';
part 'cookbook_spec_model.g.dart';
@JsonSerializable()
class CookbookSpecModel extends Object {
@JsonKey(name: 'ret')
int ret;
@JsonKey(name: 'data')
List<CookbookSpecSunModel> data;
@JsonKey(name: 'msg')
String msg;
CookbookSpecModel(
this.ret,
this.data,
this.msg,
);
factory CookbookSpecModel.fromJson(Map<String, dynamic> srcJson) =>
_$CookbookSpecModelFromJson(srcJson);
Map<String, dynamic> toJson() => _$CookbookSpecModelToJson(this);
}
@JsonSerializable()
class CookbookSpecSunModel extends Object {
@JsonKey(name: 'id')
String id;
@JsonKey(name: 'sellerid')
String sellerid;
@JsonKey(name: 'name')
String name;
@JsonKey(name: 'cdate')
String cdate;
CookbookSpecSunModel(
this.id,
this.sellerid,
this.name,
this.cdate,
);
factory CookbookSpecSunModel.fromJson(Map<String, dynamic> srcJson) =>
_$CookbookSpecSunModelFromJson(srcJson);
Map<String, dynamic> toJson() => _$CookbookSpecSunModelToJson(this);
}
... ...
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'cookbook_spec_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
CookbookSpecModel _$CookbookSpecModelFromJson(Map<String, dynamic> json) {
return CookbookSpecModel(
json['ret'] as int,
(json['data'][0] as List)
?.map((e) => e == null
? null
: CookbookSpecSunModel.fromJson(e as Map<String, dynamic>))
?.toList(),
json['msg'] as String,
);
}
Map<String, dynamic> _$CookbookSpecModelToJson(CookbookSpecModel instance) =>
<String, dynamic>{
'ret': instance.ret,
'data': instance.data,
'msg': instance.msg,
};
CookbookSpecSunModel _$CookbookSpecSunModelFromJson(Map<String, dynamic> json) {
return CookbookSpecSunModel(
json['id'] as String,
json['sellerid'] as String,
json['name'] as String,
json['cdate'] as String,
);
}
Map<String, dynamic> _$CookbookSpecSunModelToJson(
CookbookSpecSunModel instance) =>
<String, dynamic>{
'id': instance.id,
'sellerid': instance.sellerid,
'name': instance.name,
'cdate': instance.cdate,
};
... ...
... ... @@ -141,5 +141,14 @@ class HttpUrl {
"?service=App.Seller.SetTableClass"; // 添加/修改包间分类
static const String get_cookbook_by_class =
"?service=App.Cookbook.GetCookbookByClass"; //分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传
static const String get_cookbook_by_seller_id =
"?service=App.Cookbook.GetCookbookClassBySellerId"; //获取商家所有菜品分类
static const String del_cookbook_by_id =
"?service=App.Cookbook.DelCookbookClassById"; //删除菜品分类
static const String add_cookbook_class =
"?service=App.Cookbook.AddCookbookClass"; //添加菜品分类信息
static const String add_cookbook = "?service=App.Cookbook.AddCookbook"; //添加菜品
static const String get_spec_by_sellerid =
"?service=App.Cookbook.GetSpecBySellerid"; //获取商家计价单位
}
... ...
import 'dart:io';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_image/flutter_native_image.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:one_key/models/upload_img_model.dart';
import 'package:one_key/provider/menu_provider.dart';
import 'package:one_key/provider/upload_img_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/utils/upload_image_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
/**
*
* 添加菜品页面
*/
class MenuAddDishesPage extends StatefulWidget {
MenuAddDishesPage({Key key}) : super(key: key);
@override
_MenuAddDishesPageState createState() => _MenuAddDishesPageState();
}
class _MenuAddDishesPageState extends State<MenuAddDishesPage> {
bool swichState = true;
TextEditingController _nameController = TextEditingController();
TextEditingController _priceController = TextEditingController();
FocusNode _nameFocusNode = FocusNode();
FocusNode _priceFocusNode = FocusNode();
final picker = ImagePicker();
UploadImageProvider uploadImageProvider;
MenuManageProvider menuManageProvider;
List<String> categoryStrList = [];
String categoryStr = '请选择';
List<String> specStrList = [];
String specStr = '请选择';
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
uploadImageProvider.dish.process = 0.01;
uploadImageProvider.dish.qiniuUrl = '';
uploadImageProvider.notifyListeners();
_getQiniuInfo();
_getCookbookBySellerId(showLoading: false);
_getSpecBySellerid();
});
}
///计价方式
_getSpecBySellerid({bool showLoading = false}) async {
Map<String, String> params = {
"sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
await menuManageProvider.getSpecBySellerid(context, params,
showLoading: showLoading);
if (menuManageProvider.specSunModel.length > 0) {
specStrList = [];
menuManageProvider.specSunModel.forEach((element) {
specStrList.add(element.name);
});
}
}
///添加菜品
_addCookbook({bool showLoading = true}) async {
if (_nameController.text.trim().length == 0) {
Utils.showToast('请输入菜品名称');
return;
}
if (_priceController.text.trim().length == 0) {
Utils.showToast('请输入菜品价格');
return;
}
if (categoryStr == "请选择") {
Utils.showToast('请选择菜品分类');
return;
}
if (specStr == "请选择") {
Utils.showToast('请选择计价方式');
return;
}
String cid = '';
// String unit = '';
menuManageProvider.categorySunModel.forEach((element) {
if (element.className == categoryStr) {
cid = element.id;
}
});
// menuManageProvider.specSunModel.forEach((element) {
// if (element.name == specStr) {
// unit = element.id;
// }
// });
Map<String, String> params = {
"sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
'cid': cid,
'unit': specStr,
'name': _nameController.text,
'status': swichState ? '1' : '0',
'price': _priceController.text
};
if (uploadImageProvider.dish.qiniuUrl != null &&
uploadImageProvider.dish.qiniuUrl != '') {
params['image'] = uploadImageProvider.dish.qiniuUrl;
}
bool sucess = await menuManageProvider.addCookbook(context, params,
showLoading: showLoading);
if (sucess) {
EventBus().emit('menu_manage_page');
Navigator.of(context).pop();
}
}
///获取分类数据
_getCookbookBySellerId({bool showLoading = true}) async {
Map<String, String> params = {
"SellerId": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
await menuManageProvider.getCookbookClassBySellerId(context, params,
showLoading: showLoading);
if (menuManageProvider.categorySunModel.length > 0) {
categoryStrList = [];
menuManageProvider.categorySunModel.forEach((element) {
if (element.className != '10道必点菜') {
categoryStrList.add(element.className);
}
});
}
}
///获取七牛云token
///
_getQiniuInfo() async {
await uploadImageProvider.getQiniuInfo(context, {});
}
///输入框
Widget _textfield(
String title,
String hintText,
TextEditingController editingController,
FocusNode focusNode,
String subTitle,
{bool needStar = true,
TextInputType inputType = TextInputType.number}) {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Text(
title,
style: TextStyle(
color: MyColours.color_333333,
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(34)),
),
),
HEmptyView(20),
needStar
? Container(
child: Text(
'*',
style: TextStyle(
color: MyColours.color_199095,
fontWeight: FontWeight.bold,
),
),
)
: SizedBox(),
// Spacer(),
Expanded(
child: Container(
// height: ScreenUtil().setHeight(120),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(20),
right: ScreenUtil().setWidth(10),
top: ScreenUtil().setWidth(8)),
child: TextField(
controller: editingController,
textAlign: TextAlign.right,
// textAlignVertical: TextAlignVertical.bottom,
maxLines: 1,
inputFormatters: [],
// //光标颜色
// cursorColor:
// widget.isSelect ? Colors.white : MyColours.color_199095,
//输入文本的样式
style: TextStyle(
fontSize: ScreenUtil().setSp(32),
),
focusNode: focusNode,
decoration: InputDecoration(
border: OutlineInputBorder(borderSide: BorderSide.none),
hintText: hintText,
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(32),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
focusedBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
contentPadding: EdgeInsets.zero,
),
onChanged: (value) {},
onEditingComplete: () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
},
keyboardType: inputType,
)),
),
Container(
child: Text(
subTitle,
style: TextStyle(
color: MyColours.color_333333,
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(32)),
),
),
],
),
);
}
///选择
Widget _select(String title, String hintText, VoidCallback callback,
{bool needStar = true}) {
return InkWell(
onTap: callback,
child: Container(
padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(40)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Text(
title,
style: TextStyle(
color: MyColours.color_333333,
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(34)),
),
),
HEmptyView(20),
needStar
? Container(
child: Text(
'*',
style: TextStyle(
color: MyColours.color_199095,
fontWeight: FontWeight.bold,
),
),
)
: SizedBox(),
Spacer(),
Text(hintText,
style: TextStyle(
color: hintText == '请选择'
? MyColours.color_999999
: MyColours.color_333333,
fontWeight:
hintText == '请选择' ? FontWeight.normal : FontWeight.bold,
fontSize: ScreenUtil().setSp(32),
)),
HEmptyView(20),
Image.asset(
Utils.getImgPath('arr_right_gray'),
width: ScreenUtil().setWidth(12),
height: ScreenUtil().setWidth(22),
)
],
),
),
);
}
// 当前的任务状态
///#相机拍照,单图选择
_getFromPictureOrCamera(imageSource) async {
final pickedFile = await picker.getImage(source: imageSource);
File compressedFile = await FlutterNativeImage.compressImage(
pickedFile.path,
quality: 50,
percentage: 50);
setState(() {
if (pickedFile != null) {
UploadImgModel imgModel = UploadImgModel();
imgModel.file = compressedFile;
imgModel.process = 0.01;
uploadImageProvider.dish = imgModel;
} else {
print('No image selected.');
}
});
if (pickedFile != null) {
uploadImageProvider.dish.process = 0.01;
uploadImageProvider.dish.qiniuUrl = null;
UploadImageUtil().startUploadOnly(
context, File(pickedFile.path), 3, true, uploadImageProvider);
}
}
@override
Widget build(BuildContext context) {
uploadImageProvider =
Provider.of<UploadImageProvider>(context, listen: true);
menuManageProvider = Provider.of<MenuManageProvider>(context, listen: true);
return Material(
child: InkWell(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
child: Scaffold(
appBar: SystemAppBar('添加菜品', onTap: () {
Navigator.pop(context);
}),
body: Column(children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
InkWell(
onTap: () {
DialogUtil.openImageModalBottomSheet(context,
lCallback: () {
Utils.getPickPermission(context, () {
_getFromPictureOrCamera(ImageSource.camera);
Navigator.pop(context);
}, Permission.camera);
}, rCallback: () {
Utils.getPickPermission(context, () {
_getFromPictureOrCamera(ImageSource.gallery);
// _getFromPictureOrCamera(ImageSource.gallery);
Navigator.pop(context);
},
Platform.isAndroid
? Permission.storage
: Permission.photos);
});
},
child: Stack(children: [
uploadImageProvider.dish.file == null
? uploadImageProvider.dish.qiniuUrl != null &&
uploadImageProvider.dish.qiniuUrl !=
''
? CachedNetworkImage(
imageUrl:
uploadImageProvider.dish.qiniuUrl,
fit: BoxFit.cover,
width: double.infinity,
height: ScreenUtil().setWidth(400),
)
: Container(
width: double.infinity,
height: ScreenUtil().setWidth(400),
color:
Color.fromRGBO(235, 234, 239, 1),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(
ScreenUtil().setWidth(34)),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: ScreenUtil()
.setWidth(2),
color: MyColours
.color_c1c1c1,
)),
child: Image.asset(
Utils.getImgPath(
'take-picture'),
width: ScreenUtil()
.setWidth(80)),
),
VEmptyView(20),
Text(
'+菜谱效果图',
style: TextStyle(
fontSize:
ScreenUtil().setSp(30),
color:
MyColours.color_999999),
)
],
),
)
: Image.file(
uploadImageProvider.dish.file,
fit: BoxFit.cover,
width: double.infinity,
height: ScreenUtil().setWidth(400),
),
(uploadImageProvider.dish.file != null) &&
uploadImageProvider.dish.process != 1 &&
uploadImageProvider.dish.process != 0.01
? Container(
width: double.infinity,
height: ScreenUtil().setWidth(400),
child: Center(
child: Text('上传中...',
style: TextStyle(
color: MyColours.color_999999)),
),
)
: Container(),
])),
InkWell(
onTap: () {
setState(() {
swichState = !swichState;
});
},
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
vertical: ScreenUtil().setWidth(40),
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
// Container(
// child: Text(
// swichState ? '启用' : '停用',
// style: TextStyle(
// color: MyColours.color_333333,
// fontWeight: FontWeight.bold,
// fontSize: ScreenUtil().setSp(34)),
// ),
// ),
// VEmptyView(40),
Container(
child: Text(
swichState
? '商品已上架,在所有点餐设备上显示'
: '商品已下架',
style: TextStyle(
color: MyColours.color_666666,
fontSize: ScreenUtil().setSp(24)),
),
),
],
),
Image.asset(
swichState
? Utils.getImgPath('swich_on')
: Utils.getImgPath('swich_off'),
width: ScreenUtil().setWidth(122),
height: ScreenUtil().setWidth(82),
)
],
)),
),
MyDivider(
double.infinity,
ScreenUtil().setWidth(20),
color: Color.fromRGBO(235, 234, 239, 1),
),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_efefef,
margin: EdgeInsets.only(
left: ScreenUtil().setWidth(40),
right: ScreenUtil().setWidth(40)),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
),
child: _textfield('菜品名称', '请输入菜品名称',
_nameController, _nameFocusNode, '',
inputType: TextInputType.text)),
VEmptyView(10),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_efefef,
margin: EdgeInsets.only(
left: ScreenUtil().setWidth(40),
right: ScreenUtil().setWidth(40)),
),
VEmptyView(10),
Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
),
child: _textfield('菜品价格', '请输入菜品价格',
_priceController, _priceFocusNode, '元')),
VEmptyView(10),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_efefef,
margin: EdgeInsets.only(
left: ScreenUtil().setWidth(40),
right: ScreenUtil().setWidth(40)),
),
VEmptyView(10),
Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
),
child: _select('菜品分类', categoryStr, () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
DialogUtil.showSelectCusmanDialog(
context, categoryStrList, (value) {
if (value != null) {
setState(() {
categoryStr = categoryStrList[value.first];
});
}
}, selecteds: [
categoryStrList.indexOf(categoryStr)
]).then((value) {});
})),
VEmptyView(10),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_efefef,
margin: EdgeInsets.only(
left: ScreenUtil().setWidth(40),
right: ScreenUtil().setWidth(40))),
VEmptyView(10),
Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
),
child: _select('计价方式', specStr, () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
DialogUtil.showSelectCusmanDialog(
context, specStrList, (value) {
if (value != null) {
setState(() {
specStr = specStrList[value.first];
});
}
}, selecteds: [specStrList.indexOf(specStr)])
.then((value) {});
})),
VEmptyView(10),
],
),
)),
Padding(
padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(40), 0,
ScreenUtil().setWidth(40), ScreenUtil().setWidth(40)),
child: RoundButton(
onPressed: () async {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
_addCookbook();
},
text: '保存',
fontSize: 34,
isBold: false,
height: ScreenUtil().setWidth(80),
width: double.infinity,
radius: ScreenUtil().setWidth(10),
))
]))));
}
}
... ...
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/cookbook_category_model.dart';
import 'package:one_key/pages/notebook/statistics_page.dart';
import 'package:one_key/provider/menu_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/page_exception.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:provider/provider.dart';
class MenuCategoryPage extends StatefulWidget {
MenuCategoryPage({Key key}) : super(key: key);
@override
_MenuCategoryPageState createState() => _MenuCategoryPageState();
}
class _MenuCategoryPageState extends State<MenuCategoryPage> {
MenuManageProvider menuManageProvider;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_getCookbookBySellerId(showLoading: false);
});
}
///添加菜品分类
_addCookbookClass(String name, {bool showLoading = true}) async {
Map<String, String> params = {
"sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
'class_name': name
};
bool sucess = await menuManageProvider.addCookbookClass(context, params,
showLoading: showLoading);
if (sucess) {
_getCookbookBySellerId(showLoading: false);
}
}
///获取分类数据
_getCookbookBySellerId({bool showLoading = true}) async {
Map<String, String> params = {
"SellerId": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
await menuManageProvider.getCookbookClassBySellerId(context, params,
showLoading: showLoading);
}
//删除分类数据
_delCookbookById(String idstr, {bool showLoading = true}) async {
Map<String, String> params = {
"id": idstr,
};
bool success = await menuManageProvider
.delCookbookClassById(context, params, showLoading: showLoading);
if (success) {
EventBus().emit('menu_manage_page');
//删除成功
_getCookbookBySellerId(showLoading: false);
}
}
///表头
Widget _tableItem(CookbookCategorySunModel model, int index,
TableItemType type, IntCallback callback) {
return InkWell(
onTap: () {
callback(index);
},
child: Container(
padding: EdgeInsets.only(left: ScreenUtil().setWidth(30)),
height: ScreenUtil().setWidth(130),
color: type == TableItemType.TableItemTypeHeader
? Color.fromRGBO(235, 234, 239, 1)
: MyColours.color_fefefe,
child: Row(
children: [
Container(
width: ScreenUtil().setWidth(85 * 2),
height: double.infinity,
child: Row(
children: [
/*** 发版注释
Image.asset(
Utils.getImgPath(model.select ? 'select' : 'unselect'),
width: ScreenUtil().setWidth(34),
height: ScreenUtil().setWidth(34),
),
*/
// HEmptyView(20),
Expanded(
child: Text(
type == TableItemType.TableItemTypeHeader
? '序号'
: '${index + 1}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: ScreenUtil().setSp(28),
color: MyColours.color_333333),
)),
HEmptyView(30),
],
),
),
Expanded(
child: Container(
alignment: Alignment.center,
width: ScreenUtil().setWidth(87 * 2),
height: double.infinity,
child: Text(
type == TableItemType.TableItemTypeHeader
? '分类名称'
: model.className,
style: TextStyle(
fontSize: ScreenUtil().setSp(28),
color: MyColours.color_333333),
))),
Container(
alignment: Alignment.center,
width: ScreenUtil().setWidth(116 * 2),
height: double.infinity,
child: Text(
type == TableItemType.TableItemTypeHeader
? '操作'
: model.className == '10道必点菜'
? ''
: '删除',
style: TextStyle(
fontSize: ScreenUtil().setSp(28),
color: MyColours.color_333333),
)),
],
),
),
);
}
@override
Widget build(BuildContext context) {
menuManageProvider = Provider.of<MenuManageProvider>(context, listen: true);
return Scaffold(
appBar: SystemAppBar(
'分类管理',
onTap: () {
Navigator.pop(context);
},
rightImgName: '添加分类',
onTapRight: () {
//
DialogUtil.textfeildAlertDialog(context,
title: '添加分类', content: '输入分类名称', rCallback: (name) {
_addCookbookClass(name, showLoading: true);
});
},
),
body: Consumer<MenuManageProvider>(builder: (context, model, _) {
if (model.pageStateCategory != PageState.Success) {
return ExceptionPage(
pageState: model.pageStateCategory,
callback: () {
// offset = 0;
// getMessage(showLoading: true);
// _couponNetworkData();
_getCookbookBySellerId(showLoading: true);
},
emptyMsg: "菜品分类是空哒,快点击右上角添加分类吧",
emptyImg: "empty_search",
showMsg: "加载中,请稍后...",
);
} else {
return Column(
children: [
//表头
_tableItem(model.categorySunModel[0], 0,
TableItemType.TableItemTypeHeader, (index) {}),
Expanded(
child: ListView.builder(
itemCount: model.categorySunModel.length,
itemBuilder: (BuildContext context, int index) {
return Column(children: [
_tableItem(model.categorySunModel[index], index,
TableItemType.TableItemTypeBody, (index) {
if (model.categorySunModel[index].className !=
'10道必点菜') {
DialogUtil.cupertinoAlertDialog(context,
title: '',
content: '删除后,该分类下所有菜品都将删除', rCallback: () {
_delCookbookById(
model.categorySunModel[index].id);
});
}
}),
Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40)),
child: MyDivider(
double.infinity, ScreenUtil().setWidth(2),
color: MyColours.color_f5f5f5))
]);
})),
],
);
}
}));
}
}
... ...
... ... @@ -34,16 +34,27 @@ class _MenuManagePageState extends State<MenuManagePage> {
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_getCookbookByClass();
_getCookbookByClass(showLoading: false);
});
EventBus().on('menu_manage_page', (arg) {
_getCookbookByClass(showLoading: false);
});
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
EventBus().off('menu_manage_page');
}
_getCookbookByClass() async {
_getCookbookByClass({bool showLoading = true}) async {
Map<String, String> params = {
"sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
await menuManageProvider.getCookbookByClass(context, params);
await menuManageProvider.getCookbookByClass(context, params,
showLoading: showLoading);
}
@override
... ... @@ -72,6 +83,7 @@ class _MenuManagePageState extends State<MenuManagePage> {
// offset = 0;
// getMessage(showLoading: true);
// _couponNetworkData();
_getCookbookByClass(showLoading: true);
},
emptyMsg: "菜品是空哒,快点击分类管理添加分类和菜品吧",
emptyImg: "empty_search",
... ... @@ -325,15 +337,8 @@ class _MenuManagePageState extends State<MenuManagePage> {
ScreenUtil().setWidth(40)),
child: RoundButton(
onPressed: () async {
bool needRefresh =
await NavigatorUtil.goCouponEditPage(
context);
print(needRefresh);
if (needRefresh != null && needRefresh) {
//刷新页面数据
// _controller.callRefresh();
// _couponNetworkData();
}
await NavigatorUtil.goMenuAddDishesPage(
context);
},
text: '添加\n菜品',
fontSize: 26,
... ... @@ -351,7 +356,8 @@ class _MenuManagePageState extends State<MenuManagePage> {
child: RoundButton(
onPressed: () async {
bool needRefresh =
await NavigatorUtil.goCouponEditPage(context);
await NavigatorUtil.goMenuCategoryPage(
context);
print(needRefresh);
if (needRefresh != null && needRefresh) {
//刷新页面数据
... ...
... ... @@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/cookbook_category_model.dart';
import 'package:one_key/models/cookbook_model.dart';
import 'package:one_key/models/cookbook_spec_model.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
... ... @@ -10,14 +12,39 @@ import 'package:one_key/utils/utils.dart';
class MenuManageProvider extends ChangeNotifier {
PageState pageState = PageState.Loading;
PageState pageStateCategory = PageState.Loading;
List<MenuModel> menuModel; //菜品数据
List<CookbookCategorySunModel> categorySunModel; //菜品分类数据
List<CookbookSpecSunModel> specSunModel; //计价单位
/// 获取商家计价单位
getSpecBySellerid(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_spec_by_sellerid,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
specSunModel = [];
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data is List) {
if (baseResp.data.length > 0) {
specSunModel = CookbookSpecModel.fromJson(baseResp.responseData).data;
}
} else {}
} else {
Utils.showToast(baseResp.msg ?? "");
}
notifyListeners();
}
///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传
getCookbookByClass(BuildContext context, Map<String, String> params) async {
getCookbookByClass(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_cookbook_by_class,
data: params, showLoading: false)
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {
... ... @@ -54,4 +81,113 @@ class MenuManageProvider extends ChangeNotifier {
}
notifyListeners();
}
///获取商家所有菜品分类
getCookbookClassBySellerId(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.get, HttpUrl.get_cookbook_by_seller_id,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {
switch (error.type) {
case 1:
pageStateCategory = PageState.ConnectivityError;
break;
case 2:
pageStateCategory = PageState.ConnectivityTimeOut;
break;
default:
pageStateCategory = PageState.ConnectivityError;
break;
}
}
notifyListeners();
});
categorySunModel = [];
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data is List) {
if (baseResp.data.length == 0) {
pageStateCategory = PageState.Empty;
} else {
categorySunModel =
CookbookCategoryModel.fromJson(baseResp.responseData).data;
pageStateCategory = PageState.Success;
}
} else {
pageStateCategory = PageState.Empty;
}
} else {
Utils.showToast(baseResp.msg ?? "");
pageStateCategory = PageState.ConnectivityError;
}
notifyListeners();
}
///删除菜品分类
Future<bool> delCookbookClassById(
BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.del_cookbook_by_id,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data['succ'] == 1) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
///添加菜品
Future<bool> addCookbook(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.add_cookbook,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data['data'] != '') {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
///添加菜品分类信息
Future<bool> addCookbookClass(
BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.add_cookbook_class,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data['data'] != '') {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
... ...
... ... @@ -18,6 +18,7 @@ class UploadImageProvider extends ChangeNotifier {
UploadImgModel touxiang = UploadImgModel(); //头像
UploadImgModel erweima = UploadImgModel(); //二维码
UploadImgModel mentou = UploadImgModel(); //店铺信息----门头照片
UploadImgModel dish = UploadImgModel(); //菜品
double imgSizeTouxiang = 64;
double imgSizeErweima = 22;
double imgSizeMenTou = 64;
... ... @@ -28,6 +29,7 @@ class UploadImageProvider extends ChangeNotifier {
UploadImageProvider() {
touxiang.process = 0.01;
erweima.process = 0.01;
dish.process = 0.01;
}
/// 获取七牛上传token信息
... ...
... ... @@ -405,4 +405,18 @@ class NavigatorUtil {
{replace = false}) {
return _navigateTo(context, "${Routes.menu_manage_page}", replace: replace);
}
/// 菜单分类管理
static Future<dynamic> goMenuCategoryPage(BuildContext context,
{replace = false}) {
return _navigateTo(context, "${Routes.menu_category_page}",
replace: replace);
}
/// 添加菜品页面
static Future<dynamic> goMenuAddDishesPage(BuildContext context,
{replace = false}) {
return _navigateTo(context, "${Routes.menu_add_dishes_page}",
replace: replace);
}
}
... ...
... ... @@ -37,6 +37,8 @@ import 'package:one_key/pages/message/message_order_menu.dart';
import 'package:one_key/pages/my/base_info.dart';
import 'package:one_key/pages/my/book_time_set.dart';
import 'package:one_key/pages/my/contant_page.dart';
import 'package:one_key/pages/my/menu_type/menu_add_dishes_page.dart';
import 'package:one_key/pages/my/menu_type/menu_category_page.dart';
import 'package:one_key/pages/my/menu_type/menu_manage_page.dart';
import 'package:one_key/pages/my/my_integral_page.dart';
import 'package:one_key/pages/my/receive_orders_time_set.dart';
... ... @@ -628,3 +630,25 @@ var menuManagePageHandle = new Handler(
// return ChangeNotifierProvider<UploadImageProvider>(
// create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage());
});
///菜单分类管理页面
var menuCategoryPageHandle = new Handler(
handlerFunc: (BuildContext context, Map<dynamic, List<Object>> params) {
// SmsInfoData data = SmsInfoData.fromJson(json.decode(
// FluroConvertUtils.fluroCnParamsDecode(params["smsInfoData"].first)));
return ChangeNotifierProvider<MenuManageProvider>(
create: (_) => MenuManageProvider(), child: MenuCategoryPage());
// return ChangeNotifierProvider<UploadImageProvider>(
// create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage());
});
///添加菜品
var menuAddDishesPageHandle = new Handler(
handlerFunc: (BuildContext context, Map<dynamic, List<Object>> params) {
// SmsInfoData data = SmsInfoData.fromJson(json.decode(
// FluroConvertUtils.fluroCnParamsDecode(params["smsInfoData"].first)));
return ChangeNotifierProvider<MenuManageProvider>(
create: (_) => MenuManageProvider(), child: MenuAddDishesPage());
// return ChangeNotifierProvider<UploadImageProvider>(
// create: (_) => UploadImageProvider(), child: EnterStoreFrontPhotoPage());
});
... ...
... ... @@ -56,6 +56,8 @@ class Routes {
static String room_type_select_table_page =
"/room_type_select_table_page"; //包间管理中桌位选择页面
static String menu_manage_page = "/menu_manage_page"; //菜单管理页面
static String menu_category_page = "/menu_category_page"; //菜单分类管理
static String menu_add_dishes_page = "/menu_add_dishes_page"; //添加菜品页面
static void configureRoutes(FluroRouter router) {
router.notFoundHandler = new Handler(
... ... @@ -119,5 +121,7 @@ class Routes {
router.define(room_type_select_table_page,
handler: roomTypeSelectTablePageHandler);
router.define(menu_manage_page, handler: menuManagePageHandle);
router.define(menu_category_page, handler: menuCategoryPageHandle);
router.define(menu_add_dishes_page, handler: menuAddDishesPageHandle);
}
}
... ...
... ... @@ -4,6 +4,7 @@ import 'dart:ui';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/constant/constant.dart';
... ... @@ -13,6 +14,7 @@ import 'package:one_key/pages/message/message_dialog_item.dart';
import 'package:one_key/provider/message_dialog_model.dart';
import 'package:one_key/provider/table_manager_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/NumLengthInputFormatter.dart';
import 'package:one_key/utils/misc.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
... ... @@ -31,6 +33,86 @@ typedef CustomCallBack = void Function(Object object);
typedef CustomCallBackMap = void Function(Map<String, String> object);
class DialogUtil {
///添加图片UI弹出
static openImageModalBottomSheet(context,
{VoidCallback lCallback, VoidCallback rCallback}) async {
final option = await showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
isDismissible: false,
builder: (BuildContext context) {
return Container(
// height: ScreenUtil().setWidth(180 * 2),
decoration: BoxDecoration(
color: MyColours.color_ffffff,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(ScreenUtil().setWidth(24)),
topRight: Radius.circular(ScreenUtil().setWidth(24)))),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
InkWell(
onTap: lCallback,
child: Container(
width: double.infinity,
height: ScreenUtil().setWidth(58 * 2),
child: Center(
child: Text(
'拍摄',
style: TextStyle(
fontSize: ScreenUtil().setSp(32),
color: MyColours.color_353535,
fontWeight: FontWeight.bold),
),
)),
),
MyDivider(
double.infinity,
ScreenUtil().setWidth(2),
color: MyColours.color_EEEEEE,
),
InkWell(
onTap: rCallback,
child: Container(
width: double.infinity,
height: ScreenUtil().setWidth(58 * 2),
child: Center(
child: Text(
'从相册选择',
style: TextStyle(
fontSize: ScreenUtil().setSp(32),
color: MyColours.color_353535,
fontWeight: FontWeight.bold),
),
)),
),
MyDivider(
double.infinity,
ScreenUtil().setWidth(10),
color: MyColours.color_EEEEEE,
),
InkWell(
onTap: () {
Navigator.pop(context, '取消');
},
child: Container(
width: double.infinity,
height: ScreenUtil().setWidth(58 * 2),
child: Center(
child: Text(
'取消',
style: TextStyle(
fontSize: ScreenUtil().setSp(32),
color: MyColours.color_353535,
fontWeight: FontWeight.bold),
),
)))
],
),
);
});
}
static Future openCreateAreaDialog(BuildContext context,
{CustomCallBack onTap}) async {
TextEditingController controller = TextEditingController();
... ... @@ -1915,11 +1997,13 @@ class DialogUtil {
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text(title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(30),
color: MyColours.color_353535)),
title: title != ''
? Text(title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(30),
color: MyColours.color_353535))
: SizedBox(),
content: Text(content,
style: TextStyle(
fontSize: ScreenUtil().setSp(30),
... ... @@ -1950,4 +2034,93 @@ class DialogUtil {
},
);
}
//输入弹框
static Future textfeildAlertDialog(BuildContext context,
{String title = "标题",
String content = "内容",
String lTitle = "取消",
String rTitle = "确定",
VoidCallback lCallback,
CustomCallBack rCallback}) {
String name = '';
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: title != ''
? Text(title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(30),
color: MyColours.color_353535))
: SizedBox(),
content: Material(
color: Colors.transparent,
child: TextField(
maxLines: 1,
// //光标颜色
// cursorColor:
// widget.isSelect ? Colors.white : MyColours.color_199095,
//输入文本的样式
inputFormatters: [
LengthLimitingTextInputFormatter(10),
],
textAlignVertical: TextAlignVertical.bottom,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: ScreenUtil().setSp(28),
),
decoration: InputDecoration(
border: OutlineInputBorder(borderSide: BorderSide.none),
hintText: content,
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(28),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
focusedBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
),
onChanged: (value) {
name = value;
},
onEditingComplete: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
keyboardType: TextInputType.text,
)),
actions: [
CupertinoDialogAction(
child: Text(lTitle,
style: TextStyle(
fontSize: ScreenUtil().setSp(34),
color: MyColours.color_666666)),
onPressed: () {
Navigator.of(context).pop();
lCallback();
},
),
CupertinoDialogAction(
child: Text(rTitle,
style: TextStyle(
fontSize: ScreenUtil().setSp(34),
color: MyColours.color_199095)),
onPressed: () {
if (name == '' || name.trim().length == 0) {
Utils.showToast('请输入分类名称');
return;
}
Navigator.of(context).pop();
rCallback(name);
},
),
],
);
},
);
}
}
... ...
... ... @@ -183,6 +183,9 @@ class UploadImageUtil {
} else if (index == 2) {
//2 门头
uploadImageProvider.mentou.process = percent;
} else if (index == 3) {
//3 菜品
uploadImageProvider.dish.process = percent;
} else {
//1 二维码
uploadImageProvider.erweima.process = percent;
... ... @@ -232,11 +235,16 @@ class UploadImageUtil {
uploadImageProvider.erweima.qiniuUrl = imgUrl;
uploadImageProvider.erweima.file = null;
uploadImageProvider.notifyListeners();
}else if (index == 2) {
} else if (index == 2) {
uploadImageProvider.mentou.process = 1;
uploadImageProvider.mentou.qiniuUrl = imgUrl;
uploadImageProvider.mentou.file = null;
uploadImageProvider.notifyListeners();
} else if (index == 3) {
uploadImageProvider.dish.process = 1;
uploadImageProvider.dish.qiniuUrl = imgUrl;
uploadImageProvider.dish.file = null;
uploadImageProvider.notifyListeners();
}
})
..catchError((dynamic error) {
... ...