piaotou_edit.dart 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. import 'dart:math';
  2. import 'package:flustars/flustars.dart' as flustars;
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:liftmanager/common/common.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/fast_notification.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/load_image.dart';
  15. import 'package:liftmanager/widgets/text_field_item.dart';
  16. class PiaotouEdit extends StatefulWidget {
  17. PiaotouEdit(this.type, this.id);
  18. final String type;
  19. final String id;
  20. @override
  21. State<StatefulWidget> createState() {
  22. return PiaotouEditState();
  23. }
  24. }
  25. class PiaotouEditState extends State<PiaotouEdit> {
  26. int indexNow = 2;
  27. String checkFalse = "tab_first/check_false";
  28. String checkTrue = "tab_first/check_true";
  29. String centerTitle;
  30. bool _hasData = false;
  31. final FocusNode blankNode = FocusNode();
  32. TextEditingController _nameController = new TextEditingController();
  33. TextEditingController _enterpriseNumberController =
  34. new TextEditingController();
  35. TextEditingController _gmfDzController = new TextEditingController();
  36. TextEditingController _gmfDhController = new TextEditingController();
  37. TextEditingController _gmfYhController = new TextEditingController();
  38. TextEditingController _gmfZhController = new TextEditingController();
  39. var piaoObj;
  40. @override
  41. void initState() {
  42. if (widget.type == "add") {
  43. centerTitle = "添加发票抬头";
  44. } else if (widget.type == "edit") {
  45. centerTitle = "编辑发票抬头";
  46. getTouDetail();
  47. }
  48. piaoObj = {
  49. "type": 2,
  50. "name": "",
  51. "enterpriseNumber": "",
  52. "gmfDz": "",
  53. "gmfDh": "",
  54. "gmfYh": "",
  55. "gmfZh": "",
  56. "isDefault": 0,
  57. "userId": int.parse(flustars.SpUtil.getString(Constant.userId))
  58. };
  59. super.initState();
  60. }
  61. Future getTouDetail() async {
  62. await NewApiService().getTouDetail(int.parse(widget.id), onSuccess: (res) {
  63. if (res != null) {
  64. _hasData = true;
  65. piaoObj["type"] = res.type;
  66. indexNow = piaoObj["type"];
  67. _nameController.text = res.name ?? "";
  68. _enterpriseNumberController.text = res.enterpriseNumber ?? "";
  69. _gmfDzController.text = res.gmfDz ?? "";
  70. _gmfDhController.text = res.gmfDh ?? "";
  71. _gmfYhController.text = res.gmfYh ?? "";
  72. _gmfZhController.text = res.gmfZh ?? "";
  73. piaoObj["isDefault"] = res.isDefault;
  74. // LogUtil.d(JsonEncoder(detailObj));
  75. // LogUtil.d(JsonEncoder().convert(detailObj));
  76. print(9999);
  77. setState(() {});
  78. }
  79. }, onError: (code, msg) {
  80. toasts(msg);
  81. });
  82. }
  83. Future getTouDelete() async {
  84. await NewApiService().getTouDelete(int.parse(widget.id), onSuccess: (res) {
  85. toasts("删除成功");
  86. String initThisString = randomInt(1111, 9999).toString() +
  87. DateTime.now().millisecondsSinceEpoch.toString();
  88. FastNotification.push("initThis", initThisString);
  89. Navigator.of(context)..pop()..pop();
  90. }, onError: (code, msg) {
  91. toasts(msg);
  92. });
  93. }
  94. randomInt(int min, int max) {
  95. return new Random().nextInt(max) % (max - min + 1) + min;
  96. }
  97. @override
  98. Widget build(BuildContext context) {
  99. double width = MediaQuery.of(context).size.width;
  100. double height = MediaQuery.of(context).size.height;
  101. return Scaffold(
  102. resizeToAvoidBottomPadding: false,
  103. appBar: MyAppBar(
  104. centerTitle: centerTitle,
  105. actions: <Widget>[
  106. widget.type == "edit"
  107. ? FlatButton(
  108. child: Text("删除"),
  109. textColor: Colours.red,
  110. highlightColor: Colors.transparent,
  111. onPressed: () {
  112. showAlert(
  113. context,
  114. "提示",
  115. "确定要删除吗?",
  116. "确定",
  117. () {
  118. Navigator.pop(context);
  119. showLoading(context, "正在删除...");
  120. getTouDelete();
  121. },
  122. txt2: "取消",
  123. onPre2: () {
  124. NavigatorUtils.goBack(context);
  125. });
  126. },
  127. )
  128. : Container(child: null)
  129. ],
  130. ),
  131. body: GestureDetector(
  132. onTap: () {
  133. // 点击空白页面关闭键盘
  134. FocusScope.of(context).requestFocus(blankNode);
  135. },
  136. child: Stack(children: <Widget>[
  137. Container(
  138. // padding: EdgeInsets.only(top:70),
  139. child: ListView(children: <Widget>[
  140. Container(
  141. decoration: BoxDecoration(
  142. border: Border(
  143. bottom: BorderSide(width: 1, color: Color(0xfff5f5f5)),
  144. ),
  145. ),
  146. margin: EdgeInsets.only(
  147. left: ScreenUtil().setWidth(15),
  148. right: ScreenUtil().setWidth(15)),
  149. height: ScreenUtil().setWidth(60),
  150. child: Row(
  151. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  152. children: <Widget>[
  153. Text(
  154. "发票类型",
  155. style: TextStyle(
  156. // color:Color(0xff000000),
  157. // fontSize:ScreenUtil().setSp(14)
  158. ),
  159. textAlign: TextAlign.start,
  160. ),
  161. Row(
  162. children: <Widget>[
  163. GestureDetector(
  164. child: Container(
  165. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  166. child: Row(children: <Widget>[
  167. LoadAssetImage(
  168. // image: AssetImage(i['img']),
  169. indexNow == 2 ? checkTrue : checkFalse,
  170. width: ScreenUtil().setWidth(20),
  171. height: ScreenUtil().setWidth(20),
  172. // alignment: Alignment.centerLeft,
  173. ),
  174. Container(width: 5, child: null),
  175. Text(
  176. "企业单位",
  177. style: TextStyle(
  178. // color:Color(0xff000000),
  179. // fontSize:ScreenUtil().setSp(14)
  180. ),
  181. textAlign: TextAlign.start,
  182. ),
  183. ])),
  184. onTap: () {
  185. setState(() {
  186. indexNow = 2;
  187. _enterpriseNumberController.text = "";
  188. _gmfDzController.text = "";
  189. _gmfDhController.text = "";
  190. _gmfYhController.text = "";
  191. _gmfZhController.text = "";
  192. });
  193. print(indexNow);
  194. },
  195. ),
  196. Container(width: 15, child: null),
  197. GestureDetector(
  198. child: Container(
  199. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  200. child: Row(children: <Widget>[
  201. LoadAssetImage(
  202. // image: AssetImage(i['img']),
  203. indexNow == 1 ? checkTrue : checkFalse,
  204. width: ScreenUtil().setWidth(20),
  205. height: ScreenUtil().setWidth(20),
  206. // alignment: Alignment.centerLeft,
  207. ),
  208. Container(width: 5, child: null),
  209. Text(
  210. "个人",
  211. style: TextStyle(
  212. // color:Colors.black,
  213. // fontSize:ScreenUtil().setSp(14)
  214. ),
  215. textAlign: TextAlign.start,
  216. ),
  217. ])),
  218. onTap: () {
  219. setState(() {
  220. indexNow = 1;
  221. _enterpriseNumberController.text = "";
  222. _gmfDzController.text = "";
  223. _gmfDhController.text = "";
  224. _gmfYhController.text = "";
  225. _gmfZhController.text = "";
  226. });
  227. print(indexNow);
  228. },
  229. ),
  230. ],
  231. ),
  232. ])),
  233. TextFieldItem(
  234. title: "发票抬头",
  235. isMust: true,
  236. content: "",
  237. controller: _nameController,
  238. hintText: "请输入发票抬头",
  239. onChanged: (res) {},
  240. ),
  241. indexNow == 2
  242. ? TextFieldItem(
  243. title: "企业税号",
  244. isMust: true,
  245. content: '',
  246. controller: _enterpriseNumberController,
  247. hintText: "请输入企业税号",
  248. keyboardType: TextInputType.visiblePassword,
  249. onChanged: (res) {},
  250. )
  251. : Container(child: null),
  252. indexNow == 2
  253. ? TextFieldItem(
  254. title: "注册地址",
  255. isMust: true,
  256. content: '',
  257. controller: _gmfDzController,
  258. hintText: "请输入注册地址",
  259. onChanged: (res) {},
  260. )
  261. : Container(child: null),
  262. indexNow == 2
  263. ? TextFieldItem(
  264. title: "注册电话",
  265. isMust: true,
  266. content: '',
  267. controller: _gmfDhController,
  268. hintText: "请输入注册电话",
  269. keyboardType: TextInputType.phone,
  270. onChanged: (res) {},
  271. )
  272. : Container(child: null),
  273. indexNow == 2
  274. ? TextFieldItem(
  275. title: "开户银行",
  276. isMust: true,
  277. content: '',
  278. controller: _gmfYhController,
  279. hintText: "请输入开户银行",
  280. onChanged: (res) {},
  281. )
  282. : Container(child: null),
  283. indexNow == 2
  284. ? TextFieldItem(
  285. title: "银行账号",
  286. isMust: true,
  287. content: '',
  288. controller: _gmfZhController,
  289. hintText: "银行账号",
  290. keyboardType: TextInputType.number,
  291. onChanged: (res) {},
  292. )
  293. : Container(child: null),
  294. Container(
  295. decoration: BoxDecoration(
  296. border: Border(
  297. bottom: BorderSide(width: 1, color: Color(0xfff5f5f5)),
  298. ),
  299. ),
  300. margin: EdgeInsets.only(
  301. left: ScreenUtil().setWidth(15),
  302. right: ScreenUtil().setWidth(15)),
  303. height: ScreenUtil().setWidth(60),
  304. child: Row(
  305. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  306. children: <Widget>[
  307. Text(
  308. "是否默认",
  309. style: TextStyle(
  310. // color:Color(0xff000000),
  311. // fontSize:ScreenUtil().setSp(14)
  312. ),
  313. textAlign: TextAlign.start,
  314. ),
  315. Row(
  316. children: <Widget>[
  317. GestureDetector(
  318. child: Container(
  319. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  320. child: Row(children: <Widget>[
  321. LoadAssetImage(
  322. // image: AssetImage(i['img']),
  323. piaoObj["isDefault"] == 0
  324. ? checkTrue
  325. : checkFalse,
  326. width: ScreenUtil().setWidth(20),
  327. height: ScreenUtil().setWidth(20),
  328. // alignment: Alignment.centerLeft,
  329. ),
  330. Container(width: 5, child: null),
  331. Text(
  332. "否",
  333. style: TextStyle(
  334. // color:Color(0xff000000),
  335. // fontSize:ScreenUtil().setSp(14)
  336. ),
  337. textAlign: TextAlign.start,
  338. ),
  339. ])),
  340. onTap: () {
  341. setState(() {
  342. piaoObj["isDefault"] = 0;
  343. });
  344. print(piaoObj["isDefault"]);
  345. },
  346. ),
  347. Container(width: 15, child: null),
  348. GestureDetector(
  349. child: Container(
  350. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  351. child: Row(children: <Widget>[
  352. LoadAssetImage(
  353. // image: AssetImage(i['img']),
  354. piaoObj["isDefault"] == 1
  355. ? checkTrue
  356. : checkFalse,
  357. width: ScreenUtil().setWidth(20),
  358. height: ScreenUtil().setWidth(20),
  359. // alignment: Alignment.centerLeft,
  360. ),
  361. Container(width: 5, child: null),
  362. Text(
  363. "是",
  364. style: TextStyle(
  365. // color:Colors.black,
  366. // fontSize:ScreenUtil().setSp(14)
  367. ),
  368. textAlign: TextAlign.start,
  369. ),
  370. ])),
  371. onTap: () {
  372. setState(() {
  373. piaoObj["isDefault"] = 1;
  374. });
  375. print(piaoObj["isDefault"]);
  376. },
  377. ),
  378. ],
  379. ),
  380. ])),
  381. ])),
  382. Positioned(
  383. bottom: 0,
  384. left: 0,
  385. child: Container(
  386. width: width,
  387. padding: EdgeInsets.only(
  388. top: ScreenUtil().setWidth(15),
  389. bottom: ScreenUtil().setWidth(15),
  390. left: ScreenUtil().setWidth(25),
  391. right: ScreenUtil().setWidth(25)),
  392. color: ThemeUtils.getDialogTextFieldColor(context),
  393. child: Container(
  394. height: 44,
  395. decoration: BoxDecoration(
  396. color: Colours.blue_app_main,
  397. borderRadius:
  398. BorderRadius.circular(ScreenUtil().setWidth(22)),
  399. ),
  400. child: FlatButton(
  401. // padding: EdgeInsets.all(15.0),
  402. child: Text("保存"),
  403. textColor: Colors.white,
  404. // textColor: Colors.white,
  405. onPressed: () {
  406. piaoObj["type"] = indexNow;
  407. RegExp exp = RegExp(r'^1[34578]\d{9}$');
  408. piaoObj["name"] = _nameController.text ?? "";
  409. piaoObj["enterpriseNumber"] =
  410. _enterpriseNumberController.text ?? "";
  411. piaoObj["gmfDz"] = _gmfDzController.text ?? "";
  412. piaoObj["gmfDh"] = _gmfDhController.text ?? "";
  413. piaoObj["gmfYh"] = _gmfYhController.text ?? "";
  414. piaoObj["gmfZh"] = _gmfZhController.text ?? "";
  415. if (piaoObj["name"] == null ||
  416. piaoObj["name"].trim() == "") {
  417. toasts("请输入发票抬头");
  418. return;
  419. }
  420. if (indexNow == 2 &&
  421. (piaoObj["enterpriseNumber"] == null ||
  422. piaoObj["enterpriseNumber"].trim() == "")) {
  423. toasts("请输入企业税号");
  424. return;
  425. }
  426. if (indexNow == 2 &&
  427. (piaoObj["gmfDz"] == null ||
  428. piaoObj["gmfDz"].trim() == "")) {
  429. toasts("请输入注册地址");
  430. return;
  431. }
  432. if (indexNow == 2 &&
  433. (piaoObj["gmfDh"] == null ||
  434. piaoObj["gmfDh"].trim() == "")) {
  435. toasts("请输入注册电话");
  436. return;
  437. }
  438. if (indexNow == 2 &&
  439. (piaoObj["gmfYh"] == null ||
  440. piaoObj["gmfYh"].trim() == "")) {
  441. toasts("请输入开户银行");
  442. return;
  443. }
  444. if (indexNow == 2 &&
  445. (piaoObj["gmfZh"] == null ||
  446. piaoObj["gmfZh"].trim() == "")) {
  447. toasts("请输入银行账号");
  448. return;
  449. }
  450. if (indexNow == 2 && !exp.hasMatch(piaoObj["gmfDh"])) {
  451. toasts("请输入正确的手机号");
  452. return;
  453. }
  454. // addPiaoTouListPage
  455. // Navigator.pop(context);
  456. FocusScope.of(context).requestFocus(FocusNode());
  457. showLoading(context, "正在保存...");
  458. if (widget.type == "add") {
  459. NewApiService().addPiaoTouListPage(piaoObj,
  460. onSuccess: (res) {
  461. dismissLoading(context);
  462. toasts("保存成功");
  463. String initThisString = randomInt(1111, 9999)
  464. .toString() +
  465. DateTime.now().millisecondsSinceEpoch.toString();
  466. FastNotification.push("initThis", initThisString);
  467. Navigator.pop(context);
  468. print(9999);
  469. }, onError: (code, msg) {
  470. dismissLoading(context);
  471. toasts(msg);
  472. });
  473. } else if (widget.type == "edit") {
  474. Map edit = {"id": widget.id};
  475. edit.addAll(piaoObj);
  476. print(edit);
  477. print(868686);
  478. NewApiService().editPiaoTouListPage(edit,
  479. onSuccess: (res) {
  480. dismissLoading(context);
  481. toasts("保存成功");
  482. String initThisString = randomInt(1111, 9999)
  483. .toString() +
  484. DateTime.now().millisecondsSinceEpoch.toString();
  485. FastNotification.push("initThis", initThisString);
  486. Navigator.pop(context);
  487. print(9999);
  488. }, onError: (code, msg) {
  489. dismissLoading(context);
  490. toasts(msg);
  491. });
  492. }
  493. },
  494. ),
  495. ),
  496. ))
  497. ]),
  498. ),
  499. );
  500. }
  501. }