piaotou.dart 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  5. import 'package:liftmanager/internal/wode/model/piao_tou_model.dart';
  6. import 'package:liftmanager/internal/wode/presenter/piao_tou_list_presenter.dart';
  7. import 'package:liftmanager/internal/wode/wode_router.dart';
  8. import 'package:liftmanager/mvp/base_page_state.dart';
  9. import 'package:liftmanager/net/api_service.dart';
  10. import 'package:liftmanager/res/resources.dart';
  11. import 'package:liftmanager/routers/fluro_navigator.dart';
  12. import 'package:liftmanager/utils/fast_notification.dart';
  13. import 'package:liftmanager/utils/theme_utils.dart';
  14. import 'package:liftmanager/utils/toast.dart';
  15. import 'package:liftmanager/widgets/app_bar.dart';
  16. import 'package:liftmanager/widgets/my_refresh_list.dart';
  17. import 'package:liftmanager/widgets/state_layout.dart';
  18. import 'package:provider/provider.dart';
  19. class Piaotou extends StatefulWidget {
  20. Piaotou(this.checkTou, this.type);
  21. final String checkTou;
  22. final String type;
  23. @override
  24. PiaotouState createState() => PiaotouState();
  25. }
  26. class PiaotouState extends BasePageState<Piaotou, PiaotouListPresenter> {
  27. BaseListProvider<Records> provider = BaseListProvider<Records>();
  28. int _page = 1;
  29. @override
  30. void initState() {
  31. provider.setStateTypeNotNotify(StateType.loading);
  32. super.initState();
  33. _onRefresh();
  34. print("tou6666");
  35. FastNotification.addListener("initThis", (initThisString) {
  36. setState(() {});
  37. _onRefresh();
  38. });
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. double width = MediaQuery.of(context).size.width;
  43. double height = MediaQuery.of(context).size.height;
  44. return ChangeNotifierProvider<BaseListProvider<Records>>(
  45. create: (_) => provider,
  46. child: Scaffold(
  47. // resizeToAvoidBottomPadding: true,
  48. appBar: MyAppBar(
  49. centerTitle: "发票抬头",
  50. ),
  51. body: Container(
  52. color: Color(0xFFF6F6F6),
  53. child: Column(
  54. crossAxisAlignment: CrossAxisAlignment.start,
  55. children: <Widget>[
  56. widget.checkTou != "checkTou"
  57. ? GestureDetector(
  58. onTap: () {
  59. NavigatorUtils.push(context,
  60. "${WodeRouter.piaotouEdit}?type=add&id=");
  61. },
  62. child: Container(
  63. color: ThemeUtils.getDialogTextFieldColor(context),
  64. width: width,
  65. padding: EdgeInsets.only(
  66. left: ScreenUtil().setWidth(15),
  67. right: ScreenUtil().setWidth(15),
  68. top: ScreenUtil().setWidth(10),
  69. bottom: ScreenUtil().setWidth(10)),
  70. child: Row(
  71. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  72. children: <Widget>[
  73. Text(
  74. "添加发票抬头",
  75. textAlign: TextAlign.left,
  76. style: TextStyle(
  77. fontSize: ScreenUtil().setSp(15),
  78. ),
  79. ),
  80. Icon(
  81. Icons.keyboard_arrow_right,
  82. color: Color(0xffcccccc),
  83. ),
  84. ]),
  85. ),
  86. )
  87. : Container(
  88. child: null,
  89. ),
  90. Expanded(
  91. flex: 1,
  92. child: Consumer<BaseListProvider<Records>>(
  93. builder: (_, provider, __) {
  94. return MyListView(
  95. key: Key('piao_tou_list'),
  96. itemCount: provider.list.length,
  97. stateType: provider.stateType,
  98. onRefresh: _onRefresh,
  99. loadMore: _loadMore,
  100. pageSize: 10,
  101. hasMore: provider.hasMore,
  102. itemBuilder: (_, index) {
  103. return Container(
  104. // height: 20,
  105. padding: EdgeInsets.only(
  106. left: 10, bottom: 15, top: 15, right: 10),
  107. margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
  108. decoration: BoxDecoration(
  109. color: Colors.white,
  110. borderRadius:
  111. BorderRadius.all(Radius.circular(5.0)),
  112. ),
  113. child: GestureDetector(
  114. behavior: HitTestBehavior.opaque,
  115. onTap: () {
  116. print(456);
  117. if (widget.checkTou == "checkTou") {
  118. Navigator.pop(context);
  119. dynamic piaoTouObj = provider.list[index];
  120. FastNotification.push(
  121. "piaoTou", piaoTouObj);
  122. } else {
  123. NavigatorUtils.push(context,
  124. "${WodeRouter.piaotouEdit}?type=edit&id=${provider.list[index].id.toString()}");
  125. }
  126. },
  127. child: Column(
  128. children: [
  129. Row(
  130. crossAxisAlignment:
  131. CrossAxisAlignment.center,
  132. children: <Widget>[
  133. Text(
  134. provider.list[index].name ?? "",
  135. style: TextStyle(
  136. color: Color(0xff333333),
  137. fontSize:
  138. ScreenUtil().setSp(15)),
  139. textAlign: TextAlign.start,
  140. ),
  141. provider.list[index].isDefault == 1
  142. ? Container(
  143. margin:
  144. EdgeInsets.only(left: 10),
  145. padding: EdgeInsets.only(
  146. left: 5, right: 5),
  147. decoration: BoxDecoration(
  148. color:
  149. Colours.blue_app_main,
  150. borderRadius:
  151. BorderRadius.all(
  152. Radius.circular(
  153. 5.0)),
  154. ),
  155. child: Text(
  156. "默认",
  157. style: TextStyle(
  158. color: Colors.white,
  159. fontSize: ScreenUtil()
  160. .setSp(13)),
  161. textAlign: TextAlign.start,
  162. ),
  163. )
  164. : Container(child: null)
  165. ]),
  166. Row(
  167. crossAxisAlignment:
  168. CrossAxisAlignment.center,
  169. children: <Widget>[
  170. Text(
  171. "发票类型:",
  172. style: TextStyle(
  173. color: Color(0xff999999),
  174. fontSize:
  175. ScreenUtil().setSp(14)),
  176. textAlign: TextAlign.start,
  177. ),
  178. Container(
  179. padding: EdgeInsets.only(left: 5),
  180. child: Text(
  181. provider.list[index].type == 1
  182. ? "个人"
  183. : "公司",
  184. style: TextStyle(
  185. color: Color(0xff999999),
  186. fontSize:
  187. ScreenUtil().setSp(14)),
  188. textAlign: TextAlign.start,
  189. ),
  190. )
  191. ]),
  192. provider.list[index].type == 2
  193. ? Row(
  194. // crossAxisAlignment:
  195. // CrossAxisAlignment.center,
  196. // mainAxisAlignment:
  197. // MainAxisAlignment.center,
  198. children: <Widget>[
  199. Text(
  200. "税号:",
  201. style: TextStyle(
  202. color: Color(0xff999999),
  203. fontSize: ScreenUtil()
  204. .setSp(14)),
  205. textAlign: TextAlign.start,
  206. ),
  207. Container(
  208. padding:
  209. EdgeInsets.only(left: 5),
  210. child: Text(
  211. provider.list[index]
  212. .enterpriseNumber ??
  213. "",
  214. style: TextStyle(
  215. color:
  216. Color(0xff999999),
  217. fontSize: ScreenUtil()
  218. .setSp(14)),
  219. textAlign: TextAlign.start,
  220. ),
  221. )
  222. ])
  223. : Container(),
  224. Row(
  225. crossAxisAlignment:
  226. CrossAxisAlignment.end,
  227. mainAxisAlignment: MainAxisAlignment.end,
  228. children: [
  229. InkWell(
  230. onTap: () {
  231. showAlert(
  232. context,
  233. "提示",
  234. "确定要删除吗?",
  235. "确定",
  236. () {
  237. Navigator.pop(context);
  238. showLoading(
  239. context, "正在删除...");
  240. getTouDelete(provider
  241. .list[index].id
  242. .toString());
  243. },
  244. txt2: "取消",
  245. onPre2: () {
  246. NavigatorUtils.goBack(
  247. context);
  248. });
  249. },
  250. child: Container(
  251. padding: EdgeInsets.fromLTRB(
  252. 8, 1, 8, 1),
  253. decoration: BoxDecoration(
  254. border: new Border.all(
  255. width: 1,
  256. color: Colors.black),
  257. color: Colors.white,
  258. borderRadius: BorderRadius.all(
  259. Radius.circular(18.0)),
  260. ),
  261. child: Text('删除'),
  262. )),
  263. SizedBox(
  264. width: 10,
  265. ),
  266. InkWell(
  267. onTap: () {
  268. NavigatorUtils.push(context,
  269. "${WodeRouter.piaotouEdit}?type=edit&id=${provider.list[index].id.toString()}");
  270. },
  271. child: Container(
  272. padding:
  273. EdgeInsets.fromLTRB(8, 1, 8, 1),
  274. decoration: BoxDecoration(
  275. border: new Border.all(
  276. width: 1,
  277. color: Colors.black),
  278. color: Colors.white,
  279. borderRadius: BorderRadius.all(
  280. Radius.circular(18.0)),
  281. ),
  282. child: Text('编辑'),
  283. ),
  284. )
  285. ],
  286. )
  287. ],
  288. ),
  289. )
  290. // Row(
  291. // crossAxisAlignment: CrossAxisAlignment.start,
  292. // children: <Widget>[
  293. // Expanded(
  294. // child: GestureDetector(
  295. // behavior: HitTestBehavior.opaque,
  296. // onTap: () {
  297. // print(456);
  298. // if (widget.checkTou == "checkTou") {
  299. // Navigator.pop(context);
  300. // dynamic piaoTouObj = provider.list[index];
  301. // FastNotification.push(
  302. // "piaoTou", piaoTouObj);
  303. // } else {
  304. // NavigatorUtils.push(context,
  305. // "${WodeRouter.piaotouEdit}?type=edit&id=${provider.list[index].id.toString()}");
  306. // }
  307. // },
  308. // child: Row(
  309. // crossAxisAlignment:
  310. // CrossAxisAlignment.start,
  311. // children: <Widget>[
  312. // Expanded(
  313. // child: Container(
  314. // padding: EdgeInsets.only(
  315. // right: 15, left: 15),
  316. // child: Column(
  317. // children: <Widget>[
  318. // Container(
  319. // child: Row(
  320. // mainAxisAlignment:
  321. // MainAxisAlignment
  322. // .spaceBetween,
  323. // children: <Widget>[
  324. // Row(
  325. // crossAxisAlignment:
  326. // CrossAxisAlignment
  327. // .center,
  328. // children: <
  329. // Widget>[
  330. // Text(
  331. // provider
  332. // .list[
  333. // index]
  334. // .name ??
  335. // "",
  336. // style: TextStyle(
  337. // color: Color(
  338. // 0xff333333),
  339. // fontSize:
  340. // ScreenUtil()
  341. // .setSp(15)),
  342. // textAlign:
  343. // TextAlign
  344. // .start,
  345. // ),
  346. // provider.list[index].isDefault ==
  347. // 1
  348. // ? Container(
  349. // padding:
  350. // EdgeInsets.only(left: 5),
  351. // child:
  352. // Text(
  353. // "(默认)",
  354. // style: TextStyle(
  355. // color: Color(0xffff0000),
  356. // fontSize: ScreenUtil().setSp(15)),
  357. // textAlign:
  358. // TextAlign.start,
  359. // ),
  360. // )
  361. // : Container(
  362. // child:
  363. // null)
  364. // ]),
  365. // widget.checkTou !=
  366. // "checkTou"
  367. // ? Icon(
  368. // const IconData(
  369. // 0xe626,
  370. // fontFamily:
  371. // "myfont"),
  372. // size: 18.0,
  373. // color: Color(
  374. // 0xff666666),
  375. // )
  376. // : Container(
  377. // child: null,
  378. // ),
  379. // // Text("123")
  380. // ])),
  381. // Container(
  382. // child: Row(
  383. // mainAxisAlignment:
  384. // MainAxisAlignment
  385. // .spaceBetween,
  386. // children: <Widget>[
  387. // Row(
  388. // crossAxisAlignment:
  389. // CrossAxisAlignment
  390. // .center,
  391. // children: <
  392. // Widget>[
  393. // Text(
  394. // "发票类型:",
  395. // style: TextStyle(
  396. // color: Color(
  397. // 0xff999999),
  398. // fontSize:
  399. // ScreenUtil()
  400. // .setSp(14)),
  401. // textAlign:
  402. // TextAlign
  403. // .start,
  404. // ),
  405. // Container(
  406. // padding: EdgeInsets
  407. // .only(
  408. // left:
  409. // 5),
  410. // child: Text(
  411. // provider.list[index].type ==
  412. // 1
  413. // ? "个人"
  414. // : "公司",
  415. // style: TextStyle(
  416. // color: Color(
  417. // 0xff999999),
  418. // fontSize:
  419. // ScreenUtil().setSp(14)),
  420. // textAlign:
  421. // TextAlign
  422. // .start,
  423. // ),
  424. // )
  425. // ]),
  426. // ])),
  427. // provider.list[index].type ==
  428. // 2
  429. // ? Container(
  430. // child: Row(
  431. // mainAxisAlignment:
  432. // MainAxisAlignment
  433. // .spaceBetween,
  434. // children: <
  435. // Widget>[
  436. // Row(
  437. // crossAxisAlignment:
  438. // CrossAxisAlignment
  439. // .center,
  440. // mainAxisAlignment:
  441. // MainAxisAlignment
  442. // .center,
  443. // children: <
  444. // Widget>[
  445. // Text(
  446. // "税号:",
  447. // style: TextStyle(
  448. // color:
  449. // Color(0xff999999),
  450. // fontSize: ScreenUtil().setSp(14)),
  451. // textAlign:
  452. // TextAlign.start,
  453. // ),
  454. // Container(
  455. // padding:
  456. // EdgeInsets.only(left: 5),
  457. // child:
  458. // Text(
  459. // provider.list[index].enterpriseNumber ??
  460. // "",
  461. // style: TextStyle(
  462. // color: Color(0xff999999),
  463. // fontSize: ScreenUtil().setSp(14)),
  464. // textAlign:
  465. // TextAlign.start,
  466. // ),
  467. // )
  468. // ]),
  469. // ]))
  470. // : Container(
  471. // child: null),
  472. // ],
  473. // )))
  474. // ]),
  475. // )),
  476. // ],
  477. // ),
  478. );
  479. },
  480. );
  481. }))
  482. ],
  483. ),
  484. ),
  485. ));
  486. }
  487. Future _onRefresh() async {
  488. _page = 1;
  489. await presenter.getList(
  490. _page,
  491. widget.type != null && widget.type != ""
  492. ? int.parse(widget.type)
  493. : null);
  494. }
  495. Future _loadMore() async {
  496. _page++;
  497. await presenter.getList(
  498. _page,
  499. widget.type != null && widget.type != ""
  500. ? int.parse(widget.type)
  501. : null);
  502. }
  503. Future getTouDelete(id) async {
  504. await NewApiService().getTouDelete(int.parse(id), onSuccess: (res) {
  505. toasts("删除成功");
  506. String initThisString = randomInt(1111, 9999).toString() +
  507. DateTime.now().millisecondsSinceEpoch.toString();
  508. FastNotification.push("initThis", initThisString);
  509. Navigator.of(context).pop();
  510. // setState(() {});
  511. // _onRefresh();
  512. }, onError: (code, msg) {
  513. toasts(msg);
  514. });
  515. }
  516. @override
  517. PiaotouListPresenter createPresenter() {
  518. return PiaotouListPresenter();
  519. }
  520. }