piaotou_edit.dart 21 KB

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