piaotou.dart 32 KB

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