kaipiao.dart 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. import 'dart:convert';
  2. import 'dart:math';
  3. import 'package:flustars/flustars.dart' as FlutterStars;
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:liftmanager/common/common.dart';
  8. import 'package:liftmanager/internal/account/provider/user_provider.dart';
  9. import 'package:liftmanager/internal/wode/wode_router.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/res/colors.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/fast_notification.dart';
  14. import 'package:liftmanager/utils/theme_utils.dart';
  15. import 'package:liftmanager/utils/toast.dart';
  16. import 'package:liftmanager/widgets/app_bar.dart';
  17. import 'package:liftmanager/widgets/bbs_content.dart';
  18. import 'package:liftmanager/widgets/click_item.dart';
  19. import 'package:liftmanager/widgets/load_image.dart';
  20. import 'package:liftmanager/widgets/text_field_item.dart';
  21. import 'package:provider/provider.dart';
  22. class Kaipiao extends StatefulWidget {
  23. Kaipiao(this.ids, this.price);
  24. final String ids;
  25. final String price;
  26. @override
  27. State<StatefulWidget> createState() {
  28. return KaipiaoState();
  29. }
  30. }
  31. class KaipiaoState extends State<Kaipiao> with AutomaticKeepAliveClientMixin {
  32. UserProvider provider = UserProvider();
  33. FocusNode blankNode = FocusNode();
  34. /**
  35. * 发票类型
  36. */
  37. bool isTi = true;
  38. int indexNow = 2;
  39. int piaoType = 1;
  40. String checkFalse = "tab_first/check_false";
  41. String checkTrue = "tab_first/check_true";
  42. String desc = "普通发票为电子发票,可支持报销入账";
  43. int piaotouId;
  44. dynamic touObj = {
  45. "piaotouStr": "请选择发票抬头",
  46. "enterpriseNumber": "--",
  47. "gmfDz": "--",
  48. "gmfDh": "--",
  49. "gmfYh": "--",
  50. "gmfZh": "--",
  51. };
  52. var piaoObj = {
  53. "receiveTicket": "请输入",
  54. "receiveMebile": "请输入",
  55. "receiveAddress": "请输入",
  56. "gmfZh": "请输入",
  57. };
  58. GlobalKey _formKey = new GlobalKey<FormState>();
  59. TextEditingController _receiveTicketController = new TextEditingController();
  60. TextEditingController _receiveMebileController = new TextEditingController();
  61. TextEditingController _receiveAddressController = new TextEditingController();
  62. TextEditingController _emailController = new TextEditingController();
  63. String touChiose = "";
  64. List<String> touListChiose = ['tou1', 'tou2'];
  65. @override
  66. void initState() {
  67. // TODO: implement initState
  68. super.initState();
  69. getList(2);
  70. FastNotification.addListener("piaoTou", (piaoTouObj) {
  71. print(piaoTouObj);
  72. print(333);
  73. setState(() {
  74. touObj["piaotouStr"] = piaoTouObj.name;
  75. touObj["enterpriseNumber"] = piaoTouObj.enterpriseNumber;
  76. touObj["gmfDz"] = piaoTouObj.gmfDz;
  77. touObj["gmfDh"] = piaoTouObj.gmfDh;
  78. touObj["gmfYh"] = piaoTouObj.gmfYh;
  79. touObj["gmfZh"] = piaoTouObj.gmfZh;
  80. piaotouId = piaoTouObj.id;
  81. });
  82. });
  83. }
  84. Future getList(type) async {
  85. await NewApiService().getPiaoTouListPage(1, 10, null, 1, onSuccess: (res) {
  86. print(JsonEncoder().convert(res.records));
  87. if (res.records.length > 0 && res.records[0].type == type) {
  88. touObj["piaotouStr"] = res.records[0].name;
  89. touObj["enterpriseNumber"] = res.records[0].enterpriseNumber;
  90. touObj["gmfDz"] = res.records[0].gmfDz;
  91. touObj["gmfDh"] = res.records[0].gmfDh;
  92. touObj["gmfYh"] = res.records[0].gmfYh;
  93. touObj["gmfZh"] = res.records[0].gmfZh;
  94. piaotouId = res.records[0].id;
  95. } else {
  96. touObj = {
  97. "piaotouStr": "请选择发票抬头",
  98. "enterpriseNumber": "--",
  99. "gmfDz": "--",
  100. "gmfDh": "--",
  101. "gmfYh": "--",
  102. "gmfZh": "--",
  103. };
  104. }
  105. print(12345689);
  106. setState(() {});
  107. }, onError: (code, msg) {
  108. toasts(msg);
  109. });
  110. }
  111. randomInt(int min, int max) {
  112. return new Random().nextInt(max) % (max - min + 1) + min;
  113. }
  114. void applyInvoice() {
  115. if ((_formKey.currentState as FormState).validate()) {
  116. List<String> ids = widget.ids.split(',');
  117. List<dynamic> invoiceItem = [];
  118. for (var i = 0; i < ids.length; i++) {
  119. if (ids[i] != null && ids[i] != "") {
  120. invoiceItem.add({"id": int.parse(ids[i])});
  121. }
  122. }
  123. dynamic invoiceInfo = {
  124. "type": indexNow == 1 ? 1 : 2,
  125. "invoiceType": piaoType == 1 ? 1 : 2,
  126. "gmfMc": "咨询服务费",
  127. // "gmfNsrsbm": _taxidController.text,
  128. // "gmfYh": _bankController.text,
  129. // "gmfZh": _bankAccountController.text,
  130. // "gmfDz": _addressController.text,
  131. // "gmfDh": _telController.text,
  132. "email": _emailController.text,
  133. "hjje": double.parse(widget.price),
  134. "invoiceItem": invoiceItem,
  135. "userId": int.parse(FlutterStars.SpUtil.getString(Constant.userId)),
  136. "userInvoiceId": piaotouId,
  137. "receiveTicket": _receiveTicketController.text,
  138. "receiveMebile": _receiveMebileController.text,
  139. "receiveAddress": _receiveAddressController.text,
  140. };
  141. NewApiService().applyInvoice(invoiceInfo, onSuccess: (res) {
  142. toasts("发票申请成功");
  143. isTi = true;
  144. // NavigatorUtils.goBackWithParams(context, true);
  145. String initThisStringPiao = randomInt(1111, 9999).toString() +
  146. DateTime.now().millisecondsSinceEpoch.toString();
  147. FastNotification.push("initThisPiao", initThisStringPiao);
  148. Navigator.pop(context);
  149. setState(() {});
  150. }, onError: (code, msg) {
  151. isTi = true;
  152. toasts(msg);
  153. });
  154. }
  155. }
  156. @override
  157. void dispose() {
  158. // provider.dispose();
  159. super.dispose();
  160. }
  161. @override
  162. Widget build(BuildContext context) {
  163. double width = MediaQuery.of(context).size.width;
  164. titleWidget(title) {
  165. return Container(
  166. width: width,
  167. padding: EdgeInsets.only(
  168. // left: ScreenUtil().setWidth(15),
  169. right: ScreenUtil().setWidth(15),
  170. top: ScreenUtil().setWidth(10),
  171. bottom: ScreenUtil().setWidth(10)),
  172. color: Color(0xffF9F9F9),
  173. child: Row(
  174. children: [
  175. Container(
  176. height: 18,
  177. width: 2,
  178. color: Colours.blue_app_main,
  179. ),
  180. SizedBox(
  181. width: 13,
  182. ),
  183. Text(
  184. title,
  185. textAlign: TextAlign.left,
  186. style: TextStyle(
  187. // fontSize:ScreenUtil().setSp(14),
  188. color: Color(0xff333333),
  189. ),
  190. ),
  191. ],
  192. ));
  193. }
  194. return
  195. // Center(child:new Text("个人中心"));
  196. ChangeNotifierProvider<UserProvider>(
  197. create: (_) => provider,
  198. child: Scaffold(
  199. resizeToAvoidBottomPadding: false,
  200. appBar: MyAppBar(
  201. centerTitle: "开具发票",
  202. ),
  203. body: GestureDetector(
  204. onTap: () {
  205. // 点击空白页面关闭键盘
  206. FocusScope.of(context).requestFocus(blankNode);
  207. },
  208. child: Consumer<UserProvider>(
  209. builder: (_, provider, __) {
  210. return Stack(
  211. children: <Widget>[
  212. ListView(
  213. padding: EdgeInsets.all(0.0),
  214. children: <Widget>[
  215. Form(
  216. key: _formKey,
  217. child: Column(
  218. children: <Widget>[
  219. titleWidget('发票种类'),
  220. Container(
  221. padding: EdgeInsets.only(
  222. left: ScreenUtil().setWidth(15),
  223. right: ScreenUtil().setWidth(5),
  224. top: ScreenUtil().setWidth(10),
  225. bottom: ScreenUtil().setWidth(10)),
  226. child: Row(
  227. mainAxisAlignment:
  228. MainAxisAlignment.spaceBetween,
  229. children: <Widget>[
  230. Column(
  231. crossAxisAlignment:
  232. CrossAxisAlignment.start,
  233. children: <Widget>[
  234. Row(
  235. children: <Widget>[
  236. GestureDetector(
  237. onTap: () {
  238. setState(() {
  239. desc = "普通发票为电子发票,可支持报销入账";
  240. piaoType = 1;
  241. piaotouId = null;
  242. // touObj = {
  243. // "piaotouStr": "请选择发票抬头",
  244. // "enterpriseNumber": "--",
  245. // "gmfDz": "--",
  246. // "gmfDh": "--",
  247. // "gmfYh": "--",
  248. // "gmfZh": "--",
  249. // };
  250. getList(2);
  251. });
  252. },
  253. child: Container(
  254. padding: EdgeInsets.only(
  255. left: ScreenUtil()
  256. .setWidth(10),
  257. right: ScreenUtil()
  258. .setWidth(10),
  259. top: 3,
  260. bottom: 3),
  261. decoration: BoxDecoration(
  262. border: Border.all(
  263. width: 1,
  264. color: piaoType == 1
  265. ? Color(0xff1B87F6)
  266. : Color(
  267. 0xffdddddd)),
  268. borderRadius:
  269. BorderRadius.circular(
  270. 5)),
  271. child: Text(
  272. "电子发票",
  273. textAlign: TextAlign.center,
  274. style: TextStyle(
  275. fontSize:
  276. ScreenUtil().setSp(14),
  277. color: piaoType == 1
  278. ? Color(0xff1B87F6)
  279. : Color(0xff666666),
  280. ),
  281. ),
  282. )),
  283. SizedBox(
  284. width: 10,
  285. ),
  286. GestureDetector(
  287. onTap: () {
  288. setState(() {
  289. desc =
  290. "增值税发票为纸质发票,邮寄信息详见收票人信息";
  291. piaoType = 2;
  292. indexNow = 2;
  293. piaotouId = null;
  294. // touObj = {
  295. // "piaotouStr": "请选择发票抬头",
  296. // "enterpriseNumber": "--",
  297. // "gmfDz": "--",
  298. // "gmfDh": "--",
  299. // "gmfYh": "--",
  300. // "gmfZh": "--",
  301. // };
  302. getList(2);
  303. });
  304. },
  305. child: Container(
  306. padding: EdgeInsets.only(
  307. left: ScreenUtil()
  308. .setWidth(10),
  309. right: ScreenUtil()
  310. .setWidth(10),
  311. top: 3,
  312. bottom: 3),
  313. decoration: BoxDecoration(
  314. border: Border.all(
  315. width: 1,
  316. color: piaoType == 2
  317. ? Color(0xff1B87F6)
  318. : Color(
  319. 0xffdddddd)),
  320. borderRadius:
  321. BorderRadius.circular(
  322. 5)),
  323. child: Text(
  324. "专用发票",
  325. textAlign: TextAlign.center,
  326. style: TextStyle(
  327. fontSize:
  328. ScreenUtil().setSp(14),
  329. color: piaoType == 2
  330. ? Color(0xff1B87F6)
  331. : Color(0xff666666),
  332. ),
  333. ),
  334. )),
  335. ],
  336. ),
  337. SizedBox(height: 5),
  338. Text(
  339. "($desc)",
  340. textAlign: TextAlign.left,
  341. style: TextStyle(
  342. fontSize: ScreenUtil().setSp(12),
  343. color: Color(0xff999999),
  344. ),
  345. ),
  346. ],
  347. ),
  348. ],
  349. ),
  350. ),
  351. titleWidget('发票详情'),
  352. piaoType != 2
  353. ? Container(
  354. decoration: BoxDecoration(
  355. border: Border(
  356. bottom: BorderSide(
  357. width: 1, color: Color(0xfff5f5f5)),
  358. ),
  359. ),
  360. padding: EdgeInsets.only(
  361. left: ScreenUtil().setWidth(15),
  362. right: ScreenUtil().setWidth(15)),
  363. height: 50,
  364. child: Row(
  365. mainAxisAlignment:
  366. MainAxisAlignment.spaceBetween,
  367. children: <Widget>[
  368. Text(
  369. "发票类型",
  370. style: TextStyle(
  371. // color:Color(0xff999999),
  372. // fontSize:ScreenUtil().setSp(14)
  373. ),
  374. textAlign: TextAlign.start,
  375. ),
  376. Row(
  377. children: <Widget>[
  378. GestureDetector(
  379. child: Container(
  380. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  381. child: Row(
  382. children: <Widget>[
  383. LoadAssetImage(
  384. // image: AssetImage(i['img']),
  385. indexNow == 2
  386. ? checkTrue
  387. : checkFalse,
  388. width: ScreenUtil()
  389. .setWidth(16),
  390. height: ScreenUtil()
  391. .setWidth(16),
  392. // alignment: Alignment.centerLeft,
  393. ),
  394. Container(
  395. width: 5, child: null),
  396. Text(
  397. "企业单位",
  398. style: TextStyle(
  399. // color:Color(0xff000000),
  400. // fontSize:ScreenUtil().setSp(14)
  401. ),
  402. textAlign:
  403. TextAlign.start,
  404. ),
  405. ],
  406. ),
  407. ),
  408. onTap: () {
  409. setState(() {
  410. indexNow = 2;
  411. piaotouId = null;
  412. // touObj = {
  413. // "piaotouStr": "请选择发票抬头",
  414. // "enterpriseNumber": "--",
  415. // "gmfDz": "--",
  416. // "gmfDh": "--",
  417. // "gmfYh": "--",
  418. // "gmfZh": "--",
  419. // };
  420. getList(2);
  421. });
  422. print(indexNow);
  423. },
  424. ),
  425. Container(width: 15, child: null),
  426. GestureDetector(
  427. child: Container(
  428. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  429. child: Row(
  430. children: <Widget>[
  431. LoadAssetImage(
  432. // image: AssetImage(i['img']),
  433. indexNow == 1
  434. ? checkTrue
  435. : checkFalse,
  436. width: ScreenUtil()
  437. .setWidth(16),
  438. height: ScreenUtil()
  439. .setWidth(16),
  440. // alignment: Alignment.centerLeft,
  441. ),
  442. Container(
  443. width: 5, child: null),
  444. Text(
  445. "个人",
  446. style: TextStyle(
  447. // color:Colors.black,
  448. // fontSize:ScreenUtil().setSp(14)
  449. ),
  450. textAlign:
  451. TextAlign.start,
  452. ),
  453. ],
  454. ),
  455. ),
  456. onTap: () {
  457. setState(() {
  458. indexNow = 1;
  459. piaotouId = null;
  460. // touObj = {
  461. // "piaotouStr": "请选择发票抬头",
  462. // "enterpriseNumber": "--",
  463. // "gmfDz": "--",
  464. // "gmfDh": "--",
  465. // "gmfYh": "--",
  466. // "gmfZh": "--",
  467. // };
  468. getList(1);
  469. });
  470. print(indexNow);
  471. },
  472. ),
  473. ],
  474. ),
  475. ],
  476. ),
  477. )
  478. : Container(child: null),
  479. // TextFieldItem(
  480. // title: "发票抬头",
  481. // content: "",
  482. // controller: _nameController,
  483. // hintText: "请选择发票抬头",
  484. // onChanged: (res) {
  485. // // setState(() {});
  486. // },
  487. // ),
  488. ClickItem(
  489. title: "发票抬头",
  490. content: touObj["piaotouStr"],
  491. isMust: true,
  492. onTap: () {
  493. String type;
  494. if (indexNow == 1) {
  495. type = "1";
  496. } else {
  497. type = "2";
  498. }
  499. NavigatorUtils.push(context,
  500. "${WodeRouter.piaotou}?checkTou=checkTou&type=$type");
  501. },
  502. ),
  503. indexNow == 2
  504. ? ClickItem(
  505. title: "企业税号",
  506. content: touObj["enterpriseNumber"],
  507. )
  508. : Container(child: null),
  509. indexNow == 2
  510. ? ClickItem(
  511. title: "注册地址",
  512. content: touObj["gmfDz"],
  513. )
  514. : Container(child: null),
  515. indexNow == 2
  516. ? ClickItem(
  517. title: "注册电话",
  518. content: touObj["gmfDh"],
  519. )
  520. : Container(child: null),
  521. indexNow == 2
  522. ? ClickItem(
  523. title: "开户银行",
  524. content: touObj["gmfYh"],
  525. )
  526. : Container(child: null),
  527. indexNow == 2
  528. ? ClickItem(
  529. title: "银行账户",
  530. content: touObj["gmfZh"],
  531. )
  532. : Container(child: null),
  533. Heng(
  534. left: "发票内容",
  535. right: "咨询服务费",
  536. leftColor: 0xff666666,
  537. rightColor: 0xff000000,
  538. ),
  539. Heng(
  540. left: "发票金额",
  541. right:
  542. "${double.parse(widget.price).toStringAsFixed(2).toString()}元",
  543. leftColor: 0xff999999,
  544. rightColor: 0xff333333,
  545. ),
  546. piaoType != 2
  547. ? Column(
  548. children: <Widget>[
  549. titleWidget('接收方式'),
  550. TextFieldItem(
  551. title: "电子邮箱",
  552. content: "",
  553. isMust: true,
  554. controller: _emailController,
  555. hintText: "请输入电子邮箱",
  556. onChanged: (res) {
  557. // setState(() {});
  558. },
  559. ),
  560. ],
  561. )
  562. : Container(child: null),
  563. piaoType == 2
  564. ? Column(
  565. children: <Widget>[
  566. titleWidget('收票人信息'),
  567. TextFieldItem(
  568. title: "收票人",
  569. isMust: true,
  570. content: "",
  571. controller: _receiveTicketController,
  572. hintText: "请输入收票人姓名",
  573. onChanged: (res) {},
  574. ),
  575. TextFieldItem(
  576. title: "收票人电话",
  577. isMust: true,
  578. content: "",
  579. controller: _receiveMebileController,
  580. hintText: "请输入收票人电话",
  581. keyboardType: TextInputType.phone,
  582. onChanged: (res) {},
  583. ),
  584. TextFieldItem(
  585. title: "收票人地址",
  586. isMust: true,
  587. content: "",
  588. controller: _receiveAddressController,
  589. hintText: "请输入收票人地址",
  590. onChanged: (res) {},
  591. ),
  592. ],
  593. )
  594. : Container(child: null),
  595. SizedBox(height: ScreenUtil().setWidth(80))
  596. ],
  597. ),
  598. ),
  599. ],
  600. ),
  601. Positioned(
  602. bottom: 0,
  603. left: 0,
  604. child: Container(
  605. width: width,
  606. padding: EdgeInsets.only(
  607. top: ScreenUtil().setWidth(15),
  608. bottom: ScreenUtil().setWidth(15),
  609. left: ScreenUtil().setWidth(25),
  610. right: ScreenUtil().setWidth(25)),
  611. color: ThemeUtils.getDialogTextFieldColor(context),
  612. child: Container(
  613. height: ScreenUtil().setWidth(44),
  614. decoration: BoxDecoration(
  615. borderRadius: BorderRadius.circular(
  616. ScreenUtil().setWidth(22)),
  617. color: Colours.blue_app_main),
  618. child: FlatButton(
  619. // padding: EdgeInsets.all(15.0),
  620. child: Text("提交"),
  621. textColor: Colors.white,
  622. // textColor: Colors.white,
  623. onPressed: () {
  624. if (!isTi) {
  625. toasts("提交中。。。");
  626. return;
  627. }
  628. isTi = false;
  629. // Navigator.pop(context);
  630. print(_emailController.text);
  631. print(555);
  632. RegExp exp = RegExp(r'^1[34578]\d{9}$');
  633. RegExp expEmail = RegExp(
  634. r"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
  635. if (piaotouId == null) {
  636. toasts("请选择发票抬头");
  637. return;
  638. }
  639. if (piaoType == 1 &&
  640. (_emailController.text == null ||
  641. _emailController.text.trim() == '')) {
  642. toasts("请输入电子邮箱");
  643. return;
  644. }
  645. if (piaoType == 2 &&
  646. (_receiveTicketController.text == null ||
  647. _receiveTicketController.text.trim() ==
  648. '')) {
  649. toasts("请输入收票人");
  650. return;
  651. }
  652. if (piaoType == 2 &&
  653. (_receiveMebileController.text == null ||
  654. _receiveMebileController.text.trim() ==
  655. '')) {
  656. toasts("请输入收票人电话");
  657. return;
  658. }
  659. if (piaoType == 2 &&
  660. (_receiveAddressController.text == null ||
  661. _receiveAddressController.text.trim() ==
  662. '')) {
  663. toasts("请输入收票人地址");
  664. return;
  665. }
  666. if (piaoType == 2 &&
  667. !exp.hasMatch(_receiveMebileController.text)) {
  668. toasts("请输入正确的收票人电话");
  669. return;
  670. }
  671. if (piaoType == 1 &&
  672. !expEmail.hasMatch(_emailController.text)) {
  673. toasts("请输入正确的邮箱");
  674. return;
  675. }
  676. applyInvoice();
  677. },
  678. ),
  679. ),
  680. ),
  681. )
  682. ],
  683. );
  684. },
  685. ),
  686. ),
  687. ),
  688. );
  689. }
  690. @override
  691. bool get wantKeepAlive => true;
  692. }