send_express_page.dart 44 KB

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