punish_page.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  4. import 'package:bbyyy/https/url.dart';
  5. import 'package:bbyyy/my_tools/my_colors.dart';
  6. import 'package:bbyyy/my_tools/my_views.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_svg/svg.dart';
  10. import 'package:pull_to_refresh/pull_to_refresh.dart';
  11. import '../../../beans/complain_bean_entity.dart';
  12. import '../../../beans/upload_image_bean_entity.dart';
  13. import '../../../https/MyDio.dart';
  14. import '../../../https/my_request.dart';
  15. import '../../../my_tools/dims.dart';
  16. import '../../../my_tools/easy_loading/easy_loading.dart';
  17. import '../../../my_tools/my_cookie.dart';
  18. import '../../../my_tools/my_tools.dart';
  19. import 'choose_a_store_page.dart';
  20. class PunishPage extends StatefulWidget {
  21. @override
  22. _PunishPageState createState() => _PunishPageState();
  23. }
  24. class _PunishPageState extends State<PunishPage> {
  25. int selectedIndex = 0;
  26. TextEditingController _phoneNum = TextEditingController();
  27. TextEditingController _content = TextEditingController();
  28. List<ComplainBeanDataData> data = [];
  29. MyShopBeanDataData shop;
  30. @override
  31. Widget build(BuildContext context) {
  32. return GestureDetector(
  33. onTap: () {
  34. MyTools().hideKeyboard(context);
  35. },
  36. behavior: HitTestBehavior.translucent,
  37. child: Scaffold(
  38. backgroundColor: MyColors.cF7F7F7,
  39. body: Column(
  40. children: [
  41. MyViews().myAppBar('投诉', context, []),
  42. Container(
  43. height: 40,
  44. color: Colors.white,
  45. child: Row(
  46. children: [
  47. GestureDetector(
  48. onTap: () {
  49. setState(() {
  50. selectedIndex = 0;
  51. });
  52. },
  53. behavior: HitTestBehavior.translucent,
  54. child: Padding(
  55. padding: EdgeInsets.only(left: 10, right: 10),
  56. child: Column(
  57. children: [
  58. Text(
  59. '投诉',
  60. style: TextStyle(
  61. color: selectedIndex == 0
  62. ? MyColors.cFF4233
  63. : MyColors.c666666,
  64. fontSize: 15),
  65. ),
  66. Container(
  67. height: 10,
  68. child: Visibility(
  69. child: SvgPicture.asset('images/svg/tab.svg'),
  70. visible: selectedIndex == 0,
  71. ),
  72. )
  73. ],
  74. mainAxisAlignment: MainAxisAlignment.end,
  75. ),
  76. ),
  77. ),
  78. GestureDetector(
  79. onTap: () {
  80. setState(() {
  81. selectedIndex = 1;
  82. });
  83. },
  84. behavior: HitTestBehavior.translucent,
  85. child: Padding(
  86. padding: EdgeInsets.only(left: 10, right: 10),
  87. child: Column(
  88. children: [
  89. Text(
  90. '被投诉',
  91. style: TextStyle(
  92. color: selectedIndex == 1
  93. ? MyColors.cFF4233
  94. : MyColors.c666666,
  95. fontSize: 15),
  96. ),
  97. Container(
  98. height: 10,
  99. child: Visibility(
  100. child: SvgPicture.asset('images/svg/tab.svg'),
  101. visible: selectedIndex == 1,
  102. ),
  103. )
  104. ],
  105. mainAxisAlignment: MainAxisAlignment.end,
  106. ),
  107. ),
  108. )
  109. ],
  110. mainAxisAlignment: MainAxisAlignment.spaceAround,
  111. ),
  112. ),
  113. Expanded(
  114. child: selectedIndex == 0 ? complaintPage() : punishPage(),
  115. )
  116. ],
  117. ),
  118. ),
  119. );
  120. }
  121. complaintPage() {
  122. return SingleChildScrollView(
  123. child: Column(
  124. children: [
  125. Container(
  126. color: Colors.white,
  127. margin: EdgeInsets.only(top: 10),
  128. child: Column(
  129. children: [
  130. Container(
  131. padding: EdgeInsets.fromLTRB(16, 17, 14, 17),
  132. child: Row(
  133. children: [
  134. MyViews().myText('投诉货帮', MyColors.c333333, 15),
  135. GestureDetector(child:
  136. shop == null
  137. ? MyViews().myText('请选择货帮', MyColors.c333333, 15)
  138. : Row(
  139. children: [
  140. ClipRRect(
  141. borderRadius: BorderRadius.circular(10),
  142. child: MyViews()
  143. .netImg(imgURL(shop?.shopPic), 20, 20),
  144. ),
  145. Container(child: MyViews().myText(shop?.shopName, MyColors.c333333, 15),margin: EdgeInsets.only(left: 10),)
  146. ],
  147. ),onTap: (){
  148. MyTools().toPage(context, ChooseAStorePage(), (then){
  149. if(then is MyShopBeanDataData){
  150. shop = then;
  151. setState(() {
  152. });
  153. }
  154. });
  155. },
  156. behavior: HitTestBehavior.translucent,),
  157. ],mainAxisAlignment: MainAxisAlignment.spaceBetween,
  158. ),
  159. ),
  160. Container(
  161. color: MyColors.cF7F7F7,
  162. height: 0.5,
  163. margin: EdgeInsets.only(left: 16, right: 14),
  164. ),
  165. Container(
  166. padding: EdgeInsets.fromLTRB(16, 17, 14, 17),
  167. child: Row(
  168. children: [
  169. MyViews().myText('个人电话', MyColors.c333333, 15),
  170. Expanded(
  171. child: TextField(
  172. inputFormatters: [
  173. LengthLimitingTextInputFormatter(11)
  174. ],
  175. controller: _phoneNum,
  176. cursorColor: MyColors.cFF4233,
  177. cursorWidth: 1.0,
  178. textAlign: TextAlign.end,
  179. onTap: () {},
  180. decoration: InputDecoration(
  181. border: InputBorder.none,
  182. disabledBorder: InputBorder.none,
  183. enabledBorder: InputBorder.none,
  184. focusedBorder: InputBorder.none,
  185. isDense: true,
  186. hintText: '请输入电话',
  187. hintStyle: TextStyle(
  188. color: MyColors.c999999, fontSize: 14),
  189. contentPadding:
  190. const EdgeInsets.fromLTRB(14, 4.5, 0, 4.5),
  191. ),
  192. style: TextStyle(
  193. color: MyColors.c333333,
  194. fontSize: 14,
  195. height: 1.3,
  196. letterSpacing: 0.2),
  197. keyboardType: TextInputType.number,
  198. onChanged: (t) {},
  199. ),
  200. )
  201. ],
  202. ),
  203. ),
  204. ],
  205. ),
  206. ),
  207. Container(
  208. margin: EdgeInsets.only(top: 10),
  209. color: Colors.white,
  210. child: Column(
  211. children: [
  212. Container(
  213. width: double.infinity,
  214. margin: EdgeInsets.only(left: 16, top: 17),
  215. child: Text(
  216. '投诉内容',
  217. style: TextStyle(color: MyColors.c333333, fontSize: 15),
  218. ),
  219. ),
  220. Container(
  221. margin: EdgeInsets.only(left: 15, right: 15, top: 17),
  222. constraints: BoxConstraints(minHeight: 86),
  223. decoration: BoxDecoration(
  224. border: Border.all(color: MyColors.cE7E7E7, width: 1),
  225. borderRadius: BorderRadius.all(
  226. Radius.circular(4),
  227. ),
  228. ),
  229. child: TextField(
  230. controller: _content,
  231. cursorColor: MyColors.cFF4233,
  232. cursorWidth: 1.0,
  233. maxLines: null,
  234. onTap: () {},
  235. decoration: InputDecoration(
  236. border: InputBorder.none,
  237. disabledBorder: InputBorder.none,
  238. enabledBorder: InputBorder.none,
  239. focusedBorder: InputBorder.none,
  240. isDense: true,
  241. hintText: '请输入投诉内容…',
  242. hintStyle:
  243. TextStyle(color: MyColors.c999999, fontSize: 14),
  244. contentPadding:
  245. const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5),
  246. ),
  247. style: TextStyle(
  248. color: MyColors.c333333,
  249. fontSize: 14,
  250. height: 1.3,
  251. letterSpacing: 0.2),
  252. keyboardType: TextInputType.text,
  253. onChanged: (t) {},
  254. ),
  255. ),
  256. Container(
  257. width: double.infinity,
  258. margin: EdgeInsets.only(left: 16, top: 17),
  259. child: Text(
  260. '证据图片',
  261. style: TextStyle(color: MyColors.c333333, fontSize: 15),
  262. ),
  263. ),
  264. Container(
  265. margin:
  266. EdgeInsets.only(left: 15, right: 15, bottom: 17, top: 18),
  267. child: Row(
  268. children: [
  269. GestureDetector(
  270. onTap: () async {
  271. pictures[0] = await selectImage(isCover: false);
  272. setState(() {});
  273. },
  274. behavior: HitTestBehavior.translucent,
  275. child: pictures[0] == null
  276. ? Container(
  277. height: 102,
  278. width: 102,
  279. decoration: BoxDecoration(
  280. color: MyColors.cF0F0F0,
  281. borderRadius:
  282. BorderRadius.all(Radius.circular(4))),
  283. child: Icon(
  284. Icons.add,
  285. color: MyColors.cB6B6B6,
  286. size: 44,
  287. ),
  288. )
  289. : ClipRRect(
  290. child: Image.file(
  291. pictures[0],
  292. height: 102,
  293. width: 102,
  294. fit: BoxFit.cover,
  295. ),
  296. borderRadius: BorderRadius.circular(4),
  297. ),
  298. ),
  299. GestureDetector(
  300. onTap: () async {
  301. pictures[1] = await selectImage(isCover: false);
  302. setState(() {});
  303. },
  304. behavior: HitTestBehavior.translucent,
  305. child: pictures[1] == null
  306. ? Container(
  307. height: 102,
  308. width: 102,
  309. decoration: BoxDecoration(
  310. color: MyColors.cF0F0F0,
  311. borderRadius:
  312. BorderRadius.all(Radius.circular(4))),
  313. child: Icon(
  314. Icons.add,
  315. color: MyColors.cB6B6B6,
  316. size: 44,
  317. ),
  318. )
  319. : ClipRRect(
  320. child: Image.file(
  321. pictures[1],
  322. height: 102,
  323. width: 102,
  324. fit: BoxFit.cover,
  325. ),
  326. borderRadius: BorderRadius.circular(4),
  327. ),
  328. ),
  329. GestureDetector(
  330. onTap: () async {
  331. pictures[2] = await selectImage(isCover: false);
  332. setState(() {});
  333. },
  334. behavior: HitTestBehavior.translucent,
  335. child: pictures[2] == null
  336. ? Container(
  337. height: 102,
  338. width: 102,
  339. decoration: BoxDecoration(
  340. color: MyColors.cF0F0F0,
  341. borderRadius:
  342. BorderRadius.all(Radius.circular(4))),
  343. child: Icon(
  344. Icons.add,
  345. color: MyColors.cB6B6B6,
  346. size: 44,
  347. ),
  348. )
  349. : ClipRRect(
  350. child: Image.file(
  351. pictures[2],
  352. height: 102,
  353. width: 102,
  354. fit: BoxFit.cover,
  355. ),
  356. borderRadius: BorderRadius.circular(4),
  357. ),
  358. )
  359. ],
  360. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  361. ),
  362. ),
  363. ],
  364. ),
  365. ),
  366. GestureDetector(
  367. onTap: () {
  368. uploadPictureOne();
  369. },
  370. behavior: HitTestBehavior.translucent,
  371. child: Container(
  372. color: Colors.white,
  373. margin: EdgeInsets.only(top: 10),
  374. height: 50,
  375. child: MyViews().myText('确 定', MyColors.cFF4233, 16),
  376. alignment: Alignment.center,
  377. ),
  378. )
  379. ],
  380. ),
  381. );
  382. }
  383. RefreshController controller = RefreshController(initialRefresh: true);
  384. punishPage() {
  385. return SmartRefresher(
  386. controller: controller,
  387. onRefresh: onRefresh,
  388. onLoading: onLoading,
  389. enablePullDown: true,
  390. enablePullUp: true,
  391. child: ListView.builder(
  392. itemBuilder: (c, index) {
  393. return MyViews().getPunishItem(context, data[index]);
  394. },
  395. itemCount: data.length,
  396. padding: EdgeInsets.only(top: 10),
  397. ),
  398. );
  399. }
  400. List<File> pictures = [null, null, null];
  401. String picturesPath = '';
  402. void uploadPictureOne() {
  403. print('uploadPictureOne');
  404. if (pictures[0] != null) {
  405. upload(pictures[0], (r, hE) {
  406. if (!hE) {
  407. UploadImageBeanEntity data =
  408. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  409. if (picturesPath == '') {
  410. picturesPath = data.data[0].path;
  411. } else {
  412. picturesPath = picturesPath + ',' + data.data[0].path;
  413. }
  414. uploadPictureTwo();
  415. } else {
  416. EasyLoading.dismiss();
  417. }
  418. }, (e) {
  419. EasyLoading.dismiss();
  420. });
  421. } else {
  422. uploadPictureTwo();
  423. }
  424. }
  425. void uploadPictureTwo() {
  426. print('uploadPictureTwo');
  427. if (pictures[1] != null) {
  428. upload(pictures[1], (r, hE) {
  429. if (!hE) {
  430. UploadImageBeanEntity data =
  431. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  432. if (picturesPath == '') {
  433. picturesPath = data.data[0].path;
  434. } else {
  435. picturesPath = picturesPath + ',' + data.data[0].path;
  436. }
  437. uploadPictureThree();
  438. } else {
  439. EasyLoading.dismiss();
  440. }
  441. }, (e) {
  442. EasyLoading.dismiss();
  443. });
  444. } else {
  445. uploadPictureThree();
  446. }
  447. }
  448. void uploadPictureThree() {
  449. print('uploadPictureThree');
  450. if (pictures[2] != null) {
  451. upload(pictures[2], (r, hE) {
  452. if (!hE) {
  453. UploadImageBeanEntity data =
  454. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  455. if (picturesPath == '') {
  456. picturesPath = data.data[0].path;
  457. } else {
  458. picturesPath = picturesPath + ',' + data.data[0].path;
  459. }
  460. submitAComplaint();
  461. } else {
  462. EasyLoading.dismiss();
  463. }
  464. }, (e) {
  465. EasyLoading.dismiss();
  466. });
  467. } else {
  468. submitAComplaint();
  469. }
  470. }
  471. void submitAComplaint() {
  472. MyDio().save({
  473. 'key': 'complain',
  474. 'object': {
  475. 'shop_uid': shop?.shopUid,
  476. 'user_uid': MyCookie().getUID(),
  477. 'content': _content.text.toString(),
  478. 'snapshots': picturesPath
  479. }
  480. }, (response, hasError) {
  481. if (!hasError) {
  482. showToast('提交成功');
  483. Navigator.pop(context);
  484. // _content.clear();
  485. // _phoneNum.clear();
  486. // shop = null;
  487. // pictures.forEach((element) {
  488. // element = null;
  489. // });
  490. // picturesPath = '';
  491. // setState(() {});
  492. }
  493. }, (error) {});
  494. }
  495. int page = 1;
  496. inquiryAndComplaint() {
  497. MyDio().query({
  498. "key": "complain",
  499. "filters": {
  500. "conditions": ["owner_uid==${MyCookie().getUID()}"]
  501. },
  502. "dims": complainDims,
  503. "paging": [page, 20]
  504. }, (response, hasError) {
  505. if (!hasError) {
  506. ComplainBeanEntity entity = ComplainBeanEntity()
  507. .fromJson(json.decode(response.data.toString()));
  508. if (page == 1) {
  509. data.clear();
  510. }
  511. data.addAll(entity.data.data);
  512. setState(() {});
  513. }
  514. endRe(controller);
  515. }, (error) {
  516. endRe(controller);
  517. });
  518. }
  519. void onRefresh() {
  520. page = 1;
  521. inquiryAndComplaint();
  522. }
  523. void onLoading() {
  524. page++;
  525. inquiryAndComplaint();
  526. }
  527. }