repair_evaluate_page.dart 7.9 KB

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