Commit 288d1636a4b5fd0a5cb31fd0c40fb397c1f82f9e

Authored by wdn127929
1 parent 73225477

导出OK

  1 +class GetExportInfoModel {
  2 + int ret;
  3 + GetExportInfoSunModel data;
  4 + String msg;
  5 +
  6 + GetExportInfoModel({this.ret, this.data, this.msg});
  7 +
  8 + GetExportInfoModel.fromJson(Map<String, dynamic> json) {
  9 + ret = json['ret'];
  10 + data = json['data'] != null
  11 + ? new GetExportInfoSunModel.fromJson(json['data'])
  12 + : null;
  13 + msg = json['msg'];
  14 + }
  15 +
  16 + Map<String, dynamic> toJson() {
  17 + final Map<String, dynamic> data = new Map<String, dynamic>();
  18 + data['ret'] = this.ret;
  19 + if (this.data != null) {
  20 + data['data'] = this.data.toJson();
  21 + }
  22 + data['msg'] = this.msg;
  23 + return data;
  24 + }
  25 +}
  26 +
  27 +class GetExportInfoSunModel {
  28 + Info info;
  29 + List<ExcelData> list;
  30 +
  31 + List<dynamic> excelData;
  32 + List<Count> count;
  33 +
  34 + GetExportInfoSunModel({this.info, this.list, this.count});
  35 +
  36 + GetExportInfoSunModel.fromJson(Map<String, dynamic> json) {
  37 + info = json['info'] != null ? new Info.fromJson(json['info']) : null;
  38 + if (json['list'] != null) {
  39 + list = <ExcelData>[];
  40 + json['list'].forEach((v) {
  41 + list.add(new ExcelData.fromJson(v));
  42 + });
  43 +
  44 + excelData = json['list'];
  45 + }
  46 + if (json['count'] != null) {
  47 + count = <Count>[];
  48 + json['count'].forEach((v) {
  49 + count.add(new Count.fromJson(v));
  50 + });
  51 + }
  52 + }
  53 +
  54 + Map<String, dynamic> toJson() {
  55 + final Map<String, dynamic> data = new Map<String, dynamic>();
  56 + if (this.info != null) {
  57 + data['info'] = this.info.toJson();
  58 + }
  59 + if (this.list != null) {
  60 + data['list'] = this.list.map((v) => v.toJson()).toList();
  61 + }
  62 + if (this.count != null) {
  63 + data['count'] = this.count.map((v) => v.toJson()).toList();
  64 + }
  65 + return data;
  66 + }
  67 +}
  68 +
  69 +class Info {
  70 + String sellername;
  71 +
  72 + Info({this.sellername});
  73 +
  74 + Info.fromJson(Map<String, dynamic> json) {
  75 + sellername = json['sellername'];
  76 + }
  77 +
  78 + Map<String, dynamic> toJson() {
  79 + final Map<String, dynamic> data = new Map<String, dynamic>();
  80 + data['sellername'] = this.sellername;
  81 + return data;
  82 + }
  83 +}
  84 +
  85 +class ExcelData {
  86 + String cdate;
  87 + String ddate;
  88 + String status;
  89 + String ddateSolt;
  90 + String tableinfo;
  91 + String rname;
  92 + String phone;
  93 + String nickName;
  94 + String noteName;
  95 +
  96 + ExcelData(
  97 + {this.cdate,
  98 + this.ddate,
  99 + this.status,
  100 + this.ddateSolt,
  101 + this.tableinfo,
  102 + this.rname,
  103 + this.phone,
  104 + this.nickName,
  105 + this.noteName});
  106 +
  107 + ExcelData.fromJson(Map<String, dynamic> json) {
  108 + cdate = json['cdate'];
  109 + ddate = json['ddate'];
  110 + status = json['status'];
  111 + ddateSolt = json['ddate_solt'];
  112 + tableinfo = json['tableinfo'];
  113 + rname = json['rname'];
  114 + phone = json['phone'];
  115 + nickName = json['nick_name'];
  116 + noteName = json['note_name'];
  117 + }
  118 +
  119 + Map<String, dynamic> toJson() {
  120 + final Map<String, dynamic> data = new Map<String, dynamic>();
  121 + data['cdate'] = this.cdate;
  122 + data['ddate'] = this.ddate;
  123 + data['status'] = this.status;
  124 + data['ddate_solt'] = this.ddateSolt;
  125 + data['tableinfo'] = this.tableinfo;
  126 + data['rname'] = this.rname;
  127 + data['phone'] = this.phone;
  128 + data['nick_name'] = this.nickName;
  129 + data['note_name'] = this.noteName;
  130 + return data;
  131 + }
  132 +}
  133 +
  134 +class Count {
  135 + String total;
  136 + String nickName;
  137 +
  138 + Count({this.total, this.nickName});
  139 +
  140 + Count.fromJson(Map<String, dynamic> json) {
  141 + total = json['total'];
  142 + nickName = json['nick_name'];
  143 + }
  144 +
  145 + Map<String, dynamic> toJson() {
  146 + final Map<String, dynamic> data = new Map<String, dynamic>();
  147 + data['total'] = this.total;
  148 + data['nick_name'] = this.nickName;
  149 + return data;
  150 + }
  151 +}
  1 +class GetReportFieldModel {
  2 + int ret;
  3 + List<GetReportFieldSunModel> data;
  4 + String msg;
  5 +
  6 + GetReportFieldModel({this.ret, this.data, this.msg});
  7 +
  8 + GetReportFieldModel.fromJson(Map<String, dynamic> json) {
  9 + ret = json['ret'];
  10 + if (json['data'] != null) {
  11 + data = <GetReportFieldSunModel>[];
  12 + json['data'].forEach((v) {
  13 + data.add(new GetReportFieldSunModel.fromJson(v));
  14 + });
  15 + }
  16 + msg = json['msg'];
  17 + }
  18 +
  19 + Map<String, dynamic> toJson() {
  20 + final Map<String, dynamic> data = new Map<String, dynamic>();
  21 + data['ret'] = this.ret;
  22 + if (this.data != null) {
  23 + data['data'] = this.data.map((v) => v.toJson()).toList();
  24 + }
  25 + data['msg'] = this.msg;
  26 + return data;
  27 + }
  28 +}
  29 +
  30 +class GetReportFieldSunModel {
  31 + String code;
  32 + String name;
  33 + bool select = true;
  34 +
  35 + GetReportFieldSunModel({this.code, this.name});
  36 +
  37 + GetReportFieldSunModel.fromJson(Map<String, dynamic> json) {
  38 + code = json['code'];
  39 + name = json['name'];
  40 + }
  41 +
  42 + Map<String, dynamic> toJson() {
  43 + final Map<String, dynamic> data = new Map<String, dynamic>();
  44 + data['code'] = this.code;
  45 + data['name'] = this.name;
  46 + return data;
  47 + }
  48 +}
@@ -490,9 +490,9 @@ class HttpUrl { @@ -490,9 +490,9 @@ class HttpUrl {
490 static const String get_marketing_sms_template = 490 static const String get_marketing_sms_template =
491 "?service=App.SendSMS.GetMarketingSmsTemplate"; // 获取营销短信模板列表 491 "?service=App.SendSMS.GetMarketingSmsTemplate"; // 获取营销短信模板列表
492 492
493 -  
494 -static const String get_report_field =  
495 - "?service=App.Seller.GetReportField"; // 获取App导出字段  
496 - 493 + static const String get_report_field =
  494 + "?service=App.Seller.GetReportField"; // 获取App导出字段
  495 + static const String get_export_info =
  496 + "?service=App.Seller.GetExportInfo"; // 获取App导出数据
497 497
498 } 498 }
@@ -8,6 +8,8 @@ import 'package:dio/dio.dart'; @@ -8,6 +8,8 @@ import 'package:dio/dio.dart';
8 import 'package:flutter/material.dart'; 8 import 'package:flutter/material.dart';
9 import 'package:flutter_picker/Picker.dart'; 9 import 'package:flutter_picker/Picker.dart';
10 import 'package:flutter_screenutil/flutter_screenutil.dart'; 10 import 'package:flutter_screenutil/flutter_screenutil.dart';
  11 +import 'package:one_key/models/get_export_info_model.dart';
  12 +import 'package:one_key/models/get_report_field_model.dart';
11 import 'package:one_key/provider/user_model.dart'; 13 import 'package:one_key/provider/user_model.dart';
12 import 'package:one_key/res/colors.dart'; 14 import 'package:one_key/res/colors.dart';
13 import 'package:one_key/widgets/round_button.dart'; 15 import 'package:one_key/widgets/round_button.dart';
@@ -19,6 +21,7 @@ import 'package:provider/provider.dart'; @@ -19,6 +21,7 @@ import 'package:provider/provider.dart';
19 21
20 import '../../../../app.dart'; 22 import '../../../../app.dart';
21 import '../../../../net/dio_util.dart'; 23 import '../../../../net/dio_util.dart';
  24 +import '../../../../provider/customer_provider.dart';
22 import '../../../../utils/dialog_util.dart'; 25 import '../../../../utils/dialog_util.dart';
23 import '../../../../utils/screen_util.dart'; 26 import '../../../../utils/screen_util.dart';
24 import '../../../../utils/utils.dart'; 27 import '../../../../utils/utils.dart';
@@ -56,238 +59,28 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -56,238 +59,28 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
56 // DownloadTaskStatus status; 59 // DownloadTaskStatus status;
57 int progress; 60 int progress;
58 61
  62 + CustomerProvider customerProvider;
  63 +
  64 + // List<Map<String, String>> fieldData = {};
  65 +
59 @override 66 @override
60 void initState() { 67 void initState() {
61 super.initState(); 68 super.initState();
62 69
63 - // IsolateNameServer.registerPortWithName(  
64 - // _port.sendPort, 'downloader_send_port');  
65 - // _port.listen((dynamic data) {  
66 - // taskId = data[0];  
67 - // status = DownloadTaskStatus(data[1]);  
68 - // progress = data[2];  
69 - // setState(() {});  
70 - // if (status == DownloadTaskStatus.undefined) {  
71 - // // _requestDownload(task);  
72 - // } else if (status == DownloadTaskStatus.running) {  
73 - // // _pauseDownload(task);  
74 - // // setState(() {});  
75 - // } else if (status == DownloadTaskStatus.paused) {  
76 - // // _resumeDownload(task);  
77 - // // setState(() {});  
78 - // } else if (status == DownloadTaskStatus.complete ||  
79 - // status == DownloadTaskStatus.canceled) {  
80 - // // _delete(task);  
81 -  
82 - // // 显示是否打开的对话框  
83 -  
84 - // DialogUtil.cupertinoAlertDialog(context,  
85 - // title: '提示',  
86 - // content: '文件下载完成,是否打开?',  
87 - // lTitle: '取消',  
88 - // rTitle: '打开', lCallback: () {  
89 - // Navigator.pop(context);  
90 - // }, rCallback: () async {  
91 - // // Navigator.pop(context);  
92 -  
93 - // print(_localPath);  
94 -  
95 - // final tasks = await FlutterDownloader.loadTasks();  
96 - // String str = '';  
97 - // tasks.forEach((element) {  
98 - // str = element.savedDir + '/' + element.filename;  
99 - // });  
100 - // print(str);  
101 -  
102 - // if (str != '') {  
103 - // OpenFile.open(str);  
104 - // _delete();  
105 - // }  
106 - // });  
107 - // // showDialog(  
108 - // // // 设置点击 dialog 外部不取消 dialog,默认能够取消  
109 - // // barrierDismissible: false,  
110 - // // context: context,  
111 - // // builder: (context) => AlertDialog(  
112 - // // title: Text('提示'),  
113 - // // // 标题文字样式  
114 - // // content: Text('文件下载完成,是否打开?'),  
115 - // // // 内容文字样式  
116 - // // backgroundColor: MyColours.color_ffffff,  
117 - // // elevation: 8.0,  
118 - // // // 投影的阴影高度  
119 - // // semanticLabel: 'Label',  
120 - // // // 这个用于无障碍下弹出 dialog 的提示  
121 - // // shape: Border.all(),  
122 - // // // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`  
123 - // // actions: <Widget>[  
124 - // // // 点击取消按钮  
125 - // // InkWell(  
126 - // // onTap: () => Navigator.pop(context), child: Text('取消')),  
127 - // // // 点击打开按钮  
128 - // // InkWell(  
129 - // // onTap: () async {  
130 - // // Navigator.pop(context);  
131 -  
132 - // // print(_localPath);  
133 -  
134 - // // final tasks = await FlutterDownloader.loadTasks();  
135 - // // String str = '';  
136 - // // tasks.forEach((element) {  
137 - // // str = element.savedDir + '/' + element.filename;  
138 - // // });  
139 - // // print(str);  
140 - // // if (str != '') {  
141 - // // OpenFile.open(str);  
142 - // // }  
143 -  
144 - // // // 打开文件  
145 - // // // _openDownloadedFile(taskId).then((success) {  
146 - // // // if (!success) {  
147 - // // // Utils.showToast('Cannot open this file');  
148 - // // // // Scaffold.of(context).showSnackBar(SnackBar(  
149 - // // // // content: Text('Cannot open this file')));  
150 - // // // }  
151 - // // // });  
152 - // // },  
153 - // // child: Text('打开')),  
154 - // // ],  
155 - // // ));  
156 - // } else if (status == DownloadTaskStatus.failed) {  
157 - // // _retryDownload(task);  
158 - // Utils.showToast('下载异常,请稍后重试');  
159 - // }  
160 - // });  
161 -  
162 - // FlutterDownloader.registerCallback(downloadCallback);  
163 -  
164 - // // _bindBackgroundIsolate();  
165 -  
166 - // // FlutterDownloader.registerCallback(downloadCallback, step: 1);  
167 - // _delete(); 70 + WidgetsBinding.instance.addPostFrameCallback((_) async {
  71 + _getReportField();
  72 + });
168 } 73 }
169 74
170 - // _preae() async {  
171 - // final tasks = await FlutterDownloader.loadTasks();  
172 -  
173 - // if (tasks == null) {  
174 - // print('No tasks were retrieved from the database.');  
175 - // return;  
176 - // } else {  
177 - // tasks.forEach((element) {  
178 - // FlutterDownloader.remove(  
179 - // taskId: element.taskId, shouldDeleteContent: false);  
180 - // });  
181 - // }  
182 - // }  
183 -  
184 - @override  
185 - void dispose() {  
186 - // _unbindBackgroundIsolate();  
187 - super.dispose(); 75 + _getReportField() async {
  76 + bool success = await customerProvider.getReportField(context);
  77 + // if (success) {
  78 + // customerProvider.reportFieldModelData.forEach((element) {
  79 + // fieldData[element.code] = element.name;
  80 + // });
  81 + // }
188 } 82 }
189 83
190 - // @pragma('vm:entry-point')  
191 - // static void downloadCallback(  
192 - // String id,  
193 - // int status,  
194 - // int progress,  
195 - // ) {  
196 - // final SendPort send =  
197 - // IsolateNameServer.lookupPortByName('downloader_send_port');  
198 - // send.send([id, status, progress]);  
199 - // }  
200 -  
201 - // // 根据taskId打开下载文件  
202 - // Future<bool> _openDownloadedFile(taskId) {  
203 - // return FlutterDownloader.open(taskId: taskId);  
204 - // }  
205 -  
206 - // void _bindBackgroundIsolate() {  
207 - // final isSuccess = IsolateNameServer.registerPortWithName(  
208 - // _port.sendPort,  
209 - // 'downloader_send_port',  
210 - // );  
211 - // if (!isSuccess) {  
212 - // _unbindBackgroundIsolate();  
213 - // _bindBackgroundIsolate();  
214 - // return;  
215 - // }  
216 - // _port.listen((dynamic data) {  
217 - // taskId = (data as List<dynamic>)[0] as String;  
218 - // status = DownloadTaskStatus(data[1] as int);  
219 - // progressT = data[2] as int;  
220 -  
221 - // print(  
222 - // 'Callback on UI isolate: '  
223 - // 'task ($taskId) is in status ($status) and process ($progressT)',  
224 - // );  
225 - // if (status == DownloadTaskStatus.undefined) {  
226 - // // _requestDownload(task);  
227 - // } else if (status == DownloadTaskStatus.running) {  
228 - // // _pauseDownload(task);  
229 - // setState(() {});  
230 - // } else if (status == DownloadTaskStatus.paused) {  
231 - // // _resumeDownload(task);  
232 - // setState(() {});  
233 - // } else if (status == DownloadTaskStatus.complete ||  
234 - // status == DownloadTaskStatus.canceled) {  
235 - // // _delete(task);  
236 - // // 显示是否打开的对话框  
237 - // showDialog(  
238 - // // 设置点击 dialog 外部不取消 dialog,默认能够取消  
239 - // barrierDismissible: false,  
240 - // context: context,  
241 - // builder: (context) => AlertDialog(  
242 - // title: Text('提示'),  
243 - // // 标题文字样式  
244 - // content: Text('文件下载完成,是否打开?'),  
245 - // // 内容文字样式  
246 - // backgroundColor: MyColours.color_ffffff,  
247 - // elevation: 8.0,  
248 - // // 投影的阴影高度  
249 - // semanticLabel: 'Label',  
250 - // // 这个用于无障碍下弹出 dialog 的提示  
251 - // shape: Border.all(),  
252 - // // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`  
253 - // actions: <Widget>[  
254 - // // 点击取消按钮  
255 - // InkWell(  
256 - // onTap: () => Navigator.pop(context), child: Text('取消')),  
257 - // // 点击打开按钮  
258 - // InkWell(  
259 - // onTap: () {  
260 - // Navigator.pop(context);  
261 - // // 打开文件  
262 - // _openDownloadedFile(taskId).then((success) {  
263 - // if (!success) {  
264 - // Utils.showToast('Cannot open this file');  
265 - // // Scaffold.of(context).showSnackBar(SnackBar(  
266 - // // content: Text('Cannot open this file')));  
267 - // }  
268 - // });  
269 - // },  
270 - // child: Text('打开')),  
271 - // ],  
272 - // ));  
273 - // } else if (status == DownloadTaskStatus.failed) {  
274 - // // _retryDownload(task);  
275 - // Utils.showToast('下载异常,请稍后重试');  
276 - // }  
277 - // });  
278 - // }  
279 - // Future<void> _delete() async {  
280 - // final task = await FlutterDownloader.loadTasks();  
281 - // if (task != null) {  
282 - // task.forEach((element) {  
283 - // FlutterDownloader.remove(  
284 - // taskId: element.taskId,  
285 - // shouldDeleteContent: true,  
286 - // );  
287 - // });  
288 - // }  
289 - // }  
290 -  
291 Future<void> _prepareSaveDir() async { 84 Future<void> _prepareSaveDir() async {
292 _localPath = (await _getSavedDir()); 85 _localPath = (await _getSavedDir());
293 final savedDir = Directory(_localPath); 86 final savedDir = Directory(_localPath);
@@ -356,10 +149,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -356,10 +149,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
356 throw StateError('unknown platform'); 149 throw StateError('unknown platform');
357 } 150 }
358 151
359 - // void _unbindBackgroundIsolate() {  
360 - // IsolateNameServer.removePortNameMapping('downloader_send_port');  
361 - // }  
362 -  
363 ///时间选择 152 ///时间选择
364 Widget _select(String title, String hintText, GestureTapCallback onTap) { 153 Widget _select(String title, String hintText, GestureTapCallback onTap) {
365 return InkWell( 154 return InkWell(
@@ -404,17 +193,26 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -404,17 +193,26 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
404 193
405 List<Widget> itemWidget() { 194 List<Widget> itemWidget() {
406 List<Widget> data = []; 195 List<Widget> data = [];
407 - for (var i = 0; i < 10; i++) { 196 + for (var i = 0; i < customerProvider.reportFieldModelData.length; i++) {
  197 + GetReportFieldSunModel getReportFieldSunModel =
  198 + customerProvider.reportFieldModelData[i];
408 data.add( 199 data.add(
409 GestureDetector( 200 GestureDetector(
410 - onTap: () {}, 201 + onTap: () {
  202 + setState(() {
  203 + getReportFieldSunModel.select = !getReportFieldSunModel.select;
  204 + });
  205 + },
411 child: Container( 206 child: Container(
412 height: w(34), 207 height: w(34),
413 padding: 208 padding:
414 EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)), 209 EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
415 - decoration: false 210 + decoration: getReportFieldSunModel.select
416 ? BoxDecoration( 211 ? BoxDecoration(
417 color: MyColours.color_438E93, 212 color: MyColours.color_438E93,
  213 + border: Border.all(
  214 + color: MyColours.color_438E93,
  215 + width: ScreenUtil().setWidth(2)),
418 borderRadius: 216 borderRadius:
419 BorderRadius.circular(ScreenUtil().setWidth(10))) 217 BorderRadius.circular(ScreenUtil().setWidth(10)))
420 : BoxDecoration( 218 : BoxDecoration(
@@ -427,11 +225,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -427,11 +225,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
427 child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ 225 child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
428 Flexible( 226 Flexible(
429 child: Text( 227 child: Text(
430 - '下单时间', 228 + getReportFieldSunModel.name,
431 style: TextStyle( 229 style: TextStyle(
432 fontSize: ScreenUtil().setSp(28), 230 fontSize: ScreenUtil().setSp(28),
433 - color:  
434 - false ? MyColours.color_ffffff : MyColours.color_515151, 231 + color: getReportFieldSunModel.select
  232 + ? MyColours.color_ffffff
  233 + : MyColours.color_515151,
435 ), 234 ),
436 overflow: TextOverflow.ellipsis, 235 overflow: TextOverflow.ellipsis,
437 )), 236 )),
@@ -449,23 +248,70 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -449,23 +248,70 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
449 Stopwatch stopwatch = new Stopwatch()..start(); 248 Stopwatch stopwatch = new Stopwatch()..start();
450 249
451 excelUtil.Excel excel = excelUtil.Excel.createExcel(); 250 excelUtil.Excel excel = excelUtil.Excel.createExcel();
  251 +
  252 + excelUtil.Sheet sh2 = excel['Sheet2'];
  253 +
  254 + //表头
  255 +
  256 + sh2
  257 + .cell(excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: 0))
  258 + .value = '订单数';
  259 + sh2
  260 + .cell(excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: 1))
  261 + .value = '客户经理';
  262 +
  263 + for (int row = 0;
  264 + row < customerProvider.exportInfoSunModel.count.length;
  265 + row++) {
  266 + for (int column = 0; column < 2; column++) {
  267 + Count count = customerProvider.exportInfoSunModel.count[row];
  268 + if (column == 0) {
  269 + sh2
  270 + .cell(excelUtil.CellIndex.indexByColumnRow(
  271 + rowIndex: row + 1, columnIndex: column))
  272 + .value = count.total;
  273 + } else {
  274 + sh2
  275 + .cell(excelUtil.CellIndex.indexByColumnRow(
  276 + rowIndex: row + 1, columnIndex: column))
  277 + .value = count.nickName ?? '';
  278 + }
  279 + }
  280 + }
  281 +
  282 + // excel.delete('Sheet1');
452 excelUtil.Sheet sh = excel['Sheet1']; 283 excelUtil.Sheet sh = excel['Sheet1'];
  284 +
453 //表头 285 //表头
454 - for (int i = 0; i < 8; i++) { 286 + for (int i = 0; i < customerProvider.reportFieldModelData.length; i++) {
  287 + GetReportFieldSunModel getReportFieldSunModel =
  288 + customerProvider.reportFieldModelData[i];
455 sh 289 sh
456 .cell( 290 .cell(
457 excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: i)) 291 excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: i))
458 - .value = 'Column $i'; 292 + .value = getReportFieldSunModel.name;
459 //sh.cell(CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: i)).cellStyle =CellStyle(bold: true); 293 //sh.cell(CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: i)).cellStyle =CellStyle(bold: true);
460 } 294 }
461 - for (int row = 1; row < 9; row++) {  
462 - for (int column = 0; column < 8; column++) { 295 + for (int row = 0;
  296 + row < customerProvider.exportInfoSunModel.list.length;
  297 + row++) {
  298 + for (int column = 0;
  299 + column < customerProvider.reportFieldModelData.length;
  300 + column++) {
  301 + dynamic excelData = customerProvider.exportInfoSunModel.excelData[row];
  302 +
463 sh 303 sh
464 - .cell(excelUtil.CellIndex.indexByColumnRow(  
465 - rowIndex: row, columnIndex: column))  
466 - .value = '$row$column value'; 304 + .cell(excelUtil.CellIndex.indexByColumnRow(
  305 + rowIndex: row + 1, columnIndex: column))
  306 + .value =
  307 + excelData[customerProvider.reportFieldModelData[column].code];
467 } 308 }
468 } 309 }
  310 + // var sheet1rtl = excel['Sheet1'].isRTL;
  311 + // excel['Sheet1'].isRTL = true;
  312 + excel.rename('Sheet1', '订单统计列表');
  313 + excel.rename('Sheet2', '排行榜列表');
  314 +
469 print('Generating executed in ${stopwatch.elapsed}'); 315 print('Generating executed in ${stopwatch.elapsed}');
470 stopwatch.reset(); 316 stopwatch.reset();
471 var fileBytes = excel.encode(); 317 var fileBytes = excel.encode();
@@ -476,12 +322,13 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -476,12 +322,13 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
476 Provider.of<UserModel>(context, listen: false).user.sellername; 322 Provider.of<UserModel>(context, listen: false).user.sellername;
477 String starttime = fromDate.replaceAll('-', ''); 323 String starttime = fromDate.replaceAll('-', '');
478 String endtime = endDate.replaceAll('-', ''); 324 String endtime = endDate.replaceAll('-', '');
  325 + String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
  326 + String filePath = _localPath + fileName;
479 if (fileBytes != null) { 327 if (fileBytes != null) {
480 - File file =  
481 - File(_localPath + "/${sellername}${starttime}至${endtime}预订.xlsx")  
482 - ..createSync(recursive: true)  
483 - ..writeAsBytesSync(fileBytes);  
484 - file.copy('/storage/emulated/0/Download/dongle.xlsx'); 328 + File file = File(filePath)
  329 + ..createSync(recursive: true)
  330 + ..writeAsBytesSync(fileBytes);
  331 + file.copy('/storage/emulated/0/Download${fileName}');
485 Loading.hideLoading(context); 332 Loading.hideLoading(context);
486 DialogUtil.cupertinoAlertDialog(context, 333 DialogUtil.cupertinoAlertDialog(context,
487 title: '提示', 334 title: '提示',
@@ -506,8 +353,7 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -506,8 +353,7 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
506 // print(savePath); 353 // print(savePath);
507 // progress = null; 354 // progress = null;
508 // setState(() {}); 355 // setState(() {});
509 - OpenFile.open(  
510 - _localPath + "/${sellername}${starttime}至${endtime}预订.xlsx"); 356 + OpenFile.open(filePath);
511 // _delete(); 357 // _delete();
512 // } 358 // }
513 }); 359 });
@@ -524,6 +370,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -524,6 +370,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
524 370
525 @override 371 @override
526 Widget build(BuildContext context) { 372 Widget build(BuildContext context) {
  373 +//
  374 + // reportFieldModel
  375 + customerProvider = Provider.of<CustomerProvider>(context, listen: true);
527 return Scaffold( 376 return Scaffold(
528 key: scaffoldKey, 377 key: scaffoldKey,
529 backgroundColor: MyColours.color_f3f3f3, 378 backgroundColor: MyColours.color_f3f3f3,
@@ -674,82 +523,71 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -674,82 +523,71 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
674 Utils.showToast('请选择结束日期'); 523 Utils.showToast('请选择结束日期');
675 return; 524 return;
676 } 525 }
  526 + if (DateUtil.getDateTime(endDate)
  527 + .compareTo(DateUtil.getDateTime(fromDate)) <
  528 + 0) {
  529 + Utils.showToast('结束日期不能早于开始日期!');
  530 + return;
  531 + }
  532 + // }
677 533
678 - bool _permissionReady = await _checkPermission();  
679 - if (_permissionReady) {  
680 - await _prepareSaveDir();  
681 - _download();  
682 - } else {  
683 - String title = Platform.isAndroid ? '存储' : '相册';  
684 -  
685 - //用户选择不在弹出权限提示框  
686 - print('never');  
687 - // Navigator.pop(context);  
688 - DialogUtil.openAlertDialog(context, '未获得${title}权限',  
689 - "请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {  
690 - openSetting();  
691 - Navigator.pop(context, '');  
692 - }); 534 + bool temp = customerProvider.reportFieldModelData
  535 + .any((element) => element.select);
  536 + if (!temp) {
  537 + Utils.showToast('请选择导出字段');
  538 + return;
693 } 539 }
694 540
695 - // _delete();  
696 - // String savePath = _localPath + "/fff.pdf";  
697 - // Directory directory = new Directory(savePath);  
698 - // if (directory.existsSync()) {  
699 - // //删除历史  
700 - // final List<FileSystemEntity> files = directory.listSync();  
701 - // for (FileSystemEntity file in files) {  
702 - // file.deleteSync();  
703 - // }  
704 - // } 541 + String from = fromDate + ' 00:00:00';
  542 + String end = endDate + ' 23:59:59';
  543 + String stime = fromDate == '点击设置开始日期'
  544 + ? ""
  545 + : '${(DateUtil.getDateMsByTimeStr(from) / 1000).floor()}';
  546 + String etime = endDate == '点击设置结束日期'
  547 + ? ''
  548 + : '${(DateUtil.getDateMsByTimeStr(end) / 1000).floor()}';
  549 +
  550 + String fields = '';
  551 + customerProvider.reportFieldModelData.forEach((element) {
  552 + if (element.select) {
  553 + fields += element.code + ',';
  554 + }
  555 + });
  556 + if (fields.endsWith(',')) {
  557 + fields = fields.substring(0, fields.length - 1);
  558 + }
705 559
706 - // try {  
707 - // Response response = await DioUtil().download(  
708 - // 'http://englishonlineclub.com/pdf/iOS%20Programming%20-%20The%20Big%20Nerd%20Ranch%20Guide%20(6th%20Edition)%20[EnglishOnlineClub.com].pdf',  
709 - // savePath, onProgress: (received, total) {  
710 - // if (progress != 100) {  
711 - // progress = ((received / total) * 100).round();  
712 -  
713 - // setState(() {});  
714 - // }  
715 - // if (received == total) {  
716 - // //下载完成  
717 - // print('xaizaiwancheng');  
718 -  
719 - // DialogUtil.cupertinoAlertDialog(context,  
720 - // title: '提示',  
721 - // content: '文件下载完成,是否打开?',  
722 - // lTitle: '取消',  
723 - // rTitle: '打开', lCallback: () {  
724 - // progress = null;  
725 - // setState(() {});  
726 - // }, rCallback: () async {  
727 - // // Navigator.pop(context);  
728 -  
729 - // // print(_localPath);  
730 -  
731 - // // final tasks = await FlutterDownloader.loadTasks();  
732 - // // String str = '';  
733 - // // tasks.forEach((element) {  
734 - // // str = element.savedDir + '/' + element.filename;  
735 - // // });  
736 - // // print(str);  
737 -  
738 - // // if (str != '') {  
739 - // print(savePath);  
740 - // progress = null;  
741 - // setState(() {});  
742 - // OpenFile.open(savePath);  
743 - // // _delete();  
744 - // // }  
745 - // });  
746 - // }  
747 - // });  
748 - // print(response);  
749 - // } catch (e) {  
750 - // print(e);  
751 - // Utils.showToast('下载异常,请稍后重试');  
752 - // } 560 + Map<String, String> pramas = {
  561 + 'sid': Provider.of<UserModel>(context, listen: false)
  562 + .user
  563 + .sellerid,
  564 + 'time': timeType == '到店时间' ? 'ddate' : 'cdate',
  565 + 'rdate': stime,
  566 + 'edate': etime,
  567 + 'fields': fields
  568 + };
  569 + bool success =
  570 + await customerProvider.getExportInfo(context, pramas);
  571 + if (success) {
  572 + //成功
  573 +
  574 + bool _permissionReady = await _checkPermission();
  575 + if (_permissionReady) {
  576 + await _prepareSaveDir();
  577 + _download();
  578 + } else {
  579 + String title = Platform.isAndroid ? '存储' : '相册';
  580 +
  581 + //用户选择不在弹出权限提示框
  582 + print('never');
  583 + // Navigator.pop(context);
  584 + DialogUtil.openAlertDialog(context, '未获得${title}权限',
  585 + "请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {
  586 + openSetting();
  587 + Navigator.pop(context, '');
  588 + });
  589 + }
  590 + }
753 }, 591 },
754 ) 592 )
755 ], 593 ],
@@ -30,6 +30,8 @@ import 'package:one_key/widgets/loading.dart'; @@ -30,6 +30,8 @@ import 'package:one_key/widgets/loading.dart';
30 import 'package:provider/provider.dart'; 30 import 'package:provider/provider.dart';
31 31
32 import '../models/day_statics_model.dart'; 32 import '../models/day_statics_model.dart';
  33 +import '../models/get_export_info_model.dart';
  34 +import '../models/get_report_field_model.dart';
33 import '../models/marketing_sms_template_model.dart'; 35 import '../models/marketing_sms_template_model.dart';
34 import '../models/month_statics_model.dart'; 36 import '../models/month_statics_model.dart';
35 import '../models/seller_counts_list.dart'; 37 import '../models/seller_counts_list.dart';
@@ -125,6 +127,10 @@ class CustomerProvider extends ChangeNotifier { @@ -125,6 +127,10 @@ class CustomerProvider extends ChangeNotifier {
125 127
126 List<MarketingSmsTemplateSunModel> marketingSmsData = []; 128 List<MarketingSmsTemplateSunModel> marketingSmsData = [];
127 129
  130 + List<GetReportFieldSunModel> reportFieldModelData = []; //导出数据字段
  131 +
  132 + GetExportInfoSunModel exportInfoSunModel; //预订导出数据
  133 +
128 /// 获取全店日订单统计数据 134 /// 获取全店日订单统计数据
129 Future<DayStaticsSunModel> getSellerCountsListByDay( 135 Future<DayStaticsSunModel> getSellerCountsListByDay(
130 BuildContext context, Map<String, String> params, 136 BuildContext context, Map<String, String> params,
@@ -802,6 +808,84 @@ class CustomerProvider extends ChangeNotifier { @@ -802,6 +808,84 @@ class CustomerProvider extends ChangeNotifier {
802 notifyListeners(); 808 notifyListeners();
803 } 809 }
804 810
  811 + // 获取App导出数据
  812 + getExportInfo(BuildContext context, Map<String, String> params) async {
  813 + BaseResp<dynamic> baseResp = await DioUtil()
  814 + .request<dynamic>(context, Method.get, HttpUrl.get_export_info,
  815 + data: params, showLoading: false)
  816 + .catchError((error) {
  817 + print(error.toString());
  818 + if (error is MyError) {
  819 + // switch (error.type) {
  820 + // case 1:
  821 + // pageStateGuestInfo = PageState.ConnectivityError;
  822 + // break;
  823 + // case 2:
  824 + // pageStateGuestInfo = PageState.ConnectivityTimeOut;
  825 + // break;
  826 + // default:
  827 + // pageStateGuestInfo = PageState.ConnectivityError;
  828 + // break;
  829 + // }
  830 + }
  831 + notifyListeners();
  832 + return false;
  833 + });
  834 + if (baseResp != null && baseResp.code == Constant.status_success) {
  835 + // pageStateGuestInfo = PageState.Success;
  836 + exportInfoSunModel =
  837 + GetExportInfoModel.fromJson(baseResp.responseData).data;
  838 + notifyListeners();
  839 + return true;
  840 + } else {
  841 + if (baseResp != null) {
  842 + Utils.showToast(baseResp.msg ?? "");
  843 + }
  844 + // pageStateGuestInfo = PageState.ConnectivityTimeOut;
  845 + }
  846 + notifyListeners();
  847 + return false;
  848 + }
  849 +
  850 + // 获取App导出字段
  851 + getReportField(BuildContext context) async {
  852 + BaseResp<dynamic> baseResp = await DioUtil()
  853 + .request<dynamic>(context, Method.get, HttpUrl.get_report_field,
  854 + showLoading: false)
  855 + .catchError((error) {
  856 + print(error.toString());
  857 + if (error is MyError) {
  858 + // switch (error.type) {
  859 + // case 1:
  860 + // pageStateGuestInfo = PageState.ConnectivityError;
  861 + // break;
  862 + // case 2:
  863 + // pageStateGuestInfo = PageState.ConnectivityTimeOut;
  864 + // break;
  865 + // default:
  866 + // pageStateGuestInfo = PageState.ConnectivityError;
  867 + // break;
  868 + // }
  869 + }
  870 + notifyListeners();
  871 + return false;
  872 + });
  873 + if (baseResp != null && baseResp.code == Constant.status_success) {
  874 + // pageStateGuestInfo = PageState.Success;
  875 + reportFieldModelData =
  876 + GetReportFieldModel.fromJson(baseResp.responseData).data;
  877 + notifyListeners();
  878 + return true;
  879 + } else {
  880 + if (baseResp != null) {
  881 + Utils.showToast(baseResp.msg ?? "");
  882 + }
  883 + // pageStateGuestInfo = PageState.ConnectivityTimeOut;
  884 + }
  885 + notifyListeners();
  886 + return false;
  887 + }
  888 +
805 // 获取客户详情 889 // 获取客户详情
806 getGuestInfo(BuildContext context, Map<String, String> params) async { 890 getGuestInfo(BuildContext context, Map<String, String> params) async {
807 BaseResp<dynamic> baseResp = await DioUtil() 891 BaseResp<dynamic> baseResp = await DioUtil()