repair_evaluate_page.dart 7.2 KB

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