302 lines
9.4 KiB
Dart
302 lines
9.4 KiB
Dart
import 'package:collection/collection.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:sk_base_mobile/app_theme.dart';
|
|
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';
|
|
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';
|
|
import 'package:sk_base_mobile/widgets/form_item/sk_text_input.dart';
|
|
import 'package:sk_base_mobile/widgets/core/sk_appbar.dart';
|
|
|
|
class SaleQuotationEndDrawer extends StatelessWidget {
|
|
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: [
|
|
buildToolbar(),
|
|
Expanded(
|
|
child: buildTemplatePicker(),
|
|
),
|
|
// buildAction()
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget buildAction() {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: SkFlatButton(
|
|
color: AppTheme.dangerColor,
|
|
onPressed: () {
|
|
controller.clearWorkbench();
|
|
RouterUtil.back();
|
|
},
|
|
icon: Icon(
|
|
Icons.delete,
|
|
color: AppTheme.nearlyWhite,
|
|
size: ScreenAdaper.height(40),
|
|
),
|
|
buttonText: '清空工作区',
|
|
)),
|
|
Expanded(
|
|
child: SkFlatButton(
|
|
onPressed: () async {
|
|
if (controller.templateName.value != '默认') {
|
|
await controller.saveToDatabase();
|
|
await RouterUtil.back();
|
|
} else {
|
|
templateNameDialog();
|
|
}
|
|
|
|
// final isSuccessed = await controller.saveToDatabase();
|
|
// if (isSuccessed) await RouterUtil.back();
|
|
},
|
|
icon: Icon(
|
|
Icons.save,
|
|
color: AppTheme.nearlyWhite,
|
|
size: ScreenAdaper.height(40),
|
|
),
|
|
buttonText: '保存模板',
|
|
))
|
|
],
|
|
);
|
|
}
|
|
|
|
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(
|
|
onTap: controller.menus[index].onTap,
|
|
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(
|
|
child: ListView(
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: ScreenAdaper.height(20)),
|
|
children: controller.templates
|
|
.mapIndexed((int index, element) =>
|
|
buildTemplateItem(element, index))
|
|
.toList(),
|
|
))
|
|
],
|
|
),
|
|
));
|
|
}
|
|
|
|
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: () {
|
|
templateNameDialog(title: element.name);
|
|
},
|
|
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),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
));
|
|
}
|
|
|
|
void templateNameDialog({String? title = ''}) {
|
|
final textController = TextEditingController(text: title);
|
|
Get.dialog(AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(20)),
|
|
),
|
|
contentPadding: EdgeInsets.only(
|
|
top: ScreenAdaper.height(10),
|
|
right: ScreenAdaper.height(20),
|
|
left: ScreenAdaper.height(20)),
|
|
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
SkInk(
|
|
onTap: () {
|
|
RouterUtil.back();
|
|
},
|
|
child: const Icon(Icons.close))
|
|
],
|
|
),
|
|
SkTextInput(
|
|
height: ScreenAdaper.height(100),
|
|
textController: textController,
|
|
customLabel: true,
|
|
labelText: '模板名称',
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextButton(
|
|
onPressed: () {
|
|
RouterUtil.back();
|
|
},
|
|
child: const Text(
|
|
'取消',
|
|
style: TextStyle(color: AppTheme.nearlyBlack),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TextButton(
|
|
onPressed: () async {
|
|
if (textController.text.isEmpty) {
|
|
SnackBarUtil().error('模板名不能为空');
|
|
return;
|
|
}
|
|
controller.templateName.value = textController.text;
|
|
await RouterUtil.back();
|
|
await controller.saveToLocal();
|
|
await controller.saveToDatabase();
|
|
await controller.getTemplates();
|
|
},
|
|
child: const Text('确定'),
|
|
))
|
|
],
|
|
)
|
|
]),
|
|
));
|
|
}
|
|
}
|
|
|
|
// class SaleQuotationDrawerController extends GetxController{
|
|
|
|
// } |