archive.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. @override
  152. void dispose() {
  153. // provider.dispose();
  154. super.dispose();
  155. }
  156. FocusNode blankNode = FocusNode();
  157. @override
  158. Widget build(BuildContext context) {
  159. double width = MediaQuery.of(context).size.width;
  160. return
  161. // Center(child:new Text("个人中心"));
  162. ChangeNotifierProvider<UserProvider>(
  163. create: (_) => provider,
  164. child: Scaffold(
  165. key: _scaffoldKey,
  166. resizeToAvoidBottomPadding: false,
  167. appBar: MyAppBar(
  168. centerTitle: "归档",
  169. ),
  170. body: GestureDetector(
  171. onTap: () {
  172. // 点击空白页面关闭键盘
  173. FocusScope.of(context).requestFocus(blankNode);
  174. },
  175. child: Consumer<UserProvider>(
  176. builder: (_, provider, __) {
  177. return Stack(
  178. children: <Widget>[
  179. ListView(
  180. padding: EdgeInsets.all(0.0),
  181. children: <Widget>[
  182. TextFieldItem(
  183. title: "标题",
  184. content: "",
  185. controller: _title,
  186. keyboardType: TextInputType.text,
  187. // maxLength: 30,
  188. hintText: "请输入标题",
  189. onChanged: (res) {
  190. },
  191. ),
  192. Container(
  193. decoration: BoxDecoration(
  194. border: Border(
  195. bottom: BorderSide(width: 0.5, color: Colours.line),
  196. ),
  197. ),
  198. child: Column(
  199. children: <Widget>[
  200. Row(
  201. crossAxisAlignment: CrossAxisAlignment.start,
  202. mainAxisAlignment: MainAxisAlignment.start,
  203. children: <Widget>[
  204. Container(
  205. padding: EdgeInsets.only(
  206. left: ScreenUtil().setWidth(15),
  207. top: ScreenUtil().setWidth(10),
  208. bottom: ScreenUtil().setWidth(5),
  209. ),
  210. child: Text(
  211. "问题现象",
  212. textAlign: TextAlign.left,
  213. ),
  214. ),
  215. ],
  216. ),
  217. Container(
  218. padding: EdgeInsets.only(
  219. left: ScreenUtil().setWidth(15),
  220. right: ScreenUtil().setWidth(15),
  221. bottom: ScreenUtil().setWidth(20),
  222. ),
  223. child: TextFormField(
  224. cursorColor: Color(0xffcccccc),
  225. controller: _expression,
  226. maxLines: 5,
  227. maxLength: 500,
  228. decoration: InputDecoration(
  229. contentPadding: EdgeInsets.all(0),
  230. hintText: '请输入问题现象',
  231. hintStyle:
  232. TextStyle(color: Color(0xffcccccc)),
  233. focusedBorder: InputBorder.none,
  234. border: InputBorder.none,
  235. ),
  236. // 校验
  237. validator: (val) {
  238. // return val.trim().length > 0 ? null : "不能为空";
  239. },
  240. ),
  241. ),
  242. ],
  243. ),
  244. ),
  245. Container(
  246. decoration: BoxDecoration(
  247. border: Border(
  248. bottom: BorderSide(width: 0.5, color: Colours.line),
  249. ),
  250. ),
  251. child: Column(
  252. children: <Widget>[
  253. Row(
  254. crossAxisAlignment: CrossAxisAlignment.start,
  255. mainAxisAlignment: MainAxisAlignment.start,
  256. children: <Widget>[
  257. Container(
  258. padding: EdgeInsets.only(
  259. left: ScreenUtil().setWidth(15),
  260. top: ScreenUtil().setWidth(10),
  261. bottom: ScreenUtil().setWidth(5),
  262. ),
  263. child: Text(
  264. "解决方法",
  265. textAlign: TextAlign.left,
  266. ),
  267. ),
  268. ],
  269. ),
  270. Container(
  271. padding: EdgeInsets.only(
  272. left: ScreenUtil().setWidth(15),
  273. right: ScreenUtil().setWidth(15),
  274. bottom: ScreenUtil().setWidth(20),
  275. ),
  276. child: TextFormField(
  277. cursorColor: Color(0xffcccccc),
  278. controller: _solution,
  279. maxLines: 5,
  280. maxLength: 500,
  281. decoration: InputDecoration(
  282. contentPadding: EdgeInsets.all(0),
  283. hintText: '请输入解决方法',
  284. hintStyle:
  285. TextStyle(color: Color(0xffcccccc)),
  286. focusedBorder: InputBorder.none,
  287. border: InputBorder.none,
  288. ),
  289. // 校验
  290. validator: (val) {
  291. // return val.trim().length > 0 ? null : "不能为空";
  292. },
  293. ),
  294. ),
  295. ],
  296. ),
  297. ),
  298. Container(
  299. color: Colors.white,
  300. child: GridView.builder(
  301. shrinkWrap: true,
  302. padding:
  303. const EdgeInsets.fromLTRB(8.0, 12, 8.0, 12.0),
  304. physics: NeverScrollableScrollPhysics(),
  305. gridDelegate:
  306. SliverGridDelegateWithFixedCrossAxisCount(
  307. crossAxisCount: 3, childAspectRatio: 1.18),
  308. itemCount: images.length >= 3 ? 3 : images.length + 1,
  309. itemBuilder: (_, index) {
  310. return Stack(
  311. children: <Widget>[
  312. Center(
  313. child: SelectedImage(
  314. image: index < images.length
  315. ? images[index]
  316. : null,
  317. onTap: () {
  318. if (index >= images.length) {
  319. selectPicker();
  320. }
  321. FocusScope.of(context)
  322. .requestFocus(FocusNode());
  323. },
  324. ),
  325. ),
  326. index < images.length
  327. ? Positioned(
  328. top: 0,
  329. right: 0,
  330. child: GestureDetector(
  331. onTap: () {
  332. print(index);
  333. images.remove(images[index]);
  334. setState(() {});
  335. },
  336. child: Icon(
  337. IconData(0xe62a,
  338. fontFamily: "myfont"),
  339. size: 24.0,
  340. color: Color(0xff999999),
  341. ),
  342. ))
  343. : Container(
  344. child: null,
  345. )
  346. ],
  347. );
  348. },
  349. ),
  350. ),
  351. // ChioseThis(
  352. // list: bountyList,
  353. // label: "赏金",
  354. // value: '',
  355. // fun: (index) {
  356. // print(index);
  357. // Navigator.maybePop(context);
  358. // },
  359. // ),
  360. // InkWell(
  361. // onTap: () {
  362. // showPicker(context);
  363. // },
  364. // child: Container(
  365. // height: 50.0,
  366. // margin: const EdgeInsets.only(left: 16.0),
  367. // width: double.infinity,
  368. // decoration: BoxDecoration(
  369. // border: Border(
  370. // bottom: Divider.createBorderSide(context, width: 0.6),
  371. // )),
  372. // child: Row(
  373. // children: <Widget>[
  374. // Padding(
  375. // padding: const EdgeInsets.only(right: 5.0),
  376. // child: Text("赏金"),
  377. // ),
  378. // Expanded(
  379. // flex: 1,
  380. // child: Text(""),
  381. // ),
  382. // Text("请选择"),
  383. // Text(">"),
  384. // Gaps.hGap16
  385. // ],
  386. // ),
  387. // ),
  388. // ),
  389. SizedBox(height: ScreenUtil().setWidth(80))
  390. ],
  391. ),
  392. Positioned(
  393. bottom: 0,
  394. left: 0,
  395. child: Container(
  396. width: width,
  397. padding: EdgeInsets.only(
  398. top: ScreenUtil().setWidth(15),
  399. bottom: ScreenUtil().setWidth(15),
  400. left: ScreenUtil().setWidth(25),
  401. right: ScreenUtil().setWidth(25),
  402. ),
  403. color: Colors.white,
  404. child: Container(
  405. height: ScreenUtil().setWidth(44),
  406. decoration: BoxDecoration(
  407. borderRadius: BorderRadius.circular(
  408. ScreenUtil().setWidth(22),
  409. ),
  410. gradient: const LinearGradient(
  411. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
  412. ),
  413. ),
  414. child: FlatButton(
  415. // padding: EdgeInsets.all(15.0),
  416. child: Text("立即归档"),
  417. textColor: Colors.white,
  418. // textColor: Colors.white,
  419. onPressed: () {
  420. if(_title.text.length > 30){
  421. toasts("标题长度不得大于30!");
  422. }else {
  423. confirmArchive();
  424. }
  425. },
  426. ),
  427. ),
  428. ),
  429. )
  430. ],
  431. );
  432. },
  433. ),
  434. ),
  435. ),
  436. );
  437. }
  438. @override
  439. bool get wantKeepAlive => true;
  440. }