table_item.dart
8.01 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
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/notebook.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/models/table.dart' as t;
import 'package:one_key/widgets/v_empty_view.dart';
class TableItem extends StatefulWidget {
final t.Table table;
final bool canSelected; //是否能选中
final ValueChanged onSelected;
final bool canChoose; //从变更页面进来 = true
final String rid;
final Map<String, Notebook> tableMap; //记录已预订桌位对应的订单
final int height; //高度
TableItem(this.table,
{this.onSelected,
this.canSelected = false,
this.height = 183,
this.canChoose = false,
this.rid,
this.tableMap});
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new TableItemState();
}
}
class TableItemState extends State<TableItem> {
@override
Widget build(BuildContext context) {
t.Table table = widget.table;
return GestureDetector(
onTap: () {
if (widget.canSelected && widget.canChoose) {
//从变更页面进来 canChoose = true
if (widget.canSelected && table.signStr.isEmpty) {
setState(() {
table.selected = !(table.selected ?? false);
});
widget.onSelected(table);
} else {
if (table.sign == '5' || table.sign == '1') {
// 1一般是商户端
// 5是用户端
//已预订状态 不是自己的不可以选择,是自己的可以选择
//当前桌子的预订id
String idNow = '';
if (widget.tableMap.containsKey('${table.id}')) {
//包含,证明该桌子已经被预订了
idNow = widget.tableMap['${table.id}'].id;
if (idNow == widget.rid) {
setState(() {
table.selected = !(table.selected ?? false);
});
widget.onSelected(table);
}
}
}
}
} else {
//从安排桌位进来
if (widget.canSelected && table.signStr.isEmpty) {
setState(() {
table.selected = !(table.selected ?? false);
});
widget.onSelected(table);
}
}
},
child: Stack(
children: <Widget>[
Container(
width: ScreenUtil().setWidth(150),
height: ScreenUtil().setWidth(widget.height),
margin: EdgeInsets.all(ScreenUtil().setWidth(9)),
decoration: BoxDecoration(
color: MyColours.color_a8e2e4,
borderRadius: BorderRadius.all(
Radius.circular(ScreenUtil().setWidth(8)))),
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
left: 0,
top: 0,
child: table.tidStr == null
? Container()
: Container(
width: ScreenUtil().setWidth(70),
height: ScreenUtil().setHeight(32),
alignment: Alignment.center,
decoration: BoxDecoration(
color: MyColours.color_63a6d1,
borderRadius: BorderRadius.only(
topLeft:
Radius.circular(ScreenUtil().setWidth(8)),
topRight:
Radius.circular(ScreenUtil().setWidth(8)),
bottomRight: Radius.circular(
ScreenUtil().setWidth(8)))),
child: Text(table.tidStr,
style: TextStyle(
color: MyColours.color_ffffff,
fontSize: ScreenUtil().setSp(24),
decoration: TextDecoration.none,
fontWeight: FontWeight.normal)),
),
),
Container(
alignment: Alignment.centerLeft,
margin: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
VEmptyView(20),
Text(
table.name,
style: TextStyle(
color: MyColours.color_131313,
fontSize: ScreenUtil().setSp(30),
decoration: TextDecoration.none,
fontWeight: FontWeight.normal),
overflow: TextOverflow.ellipsis,
),
VEmptyView(5),
Text(
(table.reserver == null || table.reserver.isEmpty)
? table.tableNum
: table.reserver,
style: TextStyle(
color: (table.reserver == null ||
table.reserver.isEmpty)
? MyColours.color_777777
: MyColours.color_2bb5b7,
fontSize: ScreenUtil().setSp(26),
decoration: TextDecoration.none,
fontWeight: FontWeight.normal),
overflow: TextOverflow.ellipsis,
),
VEmptyView(5),
Text(
table.lowStr,
style: TextStyle(
color: MyColours.color_777777,
fontSize: ScreenUtil().setSp(26),
decoration: TextDecoration.none,
fontWeight: FontWeight.normal),
overflow: TextOverflow.ellipsis,
)
],
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: table.signStr.isEmpty
? Container()
: Container(
width: ScreenUtil().setWidth(150),
height: ScreenUtil().setHeight(40),
alignment: Alignment.center,
decoration: BoxDecoration(
color: MyColours.color_89c0b7,
borderRadius: BorderRadius.only(
bottomLeft:
Radius.circular(ScreenUtil().setWidth(8)),
bottomRight: Radius.circular(
ScreenUtil().setWidth(8)))),
child: Text(
table.signStr,
style: TextStyle(
color: MyColours.color_ffffff,
fontSize: ScreenUtil().setSp(24),
decoration: TextDecoration.none,
fontWeight: FontWeight.normal),
),
),
),
],
),
),
Positioned(
top: 3,
right: 5,
child: !(table.selected ?? false)
? Container()
: Image.asset(
"assets/icon_selected.png",
width: ScreenUtil().setWidth(40),
height: ScreenUtil().setWidth(40),
))
],
),
);
}
}