maintenance_evaluate_page.dart 8.4 KB

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