maintenance_evaluate_page.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:keyboard_actions/keyboard_actions.dart';
  5. import 'package:liftmanager/internal/maintenance/maintenance_router.dart';
  6. import 'package:liftmanager/internal/maintenance/model/maintenance_list_entity.dart';
  7. import 'package:liftmanager/internal/repair/repair_router.dart';
  8. import 'package:liftmanager/net/api_service.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/image_utils.dart';
  12. import 'package:liftmanager/utils/theme_utils.dart';
  13. import 'package:liftmanager/utils/toast.dart';
  14. import 'package:liftmanager/widgets/app_bar.dart';
  15. import 'package:liftmanager/widgets/click_item.dart';
  16. import 'package:liftmanager/widgets/star_item.dart';
  17. import 'dart:convert' as convert;
  18. class MaintenanceEvaluatePage extends StatefulWidget {
  19. MaintenanceEvaluatePage(this.id,this.category,this.maintenceType,{this.isLook=false,this.service="0",this.star="0",this.advice="",this.imgUrl=""});
  20. final String id;
  21. final int category;
  22. final String maintenceType;
  23. final bool isLook;
  24. final String service;
  25. final String star;
  26. final String advice;
  27. final String imgUrl;
  28. @override
  29. State<StatefulWidget> createState() {
  30. if(isLook){
  31. return MaintenanceEvaluatePageState(double.parse(this.service),double.parse(this.star),this.advice,this.imgUrl);
  32. }else{
  33. return MaintenanceEvaluatePageState(0.0,0.0,"","");
  34. }
  35. }
  36. }
  37. class MaintenanceEvaluatePageState extends State<MaintenanceEvaluatePage> {
  38. MaintenanceEvaluatePageState(service,star,advice,imgUrl){
  39. serviceLevel = service;
  40. starLevel = star;
  41. _controller.text = advice;
  42. mainSignImg = Image.network(imgUrl);
  43. }
  44. TextEditingController _controller = TextEditingController();
  45. double serviceLevel = 0;
  46. double starLevel = 0;
  47. var mainSignImgByte;
  48. Image mainSignImg = Image.asset(
  49. "assets/images/img_sign.png",
  50. );
  51. ///保存
  52. _saveEvaluate() async {
  53. if (mainSignImgByte == null) {
  54. toasts("请签名");
  55. return;
  56. }
  57. if (_controller.text.toString().length == 0) {
  58. toasts("请评价");
  59. return;
  60. }
  61. if (serviceLevel < 1 || serviceLevel > 5) {
  62. toasts("请给服务打分");
  63. }
  64. if (starLevel < 1 || starLevel > 5) {
  65. toasts("请给满意度打分");
  66. }
  67. String file = await ImageUtils()
  68. .saveCacheImageFile(mainSignImgByte, "rep_evaluate_${widget.id}");
  69. showLoading(context, "正在提交...");
  70. ApiService(context: context).upload(file, onSuccess: (data) {
  71. ApiService(context: context).maintenanceEvaluate(
  72. widget.id, _controller.text.toString(), serviceLevel, starLevel, data,
  73. onSuccess: (data) {
  74. dismissLoading(context);
  75. showAlert(context, "提示", "评价成功", "确定", (){
  76. NavigatorUtils.goBack(context);
  77. NavigatorUtils.goBackWithParams(context,true);
  78. });
  79. }, onError: (code, msg) {
  80. toasts(msg);
  81. dismissLoading(context);
  82. });
  83. }, onError: (code, msg) {
  84. toasts(msg);
  85. dismissLoading(context);
  86. });
  87. }
  88. @override
  89. Widget build(BuildContext context) {
  90. return Scaffold(
  91. //resizeToAvoidBottomPadding: false,
  92. appBar: MyAppBar(
  93. centerTitle: "保养评价",
  94. actions:widget.isLook?null: <Widget>[
  95. FlatButton(
  96. child: Text("保存", key: const Key('actionName')),
  97. textColor: Colours.dark_text,
  98. highlightColor: Colors.transparent,
  99. onPressed: () {
  100. _saveEvaluate();
  101. },
  102. )
  103. ],
  104. ),
  105. body: SafeArea(
  106. child: Column(
  107. children: <Widget>[
  108. Expanded(
  109. flex: 1,
  110. child: defaultTargetPlatform == TargetPlatform.iOS
  111. ? FormKeyboardActions(child: _buildBody())
  112. : SingleChildScrollView(child: _buildBody()),
  113. )
  114. ],
  115. ),
  116. ),
  117. );
  118. }
  119. _buildBody() {
  120. bool isDark = ThemeUtils.isDark(context);
  121. return Padding(
  122. padding: EdgeInsets.only(bottom: 30),
  123. child: Container(
  124. color: ThemeUtils.getBackgroundColor(context),
  125. child: Column(
  126. crossAxisAlignment: CrossAxisAlignment.start,
  127. children: <Widget>[
  128. ClickItem(
  129. title: "保养单",
  130. content: "查看",
  131. onTap: (){
  132. MaintenanceListItem item = MaintenanceListItem();
  133. item.recordId = widget.id;
  134. item.category = widget.category;
  135. item.maintenanceType = widget.maintenceType;
  136. String jsonString = convert.jsonEncode(item);
  137. NavigatorUtils.push(context, "${MaintenanceRouter.maintenanceDetail}?item=${Uri.encodeComponent(jsonString)}");
  138. },
  139. ),
  140. StarItem(
  141. title: "服务态度",
  142. starRating: serviceLevel,
  143. onRatingChanged:widget.isLook?null: (res){
  144. serviceLevel = res;
  145. setState(() {
  146. });
  147. },
  148. ),
  149. StarItem(
  150. title: "急修满意度",
  151. starRating: starLevel,
  152. onRatingChanged:widget.isLook?null: (res){
  153. starLevel = res;
  154. setState(() {
  155. });
  156. },
  157. ),
  158. Gaps.vGap8,
  159. ClickItem(title: "客户评价"),
  160. Container(
  161. color: isDark?Colours.dark_bg_gray:Colors.white,
  162. child: Padding(
  163. padding: const EdgeInsets.only(
  164. top: 5, left: 15.0, right: 15.0, bottom: 8.0),
  165. child: TextField(
  166. enabled: !widget.isLook,
  167. maxLength: 100,
  168. maxLines: 8,
  169. autofocus: false,
  170. controller: _controller,
  171. // keyboardType: widget.keyboardType,
  172. //style: TextStyles.textDark14,
  173. decoration: InputDecoration(
  174. hintText: "填写现场情况描述",
  175. border: InputBorder.none,
  176. hintStyle: TextStyles.textGray14)),
  177. ),
  178. ),
  179. SizedBox(
  180. height: 8,
  181. ),
  182. ClickItem(title: "客户手写签名", content: ""),
  183. GestureDetector(
  184. onTap: () {
  185. if(widget.isLook){
  186. return;
  187. }
  188. NavigatorUtils.pushResult(
  189. context, RepairRouter.repairSignaturePage, (result) {
  190. if (result != null) {
  191. mainSignImgByte = result;
  192. Image image = Image.memory(result);
  193. setState(() {
  194. mainSignImg = image;
  195. });
  196. }
  197. });
  198. },
  199. child: Container(
  200. height: 200,
  201. color: isDark?Colours.dark_bg_gray:Colors.white,
  202. alignment: Alignment.center,
  203. child: Stack(
  204. alignment: Alignment.center,
  205. children: <Widget>[
  206. Positioned(
  207. child: Text(
  208. "手写签名",
  209. style: TextStyle(
  210. fontSize: 12, color: Colours.text_gray_c),
  211. ),
  212. ),
  213. Container(child: mainSignImg),
  214. ],
  215. ),
  216. ),
  217. ),
  218. ])));
  219. }
  220. }