archive.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:liftmanager/internal/account/provider/user_provider.dart';
  4. import 'package:liftmanager/net/api_service.dart';
  5. import 'package:liftmanager/utils/image_utils.dart';
  6. import 'package:liftmanager/widgets/app_bar.dart';
  7. import 'package:provider/provider.dart';
  8. import 'package:liftmanager/widgets/bbs_content.dart';
  9. import 'package:flutter_screenutil/flutter_screenutil.dart';
  10. import 'package:liftmanager/widgets/text_field_item.dart';
  11. import 'package:liftmanager/utils/toast.dart';
  12. import 'package:liftmanager/internal/wode/wode_router.dart';
  13. import 'package:liftmanager/routers/fluro_navigator.dart';
  14. import 'package:liftmanager/res/resources.dart';
  15. import 'package:image_picker/image_picker.dart';
  16. import 'package:liftmanager/widgets/selected_image_change.dart';
  17. import 'dart:convert';
  18. class Archive extends StatefulWidget {
  19. Archive(this.id);
  20. final String id;
  21. @override
  22. ArchiveState createState() => ArchiveState();
  23. }
  24. class ArchiveState extends State<Archive> {
  25. final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  26. UserProvider provider = UserProvider();
  27. TextEditingController _title = TextEditingController();
  28. TextEditingController _expression = TextEditingController();
  29. TextEditingController _solution = TextEditingController();
  30. List<String> images = [];
  31. @override
  32. void initState() {
  33. // getBountyList();
  34. getQuestionDetail();
  35. super.initState();
  36. }
  37. dynamic detailObj;
  38. Future getQuestionDetail() async {
  39. await NewApiService().getQuestionDetailAll(int.parse(widget.id),
  40. onSuccess: (res) {
  41. if (res != null) {
  42. detailObj = res.records[0];
  43. print(123456);
  44. print(jsonEncode(res));
  45. _title.text = detailObj.title;
  46. _expression.text = detailObj.expression;
  47. _solution.text = detailObj.solution;
  48. images = [];
  49. detailObj.imgs.split(",").forEach((item){
  50. images.add(item);
  51. });
  52. setState(() {});
  53. }
  54. }, onError: (code, msg) {
  55. toasts(msg);
  56. });
  57. }
  58. List<String> bountyList = [];
  59. void confirmArchive() {
  60. if (_title.text == '') {
  61. toasts("请输入标题");
  62. return;
  63. }
  64. if (_expression.text == '') {
  65. toasts("请输入问题现象");
  66. return;
  67. }
  68. if (_solution.text == '') {
  69. toasts("请输入解决方案");
  70. return;
  71. }
  72. NewApiService().questionCollect({
  73. "id":detailObj!=null?detailObj.id:null,
  74. "liftCaseId": widget.id,
  75. "title": _title.text,
  76. "expression": _expression.text,
  77. "solution": _solution.text,
  78. "imgs": images.join(",")
  79. }, onSuccess: (res) {
  80. toasts("归档成功");
  81. NavigatorUtils.push(context, "${WodeRouter.orderPageMaster}?checkType=0");
  82. setState(() {});
  83. }, onError: (code, msg) {
  84. toasts(msg);
  85. });
  86. }
  87. void getBountyList() {
  88. NewApiService().queryConstant('reward_setting', 'reward', onSuccess: (res) {
  89. print(res);
  90. bountyList.clear();
  91. for (var i = 0; i < res.length; i++) {
  92. bountyList.add(res[i].value);
  93. }
  94. setState(() {});
  95. }, onError: (code, msg) {
  96. toasts(msg);
  97. });
  98. }
  99. ///选择图片
  100. void selectPicker() {
  101. showDialog(
  102. context: context,
  103. builder: (BuildContext context) {
  104. return SimpleDialog(
  105. title: Text("选择方式"),
  106. children: ["拍照", '从手机相册选择'].map((String value) {
  107. print("$value");
  108. return SimpleDialogOption(
  109. child: Text(
  110. "${value}",
  111. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  112. ),
  113. onPressed: () {
  114. _getImage(value == '拍照' ? 1 : 0);
  115. Navigator.of(context).pop();
  116. },
  117. );
  118. }).toList(),
  119. );
  120. },
  121. );
  122. }
  123. void _getImage(int key) async {
  124. try {
  125. var _imageFile = await ImagePicker.pickImage(
  126. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  127. maxWidth: 800,
  128. imageQuality: 95);
  129. if (_imageFile != null) {
  130. // images.add(_imageFile);
  131. // setState(() {});
  132. upLoadFileOnce(_imageFile.path);
  133. }
  134. } catch (e) {
  135. toasts("没有权限,无法打开相册!");
  136. }
  137. }
  138. upLoadFileOnce(path) {
  139. showLoading(context, "正在上传...");
  140. NewApiService().upload(path, onSuccess: (res) {
  141. // imagesUrl.add(res.pathUrl);
  142. dismissLoading(context);
  143. setState(() {
  144. images.add(res.pathUrl);
  145. });
  146. }, onError: (code, msg) {
  147. dismissLoading(context);
  148. toasts(msg);
  149. });
  150. }
  151. FocusNode blankNode = FocusNode();
  152. @override
  153. Widget build(BuildContext context) {
  154. double width = MediaQuery.of(context).size.width;
  155. return
  156. // Center(child:new Text("个人中心"));
  157. ChangeNotifierProvider<UserProvider>(
  158. create: (_) => provider,
  159. child: Scaffold(
  160. key: _scaffoldKey,
  161. resizeToAvoidBottomPadding: false,
  162. appBar: MyAppBar(
  163. centerTitle: "归档",
  164. ),
  165. body: GestureDetector(
  166. onTap: () {
  167. // 点击空白页面关闭键盘
  168. FocusScope.of(context).requestFocus(blankNode);
  169. },
  170. child: Consumer<UserProvider>(
  171. builder: (_, provider, __) {
  172. return Stack(
  173. children: <Widget>[
  174. ListView(
  175. padding: EdgeInsets.all(0.0),
  176. children: <Widget>[
  177. TextFieldItem(
  178. title: "标题",
  179. content: "",
  180. controller: _title,
  181. keyboardType: TextInputType.text,
  182. // maxLength: 30,
  183. hintText: "请输入标题",
  184. onChanged: (res) {
  185. },
  186. ),
  187. Container(
  188. decoration: BoxDecoration(
  189. border: Border(
  190. bottom: BorderSide(width: 0.5, color: Colours.line),
  191. ),
  192. ),
  193. child: Column(
  194. children: <Widget>[
  195. Row(
  196. crossAxisAlignment: CrossAxisAlignment.start,
  197. mainAxisAlignment: MainAxisAlignment.start,
  198. children: <Widget>[
  199. Container(
  200. padding: EdgeInsets.only(
  201. left: ScreenUtil().setWidth(15),
  202. top: ScreenUtil().setWidth(10),
  203. bottom: ScreenUtil().setWidth(5),
  204. ),
  205. child: Text(
  206. "问题现象",
  207. textAlign: TextAlign.left,
  208. ),
  209. ),
  210. ],
  211. ),
  212. Container(
  213. padding: EdgeInsets.only(
  214. left: ScreenUtil().setWidth(15),
  215. right: ScreenUtil().setWidth(15),
  216. bottom: ScreenUtil().setWidth(20),
  217. ),
  218. child: TextFormField(
  219. cursorColor: Color(0xffcccccc),
  220. controller: _expression,
  221. maxLines: 5,
  222. maxLength: 500,
  223. decoration: InputDecoration(
  224. contentPadding: EdgeInsets.all(0),
  225. hintText: '请输入问题现象',
  226. hintStyle:
  227. TextStyle(color: Color(0xffcccccc)),
  228. focusedBorder: InputBorder.none,
  229. border: InputBorder.none,
  230. ),
  231. // 校验
  232. validator: (val) {
  233. // return val.trim().length > 0 ? null : "不能为空";
  234. },
  235. ),
  236. ),
  237. ],
  238. ),
  239. ),
  240. Container(
  241. decoration: BoxDecoration(
  242. border: Border(
  243. bottom: BorderSide(width: 0.5, color: Colours.line),
  244. ),
  245. ),
  246. child: Column(
  247. children: <Widget>[
  248. Row(
  249. crossAxisAlignment: CrossAxisAlignment.start,
  250. mainAxisAlignment: MainAxisAlignment.start,
  251. children: <Widget>[
  252. Container(
  253. padding: EdgeInsets.only(
  254. left: ScreenUtil().setWidth(15),
  255. top: ScreenUtil().setWidth(10),
  256. bottom: ScreenUtil().setWidth(5),
  257. ),
  258. child: Text(
  259. "解决方法",
  260. textAlign: TextAlign.left,
  261. ),
  262. ),
  263. ],
  264. ),
  265. Container(
  266. padding: EdgeInsets.only(
  267. left: ScreenUtil().setWidth(15),
  268. right: ScreenUtil().setWidth(15),
  269. bottom: ScreenUtil().setWidth(20),
  270. ),
  271. child: TextFormField(
  272. cursorColor: Color(0xffcccccc),
  273. controller: _solution,
  274. maxLines: 5,
  275. maxLength: 500,
  276. decoration: InputDecoration(
  277. contentPadding: EdgeInsets.all(0),
  278. hintText: '请输入解决方法',
  279. hintStyle:
  280. TextStyle(color: Color(0xffcccccc)),
  281. focusedBorder: InputBorder.none,
  282. border: InputBorder.none,
  283. ),
  284. // 校验
  285. validator: (val) {
  286. // return val.trim().length > 0 ? null : "不能为空";
  287. },
  288. ),
  289. ),
  290. ],
  291. ),
  292. ),
  293. Container(
  294. color: Colors.white,
  295. child: GridView.builder(
  296. shrinkWrap: true,
  297. padding:
  298. const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  299. physics: NeverScrollableScrollPhysics(),
  300. gridDelegate:
  301. SliverGridDelegateWithFixedCrossAxisCount(
  302. crossAxisCount: 3, childAspectRatio: 1.18),
  303. itemCount: images.length >= 3 ? 3 : images.length + 1,
  304. itemBuilder: (_, index) {
  305. return Stack(
  306. children: <Widget>[
  307. Center(
  308. child: SelectedImage(
  309. image: index < images.length
  310. ? images[index]
  311. : null,
  312. onTap: () {
  313. if (index >= images.length) {
  314. selectPicker();
  315. }
  316. FocusScope.of(context)
  317. .requestFocus(FocusNode());
  318. },
  319. ),
  320. ),
  321. index < images.length
  322. ? Positioned(
  323. top: 0,
  324. right: 0,
  325. child: GestureDetector(
  326. onTap: () {
  327. print(index);
  328. images.remove(images[index]);
  329. setState(() {});
  330. },
  331. child: Icon(
  332. IconData(0xe62a,
  333. fontFamily: "myfont"),
  334. size: 24.0,
  335. color: Color(0xff999999),
  336. ),
  337. ))
  338. : Container(
  339. child: null,
  340. )
  341. ],
  342. );
  343. },
  344. ),
  345. ),
  346. // ChioseThis(
  347. // list: bountyList,
  348. // label: "赏金",
  349. // value: '',
  350. // fun: (index) {
  351. // print(index);
  352. // Navigator.maybePop(context);
  353. // },
  354. // ),
  355. // InkWell(
  356. // onTap: () {
  357. // showPicker(context);
  358. // },
  359. // child: Container(
  360. // height: 50.0,
  361. // margin: const EdgeInsets.only(left: 16.0),
  362. // width: double.infinity,
  363. // decoration: BoxDecoration(
  364. // border: Border(
  365. // bottom: Divider.createBorderSide(context, width: 0.6),
  366. // )),
  367. // child: Row(
  368. // children: <Widget>[
  369. // Padding(
  370. // padding: const EdgeInsets.only(right: 5.0),
  371. // child: Text("赏金"),
  372. // ),
  373. // Expanded(
  374. // flex: 1,
  375. // child: Text(""),
  376. // ),
  377. // Text("请选择"),
  378. // Text(">"),
  379. // Gaps.hGap16
  380. // ],
  381. // ),
  382. // ),
  383. // ),
  384. SizedBox(height: ScreenUtil().setWidth(80))
  385. ],
  386. ),
  387. Positioned(
  388. bottom: 0,
  389. left: 0,
  390. child: Container(
  391. width: width,
  392. padding: EdgeInsets.only(
  393. top: ScreenUtil().setWidth(15),
  394. bottom: ScreenUtil().setWidth(15),
  395. left: ScreenUtil().setWidth(25),
  396. right: ScreenUtil().setWidth(25),
  397. ),
  398. color: Colors.white,
  399. child: Container(
  400. height: ScreenUtil().setWidth(44),
  401. decoration: BoxDecoration(
  402. borderRadius: BorderRadius.circular(
  403. ScreenUtil().setWidth(22),
  404. ),
  405. gradient: const LinearGradient(
  406. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
  407. ),
  408. ),
  409. child: FlatButton(
  410. // padding: EdgeInsets.all(15.0),
  411. child: Text("立即归档"),
  412. textColor: Colors.white,
  413. // textColor: Colors.white,
  414. onPressed: () {
  415. if(_title.text.length > 30){
  416. toasts("标题长度不得大于30!");
  417. }else {
  418. confirmArchive();
  419. }
  420. },
  421. ),
  422. ),
  423. ),
  424. )
  425. ],
  426. );
  427. },
  428. ),
  429. ),
  430. ),
  431. );
  432. }
  433. @override
  434. bool get wantKeepAlive => true;
  435. }