mobile_skt/lib/screens/sale_quotation/sale_quotation.dart

387 lines
15 KiB
Dart
Raw Normal View History

2024-04-01 14:27:44 +08:00
import 'package:collection/collection.dart';
2024-04-01 17:35:34 +08:00
import 'package:date_format/date_format.dart';
2024-04-01 08:41:52 +08:00
import 'package:flutter/material.dart';
2024-04-01 14:27:44 +08:00
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
2024-04-01 17:35:34 +08:00
import 'package:sk_base_mobile/models/sale_quotation.model.dart';
import 'package:sk_base_mobile/screens/sale_quotation/sale_quotation.controller.dart';
import 'package:sk_base_mobile/util/modal.util.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
2024-04-01 17:35:34 +08:00
import 'package:sk_base_mobile/widgets/core/sk_number_input.dart';
import 'package:sk_base_mobile/widgets/core/sk_text_input.dart';
2024-04-02 12:24:08 +08:00
import 'package:sk_base_mobile/widgets/empty.dart';
2024-04-01 08:41:52 +08:00
import 'package:sk_base_mobile/widgets/sk_appbar.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
2024-04-01 08:41:52 +08:00
class SaleQuotationPage extends StatelessWidget {
SaleQuotationPage({super.key});
final controller = Get.put(SaleQuotationController());
final quantityWidth = 55.0;
final unitPriceWidth = 80.0;
final amountWidth = 85.0;
final headerTitleStyle = TextStyle(
2024-04-01 17:35:34 +08:00
fontSize: ScreenAdaper.height(30),
fontWeight: FontWeight.w600,
2024-04-01 14:27:44 +08:00
color: AppTheme.nearlyBlack);
final headerBgcolor = Color.fromARGB(255, 238, 238, 238);
2024-04-01 17:35:34 +08:00
2024-04-01 08:41:52 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-04-02 12:24:08 +08:00
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: FloatingActionButton(
onPressed: () {
controller.addGroup();
},
child: const Icon(Icons.add),
),
2024-04-01 14:27:44 +08:00
appBar: SkAppbar(
title: '报价计算',
action: [
TextButton(
2024-04-02 12:24:08 +08:00
onPressed: () {
controller.addGroup();
},
2024-04-01 14:27:44 +08:00
child: Row(
children: [
2024-04-02 12:24:08 +08:00
Icon(Icons.save, color: AppTheme.white),
SizedBox(
width: ScreenAdaper.width(10),
),
2024-04-01 14:27:44 +08:00
Text(
2024-04-02 12:24:08 +08:00
'保存',
2024-04-01 14:27:44 +08:00
style: TextStyle(
color: AppTheme.white,
2024-04-01 17:35:34 +08:00
fontSize: ScreenAdaper.height(25),
2024-04-01 14:27:44 +08:00
fontWeight: FontWeight.w600),
)
],
))
],
),
2024-04-01 14:59:20 +08:00
body: SafeArea(
bottom: ScreenAdaper.isLandspace() ? false : true,
child: Column(
children: [
2024-04-02 12:24:08 +08:00
builderHeader(),
2024-04-01 14:59:20 +08:00
Expanded(
2024-04-02 12:24:08 +08:00
child: Obx(() => controller.groups.isEmpty
? Empty(text: '请先添加分组')
: CustomScrollView(
slivers: controller.groups
.mapIndexed<Widget>(
(index, e) => buildBody(e, index))
.toList(),
))),
2024-04-01 14:59:20 +08:00
],
),
),
2024-04-01 08:41:52 +08:00
);
}
2024-04-02 12:24:08 +08:00
Widget builderHeader() {
return Container(
decoration: BoxDecoration(
color: headerBgcolor,
border: Border(
bottom:
BorderSide(color: AppTheme.nearlyBlack.withOpacity(0.5)))),
padding: EdgeInsets.only(
left: ScreenAdaper.width(20),
top: ScreenAdaper.height(10),
bottom: ScreenAdaper.height(10)),
child: Row(
children: [
Text(
'名称',
style: headerTitleStyle,
),
const Spacer(),
Container(
alignment: Alignment.center,
width: quantityWidth,
// constraints: BoxConstraints(minWidth: quantityWidth),
child: Text(
'数量',
style: headerTitleStyle,
),
),
Container(
alignment: Alignment.center,
width: unitPriceWidth,
// constraints: BoxConstraints(minWidth: unitPriceWidth),
child: Text(
'单价',
style: headerTitleStyle,
),
),
Container(
alignment: Alignment.center,
width: amountWidth,
child: Text(
'总价',
style: headerTitleStyle,
),
),
],
));
}
2024-04-01 14:27:44 +08:00
Widget buildBody(SaleQuotationModel group, int index) {
final titleStyle = TextStyle(
2024-04-01 17:35:34 +08:00
fontSize: ScreenAdaper.height(30),
2024-04-01 14:27:44 +08:00
color: AppTheme.nearlyBlack,
fontWeight: FontWeight.w600);
final subTextStyle =
2024-04-01 17:35:34 +08:00
TextStyle(color: AppTheme.grey, fontSize: ScreenAdaper.height(30));
return SliverStickyHeader.builder(
builder: (context, state) => Container(
height: ScreenAdaper.height(80),
2024-04-01 14:27:44 +08:00
color: headerBgcolor.withOpacity(1.0 - state.scrollPercentage),
alignment: Alignment.centerLeft,
2024-04-01 14:27:44 +08:00
child: InkWell(
onTap: () {
controller.groups[index].isExpanded.value =
!controller.groups[index].isExpanded.value;
},
child: Row(
children: [
Obx(() => controller.groups[index].isExpanded.value
? IconButton(
padding: EdgeInsets.zero,
onPressed: () {
controller.groups[index].isExpanded.value = false;
},
icon: const Icon(
Icons.expand_more,
color: AppTheme.nearlyBlack,
),
2024-04-01 14:27:44 +08:00
)
: IconButton(
padding: EdgeInsets.zero,
onPressed: () {
controller.groups[index].isExpanded.value = true;
},
icon: const Icon(
Icons.chevron_right,
color: AppTheme.nearlyBlack,
),
2024-04-01 14:27:44 +08:00
)),
Text(
group.name,
style: titleStyle,
),
const Spacer(),
IconButton(
onPressed: () {
2024-04-02 12:24:08 +08:00
ModalUtil.confirm(
title: '确定要删除此组吗?',
onConfirm: () {
controller.removeGroup(index);
});
2024-04-01 14:27:44 +08:00
},
icon: const Icon(
Icons.remove_circle_outline_outlined,
color: AppTheme.nearlyBlack,
)),
IconButton(
2024-04-02 12:24:08 +08:00
onPressed: () {
controller.addItems();
},
2024-04-01 14:27:44 +08:00
icon: const Icon(
Icons.add_circle_outline,
color: AppTheme.nearlyBlack,
)),
],
))),
sliver: Obx(() => !controller.groups[index].isExpanded.value
? SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => SizedBox(),
childCount: 0,
))
: SliverList(
delegate: SliverChildBuilderDelegate(
2024-04-01 17:35:34 +08:00
(context, int i) => Slidable(
2024-04-01 14:27:44 +08:00
key: UniqueKey(),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const DrawerMotion(),
children: [
SlidableAction(
padding: EdgeInsets.zero,
onPressed: (_) {},
backgroundColor: AppTheme.dangerColor,
foregroundColor: Colors.white,
icon: Icons.delete,
label: 'Delete',
),
],
),
child: Container(
padding: EdgeInsets.only(
left: ScreenAdaper.width(20),
top: ScreenAdaper.height(15),
bottom: ScreenAdaper.height(15),
),
constraints:
BoxConstraints(minHeight: ScreenAdaper.height(100)),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1, color: Colors.grey[200]!),
),
2024-04-01 14:27:44 +08:00
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
2024-04-01 17:35:34 +08:00
group.items[i].name,
2024-04-01 14:27:44 +08:00
style: TextStyle(
2024-04-01 17:35:34 +08:00
fontWeight: FontWeight.w600,
fontSize: ScreenAdaper.height(30)),
2024-04-01 14:27:44 +08:00
),
),
],
),
if (group.items[i].spec != null)
Row(
children: [
Text(
'规格、型号: ',
style: subTextStyle,
),
Text(
2024-04-01 17:35:34 +08:00
group.items[i].spec ?? '',
2024-04-01 14:27:44 +08:00
style: subTextStyle,
),
],
),
if (group.items[i].unit != null)
Row(
children: [
Text(
'单位: ',
style: subTextStyle,
),
Text(
2024-04-01 17:35:34 +08:00
group.items[i].unit ?? '',
2024-04-01 14:27:44 +08:00
style: subTextStyle,
),
],
),
if (group.items[i].remark != null)
Row(
children: [
Text(
'备注: ',
style: subTextStyle,
),
Expanded(
child: Text(
'${group.items[i].remark ?? ''}${group.items[i].remark ?? ''}${controller.products[i].remark ?? ''}',
overflow: TextOverflow.ellipsis,
style: subTextStyle,
),
),
],
),
],
),
2024-04-01 14:27:44 +08:00
),
VerticalDivider(),
2024-04-01 17:35:34 +08:00
buildEditCell(
Container(
alignment: Alignment.center,
width: quantityWidth,
child: Text(
2024-04-01 17:38:02 +08:00
'${controller.groups[index].items[i].quantity}',
style: TextStyle(
fontSize: ScreenAdaper.height(25)),
),
2024-04-01 17:35:34 +08:00
),
groupIndex: index,
rowIndex: i,
field: 'quantity',
inputWidth: quantityWidth,
value: controller.groups[index].items[i].quantity),
buildEditCell(
Container(
alignment: Alignment.center,
width: unitPriceWidth,
child: Text(
2024-04-01 17:38:02 +08:00
'${controller.groups[index].items[i].cost}',
style: TextStyle(
fontSize: ScreenAdaper.height(25)),
),
2024-04-01 17:35:34 +08:00
),
groupIndex: index,
rowIndex: i,
field: 'cost',
inputWidth: unitPriceWidth,
value: controller.groups[index].items[i].cost),
buildEditCell(
Container(
alignment: Alignment.center,
width: amountWidth,
child: Text(
2024-04-01 17:38:02 +08:00
'${controller.groups[index].items[i].amount}',
style: TextStyle(
fontSize: ScreenAdaper.height(25)),
),
2024-04-01 17:35:34 +08:00
),
groupIndex: index,
rowIndex: i,
field: 'amount',
inputWidth: amountWidth,
value: controller.groups[index].items[i].amount),
2024-04-01 14:27:44 +08:00
],
),
),
),
2024-04-01 14:27:44 +08:00
childCount: !controller.groups[index].isExpanded.value
? 0
: group.items.length,
),
)),
);
2024-04-01 08:41:52 +08:00
}
2024-04-01 14:27:44 +08:00
2024-04-01 17:35:34 +08:00
Widget buildEditCell(Widget content,
{required int groupIndex,
required int rowIndex,
required String field,
required double inputWidth,
required dynamic value}) {
return Obx(() => controller.editingcell[0] == groupIndex &&
controller.editingcell[1] == rowIndex &&
controller.editingcell[2] == field
? Container(
width: inputWidth,
child: SkNumberInput(
hint: '',
isDense: true,
autoFocus: true,
contentPadding: EdgeInsets.symmetric(
horizontal: ScreenAdaper.width(20),
vertical: ScreenAdaper.height(10)),
textController: TextEditingController(text: '${value}')),
)
: InkWell(
onTap: () {
controller.editingcell.value = [groupIndex, rowIndex, field];
},
child: content,
));
2024-04-01 14:27:44 +08:00
}
}