|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:one_key/models/consume_qrcode_model.dart';
|
|
|
|
import 'package:one_key/provider/finance_provider.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/route/navigator_util.dart';
|
|
|
|
import 'package:one_key/utils/dialog_util.dart';
|
|
|
|
import 'package:one_key/utils/screen_util.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
|
|
import 'package:one_key/widgets/h_empty_view.dart';
|
|
|
|
import 'package:one_key/widgets/round_button.dart';
|
|
|
|
import 'package:one_key/widgets/system_app_bar.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 发放消费金
|
|
...
|
...
|
@@ -21,18 +27,46 @@ class GrantPage extends StatefulWidget { |
|
|
|
|
|
|
|
class _GrantPageState extends State<GrantPage> {
|
|
|
|
ScrollController controller = ScrollController();
|
|
|
|
List ladderSelectFree = [];
|
|
|
|
List<ConsumeQrcodeSunModel> ladderSelectFree = [];
|
|
|
|
FinanceProvider? financeProvider;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
ladderSelectFree.add('1');
|
|
|
|
ConsumeQrcodeSunModel model = ConsumeQrcodeSunModel();
|
|
|
|
ladderSelectFree.add(model);
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
// _getConsumeConfig();
|
|
|
|
_geConsumeQrcode();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_geConsumeQrcode() async {
|
|
|
|
Map<String, String> pramas = {
|
|
|
|
'sellerid':
|
|
|
|
Provider.of<UserModel>(context, listen: false).user!.sellerid!,
|
|
|
|
};
|
|
|
|
await financeProvider!.geConsumeQrcode(context, pramas);
|
|
|
|
if (financeProvider!.consumeQrcodeData != null) {
|
|
|
|
//有数据
|
|
|
|
ladderSelectFree = [];
|
|
|
|
ladderSelectFree.addAll(financeProvider!.consumeQrcodeData!);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_createConsumeQrcode(String amounts) async {
|
|
|
|
Map<String, String> pramas = {
|
|
|
|
'sellerid':
|
|
|
|
Provider.of<UserModel>(context, listen: false).user!.sellerid!,
|
|
|
|
'amount': amounts
|
|
|
|
};
|
|
|
|
bool success = await financeProvider!.createConsumeQrcode(context, pramas);
|
|
|
|
if (success) {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///发放阶梯
|
|
|
|
Widget _ladderWidget() {
|
|
|
|
return ListView.builder(
|
|
...
|
...
|
@@ -40,7 +74,7 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: ladderSelectFree.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
dynamic data = ladderSelectFree[index];
|
|
|
|
ConsumeQrcodeSunModel data = ladderSelectFree[index];
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: w(16),
|
|
...
|
...
|
@@ -67,8 +101,28 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
//删除媒体
|
|
|
|
ladderSelectFree.remove(data);
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
// 确认是否删除
|
|
|
|
|
|
|
|
//弹框确认是否删除
|
|
|
|
DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
title: "",
|
|
|
|
content: "确定要将该发放金删除吗?",
|
|
|
|
rTitle: "确定", rCallback: () async {
|
|
|
|
Map<String, String?> pramas = {
|
|
|
|
'id': data.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool success = await financeProvider!
|
|
|
|
.delConsumeQrcode(context, pramas);
|
|
|
|
if (success) {
|
|
|
|
//删除成功,刷新页面
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
ladderSelectFree.removeAt(index);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(top: w(8), bottom: w(8)),
|
|
...
|
...
|
@@ -82,8 +136,7 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
_ladderPriceWidget(TextEditingController(), FocusNode(),
|
|
|
|
width: 50),
|
|
|
|
_ladderPriceWidget(data, FocusNode(), width: 50),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
...
|
...
|
@@ -91,8 +144,7 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
}
|
|
|
|
|
|
|
|
//阶梯返还金额widget
|
|
|
|
Widget _ladderPriceWidget(
|
|
|
|
TextEditingController controllerGive, FocusNode focusNodeGive,
|
|
|
|
Widget _ladderPriceWidget(ConsumeQrcodeSunModel data, FocusNode focusNodeGive,
|
|
|
|
{num width = 40}) {
|
|
|
|
return Container(
|
|
|
|
height: w(40),
|
|
...
|
...
|
@@ -117,7 +169,7 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(color: MyColours.color_999999, width: w(1))),
|
|
|
|
child: TextField(
|
|
|
|
controller: controllerGive,
|
|
|
|
controller: data.amountC,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
textAlignVertical: TextAlignVertical.center,
|
|
|
|
maxLines: 1,
|
|
...
|
...
|
@@ -161,21 +213,24 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
),
|
|
|
|
HEmptyView(10),
|
|
|
|
Spacer(),
|
|
|
|
RoundButton(
|
|
|
|
text: '查看二维码',
|
|
|
|
width: w(86),
|
|
|
|
height: w(24),
|
|
|
|
fontSize: 28,
|
|
|
|
gradientStart: MyColours.color_438E93,
|
|
|
|
gradientEnd: MyColours.color_438E93,
|
|
|
|
textColor: MyColours.color_ffffff,
|
|
|
|
isBold: false,
|
|
|
|
radius: 5,
|
|
|
|
onPressed: () {
|
|
|
|
//跳转到二维码展示页面
|
|
|
|
NavigatorUtil.goGrantWechatPage(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (data.qrcode != null)
|
|
|
|
RoundButton(
|
|
|
|
text: '查看二维码',
|
|
|
|
width: w(86),
|
|
|
|
height: w(24),
|
|
|
|
fontSize: 28,
|
|
|
|
gradientStart: MyColours.color_438E93,
|
|
|
|
gradientEnd: MyColours.color_438E93,
|
|
|
|
textColor: MyColours.color_ffffff,
|
|
|
|
isBold: false,
|
|
|
|
radius: 5,
|
|
|
|
onPressed: () {
|
|
|
|
//跳转到二维码展示页面
|
|
|
|
// String qrcode = data.qrcode ?? '';
|
|
|
|
// String account = data.amount ?? '';
|
|
|
|
NavigatorUtil.goGrantWechatPage(context, data);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
HEmptyView(32),
|
|
|
|
],
|
|
|
|
),
|
|
...
|
...
|
@@ -184,28 +239,85 @@ class _GrantPageState extends State<GrantPage> { |
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
financeProvider = Provider.of<FinanceProvider>(context, listen: true);
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: MyColours.color_ffffff,
|
|
|
|
appBar: SystemAppBar('发放消费金'),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
_ladderWidget(),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
// LadderData data = LadderData();
|
|
|
|
ladderSelectFree.add('1');
|
|
|
|
setState(() {});
|
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
_ladderWidget(),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
ConsumeQrcodeSunModel model = ConsumeQrcodeSunModel();
|
|
|
|
ladderSelectFree.add(model);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: w(30),
|
|
|
|
margin: EdgeInsets.only(left: w(60), right: w(16)),
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
'+增加阶梯',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_438E93, fontSize: font(12)),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: w(13), left: w(45), right: w(45), bottom: w(26)),
|
|
|
|
child: RoundButton(
|
|
|
|
text: '保存',
|
|
|
|
height: w(43),
|
|
|
|
radius: r(5),
|
|
|
|
gradientStart: MyColours.color_438E93,
|
|
|
|
gradientEnd: MyColours.color_438E93,
|
|
|
|
borderColor: MyColours.color_438E93,
|
|
|
|
textColor: MyColours.color_ffffff,
|
|
|
|
isBold: true,
|
|
|
|
fontSize: 32,
|
|
|
|
onPressed: () {
|
|
|
|
// 调用接口
|
|
|
|
// 组装amount数据
|
|
|
|
|
|
|
|
if (ladderSelectFree.length == 0) {
|
|
|
|
//请点击增加阶梯按钮设置发放消费金金额
|
|
|
|
Utils.showToast('请点击【增加阶梯】按钮设置发放消费金金额');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断阶梯里面的数据 实际支付金额是否输入
|
|
|
|
|
|
|
|
bool canPrice = ladderSelectFree
|
|
|
|
.any((e) => e.amountC.text.trim().length == 0);
|
|
|
|
if (canPrice) {
|
|
|
|
int index = ladderSelectFree
|
|
|
|
.indexWhere((e) => e.amountC.text.trim().length == 0);
|
|
|
|
|
|
|
|
Utils.showToast('请输入发放(${index + 1})的发放消费金金额!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
|
|
|
|
String amounts = '';
|
|
|
|
|
|
|
|
ladderSelectFree.forEach((e) {
|
|
|
|
amounts += (e.amountC.text + ',');
|
|
|
|
});
|
|
|
|
if (amounts.endsWith(',')) {
|
|
|
|
amounts = amounts.substring(0, amounts.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_createConsumeQrcode(amounts);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: w(30),
|
|
|
|
margin: EdgeInsets.only(left: w(60), right: w(16)),
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
'+增加阶梯',
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_438E93, fontSize: font(12)),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
...
|
...
|
|