send_express_page.dart 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:city_pickers/city_pickers.dart';
  5. import 'package:flutter_picker/flutter_picker.dart';
  6. import 'dart:async';
  7. import 'send_express_page/order_detail_page.dart';
  8. import '../util/util.dart';
  9. import '../util/api.dart';
  10. import '../util/models.dart';
  11. import '../showAlert.dart';
  12. import '../send_Dialog.dart';
  13. import '../util/session.dart';
  14. class SendExpressPage extends StatefulWidget {
  15. final Widget child;
  16. SendExpressPage({
  17. Key key,
  18. this.child
  19. }): super(key: key);
  20. _SendExpressPageState createState() => _SendExpressPageState();
  21. }
  22. class _SendExpressPageState extends State < SendExpressPage > with AutomaticKeepAliveClientMixin {
  23. ScrollController _scrollController = ScrollController();
  24. //组件自用字段-----------------------------
  25. GlobalKey _sendPhoneKey = GlobalKey();
  26. GlobalKey _getPhoneKey = GlobalKey();
  27. double tipWidth = 0;
  28. double tipHeight = 0;
  29. double tipPosX = 0;
  30. double tipPosY = 0;
  31. bool tipStatus = true;
  32. bool submitStatus = true;
  33. List < LikePhoneList > likePhoneList = [];
  34. var timer;
  35. bool sendPhoneOrGetPhoneTab = true; //区分电话提示层点击时填入发件信息或手机信息的标记
  36. TextEditingController sendCompanyPhoneController = TextEditingController();
  37. TextEditingController sendCompanyCodeController = TextEditingController();
  38. TextEditingController sendCompanyNameController = TextEditingController();
  39. TextEditingController receiptCompanyPhoneController = TextEditingController();
  40. TextEditingController receiptCompanyNameController = TextEditingController();
  41. TextEditingController sendCompanyAddressController = TextEditingController();
  42. TextEditingController receiptCompanyAddressController = TextEditingController();
  43. List < dynamic > goodsCateGoryList = [];
  44. List < dynamic > goodsPackageList = [];
  45. //请求字段-------------------------
  46. String sendCompanyId = '0'; //寄件公司Id
  47. String sendCompanyName = ''; //寄件公司名称 不能为空
  48. String sendCompanyPhone = ''; //寄件公司电话 不能为空
  49. String sendCompanyCode = ''; //寄件公司编码
  50. String sendCompanyProvinceName = ''; //寄件公司省名称 不能为空
  51. String sendCompanyProvinceCode = ''; //寄件公司省编码 不能为空
  52. String sendCompanyCityName = ''; //寄件公司市名称 不能为空
  53. String sendCompanyCityCode = ''; //寄件公司市编码 不能为空
  54. String sendCompanyAreaName = ''; //寄件公司区名称 不能为空
  55. String sendCompanyAreaCode = ''; //寄件公司区编码 不能为空
  56. String sendCompanyAddress = ''; //寄件公司详细地址,不能为空
  57. String receiptCompanyId = '0'; //收件公司id
  58. String receiptCompanyPhone = ''; //收件公司电话 不能为空
  59. String receiptCompanyName = ''; //收件公司名称 不能为空
  60. String receiptCompanyProvinceName = ''; //收件公司省名称 不能为空
  61. String receiptCompanyProvinceCode = ''; //收件公司省编码 不能为空
  62. String receiptCompanyCityName = ''; //收件公司市名称 不能为空
  63. String receiptCompanyCityCode = ''; //收件公市编码 不能为空
  64. String receiptCompanyAreaName = ''; //收件公区名称 不能为空
  65. String receiptCompanyAreaCode = ''; //收件公司区编码 不能为空
  66. String receiptCompanyAddress = ''; //收件公司地址详情 不能为空
  67. String goods = ''; //商品名称 不能为空
  68. int goodsQuantity = 1; //商品数量 不能为空
  69. int goodsPackingId; //商品包装ID
  70. int goodsCategoryId; //商品类别ID
  71. int goodsPaymentMethod = 1; //付款方式 1,现付 2 到付
  72. double goodsWeight = 0.0; //商品重量
  73. double goodsPriceProtection = 0.0; //商品保价
  74. double goodsAgencyFund = 0.0; //商品代收款
  75. double goodsFreight = 0.0; //商品运费 不能为空
  76. String memo = ''; //备注
  77. String sendPCA = ' '; //Text组件内容必须有空格,否则报null
  78. String getPCA = ' ';
  79. String showTextGoodsCategory = ' ';
  80. String showTextGoodsPackage = ' ';
  81. String showTextPaymentMehod = '现付';
  82. @override
  83. void initState() {
  84. super.initState();
  85. goodsCategory().then((resp) {
  86. if (isNotError(context, resp)) {
  87. GoodsCategory goodsCategoryObj = GoodsCategory.fromJson(resp.data);
  88. setState(() {
  89. goodsCateGoryList = goodsCategoryObj.data;
  90. showTextGoodsCategory = goodsCateGoryList[0].name;
  91. goodsCategoryId = goodsCateGoryList[0].id;
  92. });
  93. }
  94. });
  95. goodsPackage().then((resp) {
  96. if (isNotError(context, resp)) {
  97. GoodsPackage goodsPackageObj = GoodsPackage.fromJson(resp.data);
  98. setState(() {
  99. goodsPackageList = goodsPackageObj.data;
  100. showTextGoodsPackage = goodsPackageList[0].name;
  101. goodsPackingId = goodsPackageList[0].id;
  102. });
  103. }
  104. });
  105. _scrollController.addListener(() {
  106. if (!tipStatus) {
  107. setState(() {
  108. tipStatus = true;
  109. });
  110. }
  111. //if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {}
  112. });
  113. sendCompanyPhoneController.addListener(() {
  114. setState(() {
  115. sendCompanyPhone = sendCompanyPhoneController.text;
  116. });
  117. if (timer != null) {
  118. timer.cancel();
  119. }
  120. if (sendCompanyPhoneController.text.length < 6 || sendCompanyPhoneController.text.length > 11) {
  121. setState(() {
  122. tipStatus = true;
  123. });
  124. }
  125. timer = Timer(Duration(milliseconds: 500), () {
  126. if (sendCompanyPhoneController.text.length >= 6 && sendCompanyPhoneController.text.length < 11) {
  127. likePhone(sendCompanyPhoneController.text).then((resp) {
  128. if (isNotError(context, resp)) {
  129. LikePhone likePhoneObj = LikePhone.fromJson(resp.data);
  130. likePhoneList = likePhoneObj.data;
  131. }
  132. if (likePhoneList.length > 0) {
  133. sendPhoneOrGetPhoneTab = true;
  134. RenderObject sendPhoneObj = _sendPhoneKey.currentContext.findRenderObject();
  135. setState(() {
  136. tipWidth = sendPhoneObj.paintBounds.size.width;
  137. tipHeight = sendPhoneObj.paintBounds.size.height;
  138. tipPosX = sendPhoneObj.getTransformTo(null).getTranslation().x;
  139. tipPosY = sendPhoneObj.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  140. tipStatus = false;
  141. });
  142. } else {
  143. setState(() {
  144. tipStatus = true;
  145. });
  146. }
  147. });
  148. }
  149. });
  150. });
  151. receiptCompanyPhoneController.addListener(() {
  152. setState(() {
  153. receiptCompanyPhone = receiptCompanyPhoneController.text;
  154. });
  155. if (timer != null) {
  156. timer.cancel();
  157. }
  158. if (receiptCompanyPhoneController.text.length < 6 || receiptCompanyPhoneController.text.length > 11) {
  159. setState(() {
  160. tipStatus = true;
  161. });
  162. }
  163. timer = Timer(Duration(milliseconds: 500), () {
  164. if (receiptCompanyPhoneController.text.length >= 6 && receiptCompanyPhoneController.text.length < 11) {
  165. likePhone(receiptCompanyPhoneController.text).then((resp) {
  166. if (isNotError(context, resp)) {
  167. LikePhone likePhoneObj = LikePhone.fromJson(resp.data);
  168. likePhoneList = likePhoneObj.data;
  169. }
  170. if (likePhoneList.length > 0) {
  171. sendPhoneOrGetPhoneTab = false;
  172. RenderObject getPhoneKey = _getPhoneKey.currentContext.findRenderObject();
  173. setState(() {
  174. tipWidth = getPhoneKey.paintBounds.size.width;
  175. tipHeight = getPhoneKey.paintBounds.size.height;
  176. tipPosX = getPhoneKey.getTransformTo(null).getTranslation().x;
  177. tipPosY = getPhoneKey.getTransformTo(null).getTranslation().y - ScreenUtil.getInstance().setHeight(90);
  178. tipStatus = false;
  179. });
  180. } else {
  181. setState(() {
  182. tipStatus = true;
  183. });
  184. }
  185. });
  186. }
  187. });
  188. });
  189. sendCompanyAddressController.addListener(() {
  190. setState(() {
  191. sendCompanyAddress = sendCompanyAddressController.text;
  192. });
  193. });
  194. receiptCompanyAddressController.addListener(() {
  195. setState(() {
  196. receiptCompanyAddress = receiptCompanyAddressController.text;
  197. });
  198. });
  199. }
  200. @override
  201. bool get wantKeepAlive => true;
  202. @override
  203. Widget build(BuildContext context) {
  204. return Container(
  205. child: Scaffold(
  206. appBar: AppBar(
  207. title: Text('发件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
  208. centerTitle: true,
  209. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  210. ),
  211. body:
  212. Stack(
  213. children: < Widget > [
  214. Container(
  215. color: Color.fromRGBO(246, 246, 254, 1),
  216. padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(20), 0, ScreenUtil.getInstance().setHeight(20)),
  217. child: ListView(
  218. controller: _scrollController,
  219. children: < Widget > [
  220. _sendInfo(context),
  221. _getInfo(context),
  222. _itemInfoWidget(),
  223. _submitBtn()
  224. ],
  225. ),
  226. ),
  227. Positioned(
  228. top: tipPosY,
  229. left: tipPosX,
  230. child: Offstage(
  231. offstage: tipStatus,
  232. child: Container(
  233. width: tipWidth,
  234. height: ScreenUtil.getInstance().setHeight(450),
  235. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  236. decoration: BoxDecoration(
  237. color: Color.fromRGBO(244, 248, 251, 1),
  238. ),
  239. child: ListView.builder(
  240. itemCount: likePhoneList.length,
  241. itemBuilder: (BuildContext context, int index) {
  242. return _tipItem(likePhoneList[index]);
  243. },
  244. )
  245. ),
  246. )
  247. )
  248. ],
  249. ),
  250. resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  251. ),
  252. );
  253. }
  254. Widget _sendInfo(BuildContext context) {
  255. return Container(
  256. color: Colors.white,
  257. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  258. child: Column(
  259. children: < Widget > [
  260. _titleWidget('lib/images/icon_send.png', '发件信息'),
  261. _underLine(),
  262. _inputWiget('电话', 'sendPhone'),
  263. _contentWiget('企业编码', 'send', true),
  264. _contentWiget('企业名称', 'send', true),
  265. _cityWiget('城市/区域', context, 'send'),
  266. _lastContentWiget('详细地址', 'send')
  267. ],
  268. )
  269. );
  270. }
  271. Widget _getInfo(BuildContext context) {
  272. return Container(
  273. color: Colors.white,
  274. margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
  275. child: Column(
  276. children: < Widget > [
  277. _titleWidget('lib/images/icon_shoujian.png', '收件信息'),
  278. _underLine(),
  279. _inputWiget('电话', 'getPhone'),
  280. //_contentWiget('企业编码', 'get', true),
  281. _contentWiget('企业名称', 'get', true),
  282. _cityWiget('城市/区域', context, 'get'),
  283. _lastContentWiget('详细地址', 'get')
  284. ],
  285. )
  286. );
  287. }
  288. Widget _itemInfoWidget() {
  289. return Container(
  290. child: Container(
  291. color: Colors.white,
  292. child: Column(
  293. crossAxisAlignment: CrossAxisAlignment.start,
  294. children: < Widget > [
  295. _titleWidget('lib/images/icon_huowu.png', "货物信息"),
  296. _underLine(),
  297. _contentWiget("货物名称", 'goods', true),
  298. _contentWiget("数量", 'goods'),
  299. _contentWiget("运费", 'goods'),
  300. _contentWiget("代收", 'goods'),
  301. _contentWiget("保价", 'goods'),
  302. _contentWiget("重量", 'goods'),
  303. _packageType('包装类型'),
  304. _packageType('商品类型'),
  305. _packageType('付款方式'),
  306. _descWidget()
  307. ],
  308. ),
  309. )
  310. );
  311. }
  312. Widget _titleWidget(String iconUrl, String str) {
  313. return Container(
  314. height: ScreenUtil.getInstance().setHeight(90),
  315. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  316. child: Center(
  317. child: Row(
  318. mainAxisAlignment: MainAxisAlignment.start,
  319. children: < Widget > [
  320. Padding(
  321. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
  322. child: Image.asset(
  323. iconUrl,
  324. width: ScreenUtil.getInstance().setWidth(40),
  325. height: ScreenUtil.getInstance().setHeight(40),
  326. )
  327. ),
  328. Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
  329. ],
  330. ),
  331. ),
  332. );
  333. }
  334. Widget _underLine() {
  335. return Container(
  336. color: Color.fromRGBO(223, 223, 223, 1),
  337. height: ScreenUtil.getInstance().setHeight(1),
  338. );
  339. }
  340. Widget _inputWiget(String key, String tab) {
  341. return Padding(
  342. key: tab == 'sendPhone' ? _sendPhoneKey : _getPhoneKey,
  343. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  344. child: Column(
  345. children: < Widget > [
  346. SizedBox(
  347. height: ScreenUtil.getInstance().setHeight(89),
  348. child: Center(
  349. child: Row(
  350. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  351. children: < Widget > [
  352. Expanded(
  353. flex: 0,
  354. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  355. ),
  356. Expanded(
  357. child: Row(
  358. mainAxisAlignment: MainAxisAlignment.end,
  359. children: < Widget > [
  360. SizedBox(
  361. width: ScreenUtil.getInstance().setWidth(500),
  362. child: TextField(
  363. controller: tab == 'sendPhone' ? sendCompanyPhoneController : receiptCompanyPhoneController,
  364. keyboardType: TextInputType.number,
  365. textAlign: TextAlign.end,
  366. decoration: InputDecoration(
  367. border: InputBorder.none
  368. ),
  369. onEditingComplete: () {
  370. setState(() {
  371. FocusScope.of(context).requestFocus(FocusNode());
  372. tipStatus = true;
  373. });
  374. },
  375. ),
  376. ),
  377. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  378. ],
  379. )
  380. )
  381. ],
  382. ),
  383. )
  384. ),
  385. Expanded(
  386. flex: 0,
  387. child: _underLine()
  388. )
  389. ],
  390. )
  391. );
  392. }
  393. Widget _contentWiget(String key, String type, [bool keyboardType = false]) { //false是数字键盘
  394. return Padding(
  395. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  396. child: Column(
  397. children: < Widget > [
  398. SizedBox(
  399. height: ScreenUtil.getInstance().setHeight(89),
  400. child: Center(
  401. child: Row(
  402. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  403. children: < Widget > [
  404. Expanded(
  405. flex: 0,
  406. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  407. ),
  408. Expanded(
  409. child: Row(
  410. mainAxisAlignment: MainAxisAlignment.end,
  411. children: < Widget > [
  412. SizedBox(
  413. width: ScreenUtil.getInstance().setWidth(500),
  414. child: TextField(
  415. controller: (key == '企业名称') ? (type == 'send' ? sendCompanyNameController : receiptCompanyNameController) : (key == '企业编码' ? sendCompanyCodeController : null),
  416. keyboardType: keyboardType ? TextInputType.text : TextInputType.number,
  417. textAlign: TextAlign.end,
  418. decoration: InputDecoration(
  419. border: InputBorder.none
  420. ),
  421. onChanged: (value) {
  422. if (type == 'send') {
  423. if (key == '企业编码') {
  424. setState(() {
  425. sendCompanyCode = value;
  426. });
  427. } else if (key == '企业名称') {
  428. setState(() {
  429. sendCompanyName = value;
  430. });
  431. }
  432. } else if (type == 'get') {
  433. if (key == '企业编码') {
  434. setState(() {
  435. sendCompanyCode = value;
  436. });
  437. } else if (key == '企业名称') {
  438. setState(() {
  439. receiptCompanyName = value;
  440. });
  441. }
  442. } else {
  443. if (key == '货物名称') {
  444. goods = value;
  445. } else if (key == '数量') {
  446. goodsQuantity = int.parse(value);
  447. } else if (key == '运费') {
  448. goodsFreight = double.parse(value);
  449. String temp = goodsFreight.toStringAsFixed(1);
  450. goodsFreight = double.parse(temp);
  451. } else if (key == '代收') {
  452. goodsAgencyFund = double.parse(value);
  453. String temp = goodsAgencyFund.toStringAsFixed(1);
  454. goodsAgencyFund = double.parse(temp);
  455. } else if (key == '保价') {
  456. goodsPriceProtection = double.parse(value);
  457. String temp = goodsPriceProtection.toStringAsFixed(1);
  458. goodsPriceProtection = double.parse(temp);
  459. } else if (key == '重量') {
  460. goodsWeight = double.parse(value);
  461. String temp = goodsWeight.toStringAsFixed(1);
  462. goodsWeight = double.parse(temp);
  463. }
  464. }
  465. },
  466. ),
  467. ),
  468. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  469. ],
  470. )
  471. )
  472. ],
  473. ),
  474. )
  475. ),
  476. Expanded(
  477. flex: 0,
  478. child: _underLine()
  479. )
  480. ],
  481. )
  482. );
  483. }
  484. Widget _cityWiget(String key, BuildContext context, String type) {
  485. return
  486. GestureDetector(
  487. child: Padding(
  488. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  489. child: Column(
  490. children: < Widget > [
  491. SizedBox(
  492. height: ScreenUtil.getInstance().setHeight(89),
  493. child: Center(
  494. child: Row(
  495. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  496. children: < Widget > [
  497. Expanded(
  498. flex: 0,
  499. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  500. ),
  501. Expanded(
  502. child: Row(
  503. mainAxisAlignment: MainAxisAlignment.end,
  504. children: < Widget > [
  505. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  506. SizedBox(
  507. width: ScreenUtil.getInstance().setWidth(500),
  508. child: Text(type == 'send' ? sendPCA : getPCA, textAlign: TextAlign.end, overflow: TextOverflow.ellipsis, )
  509. ),
  510. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  511. ],
  512. )
  513. )
  514. ],
  515. ),
  516. )
  517. ),
  518. Expanded(
  519. flex: 0,
  520. child: _underLine()
  521. )
  522. ],
  523. )
  524. ),
  525. onTap: () {
  526. getCity(context).then((resp) {
  527. if (resp == null) {
  528. return;
  529. }
  530. print(resp.toString());
  531. setState(() {
  532. if (type == 'send') {
  533. sendPCA = resp.provinceName + ' ' + resp.cityName + ' ' + ' ' + resp.areaName;
  534. sendCompanyProvinceName = resp.provinceName;
  535. sendCompanyProvinceCode = resp.provinceId;
  536. sendCompanyCityName = resp.cityName;
  537. sendCompanyCityCode = resp.cityId;
  538. sendCompanyAreaName = resp.areaName;
  539. sendCompanyAreaCode = resp.areaId;
  540. } else {
  541. getPCA = resp.provinceName + ' ' + resp.cityName + ' ' + ' ' + resp.areaName;
  542. receiptCompanyProvinceName = resp.provinceName;
  543. receiptCompanyProvinceCode = resp.provinceId;
  544. receiptCompanyCityName = resp.cityName;
  545. receiptCompanyCityCode = resp.cityId;
  546. receiptCompanyAreaName = resp.areaName;
  547. receiptCompanyAreaCode = resp.areaId;
  548. }
  549. });
  550. //print(value);
  551. });
  552. },
  553. );
  554. }
  555. Widget _lastContentWiget(String key, String type) {
  556. return Padding(
  557. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  558. child: SizedBox(
  559. height: ScreenUtil.getInstance().setHeight(89),
  560. child: Center(
  561. child: Row(
  562. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  563. children: < Widget > [
  564. Expanded(
  565. flex: 0,
  566. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  567. ),
  568. Expanded(
  569. child: Row(
  570. mainAxisAlignment: MainAxisAlignment.end,
  571. children: < Widget > [
  572. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  573. SizedBox(
  574. width: ScreenUtil.getInstance().setWidth(500),
  575. child: TextField(
  576. controller: type == 'send' ? sendCompanyAddressController : receiptCompanyAddressController,
  577. textAlign: TextAlign.end,
  578. decoration: InputDecoration(
  579. border: InputBorder.none
  580. ),
  581. ),
  582. ),
  583. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  584. ],
  585. )
  586. )
  587. ],
  588. ),
  589. )
  590. )
  591. );
  592. }
  593. Widget _descWidget() {
  594. return
  595. Container(
  596. padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
  597. //child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  598. child: TextField(
  599. maxLines: 3,
  600. decoration: InputDecoration(
  601. border: InputBorder.none,
  602. hintText: "请输入备注内容"
  603. ),
  604. onChanged: (value) {
  605. setState(() {
  606. memo = value;
  607. });
  608. },
  609. ),
  610. );
  611. }
  612. Widget _submitBtn() {
  613. return GestureDetector(
  614. child: Container(
  615. margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
  616. height: ScreenUtil.getInstance().setHeight(88),
  617. decoration: BoxDecoration(
  618. borderRadius: BorderRadius.all(Radius.circular(4)),
  619. color: Color.fromRGBO(37, 102, 242, 1),
  620. ),
  621. child: Center(
  622. child: Row(
  623. mainAxisAlignment: MainAxisAlignment.center,
  624. children: < Widget > [
  625. Offstage(
  626. offstage: submitStatus,
  627. child: SizedBox(
  628. width: ScreenUtil.getInstance().setWidth(45),
  629. height: ScreenUtil.getInstance().setHeight(45),
  630. child: Image.asset('lib/images/loading.gif'),
  631. ),
  632. ),
  633. Text("提交", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Colors.white), ),
  634. ],
  635. )
  636. ),
  637. ),
  638. onTap: () {
  639. if (!submitStatus) {
  640. return;
  641. }
  642. String errStr = '';
  643. print('sendCompanyId---${sendCompanyId}');
  644. print('sendCompanyName---${sendCompanyName}');
  645. print('sendCompanyPhone---${sendCompanyPhone}');
  646. print('sendCompanyCode---${sendCompanyCode}');
  647. print('sendCompanyProvinceName---${sendCompanyProvinceName}');
  648. print('sendCompanyProvinceCode---${sendCompanyProvinceCode}');
  649. print('sendCompanyCityName---${sendCompanyCityName}');
  650. print('sendCompanyCityCode---${sendCompanyCityCode}');
  651. print('sendCompanyAreaName---${sendCompanyAreaName}');
  652. print('sendCompanyAreaCode---${sendCompanyAreaCode}');
  653. print('sendCompanyAddress---${sendCompanyAddress}');
  654. print('receiptCompanyId---${receiptCompanyId}');
  655. print('receiptCompanyPhone---${receiptCompanyPhone}');
  656. print('receiptCompanyName---${receiptCompanyName}');
  657. print('receiptCompanyProvinceName---${receiptCompanyProvinceName}');
  658. print('receiptCompanyProvinceCode---${receiptCompanyProvinceCode}');
  659. print('receiptCompanyCityName---${receiptCompanyCityName}');
  660. print('receiptCompanyCityCode---${receiptCompanyCityCode}');
  661. print('receiptCompanyAreaName---${receiptCompanyAreaName}');
  662. print('receiptCompanyAreaCode---${receiptCompanyAreaCode}');
  663. print('receiptCompanyAddress---${receiptCompanyAddress}');
  664. print('goods---${goods}');
  665. print('goodsQuantity---${goodsQuantity}');
  666. print('goodsPackingId---${goodsPackingId}');
  667. print('goodsCategoryId---${goodsCategoryId}');
  668. print('goodsPaymentMethod---${goodsPaymentMethod}');
  669. print('goodsWeight---${goodsWeight}');
  670. print('goodsPriceProtection---${goodsPriceProtection}');
  671. print('goodsAgencyFund---${goodsAgencyFund}');
  672. print('goodsFreight---${goodsFreight}');
  673. print('memo---${memo}');
  674. // if (!isChinaPhoneLegal(sendCompanyPhone)) {
  675. // }
  676. if (sendCompanyPhone == '') {
  677. errStr = '请填写发件电话';
  678. }
  679. if (sendCompanyName == '') {
  680. errStr = '请填写发件企业名称';
  681. }
  682. if (sendCompanyProvinceName == '') {
  683. errStr = '请填写发件城市/区域';
  684. }
  685. if (sendCompanyAddress == '') {
  686. errStr = '请填写发件详细地址';
  687. }
  688. if (receiptCompanyPhone == '') {
  689. errStr = '请填写收件电话';
  690. }
  691. if (receiptCompanyName == '') {
  692. errStr = '请填写收件企业名称';
  693. }
  694. if (receiptCompanyProvinceName == '') {
  695. errStr = '请填写收件城市/区域';
  696. }
  697. if (receiptCompanyAddress == '') {
  698. errStr = '请填写收件详细地址';
  699. }
  700. if (goods == '') {
  701. errStr = '请填写货物名称';
  702. }
  703. if (goodsQuantity == 0) {
  704. errStr = '请填写货物数量';
  705. }
  706. if (int.tryParse(goodsQuantity.toString()) == null) {
  707. errStr = '货物数量格式错误';
  708. }
  709. if (goodsFreight == 0.0) {
  710. errStr = '请填写运费';
  711. }
  712. if (int.tryParse(sendCompanyPhone) == null || int.tryParse(receiptCompanyPhone) == null || sendCompanyPhone.length != 11 || receiptCompanyPhone.length != 11) {
  713. errStr = '请输入正确的电话';
  714. }
  715. if (errStr != '') {
  716. showError(errStr);
  717. return;
  718. }
  719. setState(() {
  720. submitStatus = false;
  721. });
  722. getKey('stationId').then((value) {
  723. createOrder(
  724. value,
  725. sendCompanyId, //寄件公司Id
  726. sendCompanyName, //寄件公司名称 不能为空
  727. sendCompanyPhone, //寄件公司电话 不能为空
  728. sendCompanyCode ?? '', //寄件公司编码
  729. sendCompanyProvinceName, //寄件公司省名称 不能为空
  730. sendCompanyProvinceCode, //寄件公司省编码 不能为空
  731. sendCompanyCityName, //寄件公司市名称 不能为空
  732. sendCompanyCityCode, //寄件公司市编码 不能为空
  733. sendCompanyAreaName, //寄件公司区名称 不能为空
  734. sendCompanyAreaCode, //寄件公司区编码 不能为空
  735. sendCompanyAddress, //寄件公司详细地址,不能为空
  736. receiptCompanyId, //收件公司id
  737. receiptCompanyPhone, //收件公司电话 不能为空
  738. receiptCompanyName, //收件公司名称 不能为空
  739. receiptCompanyProvinceName, //收件公司省名称 不能为空
  740. receiptCompanyProvinceCode, //收件公司省编码 不能为空
  741. receiptCompanyCityName, //收件公司市名称 不能为空
  742. receiptCompanyCityCode, //收件公市编码 不能为空
  743. receiptCompanyAreaName, //收件公区名称 不能为空
  744. receiptCompanyAreaCode, //收件公司区编码 不能为空
  745. receiptCompanyAddress, //收件公司地址详情 不能为空
  746. goods, //商品名称 不能为空
  747. goodsQuantity, //商品数量 不能为空
  748. goodsPackingId, //商品包装ID
  749. goodsCategoryId, //商品类别ID
  750. goodsPaymentMethod, //付款方式 1,现付 2 到付
  751. goodsWeight, //商品重量
  752. goodsPriceProtection * 100, //商品保价,已分为单位
  753. goodsAgencyFund * 100, //商品代收款,已分为单位
  754. goodsFreight * 100, //商品运费 不能为空 ,已分为单位
  755. memo, //备注
  756. ).then((resp) {
  757. if (isNotError(context, resp)) {
  758. setState(() {
  759. submitStatus = true;
  760. });
  761. CreateOrder orderObj = CreateOrder.fromJson(resp.data);
  762. showDialog < Null > (
  763. context: context, //BuildContext对象
  764. barrierDismissible: false,
  765. builder: (BuildContext context) {
  766. return SendDialog( //调用对话框
  767. orderNo: orderObj.orderNo,
  768. childCallback: (val) {
  769. if (!val) {
  770. //跳转
  771. Navigator.push(context, MaterialPageRoute(builder: (context) {
  772. return OrderDetail(orderId: orderObj.orderNo, );
  773. }));
  774. }
  775. },
  776. );
  777. });
  778. } else {
  779. setState(() {
  780. submitStatus = true;
  781. });
  782. }
  783. });
  784. });
  785. },
  786. );
  787. }
  788. showError(String str) {
  789. showDialog < Null > (
  790. context: context, //BuildContext对象
  791. barrierDismissible: false,
  792. builder: (BuildContext context) {
  793. return MyAlertDialog( //调用对话框
  794. text: str, childCallback: (val) {},
  795. );
  796. });
  797. }
  798. Future getCity(context) async {
  799. Result result = await CityPickers.showCityPicker(
  800. context: context,
  801. );
  802. return result;
  803. }
  804. Widget _tipItem(LikePhoneList obj) {
  805. return Container(
  806. child: Column(
  807. children: < Widget > [
  808. InkWell(
  809. child: Container(
  810. height: ScreenUtil.getInstance().setHeight(89),
  811. child: Center(
  812. child: Row(
  813. mainAxisAlignment: MainAxisAlignment.start,
  814. children: < Widget > [
  815. Padding(
  816. padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(50)),
  817. child: Text(obj.uzerPhone, style: TextStyle(
  818. fontSize: ScreenUtil.getInstance().setSp(28),
  819. color: Color.fromRGBO(74, 74, 74, 1)
  820. ), )
  821. ),
  822. SizedBox(
  823. width: ScreenUtil.getInstance().setWidth(185),
  824. child: Text(obj.areaCode,
  825. textAlign: TextAlign.left,
  826. style: TextStyle(
  827. fontSize: ScreenUtil.getInstance().setSp(28),
  828. color: Color.fromRGBO(155, 155, 155, 1)
  829. ), ),
  830. ),
  831. Text(obj.companyName,
  832. textAlign: TextAlign.left,
  833. overflow: TextOverflow.ellipsis,
  834. style: TextStyle(
  835. fontSize: ScreenUtil.getInstance().setSp(28),
  836. color: Color.fromRGBO(155, 155, 155, 1)
  837. ),
  838. )
  839. ],
  840. ),
  841. ),
  842. ),
  843. onTap: () {
  844. if (sendPhoneOrGetPhoneTab) {
  845. sendCompanyPhone = obj.uzerPhone;
  846. sendCompanyCode = obj.companyCode;
  847. sendCompanyName = obj.companyName;
  848. sendCompanyId = obj.id.toString();
  849. sendCompanyPhoneController.text = obj.uzerPhone;
  850. sendCompanyCodeController.text = obj.companyCode;
  851. sendCompanyNameController.text = obj.companyName;
  852. sendPCA = obj.provinceName + ' ' + obj.cityName + ' ' + ' ' + obj.areaName;
  853. sendCompanyProvinceName = obj.provinceName;
  854. sendCompanyProvinceCode = obj.provinceCode;
  855. sendCompanyCityName = obj.cityName;
  856. sendCompanyCityCode = obj.cityCode;
  857. sendCompanyAreaName = obj.areaName;
  858. sendCompanyAreaCode = obj.areaCode;
  859. sendCompanyAddressController.text = obj.address;
  860. } else {
  861. receiptCompanyPhone = obj.uzerPhone;
  862. receiptCompanyName = obj.companyName;
  863. receiptCompanyPhoneController.text = obj.uzerPhone;
  864. receiptCompanyNameController.text = obj.companyName;
  865. receiptCompanyId = obj.id.toString();
  866. getPCA = obj.provinceName + ' ' + obj.cityName + ' ' + ' ' + obj.areaName;
  867. receiptCompanyProvinceName = obj.provinceName;
  868. receiptCompanyProvinceCode = obj.provinceCode;
  869. receiptCompanyCityName = obj.cityName;
  870. receiptCompanyCityCode = obj.cityCode;
  871. receiptCompanyAreaName = obj.areaName;
  872. receiptCompanyAreaCode = obj.areaCode;
  873. receiptCompanyAddressController.text = obj.address;
  874. }
  875. setState(() {
  876. FocusScope.of(context).requestFocus(FocusNode());
  877. tipStatus = true;
  878. });
  879. },
  880. ),
  881. _underLine()
  882. ],
  883. ),
  884. );
  885. }
  886. Widget _packageType(String key) {
  887. return Padding(
  888. padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
  889. child: Column(
  890. children: < Widget > [
  891. InkWell(
  892. child: SizedBox(
  893. height: ScreenUtil.getInstance().setHeight(89),
  894. child: Center(
  895. child: Row(
  896. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  897. children: < Widget > [
  898. Expanded(
  899. flex: 0,
  900. child: Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
  901. ),
  902. Expanded(
  903. child: Row(
  904. mainAxisAlignment: MainAxisAlignment.end,
  905. children: < Widget > [
  906. //Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
  907. SizedBox(
  908. width: ScreenUtil.getInstance().setWidth(500),
  909. child: Text(key == '包装类型' ? showTextGoodsPackage : key == '商品类型' ? showTextGoodsCategory : showTextPaymentMehod, textAlign: TextAlign.end, )
  910. ),
  911. Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
  912. ],
  913. )
  914. )
  915. ],
  916. ),
  917. )
  918. ),
  919. onTap: () {
  920. showPickerModal(context, key);
  921. },
  922. ),
  923. Expanded(
  924. flex: 0,
  925. child: _underLine()
  926. )
  927. ],
  928. )
  929. );
  930. }
  931. showPickerModal(BuildContext context, String type) {
  932. List < dynamic > data = [];
  933. if (type == '包装类型') {
  934. for (int i = 0; i < goodsPackageList.length; i++) {
  935. data.add(goodsPackageList[i].name);
  936. }
  937. } else if (type == '商品类型') {
  938. for (int i = 0; i < goodsCateGoryList.length; i++) {
  939. data.add(goodsCateGoryList[i].name);
  940. }
  941. } else if (type == '付款方式') {
  942. data = ['现付', '到付'];
  943. }
  944. new Picker(
  945. adapter: PickerDataAdapter < String > (pickerdata: data),
  946. height: ScreenUtil.getInstance().setHeight(450),
  947. confirmText: '确定',
  948. confirmTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(64, 98, 254, 1)),
  949. cancelText: '取消',
  950. cancelTextStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(153, 153, 153, 1)),
  951. headercolor: Color.fromRGBO(245, 245, 245, 1),
  952. itemExtent: ScreenUtil.getInstance().setHeight(80),
  953. textStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(42, 42, 42, 1)),
  954. changeToFirst: true,
  955. hideHeader: false,
  956. onConfirm: (Picker picker, List value) {
  957. if (type == '包装类型') {
  958. setState(() {
  959. showTextGoodsPackage = goodsPackageList[value[0]].name;
  960. goodsPackingId = goodsPackageList[value[0]].id;
  961. });
  962. } else if (type == '商品类型') {
  963. showTextGoodsCategory = goodsCateGoryList[value[0]].name;
  964. goodsCategoryId = goodsCateGoryList[value[0]].id;
  965. } else if (type == '付款方式') {
  966. showTextPaymentMehod = data[value[0]];
  967. if (showTextPaymentMehod == '现付') {
  968. goodsPaymentMethod = 1;
  969. } else {
  970. goodsPaymentMethod = 2;
  971. }
  972. }
  973. }
  974. ).showModal(this.context); //_scaffoldKey.currentState);
  975. }
  976. }