173 lines
5.9 KiB
Dart
173 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:logger/logger.dart';
|
||
import 'package:satu/core/entity/category_entity.dart';
|
||
import 'package:satu/core/models/dialog_models.dart';
|
||
import 'package:satu/core/models/dictionary/category_row_data.dart';
|
||
import 'package:satu/core/models/dictionary/good_row_data.dart';
|
||
import 'package:satu/core/services/dialog_service.dart';
|
||
import 'package:satu/core/services/dictionary_service.dart';
|
||
import 'package:satu/core/services/navigator_service.dart';
|
||
import 'package:satu/core/utils/locator.dart';
|
||
import 'package:satu/core/utils/logger.dart';
|
||
import 'package:satu/routes/route_names.dart';
|
||
import 'package:satu/shared/ui_helpers.dart';
|
||
import 'package:satu/views/dictionaries/category/category_view.dart';
|
||
import 'package:satu/widgets/bar/products_app_bar.dart';
|
||
import 'package:satu/widgets/buttons/busy_button.dart';
|
||
import 'package:satu/widgets/fields/input_field.dart';
|
||
import 'package:satu/widgets/fields/line_tile.dart';
|
||
import 'package:satu/widgets/fields/note_text.dart';
|
||
|
||
class GoodEdit extends StatefulWidget {
|
||
const GoodEdit({
|
||
required this.good,
|
||
Key? key,
|
||
}) : super(key: key);
|
||
final GoodRowDao good;
|
||
|
||
@override
|
||
_GoodEditState createState() => _GoodEditState();
|
||
}
|
||
|
||
class _GoodEditState extends State<GoodEdit> {
|
||
final NavigatorService _navigatorService = locator<NavigatorService>();
|
||
final DictionaryService _dictionaryService = locator<DictionaryService>();
|
||
final DialogService _dialogService = locator<DialogService>();
|
||
final Logger log = getLogger('_GoodEditState');
|
||
late TextEditingController _controller;
|
||
|
||
String parentCategoryName = '';
|
||
int? parentCategoryId;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
if (widget.good.categoryId != null) {
|
||
parentCategoryId = widget.good.categoryId;
|
||
}
|
||
_controller = TextEditingController(text: widget.good.name);
|
||
|
||
getAndStateCategoryName(parentCategoryId);
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_controller.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
Future<void> getAndStateCategoryName(int? id) async {
|
||
String name = '';
|
||
if (id == null) {
|
||
} else if (id == 0) {
|
||
name = 'Корневая категория';
|
||
} else {
|
||
final Category? category = await _dictionaryService.getCategoryById(id);
|
||
if (category != null) {
|
||
name = category.name;
|
||
}
|
||
}
|
||
setState(() {
|
||
parentCategoryName = name;
|
||
parentCategoryId = id;
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: ProductsAppBar(
|
||
title: widget.good.id == null
|
||
? 'Создание товара'
|
||
: 'Редактирование товара',
|
||
),
|
||
body: SingleChildScrollView(
|
||
physics: const BouncingScrollPhysics(),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
verticalSpaceSmall,
|
||
InputField(
|
||
isReadOnly: true,
|
||
controller: _controller,
|
||
labelText: 'Номенклатурный номер',
|
||
placeholder: 'Не присвоен',
|
||
),
|
||
LineTile(
|
||
parentCategoryName,
|
||
onTap: selectCategory,
|
||
labelText: 'Категория',
|
||
placeholder: 'Выберите категорию',
|
||
),
|
||
verticalSpaceSmall,
|
||
InputField(
|
||
controller: _controller,
|
||
labelText: 'Наименование',
|
||
placeholder: 'Введите наименование товара',
|
||
),
|
||
InputField(
|
||
controller: _controller,
|
||
labelText: 'Розничная цена',
|
||
placeholder: 'Введите розничную цену',
|
||
),
|
||
InputField(
|
||
controller: _controller,
|
||
labelText: 'Оптовая цена',
|
||
placeholder: 'Введите оптовую цену',
|
||
),
|
||
InputField(
|
||
controller: _controller,
|
||
labelText:
|
||
'Закупочная цена для автоматически пополняемого товара',
|
||
placeholder: 'Введите закупочную цену',
|
||
),
|
||
InputField(
|
||
controller: _controller,
|
||
labelText: 'EAN Штрих-код',
|
||
placeholder: 'Введите EAN',
|
||
),
|
||
InputField(
|
||
controller: _controller,
|
||
labelText: 'Наименование',
|
||
placeholder: 'Введите наименование товара',
|
||
),
|
||
Padding(
|
||
padding:
|
||
const EdgeInsets.symmetric(horizontal: 45.0, vertical: 20.0),
|
||
child: BusyButton(title: 'СОХРАНИТЬ', onPressed: () {}),
|
||
),
|
||
if (widget.good.id != null)
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: 45.0, vertical: 20.0),
|
||
child: BusyButton(
|
||
title: 'УДАЛИТЬ',
|
||
onPressed: () async {
|
||
DialogResponse response =
|
||
await _dialogService.showConfirmationDialog(
|
||
title: 'Внимание',
|
||
description:
|
||
'Вы уверены, что хотите удалить категорию?',
|
||
confirmationTitle: 'Удалить',
|
||
cancelTitle: 'Отмена');
|
||
|
||
return response.confirmed;
|
||
},
|
||
isDanger: true,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Future<void> selectCategory() async {
|
||
final dynamic result =
|
||
await _navigatorService.push(categorySelectViewRoute);
|
||
if (result != null) {
|
||
getAndStateCategoryName(result as int);
|
||
}
|
||
}
|
||
}
|