freight_config_page.dart
9.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import 'package:flutter/material.dart';
import 'package:one_poem/res/resources.dart';
import 'package:one_poem/routers/fluro_navigator.dart';
import 'package:one_poem/shop/models/freight_config_model.dart';
import 'package:one_poem/shop/widgets/price_input_dialog.dart';
import 'package:one_poem/shop/widgets/range_price_input_dialog.dart';
import 'package:one_poem/util/theme_utils.dart';
import 'package:one_poem/util/toast_utils.dart';
import 'package:one_poem/widgets/load_image.dart';
import 'package:one_poem/widgets/my_app_bar.dart';
import 'package:one_poem/widgets/my_button.dart';
import 'package:one_poem/widgets/my_card.dart';
/// design/7店铺-店铺配置/index.html
class FreightConfigPage extends StatefulWidget {
const FreightConfigPage({Key? key}) : super(key: key);
@override
_FreightConfigPageState createState() => _FreightConfigPageState();
}
class _FreightConfigPageState extends State<FreightConfigPage> {
final List<FreightConfigModel> _list = [];
@override
void initState() {
super.initState();
_reset();
}
void _reset() {
_list.clear();
_list.add(FreightConfigModel('0', '', 1, false, ''));
_list.add(FreightConfigModel('', '', 1, true, ''));
_list.add(FreightConfigModel('', '-1', 1, false, ''));
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: MyAppBar(
title: '运费比例配置',
actionName: '重置',
onPressed: () {
setState(() {
_reset();
});
},
),
body: SafeArea(
child: Stack(
children: <Widget>[
Positioned(
left: 16.0,
right: 16.0,
bottom: 8.0,
child: MyButton(
onPressed: () {
NavigatorUtils.goBack(context);
},
text: '完成',
),
),
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
bottom: 64.0,
child: ListView.builder(
itemExtent: 114.0,
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
itemBuilder: (_, index) => _buildItem(index),
itemCount: _list.length,
),
),
],
),
),
);
}
// 暂时没有对输入数据进行校验
Widget _buildItem(int index) {
return _list[index].isAdd ?
Semantics(
label: '添加区间',
child: GestureDetector(
onTap: () {
final FreightConfigModel config = _list[index - 1];
if (config.max.isNotEmpty && config.min.isNotEmpty) {
setState(() {
_list.insert(_list.length - 2, FreightConfigModel('', '', 1, false, ''));
});
} else {
Toast.show('请先完善上一个区间金额!');
return;
}
},
child: Container(
key: const Key('add'),
margin: const EdgeInsets.only(bottom: 8.0),
padding: const EdgeInsets.symmetric(vertical: 32.0),
decoration: BoxDecoration(
color: context.isDark ? Colours.dark_bg_gray : Colours.bg_gray,
borderRadius: BorderRadius.circular(8.0),
),
child: const LoadAssetImage('shop/tj',),
),
),
) :
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: MyCard(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(index == 0 ? '订单金额小于' : (index == _list.length - 1 ? '订单金额不小于' : '订单金额区间')),
Expanded(
child: Semantics(
label: '填写订单金额',
child: InkWell(
onTap: () {
if (index == 0 || index == _list.length - 1) {
_showOrderPriceInputDialog(index);
} else {
_showRangePriceInputDialog(index);
}
},
child: Text(
_getPriceText(index).isEmpty ? '订单金额' : _getPriceText(index),
key: Key('订单金额$index'),
textAlign: TextAlign.end,
style: _getPriceText(index).isEmpty ? Theme.of(context).textTheme.subtitle2?.copyWith(fontSize: Dimens.font_sp14) : null,
),
),
)),
Gaps.hGap5,
const Text('元'),
],
),
Gaps.vGap15,
Gaps.line,
Gaps.vGap15,
Row(
children: <Widget>[
Semantics(
label: '选择比率',
child: InkWell(
onTap: () {
setState(() {
_list[index].type = 1;
});
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
LoadAssetImage(_list[index].type == 1 ? 'shop/xzyf' : 'shop/wxzyf', width: 16.0,),
Gaps.hGap4,
const Text('比率'),
],
),
),
),
Gaps.hGap16,
Semantics(
label: '选择金额',
child: InkWell(
onTap: () {
setState(() {
_list[index].type = 0;
});
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
LoadAssetImage(_list[index].type == 0 ? 'shop/xzyf' : 'shop/wxzyf', width: 16.0),
Gaps.hGap4,
const Text('金额'),
],
),
),
),
Expanded(
child: Semantics(
label: '填写${_list[index].type == 1 ? '运费比率' : '运费金额'}',
child: InkWell(
onTap: () => _showFreightInputDialog(index),
child: Text(
_list[index].price.isEmpty ? (_list[index].type == 1 ? '运费比率' : '运费金额'): _list[index].price,
textAlign: TextAlign.end,
style: _list[index].price.isEmpty ? Theme.of(context).textTheme.subtitle2?.copyWith(fontSize: Dimens.font_sp14) : null,
),
),
)),
Gaps.hGap5,
Text(_list[index].type == 1 ? '%' : '元'),
],
)
],
),
),
),
);
}
void _showOrderPriceInputDialog(int index) {
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return PriceInputDialog(
title: '订单金额',
onPressed: (value) {
setState(() {
if (index == 0) {
_list[index].max = value;
} else {
_list[index].min = value;
}
});
},
);
}
);
}
void _showRangePriceInputDialog(int index) {
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return RangePriceInputDialog(
title: '订单金额',
onPressed: (min, max) {
setState(() {
_list[index].min = min;
_list[index].max = max;
});
},
);
}
);
}
void _showFreightInputDialog(int index) {
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return PriceInputDialog(
title: _list[index].type == 1 ? '运费比率' : '运费金额',
inputMaxPrice: _list[index].type == 1 ? 100 : 100000,
onPressed: (value) {
setState(() {
_list[index].price = value;
});
},
);
}
);
}
String _getPriceText(int index) {
if (index == 0) {
if (_list[index].max.isEmpty) {
return '';
} else {
return _list[index].max;
}
} else if (index == _list.length - 1) {
if (_list[index].min.isEmpty) {
return '';
} else {
return _list[index].min;
}
} else {
if (_list[index].min.isEmpty || _list[index].max.isEmpty) {
return '';
} else {
return '${_list[index].min}~${_list[index].max}';
}
}
}
}