mobile_skt/lib/screens/sale_quotation/components/sale_quotation_drawer.dart

290 lines
9.6 KiB
Dart
Raw Normal View History

2024-04-12 09:56:00 +08:00
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
2024-04-12 09:56:00 +08:00
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
2024-04-12 09:56:00 +08:00
import 'package:sk_base_mobile/models/sale_quotation_template.model.dart';
import 'package:sk_base_mobile/router/router.util.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-12 09:56:00 +08:00
import 'package:sk_base_mobile/util/snack_bar.util.dart';
import 'package:sk_base_mobile/widgets/core/sk_flat_button.dart';
import 'package:sk_base_mobile/widgets/core/sk_ink.dart';
2024-04-15 10:59:12 +08:00
import 'package:sk_base_mobile/widgets/empty.dart';
2024-04-12 09:56:00 +08:00
import 'package:sk_base_mobile/widgets/form_item/sk_text_input.dart';
2024-04-09 08:31:17 +08:00
import 'package:sk_base_mobile/widgets/core/sk_appbar.dart';
class SaleQuotationEndDrawer extends StatelessWidget {
2024-04-12 09:56:00 +08:00
final controller = Get.find<SaleQuotationController>();
SaleQuotationEndDrawer({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const SkAppbar(title: '', hideLeading: true), body: buildBody()
// Only render the body if '_isRendered' is true
);
}
Widget buildBody() {
return Column(
children: [
2024-04-12 09:56:00 +08:00
buildToolbar(),
Expanded(
child: buildTemplatePicker(),
),
2024-04-15 10:59:12 +08:00
buildAction()
2024-04-12 09:56:00 +08:00
],
);
}
Widget buildAction() {
return Row(
children: [
Expanded(
child: SkFlatButton(
2024-04-15 10:59:12 +08:00
color: Colors.green,
onPressed: () async {
// ModalUtil.alert(
// title: '请注意',
// content: Text(
// '之前的模板保存了吗?不保存会丢失。',
// style: TextStyle(fontSize: ScreenAdaper.height(30)),
// ),
// onConfirm: () async {
2024-04-12 09:56:00 +08:00
controller.clearWorkbench();
RouterUtil.back();
2024-04-15 10:59:12 +08:00
// });
2024-04-12 09:56:00 +08:00
},
icon: Icon(
2024-04-15 10:59:12 +08:00
Icons.add,
2024-04-12 09:56:00 +08:00
color: AppTheme.nearlyWhite,
2024-04-15 10:59:12 +08:00
size: ScreenAdaper.height(35),
),
buttonText: '新建模板',
)),
Expanded(
child: SkFlatButton(
color: AppTheme.nearlyWhite,
textColor: AppTheme.nearlyBlack,
onPressed: () async {
controller.openTemplateNameEditPopup(
title: '',
onConfirm: (name) async {
controller.templateName.value = name;
await controller.saveToLocal();
await controller.saveToDatabase(isSaveAs: true);
await controller.getTemplates();
});
},
icon: Icon(
Icons.save_as,
color: AppTheme.nearlyBlack,
size: ScreenAdaper.height(35),
2024-04-12 09:56:00 +08:00
),
2024-04-15 10:59:12 +08:00
buttonText: '另存为',
2024-04-12 09:56:00 +08:00
)),
Expanded(
child: SkFlatButton(
onPressed: () async {
2024-04-15 10:59:12 +08:00
if (!controller.checkIsValid()) {
return;
}
2024-04-12 09:56:00 +08:00
if (controller.templateName.value != '默认') {
2024-04-15 10:59:12 +08:00
final isSuccessed = await controller.saveToDatabase();
if (isSuccessed) await RouterUtil.back();
2024-04-12 09:56:00 +08:00
} else {
2024-04-15 10:59:12 +08:00
controller.openTemplateNameEditPopup(onConfirm: (name) async {
controller.templateName.value = name;
await controller.saveToLocal();
await controller.saveToDatabase();
await controller.getTemplates();
});
2024-04-12 09:56:00 +08:00
}
},
icon: Icon(
Icons.save,
color: AppTheme.nearlyWhite,
2024-04-15 10:59:12 +08:00
size: ScreenAdaper.height(35),
),
2024-04-12 09:56:00 +08:00
buttonText: '保存模板',
2024-04-15 10:59:12 +08:00
)),
],
);
}
2024-04-12 09:56:00 +08:00
Widget buildToolbar() {
return Container(
decoration: BoxDecoration(
color: AppTheme.nearlyWhite,
borderRadius: BorderRadius.circular(ScreenAdaper.sp(20))),
margin: EdgeInsets.symmetric(
horizontal: ScreenAdaper.height(20),
vertical: ScreenAdaper.height(20)),
child: Column(
children: [
buildGroupHeader('工具栏'),
Row(
children: controller.menus
.mapIndexed(
(index, item) => Expanded(child: buildItem(index)))
.toList())
],
),
);
}
Widget buildGroupHeader(String text) {
return Container(
padding: EdgeInsets.only(
right: ScreenAdaper.width(20),
left: ScreenAdaper.width(20),
top: ScreenAdaper.height(20)),
alignment: Alignment.centerLeft,
child: Text(
text,
style: TextStyle(
fontSize: ScreenAdaper.height(25), color: Colors.grey[600]),
),
);
}
Widget buildItem(int index) {
return SkInk(
2024-04-15 10:59:12 +08:00
onTap: controller.menus[index].onTap ?? () {},
2024-04-12 09:56:00 +08:00
child: Container(
alignment: Alignment.center,
padding: EdgeInsets.only(
top: ScreenAdaper.height(20), bottom: ScreenAdaper.height(20)),
child: Column(
children: [
SvgPicture.asset(
'assets/icons/${controller.menus[index].icon}',
width: ScreenAdaper.width(75),
height: ScreenAdaper.width(75),
),
SizedBox(
height: ScreenAdaper.height(10),
),
Text(
controller.menus[index].title,
style: TextStyle(
fontSize: ScreenAdaper.height(22),
),
)
],
),
),
);
}
Widget buildTemplatePicker() {
return Obx(() => Container(
decoration: BoxDecoration(
color: AppTheme.nearlyWhite,
borderRadius: BorderRadius.circular(ScreenAdaper.sp(20))),
margin: EdgeInsets.only(
left: ScreenAdaper.height(20),
right: ScreenAdaper.height(20),
bottom: ScreenAdaper.height(20)),
child: Column(
children: [
buildGroupHeader('请选择模板'),
SizedBox(
height: ScreenAdaper.height(10),
),
Expanded(
2024-04-15 10:59:12 +08:00
child: controller.templates.isEmpty
? Empty(
onTap: () {
Get.back();
controller.addGroup();
},
text: '暂无模板,点我开始创建')
: ListView(
padding: EdgeInsets.symmetric(
horizontal: ScreenAdaper.height(20)),
children: controller.templates
.mapIndexed((int index, element) =>
buildTemplateItem(element, index))
.toList(),
))
2024-04-12 09:56:00 +08:00
],
),
));
}
Widget buildTemplateItem(SaleQuotationTemplateModel element, int index) {
return Obx(() => SkInk(
color: controller.templateId.value == element.id
? AppTheme.primaryColorLight
: Colors.transparent,
onTap: () async {
controller.changeTemplate(element);
await RouterUtil.back();
},
margin: EdgeInsets.symmetric(
horizontal: ScreenAdaper.width(10),
vertical: ScreenAdaper.height(10)),
border: Border.all(color: AppTheme.dividerColor),
borderRadius: BorderRadius.circular(ScreenAdaper.sp(15)),
child: Container(
padding: EdgeInsets.symmetric(
vertical: ScreenAdaper.height(20),
horizontal: ScreenAdaper.width(20)),
child: Row(children: [
Expanded(
child: Text(
'${element.name}',
style: TextStyle(fontSize: ScreenAdaper.height(25)),
)),
SkInk(
onTap: () {
2024-04-15 10:59:12 +08:00
controller.openTemplateNameEditPopup(
title: element.name,
onConfirm: (name) async {
controller.templateName.value = name;
await controller.saveToLocal();
await controller.saveToDatabase();
await controller.getTemplates();
});
},
child: Icon(
Icons.edit,
color: Colors.grey[600],
size: ScreenAdaper.height(40),
),
),
SizedBox(
width: ScreenAdaper.width(10),
),
SkInk(
color: Colors.transparent,
onTap: () {
ModalUtil.alert(
title: '删除模板',
content: Text(
'确定删除模板${element.name}吗?',
style: TextStyle(fontSize: ScreenAdaper.height(30)),
),
onConfirm: () async {
await controller.deleteTemplate(element.id!);
controller.templates.removeAt(index);
});
},
child: Icon(
Icons.delete,
color: Colors.grey[600],
size: ScreenAdaper.height(40),
),
),
]),
2024-04-12 09:56:00 +08:00
),
));
2024-04-12 09:56:00 +08:00
}
}
2024-04-12 09:56:00 +08:00
// class SaleQuotationDrawerController extends GetxController{
// }