Commit 490142acf34cccdc6308bd3c566c72dc6363f8b0

Authored by wdn127929
1 parent c2372ef5

优惠券带图

... ... @@ -2,6 +2,9 @@ import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
import 'package:one_key/models/filter_btn_model.dart';
import 'package:one_key/models/upload_img_model.dart';
import 'dart:convert' as convert;
part 'coupon_model.g.dart';
... ... @@ -148,8 +151,11 @@ class CouponUse extends Object {
@JsonKey(name: 'dish')
String dish;
@JsonKey(name: 'images')
List<String> images;
CouponUse(this.isCash, this.isDiscount, this.isDish, this.cash, this.discount,
this.dish);
this.dish, this.images);
factory CouponUse.fromJson(Map<String, dynamic> srcJson) =>
_$CouponUseFromJson(srcJson);
... ...
... ... @@ -110,15 +110,27 @@ CouponUse _$CouponUseFromJson(Map<String, dynamic> json) {
} else if (json['is_dish'] is bool) {
isdish = json['is_dish'] ? true : false;
}
List<String> img = [];
if (isdish && json['images'] != '' && json['images'] != null) {
if (json['images'] is List) {
json['images'].forEach((v) {
// UploadImgModel uploadImgModel = UploadImgModel();
// uploadImgModel.qiniuUrl = v;
// uploadImgModel.process = 1;
img.add(v);
});
} else {
convert.jsonDecode(json['images']).forEach((v) {
// UploadImgModel uploadImgModel = UploadImgModel();
// uploadImgModel.qiniuUrl = v;
// uploadImgModel.process = 1;
img.add(v);
});
}
}
return CouponUse(
iscash,
isdiscount,
isdish,
json['cash'] as String,
json['discount'] as String,
json['dish'] as String,
);
return CouponUse(iscash, isdiscount, isdish, json['cash'] as String,
json['discount'] as String, json['dish'] as String, img);
}
Map<String, dynamic> _$CouponUseToJson(CouponUse instance) => <String, dynamic>{
... ... @@ -128,6 +140,7 @@ Map<String, dynamic> _$CouponUseToJson(CouponUse instance) => <String, dynamic>{
'cash': instance.cash,
'discount': instance.discount,
'dish': instance.dish,
'images': instance.images
};
ExpDate _$ExpDateFromJson(Map<String, dynamic> json) {
... ...
import 'package:cached_network_image/cached_network_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_picker/flutter_picker.dart';
... ... @@ -21,6 +22,7 @@ import 'package:provider/provider.dart';
import '../../provider/base_info_provider.dart';
import '../../utils/screen_util.dart';
import '../../widgets/page_exception.dart';
import '../online_check/photo_view_wiget.dart';
/**
* 新建券
... ... @@ -222,6 +224,102 @@ class _CouponDetailPageState extends State<CouponDetailPage> {
);
}
List<Widget> imageWidget(List<String> temp) {
List<Widget> data = [];
for (int i = 0; i < temp.length; i++) {
data.add(InkWell(
onTap: () {
///没有上传完成的不可以点击
_showPhotoView(context, i, temp);
},
child: Container(
margin: EdgeInsets.only(
right: i < temp.length - 1
? ((ScreenUtil().screenWidth - w(100) * 3 - w(16) * 2) /
2)
: 0),
child: CachedNetworkImage(
imageUrl: temp[i],
fit: BoxFit.cover,
width: ScreenUtil().setWidth(100 * 2),
height: ScreenUtil().setWidth(100 * 2),
))));
}
return data;
}
/// 九宫格
Widget _getGridImg(context, List<String> temp) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: imageWidget(temp),
);
return GridView.builder(
controller: controller,
// padding: EdgeInsets.only(top: ScreenUtil().getAdapterSize(10)),
shrinkWrap: true,
itemCount: temp.length,
//SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//横轴元素个数
crossAxisCount: 3,
//纵轴间距
mainAxisSpacing: ScreenUtil().setWidth(40),
//横轴间距
crossAxisSpacing: ScreenUtil().setWidth(36),
//子组件宽高长度比例
childAspectRatio: 1.0),
itemBuilder: (BuildContext context, int index) {
//Widget Function(BuildContext context, int index)
return temp.length < 1
? Text('')
: InkWell(
onTap: () {
///没有上传完成的不可以点击
_showPhotoView(context, index, temp);
},
child: CachedNetworkImage(
imageUrl: temp[index],
fit: BoxFit.cover,
width: ScreenUtil().setWidth(100 * 2),
height: ScreenUtil().setWidth(100 * 2),
));
});
}
//查看大图
_showPhotoView(BuildContext context, int index, List<String> imgs,
{isShow = false, List dashName}) async {
// if (imgs.length == 1 &&
// imgs[0] ==
// 'http://nosqn.colorcun.com/custom/lite-online/image/def-banner.png') {
// imgs[0] = 'http://nosqn.colorcun.com/app/seller-hj-empty.png';
// }
Utils.setBarStatus(false, color: Colors.black);
dynamic result = await showGeneralDialog(
context: context,
barrierDismissible: false,
// barrierColor: Colors.red,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 150),
pageBuilder: (BuildContext context, Animation animation,
Animation secondaryAnimation) {
Widget child = Stack(
children: <Widget>[
PhotoPreview(
initialIndex: index,
photoList: imgs,
isShow: isShow,
dashName: dashName)
],
);
return child;
});
Utils.setBarStatus(true, color: Colors.white);
}
@override
Widget build(BuildContext context) {
couponProvider = Provider.of<CouponProvider>(context, listen: true);
... ... @@ -355,6 +453,16 @@ class _CouponDetailPageState extends State<CouponDetailPage> {
? couponProvider
.couponSunModel.use.dish
: ''),
if (couponProvider
.couponSunModel.use.isDish &&
couponProvider.couponSunModel.use.images
.length >
0)
_getGridImg(
context,
couponProvider
.couponSunModel.use.images),
VEmptyView(24),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
... ...
... ... @@ -20,7 +20,11 @@ import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import '../../models/filter_btn_model.dart';
import '../../models/upload_img_model.dart';
import '../../provider/upload_img_provider.dart';
import '../../utils/screen_util.dart';
import '../../utils/upload_image_util.dart';
import '../online_check/img_picker_widget.dart';
/**
* 新建券
... ... @@ -78,6 +82,9 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
String noon;
String night;
UploadImageProvider _uploadImageProvider;
List<UploadImgModel> img = [];
@override
void initState() {
super.initState();
... ... @@ -158,9 +165,23 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
WidgetsBinding.instance.addPostFrameCallback((_) {
// _couponNetworkData(0);
_initWeekData();
_getQiniuInfo();
});
}
@override
void dispose() {
super.dispose();
_uploadImageProvider.qiniuInfoSunModel.token = null;
}
///获取七牛云token
///
_getQiniuInfo() async {
await _uploadImageProvider.getQiniuInfo(context, {});
}
// //初始化时间
// initWeekData() async {
// // UserModel userModel = Provider.of<UserModel>(context, listen: false);
... ... @@ -222,14 +243,20 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
params['uid_list'] = uids;
params['price'] =
_priceControl.text.trim().length == 0 ? '0' : _priceControl.text;
List<String> images = [];
if (img.length > 0) {
img.forEach((value) {
images.add(value.qiniuUrl);
});
}
Map use = {
'is_cash': money ? '1' : '0',
'is_discount': discount ? '1' : '0',
'is_dish': dish ? '1' : '0',
'cash': moneyControl.text,
'discount': discountControl.text,
'dish': dishControl.text
'dish': dishControl.text,
'images': json.encode(images)
};
params['use'] = jsonEncode(use);
... ... @@ -651,6 +678,8 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
@override
Widget build(BuildContext context) {
couponProvider = Provider.of<CouponProvider>(context, listen: true);
_uploadImageProvider =
Provider.of<UploadImageProvider>(context, listen: true);
return Scaffold(
backgroundColor: MyColours.color_ffffff,
key: scaffoldKey,
... ... @@ -792,6 +821,56 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
_textfieldSelect('菜品:', '点击输入赠送菜品名称',
dishControl, dishFocusNode,
textInputType: TextInputType.text),
if (dish) VEmptyView(20),
if (dish)
Padding(
padding: EdgeInsets.only(
left: w(10), right: w(15)),
child: Consumer<UploadImageProvider>(
builder: (context, model, _) {
return ImgPickerWidget(
scrollController: controller,
model: _uploadImageProvider,
maxImageNumber: 3,
maxRemind: '三',
imageList: img,
uploadType:
UploadType.CouponDishType,
deleteCallback: (int index) {
img.removeWhere((element) =>
element == img[index]);
setState(() {});
},
callback: () {
// for (UploadImgModel item
// in _uploadImageProvider
// .tableImageList) {
// if (item.process < 1) {
// Utils.showToast('正在上传图片,请稍等');
// return;
// }
// }
// //接口,和桌子绑定
// List imageQiniuUrlList = [];
// for (int i = 0;
// i <
// _uploadImageProvider
// .tableImageList.length;
// i++) {
// if (!_uploadImageProvider
// .tableImageList[i].isUpload) {
// imageQiniuUrlList.add({
// "url": _uploadImageProvider
// .tableImageList[i].qiniuUrl
// });
// }
// }
// _setTablePhoto(
// context, imageQiniuUrlList);
},
);
})),
VEmptyView(48),
Container(
height: ScreenUtil().setWidth(2),
... ... @@ -1035,68 +1114,82 @@ class _CouponEidtPageState extends State<CouponEidtPage> {
VEmptyView(20),
RoundButton(
onPressed: () {
if (_couponNameEditControl.text.trim().length == 0) {
Utils.showToast('请填写券名称');
return;
print(img);
bool can = true;
innerloop:
for (UploadImgModel item in img) {
if (item.process < 1) {
Utils.showToast('正在上传图片,请稍等');
// return false;
can = false;
break innerloop;
}
}
if (!widget.isMine) {
if (money && moneyControl.text.trim().length == 0) {
Utils.showToast('请输入代金券金额!');
if (can) {
if (_couponNameEditControl.text.trim().length == 0) {
Utils.showToast('请填写券名称');
return;
}
if (discount && discountControl.text.trim().length == 0) {
Utils.showToast('请输入折扣率!');
return;
if (!widget.isMine) {
if (money && moneyControl.text.trim().length == 0) {
Utils.showToast('请输入代金券金额!');
return;
}
if (discount &&
discountControl.text.trim().length == 0) {
Utils.showToast('请输入折扣率!');
return;
}
if (dish && dishControl.text.trim().length == 0) {
Utils.showToast('请输入菜品!');
return;
}
if (limitWeek && weekShow == '点击设置可用日期') {
Utils.showToast('请设置可用日期!');
return;
}
if (uids == null || uids == '') {
Utils.showToast('请设置发放人!');
return;
}
bool isNumber = Utils.isInteger(
_limitNumControl.text.trim()); //判断输入的内容是否是数字
if (!isNumber) {
Utils.showToast('发放总量限制请输入数字');
_limitNumControl.text = '';
return;
}
}
if (dish && dishControl.text.trim().length == 0) {
Utils.showToast('请输入菜品!');
if (_couponRequireEditControl.text.trim().length == 0) {
Utils.showToast('请填写券要求');
return;
}
if (limitWeek && weekShow == '点击设置可用日期') {
Utils.showToast('请设置可用日期!');
if (fromDate == '点击选择') {
Utils.showToast('请选择有效期起始时间');
return;
}
if (uids == null || uids == '') {
Utils.showToast('请设置发放人!');
if (endDate == '点击选择') {
Utils.showToast('请选择有效期结束时间');
return;
}
bool isNumber = Utils.isInteger(
_limitNumControl.text.trim()); //判断输入的内容是否是数字
if (!isNumber) {
Utils.showToast('发放总量限制请输入数字');
_limitNumControl.text = '';
if (DateUtil.getDateTime(endDate)
.compareTo(DateUtil.getDateTime(fromDate)) <
0) {
Utils.showToast('有效期结束时间不能早于起始时间');
return;
}
}
if (_couponRequireEditControl.text.trim().length == 0) {
Utils.showToast('请填写券要求');
return;
}
if (fromDate == '点击选择') {
Utils.showToast('请选择有效期起始时间');
return;
}
if (endDate == '点击选择') {
Utils.showToast('请选择有效期结束时间');
return;
}
if (DateUtil.getDateTime(endDate)
.compareTo(DateUtil.getDateTime(fromDate)) <
0) {
Utils.showToast('有效期结束时间不能早于起始时间');
return;
}
// ***参数***
// _couponNameEditControl.text
// _couponRequireEditControl.text
// fromDate
// endDate
// _couponExplainEditControl.text
// swichState
_createNewCoupon();
// ***参数***
// _couponNameEditControl.text
// _couponRequireEditControl.text
// fromDate
// endDate
// _couponExplainEditControl.text
// swichState
_createNewCoupon();
}
},
text: '立即创建',
fontSize: 24,
... ...
... ... @@ -5,6 +5,7 @@ import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/upload_img_model.dart';
import 'package:one_key/pages/online_check/photo_view_wiget.dart';
... ... @@ -96,14 +97,24 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
Future _getFromPictureOrCamera(imageSource) async {
final pickedFile = await picker.pickImage(
source: imageSource, preferredCameraDevice: CameraDevice.rear);
File compressedFile = await FlutterNativeImage.compressImage(
pickedFile.path,
quality: 50,
percentage: 50);
//从相册选取照片后进行裁剪压缩
File yourFile = File(pickedFile.path);
Uint8List afterImg = await yourFile.readAsBytes();
Uint8List newImg = await Utils.testFromFileComporessList(context, afterImg);
String path = await Utils.saveImage(newImg);
if (path == null) {
File compressedFile = await FlutterNativeImage.compressImage(
yourFile.path,
quality: 50,
percentage: 50);
path = compressedFile.path;
}
setState(() {
if (pickedFile != null) {
UploadImgModel imgModel = UploadImgModel();
imgModel.file = compressedFile;
imgModel.file = File(path);
imgModel.process = 0.01;
if (widget.uploadType == UploadType.ConsumptionUploadType) {
widget.model.imageList.add(imgModel);
... ... @@ -115,6 +126,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
widget.model.tableImageList.add(imgModel);
} else if (widget.uploadType == UploadType.WineManageType) {
widget.imageList.add(imgModel);
} else if (widget.uploadType == UploadType.CouponDishType) {
widget.imageList.add(imgModel);
}
} else {
print('No image selected.');
... ... @@ -133,11 +146,13 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
temp = widget.model.tableImageList;
} else if (widget.uploadType == UploadType.WineManageType) {
temp = widget.imageList;
} else if (widget.uploadType == UploadType.CouponDishType) {
temp = widget.imageList;
}
bool need = await Utils.sizeNeed(File(pickedFile.path));
File file = File(pickedFile.path);
if (need) {
file = File(compressedFile.absolute.path);
file = File(path);
}
UploadImageUtil().startUpload(
context, file, temp.length - 1, true, widget.model, widget.uploadType,
... ... @@ -158,6 +173,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
temp = widget.model.tableImageList;
} else if (widget.uploadType == UploadType.WineManageType) {
temp = widget.imageList;
} else if (widget.uploadType == UploadType.CouponDishType) {
temp = widget.imageList;
}
List<AssetEntity> imgList = await AssetPicker.pickAssets(context,
pickerConfig: AssetPickerConfig(
... ... @@ -214,13 +231,27 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
} else {
for (int i = 0; i < imgList.length; i++) {
var file = await imgList[i].file;
File compressedFile = await FlutterNativeImage.compressImage(
file.absolute.path,
quality: 50,
percentage: 50);
//从相册选取照片后进行裁剪压缩
File yourFile = file;
Uint8List afterImg = await yourFile.readAsBytes();
Uint8List newImg =
await Utils.testFromFileComporessList(context, afterImg);
String path = await Utils.saveImage(newImg);
// File compressedFile;
if (path == null) {
File compressedFile = await FlutterNativeImage.compressImage(
file.path,
quality: 50,
percentage: 50);
path = compressedFile.path;
}
// File compressedFile = await FlutterNativeImage.compressImage(
// file.absolute.path,
// quality: 50,
// percentage: 50);
setState(() {
UploadImgModel imgModel = UploadImgModel();
imgModel.file = compressedFile;
imgModel.file = File(path);
imgModel.process = 0.01;
temp.add(imgModel);
... ... @@ -228,10 +259,10 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
bool need = await Utils.sizeNeed(file);
if (need) {
file = File(compressedFile.absolute.path);
file = File(path);
}
UploadImageUtil().startUpload(context, file, temp.length - 1, false,
widget.model, widget.uploadType,
UploadImageUtil().startUpload(context, File(path), temp.length - 1,
false, widget.model, widget.uploadType,
countAll: imgList.length,
callback: widget.callback,
imageList: widget.imageList);
... ... @@ -469,6 +500,8 @@ class _ImgPickerWidgetState extends DisposableState<ImgPickerWidget> {
temp = widget.model.tableImageList;
} else if (widget.uploadType == UploadType.WineManageType) {
temp = widget.imageList;
} else if (widget.uploadType == UploadType.CouponDishType) {
temp = widget.imageList;
}
return _getGridImg(
temp.length < widget.maxImageNumber ? temp.length + 1 : temp.length,
... ...
... ... @@ -621,9 +621,11 @@ var handleCouponEditPageHandler = new Handler(
handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
// String rid = params["rid"].first;
bool isMine = FluroConvertUtils.string2bool(params["isMine"].first);
return CouponEidtPage(
return ChangeNotifierProvider<UploadImageProvider>(
create: (_) => UploadImageProvider(),
child:CouponEidtPage(
isMine: isMine,
);
));
});
///选择优惠券
... ...
... ... @@ -25,7 +25,8 @@ enum UploadType {
FeastRemarkContractType, //宴会备注--合同
FeastRemarkInvoiceType, //宴会备注--发票
InvitationStoreType, //预订安排定制----店铺图片
WineManageType //新建存酒
WineManageType, //新建存酒
CouponDishType //新建优惠券菜品券图片
}
... ... @@ -102,6 +103,9 @@ class UploadImageUtil {
} else if (uploadType == UploadType.WineManageType) {
//新建存酒
imageList[index].process = percent;
} else if (uploadType == UploadType.CouponDishType) {
//新建优惠券
imageList[index].process = percent;
}
uploadImageProvider.notifyListeners();
... ... @@ -190,6 +194,10 @@ class UploadImageUtil {
//新建存酒
imageList[index].process = 1;
imageList[index].qiniuUrl = imgUrl;
} else if (uploadType == UploadType.CouponDishType) {
//新建优惠券
imageList[index].process = 1;
imageList[index].qiniuUrl = imgUrl;
}
// 取消当前任务
... ... @@ -230,6 +238,9 @@ class UploadImageUtil {
} else if (uploadType == UploadType.WineManageType) {
//新建存酒
imageList.removeAt(index);
} else if (uploadType == UploadType.CouponDishType) {
//新建存酒
imageList.removeAt(index);
}
// 取消当前任务
... ...
... ... @@ -1323,7 +1323,7 @@ class Utils {
Loading.showLoading(context);
String _webPageUrl = "http://colorcun.com/";
// String _thumbnail = img;
// String _thumbnail = sellerImage == null || sellerImage == ''
// ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
// : sellerImage;
... ... @@ -1857,6 +1857,9 @@ class Utils {
}
} else if (use.isDish) {
_thumbnail = 'https://nosqn.colorcun.com/share_dish.png';
if (use.images.length > 0) {
_thumbnail = use.images[0];
}
if (price == '0') {
_title =
'免费获取${Provider.of<UserModel>(context, listen: false).user.sellername}${couponSunModel.aname},点击查看详情。';
... ...