Commit 490142acf34cccdc6308bd3c566c72dc6363f8b0

Authored by wdn127929
1 parent c2372ef5

优惠券带图

@@ -2,6 +2,9 @@ import 'dart:convert'; @@ -2,6 +2,9 @@ import 'dart:convert';
2 2
3 import 'package:json_annotation/json_annotation.dart'; 3 import 'package:json_annotation/json_annotation.dart';
4 import 'package:one_key/models/filter_btn_model.dart'; 4 import 'package:one_key/models/filter_btn_model.dart';
  5 +import 'package:one_key/models/upload_img_model.dart';
  6 +
  7 +import 'dart:convert' as convert;
5 8
6 part 'coupon_model.g.dart'; 9 part 'coupon_model.g.dart';
7 10
@@ -148,8 +151,11 @@ class CouponUse extends Object { @@ -148,8 +151,11 @@ class CouponUse extends Object {
148 @JsonKey(name: 'dish') 151 @JsonKey(name: 'dish')
149 String dish; 152 String dish;
150 153
  154 + @JsonKey(name: 'images')
  155 + List<String> images;
  156 +
151 CouponUse(this.isCash, this.isDiscount, this.isDish, this.cash, this.discount, 157 CouponUse(this.isCash, this.isDiscount, this.isDish, this.cash, this.discount,
152 - this.dish); 158 + this.dish, this.images);
153 159
154 factory CouponUse.fromJson(Map<String, dynamic> srcJson) => 160 factory CouponUse.fromJson(Map<String, dynamic> srcJson) =>
155 _$CouponUseFromJson(srcJson); 161 _$CouponUseFromJson(srcJson);
@@ -110,15 +110,27 @@ CouponUse _$CouponUseFromJson(Map<String, dynamic> json) { @@ -110,15 +110,27 @@ CouponUse _$CouponUseFromJson(Map<String, dynamic> json) {
110 } else if (json['is_dish'] is bool) { 110 } else if (json['is_dish'] is bool) {
111 isdish = json['is_dish'] ? true : false; 111 isdish = json['is_dish'] ? true : false;
112 } 112 }
  113 + List<String> img = [];
  114 + if (isdish && json['images'] != '' && json['images'] != null) {
  115 + if (json['images'] is List) {
  116 + json['images'].forEach((v) {
  117 + // UploadImgModel uploadImgModel = UploadImgModel();
  118 + // uploadImgModel.qiniuUrl = v;
  119 + // uploadImgModel.process = 1;
  120 + img.add(v);
  121 + });
  122 + } else {
  123 + convert.jsonDecode(json['images']).forEach((v) {
  124 + // UploadImgModel uploadImgModel = UploadImgModel();
  125 + // uploadImgModel.qiniuUrl = v;
  126 + // uploadImgModel.process = 1;
  127 + img.add(v);
  128 + });
  129 + }
  130 + }
113 131
114 - return CouponUse(  
115 - iscash,  
116 - isdiscount,  
117 - isdish,  
118 - json['cash'] as String,  
119 - json['discount'] as String,  
120 - json['dish'] as String,  
121 - ); 132 + return CouponUse(iscash, isdiscount, isdish, json['cash'] as String,
  133 + json['discount'] as String, json['dish'] as String, img);
122 } 134 }
123 135
124 Map<String, dynamic> _$CouponUseToJson(CouponUse instance) => <String, dynamic>{ 136 Map<String, dynamic> _$CouponUseToJson(CouponUse instance) => <String, dynamic>{
@@ -128,6 +140,7 @@ Map<String, dynamic> _$CouponUseToJson(CouponUse instance) => <String, dynamic>{ @@ -128,6 +140,7 @@ Map<String, dynamic> _$CouponUseToJson(CouponUse instance) => <String, dynamic>{
128 'cash': instance.cash, 140 'cash': instance.cash,
129 'discount': instance.discount, 141 'discount': instance.discount,
130 'dish': instance.dish, 142 'dish': instance.dish,
  143 + 'images': instance.images
131 }; 144 };
132 145
133 ExpDate _$ExpDateFromJson(Map<String, dynamic> json) { 146 ExpDate _$ExpDateFromJson(Map<String, dynamic> json) {
  1 +import 'package:cached_network_image/cached_network_image.dart';
1 import 'package:common_utils/common_utils.dart'; 2 import 'package:common_utils/common_utils.dart';
2 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
3 import 'package:flutter_picker/flutter_picker.dart'; 4 import 'package:flutter_picker/flutter_picker.dart';
@@ -21,6 +22,7 @@ import 'package:provider/provider.dart'; @@ -21,6 +22,7 @@ import 'package:provider/provider.dart';
21 import '../../provider/base_info_provider.dart'; 22 import '../../provider/base_info_provider.dart';
22 import '../../utils/screen_util.dart'; 23 import '../../utils/screen_util.dart';
23 import '../../widgets/page_exception.dart'; 24 import '../../widgets/page_exception.dart';
  25 +import '../online_check/photo_view_wiget.dart';
24 26
25 /** 27 /**
26 * 新建券 28 * 新建券
@@ -222,6 +224,102 @@ class _CouponDetailPageState extends State<CouponDetailPage> { @@ -222,6 +224,102 @@ class _CouponDetailPageState extends State<CouponDetailPage> {
222 ); 224 );
223 } 225 }
224 226
  227 + List<Widget> imageWidget(List<String> temp) {
  228 + List<Widget> data = [];
  229 + for (int i = 0; i < temp.length; i++) {
  230 + data.add(InkWell(
  231 + onTap: () {
  232 + ///没有上传完成的不可以点击
  233 + _showPhotoView(context, i, temp);
  234 + },
  235 + child: Container(
  236 + margin: EdgeInsets.only(
  237 + right: i < temp.length - 1
  238 + ? ((ScreenUtil().screenWidth - w(100) * 3 - w(16) * 2) /
  239 + 2)
  240 + : 0),
  241 + child: CachedNetworkImage(
  242 + imageUrl: temp[i],
  243 + fit: BoxFit.cover,
  244 + width: ScreenUtil().setWidth(100 * 2),
  245 + height: ScreenUtil().setWidth(100 * 2),
  246 + ))));
  247 + }
  248 + return data;
  249 + }
  250 +
  251 + /// 九宫格
  252 + Widget _getGridImg(context, List<String> temp) {
  253 + return Row(
  254 + mainAxisAlignment: MainAxisAlignment.end,
  255 + children: imageWidget(temp),
  256 + );
  257 + return GridView.builder(
  258 + controller: controller,
  259 + // padding: EdgeInsets.only(top: ScreenUtil().getAdapterSize(10)),
  260 + shrinkWrap: true,
  261 + itemCount: temp.length,
  262 + //SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
  263 + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  264 + //横轴元素个数
  265 + crossAxisCount: 3,
  266 + //纵轴间距
  267 + mainAxisSpacing: ScreenUtil().setWidth(40),
  268 + //横轴间距
  269 + crossAxisSpacing: ScreenUtil().setWidth(36),
  270 + //子组件宽高长度比例
  271 + childAspectRatio: 1.0),
  272 + itemBuilder: (BuildContext context, int index) {
  273 + //Widget Function(BuildContext context, int index)
  274 +
  275 + return temp.length < 1
  276 + ? Text('')
  277 + : InkWell(
  278 + onTap: () {
  279 + ///没有上传完成的不可以点击
  280 + _showPhotoView(context, index, temp);
  281 + },
  282 + child: CachedNetworkImage(
  283 + imageUrl: temp[index],
  284 + fit: BoxFit.cover,
  285 + width: ScreenUtil().setWidth(100 * 2),
  286 + height: ScreenUtil().setWidth(100 * 2),
  287 + ));
  288 + });
  289 + }
  290 +
  291 + //查看大图
  292 + _showPhotoView(BuildContext context, int index, List<String> imgs,
  293 + {isShow = false, List dashName}) async {
  294 + // if (imgs.length == 1 &&
  295 + // imgs[0] ==
  296 + // 'http://nosqn.colorcun.com/custom/lite-online/image/def-banner.png') {
  297 + // imgs[0] = 'http://nosqn.colorcun.com/app/seller-hj-empty.png';
  298 + // }
  299 + Utils.setBarStatus(false, color: Colors.black);
  300 + dynamic result = await showGeneralDialog(
  301 + context: context,
  302 + barrierDismissible: false,
  303 + // barrierColor: Colors.red,
  304 + barrierLabel:
  305 + MaterialLocalizations.of(context).modalBarrierDismissLabel,
  306 + transitionDuration: const Duration(milliseconds: 150),
  307 + pageBuilder: (BuildContext context, Animation animation,
  308 + Animation secondaryAnimation) {
  309 + Widget child = Stack(
  310 + children: <Widget>[
  311 + PhotoPreview(
  312 + initialIndex: index,
  313 + photoList: imgs,
  314 + isShow: isShow,
  315 + dashName: dashName)
  316 + ],
  317 + );
  318 + return child;
  319 + });
  320 + Utils.setBarStatus(true, color: Colors.white);
  321 + }
  322 +
225 @override 323 @override
226 Widget build(BuildContext context) { 324 Widget build(BuildContext context) {
227 couponProvider = Provider.of<CouponProvider>(context, listen: true); 325 couponProvider = Provider.of<CouponProvider>(context, listen: true);
@@ -355,6 +453,16 @@ class _CouponDetailPageState extends State<CouponDetailPage> { @@ -355,6 +453,16 @@ class _CouponDetailPageState extends State<CouponDetailPage> {
355 ? couponProvider 453 ? couponProvider
356 .couponSunModel.use.dish 454 .couponSunModel.use.dish
357 : ''), 455 : ''),
  456 + if (couponProvider
  457 + .couponSunModel.use.isDish &&
  458 + couponProvider.couponSunModel.use.images
  459 + .length >
  460 + 0)
  461 + _getGridImg(
  462 + context,
  463 + couponProvider
  464 + .couponSunModel.use.images),
  465 + VEmptyView(24),
358 Container( 466 Container(
359 height: ScreenUtil().setWidth(2), 467 height: ScreenUtil().setWidth(2),
360 color: MyColours.color_E7E7E7, 468 color: MyColours.color_E7E7E7,
@@ -20,7 +20,11 @@ import 'package:one_key/widgets/v_empty_view.dart'; @@ -20,7 +20,11 @@ import 'package:one_key/widgets/v_empty_view.dart';
20 import 'package:provider/provider.dart'; 20 import 'package:provider/provider.dart';
21 21
22 import '../../models/filter_btn_model.dart'; 22 import '../../models/filter_btn_model.dart';
  23 +import '../../models/upload_img_model.dart';
  24 +import '../../provider/upload_img_provider.dart';
23 import '../../utils/screen_util.dart'; 25 import '../../utils/screen_util.dart';
  26 +import '../../utils/upload_image_util.dart';
  27 +import '../online_check/img_picker_widget.dart';
24 28
25 /** 29 /**
26 * 新建券 30 * 新建券
@@ -78,6 +82,9 @@ class _CouponEidtPageState extends State<CouponEidtPage> { @@ -78,6 +82,9 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
78 String noon; 82 String noon;
79 String night; 83 String night;
80 84
  85 + UploadImageProvider _uploadImageProvider;
  86 + List<UploadImgModel> img = [];
  87 +
81 @override 88 @override
82 void initState() { 89 void initState() {
83 super.initState(); 90 super.initState();
@@ -158,9 +165,23 @@ class _CouponEidtPageState extends State<CouponEidtPage> { @@ -158,9 +165,23 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
158 WidgetsBinding.instance.addPostFrameCallback((_) { 165 WidgetsBinding.instance.addPostFrameCallback((_) {
159 // _couponNetworkData(0); 166 // _couponNetworkData(0);
160 _initWeekData(); 167 _initWeekData();
  168 + _getQiniuInfo();
161 }); 169 });
162 } 170 }
163 171
  172 + @override
  173 + void dispose() {
  174 + super.dispose();
  175 +
  176 + _uploadImageProvider.qiniuInfoSunModel.token = null;
  177 + }
  178 +
  179 + ///获取七牛云token
  180 + ///
  181 + _getQiniuInfo() async {
  182 + await _uploadImageProvider.getQiniuInfo(context, {});
  183 + }
  184 +
164 // //初始化时间 185 // //初始化时间
165 // initWeekData() async { 186 // initWeekData() async {
166 // // UserModel userModel = Provider.of<UserModel>(context, listen: false); 187 // // UserModel userModel = Provider.of<UserModel>(context, listen: false);
@@ -222,14 +243,20 @@ class _CouponEidtPageState extends State<CouponEidtPage> { @@ -222,14 +243,20 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
222 params['uid_list'] = uids; 243 params['uid_list'] = uids;
223 params['price'] = 244 params['price'] =
224 _priceControl.text.trim().length == 0 ? '0' : _priceControl.text; 245 _priceControl.text.trim().length == 0 ? '0' : _priceControl.text;
225 - 246 + List<String> images = [];
  247 + if (img.length > 0) {
  248 + img.forEach((value) {
  249 + images.add(value.qiniuUrl);
  250 + });
  251 + }
226 Map use = { 252 Map use = {
227 'is_cash': money ? '1' : '0', 253 'is_cash': money ? '1' : '0',
228 'is_discount': discount ? '1' : '0', 254 'is_discount': discount ? '1' : '0',
229 'is_dish': dish ? '1' : '0', 255 'is_dish': dish ? '1' : '0',
230 'cash': moneyControl.text, 256 'cash': moneyControl.text,
231 'discount': discountControl.text, 257 'discount': discountControl.text,
232 - 'dish': dishControl.text 258 + 'dish': dishControl.text,
  259 + 'images': json.encode(images)
233 }; 260 };
234 params['use'] = jsonEncode(use); 261 params['use'] = jsonEncode(use);
235 262
@@ -651,6 +678,8 @@ class _CouponEidtPageState extends State<CouponEidtPage> { @@ -651,6 +678,8 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
651 @override 678 @override
652 Widget build(BuildContext context) { 679 Widget build(BuildContext context) {
653 couponProvider = Provider.of<CouponProvider>(context, listen: true); 680 couponProvider = Provider.of<CouponProvider>(context, listen: true);
  681 + _uploadImageProvider =
  682 + Provider.of<UploadImageProvider>(context, listen: true);
654 return Scaffold( 683 return Scaffold(
655 backgroundColor: MyColours.color_ffffff, 684 backgroundColor: MyColours.color_ffffff,
656 key: scaffoldKey, 685 key: scaffoldKey,
@@ -792,6 +821,56 @@ class _CouponEidtPageState extends State<CouponEidtPage> { @@ -792,6 +821,56 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
792 _textfieldSelect('菜品:', '点击输入赠送菜品名称', 821 _textfieldSelect('菜品:', '点击输入赠送菜品名称',
793 dishControl, dishFocusNode, 822 dishControl, dishFocusNode,
794 textInputType: TextInputType.text), 823 textInputType: TextInputType.text),
  824 + if (dish) VEmptyView(20),
  825 +
  826 + if (dish)
  827 + Padding(
  828 + padding: EdgeInsets.only(
  829 + left: w(10), right: w(15)),
  830 + child: Consumer<UploadImageProvider>(
  831 + builder: (context, model, _) {
  832 + return ImgPickerWidget(
  833 + scrollController: controller,
  834 + model: _uploadImageProvider,
  835 + maxImageNumber: 3,
  836 + maxRemind: '三',
  837 + imageList: img,
  838 + uploadType:
  839 + UploadType.CouponDishType,
  840 + deleteCallback: (int index) {
  841 + img.removeWhere((element) =>
  842 + element == img[index]);
  843 + setState(() {});
  844 + },
  845 + callback: () {
  846 + // for (UploadImgModel item
  847 + // in _uploadImageProvider
  848 + // .tableImageList) {
  849 + // if (item.process < 1) {
  850 + // Utils.showToast('正在上传图片,请稍等');
  851 + // return;
  852 + // }
  853 + // }
  854 + // //接口,和桌子绑定
  855 + // List imageQiniuUrlList = [];
  856 + // for (int i = 0;
  857 + // i <
  858 + // _uploadImageProvider
  859 + // .tableImageList.length;
  860 + // i++) {
  861 + // if (!_uploadImageProvider
  862 + // .tableImageList[i].isUpload) {
  863 + // imageQiniuUrlList.add({
  864 + // "url": _uploadImageProvider
  865 + // .tableImageList[i].qiniuUrl
  866 + // });
  867 + // }
  868 + // }
  869 + // _setTablePhoto(
  870 + // context, imageQiniuUrlList);
  871 + },
  872 + );
  873 + })),
795 VEmptyView(48), 874 VEmptyView(48),
796 Container( 875 Container(
797 height: ScreenUtil().setWidth(2), 876 height: ScreenUtil().setWidth(2),
@@ -1035,68 +1114,82 @@ class _CouponEidtPageState extends State<CouponEidtPage> { @@ -1035,68 +1114,82 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
1035 VEmptyView(20), 1114 VEmptyView(20),
1036 RoundButton( 1115 RoundButton(
1037 onPressed: () { 1116 onPressed: () {
1038 - if (_couponNameEditControl.text.trim().length == 0) {  
1039 - Utils.showToast('请填写券名称');  
1040 - return; 1117 + print(img);
  1118 + bool can = true;
  1119 + innerloop:
  1120 + for (UploadImgModel item in img) {
  1121 + if (item.process < 1) {
  1122 + Utils.showToast('正在上传图片,请稍等');
  1123 + // return false;
  1124 + can = false;
  1125 + break innerloop;
  1126 + }
1041 } 1127 }
1042 - if (!widget.isMine) {  
1043 - if (money && moneyControl.text.trim().length == 0) {  
1044 - Utils.showToast('请输入代金券金额!'); 1128 + if (can) {
  1129 + if (_couponNameEditControl.text.trim().length == 0) {
  1130 + Utils.showToast('请填写券名称');
1045 return; 1131 return;
1046 } 1132 }
1047 - if (discount && discountControl.text.trim().length == 0) {  
1048 - Utils.showToast('请输入折扣率!');  
1049 - return; 1133 + if (!widget.isMine) {
  1134 + if (money && moneyControl.text.trim().length == 0) {
  1135 + Utils.showToast('请输入代金券金额!');
  1136 + return;
  1137 + }
  1138 + if (discount &&
  1139 + discountControl.text.trim().length == 0) {
  1140 + Utils.showToast('请输入折扣率!');
  1141 + return;
  1142 + }
  1143 + if (dish && dishControl.text.trim().length == 0) {
  1144 + Utils.showToast('请输入菜品!');
  1145 + return;
  1146 + }
  1147 +
  1148 + if (limitWeek && weekShow == '点击设置可用日期') {
  1149 + Utils.showToast('请设置可用日期!');
  1150 + return;
  1151 + }
  1152 + if (uids == null || uids == '') {
  1153 + Utils.showToast('请设置发放人!');
  1154 + return;
  1155 + }
  1156 +
  1157 + bool isNumber = Utils.isInteger(
  1158 + _limitNumControl.text.trim()); //判断输入的内容是否是数字
  1159 + if (!isNumber) {
  1160 + Utils.showToast('发放总量限制请输入数字');
  1161 + _limitNumControl.text = '';
  1162 + return;
  1163 + }
1050 } 1164 }
1051 - if (dish && dishControl.text.trim().length == 0) {  
1052 - Utils.showToast('请输入菜品!'); 1165 + if (_couponRequireEditControl.text.trim().length == 0) {
  1166 + Utils.showToast('请填写券要求');
1053 return; 1167 return;
1054 } 1168 }
1055 -  
1056 - if (limitWeek && weekShow == '点击设置可用日期') {  
1057 - Utils.showToast('请设置可用日期!'); 1169 + if (fromDate == '点击选择') {
  1170 + Utils.showToast('请选择有效期起始时间');
1058 return; 1171 return;
1059 } 1172 }
1060 - if (uids == null || uids == '') {  
1061 - Utils.showToast('请设置发放人!'); 1173 + if (endDate == '点击选择') {
  1174 + Utils.showToast('请选择有效期结束时间');
1062 return; 1175 return;
1063 } 1176 }
1064 -  
1065 - bool isNumber = Utils.isInteger(  
1066 - _limitNumControl.text.trim()); //判断输入的内容是否是数字  
1067 - if (!isNumber) {  
1068 - Utils.showToast('发放总量限制请输入数字');  
1069 - _limitNumControl.text = ''; 1177 + if (DateUtil.getDateTime(endDate)
  1178 + .compareTo(DateUtil.getDateTime(fromDate)) <
  1179 + 0) {
  1180 + Utils.showToast('有效期结束时间不能早于起始时间');
1070 return; 1181 return;
1071 } 1182 }
1072 - }  
1073 - if (_couponRequireEditControl.text.trim().length == 0) {  
1074 - Utils.showToast('请填写券要求');  
1075 - return;  
1076 - }  
1077 - if (fromDate == '点击选择') {  
1078 - Utils.showToast('请选择有效期起始时间');  
1079 - return;  
1080 - }  
1081 - if (endDate == '点击选择') {  
1082 - Utils.showToast('请选择有效期结束时间');  
1083 - return;  
1084 - }  
1085 - if (DateUtil.getDateTime(endDate)  
1086 - .compareTo(DateUtil.getDateTime(fromDate)) <  
1087 - 0) {  
1088 - Utils.showToast('有效期结束时间不能早于起始时间');  
1089 - return;  
1090 - }  
1091 1183
1092 - // ***参数***  
1093 - // _couponNameEditControl.text  
1094 - // _couponRequireEditControl.text  
1095 - // fromDate  
1096 - // endDate  
1097 - // _couponExplainEditControl.text  
1098 - // swichState  
1099 - _createNewCoupon(); 1184 + // ***参数***
  1185 + // _couponNameEditControl.text
  1186 + // _couponRequireEditControl.text
  1187 + // fromDate
  1188 + // endDate
  1189 + // _couponExplainEditControl.text
  1190 + // swichState
  1191 + _createNewCoupon();
  1192 + }
1100 }, 1193 },
1101 text: '立即创建', 1194 text: '立即创建',
1102 fontSize: 24, 1195 fontSize: 24,
@@ -5,6 +5,7 @@ import 'dart:async'; @@ -5,6 +5,7 @@ import 'dart:async';
5 5
6 import 'package:cached_network_image/cached_network_image.dart'; 6 import 'package:cached_network_image/cached_network_image.dart';
7 import 'package:flutter/material.dart'; 7 import 'package:flutter/material.dart';
  8 +import 'package:flutter/services.dart';
8 import 'package:flutter_screenutil/flutter_screenutil.dart'; 9 import 'package:flutter_screenutil/flutter_screenutil.dart';
9 import 'package:one_key/models/upload_img_model.dart'; 10 import 'package:one_key/models/upload_img_model.dart';
10 import 'package:one_key/pages/online_check/photo_view_wiget.dart'; 11 import 'package:one_key/pages/online_check/photo_view_wiget.dart';
@@ -96,14 +97,24 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -96,14 +97,24 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
96 Future _getFromPictureOrCamera(imageSource) async { 97 Future _getFromPictureOrCamera(imageSource) async {
97 final pickedFile = await picker.pickImage( 98 final pickedFile = await picker.pickImage(
98 source: imageSource, preferredCameraDevice: CameraDevice.rear); 99 source: imageSource, preferredCameraDevice: CameraDevice.rear);
99 - File compressedFile = await FlutterNativeImage.compressImage(  
100 - pickedFile.path,  
101 - quality: 50,  
102 - percentage: 50); 100 +
  101 + //从相册选取照片后进行裁剪压缩
  102 + File yourFile = File(pickedFile.path);
  103 + Uint8List afterImg = await yourFile.readAsBytes();
  104 + Uint8List newImg = await Utils.testFromFileComporessList(context, afterImg);
  105 + String path = await Utils.saveImage(newImg);
  106 + if (path == null) {
  107 + File compressedFile = await FlutterNativeImage.compressImage(
  108 + yourFile.path,
  109 + quality: 50,
  110 + percentage: 50);
  111 + path = compressedFile.path;
  112 + }
  113 +
103 setState(() { 114 setState(() {
104 if (pickedFile != null) { 115 if (pickedFile != null) {
105 UploadImgModel imgModel = UploadImgModel(); 116 UploadImgModel imgModel = UploadImgModel();
106 - imgModel.file = compressedFile; 117 + imgModel.file = File(path);
107 imgModel.process = 0.01; 118 imgModel.process = 0.01;
108 if (widget.uploadType == UploadType.ConsumptionUploadType) { 119 if (widget.uploadType == UploadType.ConsumptionUploadType) {
109 widget.model.imageList.add(imgModel); 120 widget.model.imageList.add(imgModel);
@@ -115,6 +126,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -115,6 +126,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
115 widget.model.tableImageList.add(imgModel); 126 widget.model.tableImageList.add(imgModel);
116 } else if (widget.uploadType == UploadType.WineManageType) { 127 } else if (widget.uploadType == UploadType.WineManageType) {
117 widget.imageList.add(imgModel); 128 widget.imageList.add(imgModel);
  129 + } else if (widget.uploadType == UploadType.CouponDishType) {
  130 + widget.imageList.add(imgModel);
118 } 131 }
119 } else { 132 } else {
120 print('No image selected.'); 133 print('No image selected.');
@@ -133,11 +146,13 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -133,11 +146,13 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
133 temp = widget.model.tableImageList; 146 temp = widget.model.tableImageList;
134 } else if (widget.uploadType == UploadType.WineManageType) { 147 } else if (widget.uploadType == UploadType.WineManageType) {
135 temp = widget.imageList; 148 temp = widget.imageList;
  149 + } else if (widget.uploadType == UploadType.CouponDishType) {
  150 + temp = widget.imageList;
136 } 151 }
137 bool need = await Utils.sizeNeed(File(pickedFile.path)); 152 bool need = await Utils.sizeNeed(File(pickedFile.path));
138 File file = File(pickedFile.path); 153 File file = File(pickedFile.path);
139 if (need) { 154 if (need) {
140 - file = File(compressedFile.absolute.path); 155 + file = File(path);
141 } 156 }
142 UploadImageUtil().startUpload( 157 UploadImageUtil().startUpload(
143 context, file, temp.length - 1, true, widget.model, widget.uploadType, 158 context, file, temp.length - 1, true, widget.model, widget.uploadType,
@@ -158,6 +173,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -158,6 +173,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
158 temp = widget.model.tableImageList; 173 temp = widget.model.tableImageList;
159 } else if (widget.uploadType == UploadType.WineManageType) { 174 } else if (widget.uploadType == UploadType.WineManageType) {
160 temp = widget.imageList; 175 temp = widget.imageList;
  176 + } else if (widget.uploadType == UploadType.CouponDishType) {
  177 + temp = widget.imageList;
161 } 178 }
162 List<AssetEntity> imgList = await AssetPicker.pickAssets(context, 179 List<AssetEntity> imgList = await AssetPicker.pickAssets(context,
163 pickerConfig: AssetPickerConfig( 180 pickerConfig: AssetPickerConfig(
@@ -214,13 +231,27 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -214,13 +231,27 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
214 } else { 231 } else {
215 for (int i = 0; i < imgList.length; i++) { 232 for (int i = 0; i < imgList.length; i++) {
216 var file = await imgList[i].file; 233 var file = await imgList[i].file;
217 - File compressedFile = await FlutterNativeImage.compressImage(  
218 - file.absolute.path,  
219 - quality: 50,  
220 - percentage: 50); 234 + //从相册选取照片后进行裁剪压缩
  235 + File yourFile = file;
  236 + Uint8List afterImg = await yourFile.readAsBytes();
  237 + Uint8List newImg =
  238 + await Utils.testFromFileComporessList(context, afterImg);
  239 + String path = await Utils.saveImage(newImg);
  240 + // File compressedFile;
  241 + if (path == null) {
  242 + File compressedFile = await FlutterNativeImage.compressImage(
  243 + file.path,
  244 + quality: 50,
  245 + percentage: 50);
  246 + path = compressedFile.path;
  247 + }
  248 + // File compressedFile = await FlutterNativeImage.compressImage(
  249 + // file.absolute.path,
  250 + // quality: 50,
  251 + // percentage: 50);
221 setState(() { 252 setState(() {
222 UploadImgModel imgModel = UploadImgModel(); 253 UploadImgModel imgModel = UploadImgModel();
223 - imgModel.file = compressedFile; 254 + imgModel.file = File(path);
224 imgModel.process = 0.01; 255 imgModel.process = 0.01;
225 256
226 temp.add(imgModel); 257 temp.add(imgModel);
@@ -228,10 +259,10 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -228,10 +259,10 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
228 bool need = await Utils.sizeNeed(file); 259 bool need = await Utils.sizeNeed(file);
229 260
230 if (need) { 261 if (need) {
231 - file = File(compressedFile.absolute.path); 262 + file = File(path);
232 } 263 }
233 - UploadImageUtil().startUpload(context, file, temp.length - 1, false,  
234 - widget.model, widget.uploadType, 264 + UploadImageUtil().startUpload(context, File(path), temp.length - 1,
  265 + false, widget.model, widget.uploadType,
235 countAll: imgList.length, 266 countAll: imgList.length,
236 callback: widget.callback, 267 callback: widget.callback,
237 imageList: widget.imageList); 268 imageList: widget.imageList);
@@ -469,6 +500,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> { @@ -469,6 +500,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
469 temp = widget.model.tableImageList; 500 temp = widget.model.tableImageList;
470 } else if (widget.uploadType == UploadType.WineManageType) { 501 } else if (widget.uploadType == UploadType.WineManageType) {
471 temp = widget.imageList; 502 temp = widget.imageList;
  503 + } else if (widget.uploadType == UploadType.CouponDishType) {
  504 + temp = widget.imageList;
472 } 505 }
473 return _getGridImg( 506 return _getGridImg(
474 temp.length < widget.maxImageNumber ? temp.length + 1 : temp.length, 507 temp.length < widget.maxImageNumber ? temp.length + 1 : temp.length,
@@ -621,9 +621,11 @@ var handleCouponEditPageHandler = new Handler( @@ -621,9 +621,11 @@ var handleCouponEditPageHandler = new Handler(
621 handlerFunc: (BuildContext context, Map<String, List<Object>> params) { 621 handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
622 // String rid = params["rid"].first; 622 // String rid = params["rid"].first;
623 bool isMine = FluroConvertUtils.string2bool(params["isMine"].first); 623 bool isMine = FluroConvertUtils.string2bool(params["isMine"].first);
624 - return CouponEidtPage( 624 + return ChangeNotifierProvider<UploadImageProvider>(
  625 + create: (_) => UploadImageProvider(),
  626 + child:CouponEidtPage(
625 isMine: isMine, 627 isMine: isMine,
626 - ); 628 + ));
627 }); 629 });
628 630
629 ///选择优惠券 631 ///选择优惠券
@@ -25,7 +25,8 @@ enum UploadType { @@ -25,7 +25,8 @@ enum UploadType {
25 FeastRemarkContractType, //宴会备注--合同 25 FeastRemarkContractType, //宴会备注--合同
26 FeastRemarkInvoiceType, //宴会备注--发票 26 FeastRemarkInvoiceType, //宴会备注--发票
27 InvitationStoreType, //预订安排定制----店铺图片 27 InvitationStoreType, //预订安排定制----店铺图片
28 - WineManageType //新建存酒 28 + WineManageType, //新建存酒
  29 + CouponDishType //新建优惠券菜品券图片
29 30
30 } 31 }
31 32
@@ -102,6 +103,9 @@ class UploadImageUtil { @@ -102,6 +103,9 @@ class UploadImageUtil {
102 } else if (uploadType == UploadType.WineManageType) { 103 } else if (uploadType == UploadType.WineManageType) {
103 //新建存酒 104 //新建存酒
104 imageList[index].process = percent; 105 imageList[index].process = percent;
  106 + } else if (uploadType == UploadType.CouponDishType) {
  107 + //新建优惠券
  108 + imageList[index].process = percent;
105 } 109 }
106 110
107 uploadImageProvider.notifyListeners(); 111 uploadImageProvider.notifyListeners();
@@ -190,6 +194,10 @@ class UploadImageUtil { @@ -190,6 +194,10 @@ class UploadImageUtil {
190 //新建存酒 194 //新建存酒
191 imageList[index].process = 1; 195 imageList[index].process = 1;
192 imageList[index].qiniuUrl = imgUrl; 196 imageList[index].qiniuUrl = imgUrl;
  197 + } else if (uploadType == UploadType.CouponDishType) {
  198 + //新建优惠券
  199 + imageList[index].process = 1;
  200 + imageList[index].qiniuUrl = imgUrl;
193 } 201 }
194 202
195 // 取消当前任务 203 // 取消当前任务
@@ -230,6 +238,9 @@ class UploadImageUtil { @@ -230,6 +238,9 @@ class UploadImageUtil {
230 } else if (uploadType == UploadType.WineManageType) { 238 } else if (uploadType == UploadType.WineManageType) {
231 //新建存酒 239 //新建存酒
232 imageList.removeAt(index); 240 imageList.removeAt(index);
  241 + } else if (uploadType == UploadType.CouponDishType) {
  242 + //新建存酒
  243 + imageList.removeAt(index);
233 } 244 }
234 245
235 // 取消当前任务 246 // 取消当前任务
@@ -1323,7 +1323,7 @@ class Utils { @@ -1323,7 +1323,7 @@ class Utils {
1323 Loading.showLoading(context); 1323 Loading.showLoading(context);
1324 String _webPageUrl = "http://colorcun.com/"; 1324 String _webPageUrl = "http://colorcun.com/";
1325 // String _thumbnail = img; 1325 // String _thumbnail = img;
1326 - 1326 +
1327 // String _thumbnail = sellerImage == null || sellerImage == '' 1327 // String _thumbnail = sellerImage == null || sellerImage == ''
1328 // ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png' 1328 // ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
1329 // : sellerImage; 1329 // : sellerImage;
@@ -1857,6 +1857,9 @@ class Utils { @@ -1857,6 +1857,9 @@ class Utils {
1857 } 1857 }
1858 } else if (use.isDish) { 1858 } else if (use.isDish) {
1859 _thumbnail = 'https://nosqn.colorcun.com/share_dish.png'; 1859 _thumbnail = 'https://nosqn.colorcun.com/share_dish.png';
  1860 + if (use.images.length > 0) {
  1861 + _thumbnail = use.images[0];
  1862 + }
1860 if (price == '0') { 1863 if (price == '0') {
1861 _title = 1864 _title =
1862 '免费获取${Provider.of<UserModel>(context, listen: false).user.sellername}${couponSunModel.aname},点击查看详情。'; 1865 '免费获取${Provider.of<UserModel>(context, listen: false).user.sellername}${couponSunModel.aname},点击查看详情。';