提交 047a73da authored 作者: maodou's avatar maodou

订单评价

上级 54488db0
...@@ -3,10 +3,11 @@ part of user_order_evaluate; ...@@ -3,10 +3,11 @@ part of user_order_evaluate;
/// 订单评价 /// 订单评价
class UserOrderEvaluateController extends GetxController { class UserOrderEvaluateController extends GetxController {
OrderInfoModel orderInfoModel; late OrderInfoModel orderInfoModel = OrderInfoModel();
String orderNum; String orderNum;
UserOrderEvaluateController(this.orderNum,this.orderInfoModel); // 已完成订单 UserOrderEvaluateController(this.orderNum); // 已完成订单
final TextEditingController commentsInput = TextEditingController();
final FocusNode _focusNode = FocusNode();
// 按钮是否可用 // 按钮是否可用
bool _enable = false; bool _enable = false;
bool get enable => _enable; bool get enable => _enable;
...@@ -33,8 +34,8 @@ class UserOrderEvaluateController extends GetxController { ...@@ -33,8 +34,8 @@ class UserOrderEvaluateController extends GetxController {
} }
} }
void setCanClick(num double){ void setCanClick({num double=0}){
if (double > 0){ if (double > 0 || commentsInput.text!=''){
_enable = true; _enable = true;
} }
else{ else{
...@@ -42,4 +43,11 @@ class UserOrderEvaluateController extends GetxController { ...@@ -42,4 +43,11 @@ class UserOrderEvaluateController extends GetxController {
} }
update(); update();
} }
@override
void onClose() {
commentsInput.dispose();
_focusNode.dispose();
super.onClose();
}
} }
...@@ -16,37 +16,34 @@ class UserOrderEvaluatePage extends StatefulWidget { ...@@ -16,37 +16,34 @@ class UserOrderEvaluatePage extends StatefulWidget {
} }
class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with AutomaticKeepAliveClientMixin{ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with AutomaticKeepAliveClientMixin{
late UserOrderEvaluateController myController; // late UserOrderEvaluateController myController;
List<TextEditingController> controllers = [];
List<OrderEvaluate> orderEvaluates = []; List<OrderEvaluate> orderEvaluates = [];
List<double> ratings = []; List<double> ratings = [];
@override @override
void initState() { void initState() {
myController = Get.put(UserOrderEvaluateController(widget.orderNum,widget.orderInfoModel)); // myController = Get.put(UserOrderEvaluateController(widget.orderNum));
super.initState(); super.initState();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); // super.build(context);
return Scaffold( return
GetBuilder<UserOrderEvaluateController>(
init: UserOrderEvaluateController(widget.orderNum),
builder: (controller) => Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
title: const Text('订单评价'), title: const Text('订单评价'),
), ),
body: FutureBuilder( body:(controller.orderInfoModel==null ||controller.orderInfoModel.bookList==null)?
future: myController.getOrderInfo(), Container(
builder: (context, snapshot) {
if(snapshot.connectionState == ConnectionState.waiting){
return Container(
alignment: Alignment.center, alignment: Alignment.center,
child: const CircularProgressIndicator(), child: const CircularProgressIndicator(),):
); // 加载中的指示 Column(
}else{
return Column(
children: [ children: [
Expanded( Expanded(
child: SingleChildScrollView( child: Container(child: SingleChildScrollView(
child: Column( child: Column(
children: [ children: [
ListView.builder( ListView.builder(
...@@ -54,15 +51,15 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto ...@@ -54,15 +51,15 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
shrinkWrap: true, shrinkWrap: true,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return listItem( return listItem(
myController.orderInfoModel.bookList![index], controller.orderInfoModel.bookList![index],index,controller
orderEvaluates,controllers); /*orderEvaluates,*//*controllers*/);
}, },
itemCount: itemCount:
myController.orderInfoModel.bookList?.length, controller.orderInfoModel.bookList?.length,
), ),
], ],
), ),
), ),),
), ),
SizedBox( SizedBox(
height: 26.w, height: 26.w,
...@@ -71,13 +68,14 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto ...@@ -71,13 +68,14 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
margin: EdgeInsets.symmetric(horizontal: 10.w), margin: EdgeInsets.symmetric(horizontal: 10.w),
child: CustomGradientButton( child: CustomGradientButton(
text: '提交评价', text: '提交评价',
isEnabled: myController.enable, isEnabled: controller.enable,
onPressed: () { onPressed: () {
controller._focusNode.unfocus();
for(int i=0;i<orderEvaluates.length;i++){ for(int i=0;i<orderEvaluates.length;i++){
orderEvaluates[i].comments=controllers[i].text.toString(); // orderEvaluates[i].comments=controllers[i].text.toString();
} }
print(jsonEncode(orderEvaluates)); print(jsonEncode(orderEvaluates));
myController.UpOrderEvaluate(jsonEncode(orderEvaluates)); controller.UpOrderEvaluate(jsonEncode(orderEvaluates));
}, },
), ),
), ),
...@@ -85,27 +83,24 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto ...@@ -85,27 +83,24 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
height: 41.w, height: 41.w,
) )
], ],
);
}
},
), ),
);
),);
} }
Widget listItem(BookListModel bookListModel, Widget listItem(BookListModel bookListModel,int index,UserOrderEvaluateController myController) {
List<OrderEvaluate> orderEvaluates,
List<TextEditingController> controllers) {
int indexToUpdate = orderEvaluates.indexWhere((obj) => obj.recordId == bookListModel.recordId); int indexToUpdate = orderEvaluates.indexWhere((obj) => obj.recordId == bookListModel.recordId);
// TextEditingController textFieldController= TextEditingController(); myController.commentsInput.text =bookListModel.comments.toString();
// if(indexToUpdate==-1){ if(indexToUpdate==-1){
// OrderEvaluate evaluate = OrderEvaluate(recordId: bookListModel.recordId); OrderEvaluate evaluate = OrderEvaluate(recordId: bookListModel.recordId,rating: bookListModel.rating,comments: bookListModel.comments);
// orderEvaluates.add(evaluate); orderEvaluates.add(evaluate);
// controllers.add(textFieldController); }
// }else{
// textFieldController = controllers[indexToUpdate];
// }
int index = orderEvaluates.length-1;
return Container( return Container(
margin: margin:
EdgeInsets.only(left: 10.w, top: 10.w, right: 10.w), EdgeInsets.only(left: 10.w, top: 10.w, right: 10.w),
...@@ -196,39 +191,70 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto ...@@ -196,39 +191,70 @@ class _UserOrderEvaluatePageState extends State<UserOrderEvaluatePage> with Auto
absorbing: false, absorbing: false,
child: CustomRating( child: CustomRating(
max: 5, max: 5,
score: 0, score:bookListModel.rating !=null ?bookListModel.rating!.toDouble():0,
star: Star( star: Star(
fat: 0.5, fat: 0.5,
progress: 7, progress: 3,
fillColor: AppTheme.primary, fillColor: AppTheme.primary,
size: 16.w, size: 16.w,
emptyColor: Colours.cE2, emptyColor: Colours.cE2,
), ),
onRating: (double) { onRating: (double) {
orderEvaluates[index].rating=double; orderEvaluates[index].rating=double;
myController.setCanClick(double); myController.setCanClick(double: double);
print(double); print(double);
}, },
), ),
), ),
], ],
), ),
Expanded( TextField(
// color: Colors.red, controller: myController.commentsInput,
child: CustomInput( style:
TextStyle(fontSize: 14.w, color: Colours.c3),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: InputBorder.none, focusedBorder: InputBorder.none,
border: InputBorder.none, border: InputBorder.none,
enabledBorder: InputBorder.none, enabledBorder: InputBorder.none,
errorBorder: InputBorder.none, errorBorder: InputBorder.none,
fillColor: Colors.white, fillColor: Colors.white,
hintText: '请简要描述',
hintStyle: TextStyle( hintStyle: TextStyle(
fontSize: 14.w, height: 1.5, color: Colours.c6)), fontSize: 14.w, height: 1.5, color: Colours.c6)),
maxLines: 5, maxLines: 5,
// controller: textFieldController, onChanged: (text){
hintText: '请简要描述', myController.setCanClick();
), orderEvaluates[index].comments=myController.commentsInput.text;
},
focusNode: myController._focusNode,
// onTap: () {
// // 在文本框获取焦点时,将光标移动到文本末尾
// myController.commentsInput.selection = TextSelection.fromPosition(
// TextPosition(offset: myController.commentsInput.text.length),
// );
// },
), ),
// CustomInputCommands(
// decoration: InputDecoration(
// focusedBorder: InputBorder.none,
// border: InputBorder.none,
// enabledBorder: InputBorder.none,
// errorBorder: InputBorder.none,
// fillColor: Colors.white,
// hintStyle: TextStyle(
// fontSize: 14.w, height: 1.5, color: Colours.c6)),
// maxLines: 5,
// controller: myController.commentsInput,
// hintText: '请简要描述',
// onChanged: (text){
// myController.setCanClick();
// print(myController.commentsInput.text);
// orderEvaluates[index].comments=myController.commentsInput.text;
// },
// focusNode: myController._focusNode,
// ),
], ],
), ),
), ),
......
...@@ -433,4 +433,159 @@ class CustomInputSearch extends StatelessWidget { ...@@ -433,4 +433,159 @@ class CustomInputSearch extends StatelessWidget {
} }
} }
class CustomInputCommands extends StatelessWidget {
final TextEditingController? controller;
final String? label;
final String? helper;
final String? hintText;
final String? error;
final bool required;
final bool readOnly;
final bool obscureText;
final Widget? iconData;
final int? minLines;
final int? maxLines;
final void Function()? onTap;
final void Function()? onIcon;
final ValueChanged<String>? onChanged;
final InputDecoration decoration;
final TextInputType? keyboardType;
final bool autofocus;
final FocusNode focusNode;
final List<TextInputFormatter>? inputFormatters;
const CustomInputCommands({
Key? key,
this.controller,
this.label,
this.helper,
this.hintText,
this.error,
this.required = false,
this.readOnly = false,
this.obscureText = false,
this.onTap,
this.onIcon,
this.iconData,
this.onChanged,
this.decoration = const InputDecoration(),
this.minLines,
this.maxLines = 1,
this.keyboardType,
this.autofocus = false,
this.inputFormatters,
required this.focusNode,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final decorationTheme = theme.inputDecorationTheme;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (label != null || required)
Padding(
padding: EdgeInsets.symmetric(
horizontal: (decorationTheme.contentPadding?.horizontal ?? 0) / 2,
vertical: 10.w,
).copyWith(top: 0),
child: RichText(
text: TextSpan(
text: label,
style: decorationTheme.labelStyle,
children: [
if (required)
TextSpan(
text: label != null ? ' *' : '*',
style: const TextStyle(color: AppTheme.error),
),
],
),
),
),
DecoratedBox(
decoration: const BoxDecoration(
boxShadow: [
// BoxShadow(
// color: theme.colorScheme.shadow,
// offset: Offset(0, 20.w),
// blurRadius: 10.w,
// spreadRadius: -10.w,
// ),
],
),
child: TextField(
focusNode: focusNode,
autofocus: autofocus,
controller: controller,
readOnly: readOnly,
onTap: onTap,
obscureText: obscureText,
onChanged: onChanged,
minLines: minLines,
maxLines: maxLines,
inputFormatters: inputFormatters,
keyboardType: keyboardType,
style: TextStyle(
// fontFamily: 'Sans',
fontSize: 15.w,
height: 1.2,
// fontWeight: FontWeight.w600,
),
decoration: decoration.copyWith(
hintText: hintText,
hintStyle: const TextStyle(fontWeight: FontWeight.normal,color: Colours.c9,fontSize: 13),
suffixIconConstraints: const BoxConstraints(),
suffixIcon: _suffixIcon(decorationTheme),
),
),
),
AnimatedSize(
duration: const Duration(milliseconds: 180),
alignment: Alignment.topCenter,
child: error != null
? Padding(
padding: EdgeInsets.only(top: 10.w),
// child: CustomAlert.error(
// size: CustomAlertSize.mini,
// text: Text(error!),
// ),
)
: const SizedBox.shrink(),
),
if (helper != null)
Padding(
padding: EdgeInsets.symmetric(
horizontal: (decorationTheme.contentPadding?.horizontal ?? 0) / 2,
vertical: 10.w,
).copyWith(bottom: 0),
child: Text(
helper!,
style: decorationTheme.helperStyle,
),
)
],
);
}
Widget? _suffixIcon(InputDecorationTheme decorationTheme) {
if (iconData == null) return null;
return Padding(
padding: EdgeInsetsDirectional.only(
end: (decorationTheme.contentPadding?.horizontal ?? 0) / 2,
),
child: GestureDetector(
onTap: onIcon,
child: SizedBox(
width: 24,
height: 24,
child: iconData,
)
),
);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论