Files
pj_supermarket_cloud/lib/pages/take_food/view.dart
T
2025-03-12 19:39:18 +08:00

168 lines
5.3 KiB
Dart

import 'package:data_table_2/data_table_2.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:forui/forui.dart';
import 'package:get/get.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
import 'index.dart';
class TakeFoodPage extends GetView<TakeFoodController> {
const TakeFoodPage({super.key});
// 主视图
Widget _buildView(BuildContext context) {
final theme = FTheme.of(context);
final width = context.width;
return <Widget>[
_buildTable(context).expanded(),
SizedBox(width: 15.w),
_buildUserInfo(context).width(width * 0.25).decorated(
border: Border.all(
color: theme.colorScheme.primary,
width: 1,
),
borderRadius: theme.style.borderRadius,
),
]
.toRow(crossAxisAlignment: CrossAxisAlignment.start)
.marginOnly(bottom: 20.h);
}
// 表格
Widget _buildTable(BuildContext context) {
final theme = FTheme.of(context);
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final width = constraints.maxWidth;
final height = constraints.maxHeight;
final hdHeight = (height - 50.h) / 10.5;
final hdWidth = (width - 50.h) / 4.5;
return Obx(
() => DataTable2(
columnSpacing: 12.w,
horizontalMargin: 12.w,
minWidth: hdWidth,
showBottomBorder: true,
headingTextStyle: theme.typography.lg,
dataTextStyle: theme.typography.base,
dataRowHeight: hdHeight,
columns: [
DataColumn2(
label: Text("菜品名称", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
),
DataColumn2(
label: Text("数量", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
),
DataColumn2(
label: Text("单价金额", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
),
DataColumn2(
label: Text("总金额", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
),
],
rows: controller.carList
.map(
(v) => DataRow(
cells: [
DataCell(
Text(
"${v.productName}",
textAlign: TextAlign.center,
).center(),
),
DataCell(
Text(
"${v.productCount}",
textAlign: TextAlign.center,
).center(),
),
DataCell(
appPrice(context, v.productPrice),
),
DataCell(
appPrice(context, v.totalPrice),
),
],
),
)
.toList(),
),
);
},
);
}
// 用户
Widget _buildUserInfo(BuildContext context) {
final theme = FTheme.of(context);
return <Widget>[
Obx(() {
final payUser = controller.payUser.value;
return appUserInfo(
context,
username: payUser?.username,
balance: payUser?.walletBalance,
avatar: payUser?.userAvatar,
);
}).width(400.w).center(),
SizedBox(height: 200.h),
<Widget>[
FButton(
style: FButtonStyle.destructive,
label: Text(
"取消点餐",
style: theme.typography.xl.copyWith(
color: theme.colorScheme.secondary,
),
),
onPress: () => controller.doCancelPay(),
).flexible(flex: 1),
SizedBox(width: 20.w),
FButton(
label: Text(
"确认点餐",
style: theme.typography.xl.copyWith(
color: theme.colorScheme.secondary,
),
),
onPress: () => controller.doPay(),
).flexible(flex: 1),
].toRow(crossAxisAlignment: CrossAxisAlignment.end).expanded(),
].toColumn().padding(vertical: 10.h, horizontal: 10.w);
}
@override
Widget build(BuildContext context) {
final theme = FTheme.of(context);
final height = context.height;
return GetBuilder<TakeFoodController>(
init: TakeFoodController(),
id: "take_food",
builder: (_) {
return FScaffold(
header: FHeader.nested(
title: Text("取餐"),
prefixActions: [
FHeaderAction.back(onPress: Get.back),
],
style: theme.headerStyle.nestedStyle.copyWith(
titleTextStyle: theme.typography.lg,
actionStyle: theme.headerStyle.nestedStyle.actionStyle.copyWith(
size: theme.typography.xl2.fontSize,
),
),
).height(height * 0.1),
content: _buildView(context),
resizeToAvoidBottomInset: false,
);
},
);
}
}