|
...
|
...
|
@@ -8,6 +8,8 @@ import 'package:dio/dio.dart'; |
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_picker/Picker.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:one_key/models/get_export_info_model.dart';
|
|
|
|
import 'package:one_key/models/get_report_field_model.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/widgets/round_button.dart';
|
|
...
|
...
|
@@ -19,6 +21,7 @@ import 'package:provider/provider.dart'; |
|
|
|
|
|
|
|
import '../../../../app.dart';
|
|
|
|
import '../../../../net/dio_util.dart';
|
|
|
|
import '../../../../provider/customer_provider.dart';
|
|
|
|
import '../../../../utils/dialog_util.dart';
|
|
|
|
import '../../../../utils/screen_util.dart';
|
|
|
|
import '../../../../utils/utils.dart';
|
|
...
|
...
|
@@ -56,238 +59,28 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
// DownloadTaskStatus status;
|
|
|
|
int progress;
|
|
|
|
|
|
|
|
CustomerProvider customerProvider;
|
|
|
|
|
|
|
|
// List<Map<String, String>> fieldData = {};
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
// IsolateNameServer.registerPortWithName(
|
|
|
|
// _port.sendPort, 'downloader_send_port');
|
|
|
|
// _port.listen((dynamic data) {
|
|
|
|
// taskId = data[0];
|
|
|
|
// status = DownloadTaskStatus(data[1]);
|
|
|
|
// progress = data[2];
|
|
|
|
// setState(() {});
|
|
|
|
// if (status == DownloadTaskStatus.undefined) {
|
|
|
|
// // _requestDownload(task);
|
|
|
|
// } else if (status == DownloadTaskStatus.running) {
|
|
|
|
// // _pauseDownload(task);
|
|
|
|
// // setState(() {});
|
|
|
|
// } else if (status == DownloadTaskStatus.paused) {
|
|
|
|
// // _resumeDownload(task);
|
|
|
|
// // setState(() {});
|
|
|
|
// } else if (status == DownloadTaskStatus.complete ||
|
|
|
|
// status == DownloadTaskStatus.canceled) {
|
|
|
|
// // _delete(task);
|
|
|
|
|
|
|
|
// // 显示是否打开的对话框
|
|
|
|
|
|
|
|
// DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
// title: '提示',
|
|
|
|
// content: '文件下载完成,是否打开?',
|
|
|
|
// lTitle: '取消',
|
|
|
|
// rTitle: '打开', lCallback: () {
|
|
|
|
// Navigator.pop(context);
|
|
|
|
// }, rCallback: () async {
|
|
|
|
// // Navigator.pop(context);
|
|
|
|
|
|
|
|
// print(_localPath);
|
|
|
|
|
|
|
|
// final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
// String str = '';
|
|
|
|
// tasks.forEach((element) {
|
|
|
|
// str = element.savedDir + '/' + element.filename;
|
|
|
|
// });
|
|
|
|
// print(str);
|
|
|
|
|
|
|
|
// if (str != '') {
|
|
|
|
// OpenFile.open(str);
|
|
|
|
// _delete();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// // showDialog(
|
|
|
|
// // // 设置点击 dialog 外部不取消 dialog,默认能够取消
|
|
|
|
// // barrierDismissible: false,
|
|
|
|
// // context: context,
|
|
|
|
// // builder: (context) => AlertDialog(
|
|
|
|
// // title: Text('提示'),
|
|
|
|
// // // 标题文字样式
|
|
|
|
// // content: Text('文件下载完成,是否打开?'),
|
|
|
|
// // // 内容文字样式
|
|
|
|
// // backgroundColor: MyColours.color_ffffff,
|
|
|
|
// // elevation: 8.0,
|
|
|
|
// // // 投影的阴影高度
|
|
|
|
// // semanticLabel: 'Label',
|
|
|
|
// // // 这个用于无障碍下弹出 dialog 的提示
|
|
|
|
// // shape: Border.all(),
|
|
|
|
// // // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`
|
|
|
|
// // actions: <Widget>[
|
|
|
|
// // // 点击取消按钮
|
|
|
|
// // InkWell(
|
|
|
|
// // onTap: () => Navigator.pop(context), child: Text('取消')),
|
|
|
|
// // // 点击打开按钮
|
|
|
|
// // InkWell(
|
|
|
|
// // onTap: () async {
|
|
|
|
// // Navigator.pop(context);
|
|
|
|
|
|
|
|
// // print(_localPath);
|
|
|
|
|
|
|
|
// // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
// // String str = '';
|
|
|
|
// // tasks.forEach((element) {
|
|
|
|
// // str = element.savedDir + '/' + element.filename;
|
|
|
|
// // });
|
|
|
|
// // print(str);
|
|
|
|
// // if (str != '') {
|
|
|
|
// // OpenFile.open(str);
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // // 打开文件
|
|
|
|
// // // _openDownloadedFile(taskId).then((success) {
|
|
|
|
// // // if (!success) {
|
|
|
|
// // // Utils.showToast('Cannot open this file');
|
|
|
|
// // // // Scaffold.of(context).showSnackBar(SnackBar(
|
|
|
|
// // // // content: Text('Cannot open this file')));
|
|
|
|
// // // }
|
|
|
|
// // // });
|
|
|
|
// // },
|
|
|
|
// // child: Text('打开')),
|
|
|
|
// // ],
|
|
|
|
// // ));
|
|
|
|
// } else if (status == DownloadTaskStatus.failed) {
|
|
|
|
// // _retryDownload(task);
|
|
|
|
// Utils.showToast('下载异常,请稍后重试');
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
// FlutterDownloader.registerCallback(downloadCallback);
|
|
|
|
|
|
|
|
// // _bindBackgroundIsolate();
|
|
|
|
|
|
|
|
// // FlutterDownloader.registerCallback(downloadCallback, step: 1);
|
|
|
|
// _delete();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
_getReportField();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// _preae() async {
|
|
|
|
// final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
|
|
|
|
// if (tasks == null) {
|
|
|
|
// print('No tasks were retrieved from the database.');
|
|
|
|
// return;
|
|
|
|
// } else {
|
|
|
|
// tasks.forEach((element) {
|
|
|
|
// FlutterDownloader.remove(
|
|
|
|
// taskId: element.taskId, shouldDeleteContent: false);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
// _unbindBackgroundIsolate();
|
|
|
|
super.dispose();
|
|
|
|
_getReportField() async {
|
|
|
|
bool success = await customerProvider.getReportField(context);
|
|
|
|
// if (success) {
|
|
|
|
// customerProvider.reportFieldModelData.forEach((element) {
|
|
|
|
// fieldData[element.code] = element.name;
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
// @pragma('vm:entry-point')
|
|
|
|
// static void downloadCallback(
|
|
|
|
// String id,
|
|
|
|
// int status,
|
|
|
|
// int progress,
|
|
|
|
// ) {
|
|
|
|
// final SendPort send =
|
|
|
|
// IsolateNameServer.lookupPortByName('downloader_send_port');
|
|
|
|
// send.send([id, status, progress]);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 根据taskId打开下载文件
|
|
|
|
// Future<bool> _openDownloadedFile(taskId) {
|
|
|
|
// return FlutterDownloader.open(taskId: taskId);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void _bindBackgroundIsolate() {
|
|
|
|
// final isSuccess = IsolateNameServer.registerPortWithName(
|
|
|
|
// _port.sendPort,
|
|
|
|
// 'downloader_send_port',
|
|
|
|
// );
|
|
|
|
// if (!isSuccess) {
|
|
|
|
// _unbindBackgroundIsolate();
|
|
|
|
// _bindBackgroundIsolate();
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// _port.listen((dynamic data) {
|
|
|
|
// taskId = (data as List<dynamic>)[0] as String;
|
|
|
|
// status = DownloadTaskStatus(data[1] as int);
|
|
|
|
// progressT = data[2] as int;
|
|
|
|
|
|
|
|
// print(
|
|
|
|
// 'Callback on UI isolate: '
|
|
|
|
// 'task ($taskId) is in status ($status) and process ($progressT)',
|
|
|
|
// );
|
|
|
|
// if (status == DownloadTaskStatus.undefined) {
|
|
|
|
// // _requestDownload(task);
|
|
|
|
// } else if (status == DownloadTaskStatus.running) {
|
|
|
|
// // _pauseDownload(task);
|
|
|
|
// setState(() {});
|
|
|
|
// } else if (status == DownloadTaskStatus.paused) {
|
|
|
|
// // _resumeDownload(task);
|
|
|
|
// setState(() {});
|
|
|
|
// } else if (status == DownloadTaskStatus.complete ||
|
|
|
|
// status == DownloadTaskStatus.canceled) {
|
|
|
|
// // _delete(task);
|
|
|
|
// // 显示是否打开的对话框
|
|
|
|
// showDialog(
|
|
|
|
// // 设置点击 dialog 外部不取消 dialog,默认能够取消
|
|
|
|
// barrierDismissible: false,
|
|
|
|
// context: context,
|
|
|
|
// builder: (context) => AlertDialog(
|
|
|
|
// title: Text('提示'),
|
|
|
|
// // 标题文字样式
|
|
|
|
// content: Text('文件下载完成,是否打开?'),
|
|
|
|
// // 内容文字样式
|
|
|
|
// backgroundColor: MyColours.color_ffffff,
|
|
|
|
// elevation: 8.0,
|
|
|
|
// // 投影的阴影高度
|
|
|
|
// semanticLabel: 'Label',
|
|
|
|
// // 这个用于无障碍下弹出 dialog 的提示
|
|
|
|
// shape: Border.all(),
|
|
|
|
// // dialog 的操作按钮,actions 的个数尽量控制不要过多,否则会溢出 `Overflow`
|
|
|
|
// actions: <Widget>[
|
|
|
|
// // 点击取消按钮
|
|
|
|
// InkWell(
|
|
|
|
// onTap: () => Navigator.pop(context), child: Text('取消')),
|
|
|
|
// // 点击打开按钮
|
|
|
|
// InkWell(
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pop(context);
|
|
|
|
// // 打开文件
|
|
|
|
// _openDownloadedFile(taskId).then((success) {
|
|
|
|
// if (!success) {
|
|
|
|
// Utils.showToast('Cannot open this file');
|
|
|
|
// // Scaffold.of(context).showSnackBar(SnackBar(
|
|
|
|
// // content: Text('Cannot open this file')));
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// child: Text('打开')),
|
|
|
|
// ],
|
|
|
|
// ));
|
|
|
|
// } else if (status == DownloadTaskStatus.failed) {
|
|
|
|
// // _retryDownload(task);
|
|
|
|
// Utils.showToast('下载异常,请稍后重试');
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// Future<void> _delete() async {
|
|
|
|
// final task = await FlutterDownloader.loadTasks();
|
|
|
|
// if (task != null) {
|
|
|
|
// task.forEach((element) {
|
|
|
|
// FlutterDownloader.remove(
|
|
|
|
// taskId: element.taskId,
|
|
|
|
// shouldDeleteContent: true,
|
|
|
|
// );
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
Future<void> _prepareSaveDir() async {
|
|
|
|
_localPath = (await _getSavedDir());
|
|
|
|
final savedDir = Directory(_localPath);
|
|
...
|
...
|
@@ -356,10 +149,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
throw StateError('unknown platform');
|
|
|
|
}
|
|
|
|
|
|
|
|
// void _unbindBackgroundIsolate() {
|
|
|
|
// IsolateNameServer.removePortNameMapping('downloader_send_port');
|
|
|
|
// }
|
|
|
|
|
|
|
|
///时间选择
|
|
|
|
Widget _select(String title, String hintText, GestureTapCallback onTap) {
|
|
|
|
return InkWell(
|
|
...
|
...
|
@@ -404,17 +193,26 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
|
|
|
|
List<Widget> itemWidget() {
|
|
|
|
List<Widget> data = [];
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
for (var i = 0; i < customerProvider.reportFieldModelData.length; i++) {
|
|
|
|
GetReportFieldSunModel getReportFieldSunModel =
|
|
|
|
customerProvider.reportFieldModelData[i];
|
|
|
|
data.add(
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {},
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
getReportFieldSunModel.select = !getReportFieldSunModel.select;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: w(34),
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
|
|
|
|
decoration: false
|
|
|
|
decoration: getReportFieldSunModel.select
|
|
|
|
? BoxDecoration(
|
|
|
|
color: MyColours.color_438E93,
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_438E93,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(ScreenUtil().setWidth(10)))
|
|
|
|
: BoxDecoration(
|
|
...
|
...
|
@@ -427,11 +225,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
'下单时间',
|
|
|
|
getReportFieldSunModel.name,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(28),
|
|
|
|
color:
|
|
|
|
false ? MyColours.color_ffffff : MyColours.color_515151,
|
|
|
|
color: getReportFieldSunModel.select
|
|
|
|
? MyColours.color_ffffff
|
|
|
|
: MyColours.color_515151,
|
|
|
|
),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
)),
|
|
...
|
...
|
@@ -449,23 +248,70 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
Stopwatch stopwatch = new Stopwatch()..start();
|
|
|
|
|
|
|
|
excelUtil.Excel excel = excelUtil.Excel.createExcel();
|
|
|
|
|
|
|
|
excelUtil.Sheet sh2 = excel['Sheet2'];
|
|
|
|
|
|
|
|
//表头
|
|
|
|
|
|
|
|
sh2
|
|
|
|
.cell(excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: 0))
|
|
|
|
.value = '订单数';
|
|
|
|
sh2
|
|
|
|
.cell(excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: 1))
|
|
|
|
.value = '客户经理';
|
|
|
|
|
|
|
|
for (int row = 0;
|
|
|
|
row < customerProvider.exportInfoSunModel.count.length;
|
|
|
|
row++) {
|
|
|
|
for (int column = 0; column < 2; column++) {
|
|
|
|
Count count = customerProvider.exportInfoSunModel.count[row];
|
|
|
|
if (column == 0) {
|
|
|
|
sh2
|
|
|
|
.cell(excelUtil.CellIndex.indexByColumnRow(
|
|
|
|
rowIndex: row + 1, columnIndex: column))
|
|
|
|
.value = count.total;
|
|
|
|
} else {
|
|
|
|
sh2
|
|
|
|
.cell(excelUtil.CellIndex.indexByColumnRow(
|
|
|
|
rowIndex: row + 1, columnIndex: column))
|
|
|
|
.value = count.nickName ?? '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// excel.delete('Sheet1');
|
|
|
|
excelUtil.Sheet sh = excel['Sheet1'];
|
|
|
|
|
|
|
|
//表头
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
for (int i = 0; i < customerProvider.reportFieldModelData.length; i++) {
|
|
|
|
GetReportFieldSunModel getReportFieldSunModel =
|
|
|
|
customerProvider.reportFieldModelData[i];
|
|
|
|
sh
|
|
|
|
.cell(
|
|
|
|
excelUtil.CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: i))
|
|
|
|
.value = 'Column $i';
|
|
|
|
.value = getReportFieldSunModel.name;
|
|
|
|
//sh.cell(CellIndex.indexByColumnRow(rowIndex: 0, columnIndex: i)).cellStyle =CellStyle(bold: true);
|
|
|
|
}
|
|
|
|
for (int row = 1; row < 9; row++) {
|
|
|
|
for (int column = 0; column < 8; column++) {
|
|
|
|
for (int row = 0;
|
|
|
|
row < customerProvider.exportInfoSunModel.list.length;
|
|
|
|
row++) {
|
|
|
|
for (int column = 0;
|
|
|
|
column < customerProvider.reportFieldModelData.length;
|
|
|
|
column++) {
|
|
|
|
dynamic excelData = customerProvider.exportInfoSunModel.excelData[row];
|
|
|
|
|
|
|
|
sh
|
|
|
|
.cell(excelUtil.CellIndex.indexByColumnRow(
|
|
|
|
rowIndex: row, columnIndex: column))
|
|
|
|
.value = '$row$column value';
|
|
|
|
.cell(excelUtil.CellIndex.indexByColumnRow(
|
|
|
|
rowIndex: row + 1, columnIndex: column))
|
|
|
|
.value =
|
|
|
|
excelData[customerProvider.reportFieldModelData[column].code];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// var sheet1rtl = excel['Sheet1'].isRTL;
|
|
|
|
// excel['Sheet1'].isRTL = true;
|
|
|
|
excel.rename('Sheet1', '订单统计列表');
|
|
|
|
excel.rename('Sheet2', '排行榜列表');
|
|
|
|
|
|
|
|
print('Generating executed in ${stopwatch.elapsed}');
|
|
|
|
stopwatch.reset();
|
|
|
|
var fileBytes = excel.encode();
|
|
...
|
...
|
@@ -476,12 +322,13 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
Provider.of<UserModel>(context, listen: false).user.sellername;
|
|
|
|
String starttime = fromDate.replaceAll('-', '');
|
|
|
|
String endtime = endDate.replaceAll('-', '');
|
|
|
|
String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
|
|
|
|
String filePath = _localPath + fileName;
|
|
|
|
if (fileBytes != null) {
|
|
|
|
File file =
|
|
|
|
File(_localPath + "/${sellername}${starttime}至${endtime}预订.xlsx")
|
|
|
|
..createSync(recursive: true)
|
|
|
|
..writeAsBytesSync(fileBytes);
|
|
|
|
file.copy('/storage/emulated/0/Download/dongle.xlsx');
|
|
|
|
File file = File(filePath)
|
|
|
|
..createSync(recursive: true)
|
|
|
|
..writeAsBytesSync(fileBytes);
|
|
|
|
file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
Loading.hideLoading(context);
|
|
|
|
DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
title: '提示',
|
|
...
|
...
|
@@ -506,8 +353,7 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
// print(savePath);
|
|
|
|
// progress = null;
|
|
|
|
// setState(() {});
|
|
|
|
OpenFile.open(
|
|
|
|
_localPath + "/${sellername}${starttime}至${endtime}预订.xlsx");
|
|
|
|
OpenFile.open(filePath);
|
|
|
|
// _delete();
|
|
|
|
// }
|
|
|
|
});
|
|
...
|
...
|
@@ -524,6 +370,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
//
|
|
|
|
// reportFieldModel
|
|
|
|
customerProvider = Provider.of<CustomerProvider>(context, listen: true);
|
|
|
|
return Scaffold(
|
|
|
|
key: scaffoldKey,
|
|
|
|
backgroundColor: MyColours.color_f3f3f3,
|
|
...
|
...
|
@@ -674,82 +523,71 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
Utils.showToast('请选择结束日期');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (DateUtil.getDateTime(endDate)
|
|
|
|
.compareTo(DateUtil.getDateTime(fromDate)) <
|
|
|
|
0) {
|
|
|
|
Utils.showToast('结束日期不能早于开始日期!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
bool _permissionReady = await _checkPermission();
|
|
|
|
if (_permissionReady) {
|
|
|
|
await _prepareSaveDir();
|
|
|
|
_download();
|
|
|
|
} else {
|
|
|
|
String title = Platform.isAndroid ? '存储' : '相册';
|
|
|
|
|
|
|
|
//用户选择不在弹出权限提示框
|
|
|
|
print('never');
|
|
|
|
// Navigator.pop(context);
|
|
|
|
DialogUtil.openAlertDialog(context, '未获得${title}权限',
|
|
|
|
"请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {
|
|
|
|
openSetting();
|
|
|
|
Navigator.pop(context, '');
|
|
|
|
});
|
|
|
|
bool temp = customerProvider.reportFieldModelData
|
|
|
|
.any((element) => element.select);
|
|
|
|
if (!temp) {
|
|
|
|
Utils.showToast('请选择导出字段');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// _delete();
|
|
|
|
// String savePath = _localPath + "/fff.pdf";
|
|
|
|
// Directory directory = new Directory(savePath);
|
|
|
|
// if (directory.existsSync()) {
|
|
|
|
// //删除历史
|
|
|
|
// final List<FileSystemEntity> files = directory.listSync();
|
|
|
|
// for (FileSystemEntity file in files) {
|
|
|
|
// file.deleteSync();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
String from = fromDate + ' 00:00:00';
|
|
|
|
String end = endDate + ' 23:59:59';
|
|
|
|
String stime = fromDate == '点击设置开始日期'
|
|
|
|
? ""
|
|
|
|
: '${(DateUtil.getDateMsByTimeStr(from) / 1000).floor()}';
|
|
|
|
String etime = endDate == '点击设置结束日期'
|
|
|
|
? ''
|
|
|
|
: '${(DateUtil.getDateMsByTimeStr(end) / 1000).floor()}';
|
|
|
|
|
|
|
|
String fields = '';
|
|
|
|
customerProvider.reportFieldModelData.forEach((element) {
|
|
|
|
if (element.select) {
|
|
|
|
fields += element.code + ',';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (fields.endsWith(',')) {
|
|
|
|
fields = fields.substring(0, fields.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try {
|
|
|
|
// Response response = await DioUtil().download(
|
|
|
|
// 'http://englishonlineclub.com/pdf/iOS%20Programming%20-%20The%20Big%20Nerd%20Ranch%20Guide%20(6th%20Edition)%20[EnglishOnlineClub.com].pdf',
|
|
|
|
// savePath, onProgress: (received, total) {
|
|
|
|
// if (progress != 100) {
|
|
|
|
// progress = ((received / total) * 100).round();
|
|
|
|
|
|
|
|
// setState(() {});
|
|
|
|
// }
|
|
|
|
// if (received == total) {
|
|
|
|
// //下载完成
|
|
|
|
// print('xaizaiwancheng');
|
|
|
|
|
|
|
|
// DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
// title: '提示',
|
|
|
|
// content: '文件下载完成,是否打开?',
|
|
|
|
// lTitle: '取消',
|
|
|
|
// rTitle: '打开', lCallback: () {
|
|
|
|
// progress = null;
|
|
|
|
// setState(() {});
|
|
|
|
// }, rCallback: () async {
|
|
|
|
// // Navigator.pop(context);
|
|
|
|
|
|
|
|
// // print(_localPath);
|
|
|
|
|
|
|
|
// // final tasks = await FlutterDownloader.loadTasks();
|
|
|
|
// // String str = '';
|
|
|
|
// // tasks.forEach((element) {
|
|
|
|
// // str = element.savedDir + '/' + element.filename;
|
|
|
|
// // });
|
|
|
|
// // print(str);
|
|
|
|
|
|
|
|
// // if (str != '') {
|
|
|
|
// print(savePath);
|
|
|
|
// progress = null;
|
|
|
|
// setState(() {});
|
|
|
|
// OpenFile.open(savePath);
|
|
|
|
// // _delete();
|
|
|
|
// // }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// print(response);
|
|
|
|
// } catch (e) {
|
|
|
|
// print(e);
|
|
|
|
// Utils.showToast('下载异常,请稍后重试');
|
|
|
|
// }
|
|
|
|
Map<String, String> pramas = {
|
|
|
|
'sid': Provider.of<UserModel>(context, listen: false)
|
|
|
|
.user
|
|
|
|
.sellerid,
|
|
|
|
'time': timeType == '到店时间' ? 'ddate' : 'cdate',
|
|
|
|
'rdate': stime,
|
|
|
|
'edate': etime,
|
|
|
|
'fields': fields
|
|
|
|
};
|
|
|
|
bool success =
|
|
|
|
await customerProvider.getExportInfo(context, pramas);
|
|
|
|
if (success) {
|
|
|
|
//成功
|
|
|
|
|
|
|
|
bool _permissionReady = await _checkPermission();
|
|
|
|
if (_permissionReady) {
|
|
|
|
await _prepareSaveDir();
|
|
|
|
_download();
|
|
|
|
} else {
|
|
|
|
String title = Platform.isAndroid ? '存储' : '相册';
|
|
|
|
|
|
|
|
//用户选择不在弹出权限提示框
|
|
|
|
print('never');
|
|
|
|
// Navigator.pop(context);
|
|
|
|
DialogUtil.openAlertDialog(context, '未获得${title}权限',
|
|
|
|
"请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {
|
|
|
|
openSetting();
|
|
|
|
Navigator.pop(context, '');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
...
|
...
|
|