RecieveInfoViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using Muchinfo.MTPClient.Data.Enums;
  4. using Muchinfo.MTPClient.Infrastructure.Utilities;
  5. using Muchinfo.MTPClient.IService;
  6. using System.Windows;
  7. using System.Linq;
  8. using Muchinfo.MTPClient.Data.Model.Delivery;
  9. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  10. using Muchinfo.MTPClient.Resources;
  11. using System.Collections.Generic;
  12. using System;
  13. using Muchinfo.MTPClient.Infrastructure.Helpers;
  14. using Muchinfo.MTPClient.Data;
  15. using GalaSoft.MvvmLight.Ioc;
  16. namespace Muchinfo.MTPClient.Delivery.ViewModels
  17. {
  18. /// <summary>
  19. /// 仓单提货人信息
  20. /// <para>
  21. /// </para>
  22. /// </summary>
  23. public class RecieveInfoViewModel : ViewModelBase
  24. {
  25. #region "=========私有成员/Private Data Members"
  26. protected IDeliveryService _deliveryService;
  27. private Window _openWindow;
  28. private DeliveryWarehouse _itemWarehouse;
  29. #endregion "Private Data Members"
  30. #region "=========构造函数/Constructor/Initialization"
  31. public RecieveInfoViewModel(DeliveryWarehouse itemWarehouse)
  32. {
  33. this._itemWarehouse = itemWarehouse;
  34. GoodsName = itemWarehouse.DeliveryGoodsCodeNameDisplay;
  35. GoodsUnitIdDisplay = itemWarehouse.GoodsUnitIdDisplay;
  36. AvailableQty = itemWarehouse.Qty - itemWarehouse.FreezeQty - itemWarehouse.PayQty;
  37. //RecieveAddress = itemWarehouse.address;
  38. //RecievePerson = itemWarehouse.personname;
  39. //PhoneNum = itemWarehouse.telphone;
  40. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  41. CheckRecievePersonInfo();
  42. }
  43. #endregion "Constructor/Initialization"
  44. #region "=========接口重写/Interface implementation Or override"
  45. //To do interface implementation
  46. #endregion "Interface implementation Or override"
  47. #region "=========公共属性/Public Properties To Get/Set "
  48. #region 交易商品名称
  49. private string _goodsName = string.Empty;
  50. /// <summary>
  51. /// 交易商品名称
  52. /// </summary>
  53. public string GoodsName
  54. {
  55. get
  56. {
  57. return _goodsName;
  58. }
  59. set
  60. {
  61. Set(() => GoodsName, ref _goodsName, value);
  62. }
  63. }
  64. #endregion
  65. #region 可用数量
  66. private decimal _availableQty = decimal.Zero;
  67. /// <summary>
  68. /// Sets and gets the Qty property.
  69. /// </summary>
  70. public decimal AvailableQty
  71. {
  72. get
  73. {
  74. return _availableQty;
  75. }
  76. set
  77. {
  78. Set(() => AvailableQty, ref _availableQty, value);
  79. }
  80. }
  81. #endregion
  82. #region 商品单位
  83. private string _GoodsUnitIdDisplay = string.Empty;
  84. /// <summary>
  85. /// 商品单位
  86. /// </summary>
  87. public string GoodsUnitIdDisplay
  88. {
  89. get
  90. {
  91. return _GoodsUnitIdDisplay;
  92. }
  93. set
  94. {
  95. Set(() => GoodsUnitIdDisplay, ref _GoodsUnitIdDisplay, value);
  96. }
  97. }
  98. #endregion
  99. #region 当前勾选单据
  100. private List<OutStoreReqDetailModel> _currentSelectedOutStore = null;
  101. /// <summary>
  102. /// 当前勾选的提货单据LIST
  103. /// </summary>
  104. public List<OutStoreReqDetailModel> CurrentSelectedOutStore
  105. {
  106. get
  107. {
  108. return _currentSelectedOutStore;
  109. }
  110. set
  111. {
  112. Set(() => CurrentSelectedOutStore, ref _currentSelectedOutStore, value);
  113. }
  114. }
  115. #endregion
  116. #region 按钮是否可用
  117. private bool _oKButtonEnabled = true;
  118. /// <summary>
  119. ///按钮是否可用
  120. /// </summary>
  121. public bool OKButtonEnabled
  122. {
  123. get
  124. {
  125. return _oKButtonEnabled;
  126. }
  127. set
  128. {
  129. Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
  130. }
  131. }
  132. #endregion
  133. #region 是否忙
  134. private bool _isBusy;
  135. /// <summary>
  136. /// 是否忙
  137. /// </summary>
  138. public bool IsBusy
  139. {
  140. get { return _isBusy; }
  141. set { Set(() => IsBusy, ref _isBusy, value); }
  142. }
  143. #endregion
  144. #region 收货人
  145. private string _RecievePerson = string.Empty;
  146. /// <summary>
  147. /// 收货人
  148. /// </summary>
  149. public string RecievePerson
  150. {
  151. get
  152. {
  153. return _RecievePerson;
  154. }
  155. set
  156. {
  157. Set(() => RecievePerson, ref _RecievePerson, value);
  158. }
  159. }
  160. #endregion
  161. #region 收货地址
  162. private string _RecieveAddress = string.Empty;
  163. /// <summary>
  164. /// 收货地址
  165. /// </summary>
  166. public string RecieveAddress
  167. {
  168. get
  169. {
  170. return _RecieveAddress;
  171. }
  172. set
  173. {
  174. Set(() => RecieveAddress, ref _RecieveAddress, value);
  175. }
  176. }
  177. #endregion
  178. #region 联系方式
  179. private string _PhoneNum = string.Empty;
  180. /// <summary>
  181. /// 联系方式
  182. /// </summary>
  183. public string PhoneNum
  184. {
  185. get
  186. {
  187. return _PhoneNum;
  188. }
  189. set
  190. {
  191. Set(() => PhoneNum, ref _PhoneNum, value);
  192. }
  193. }
  194. #endregion
  195. private string _IdCardNum;
  196. /// <summary>
  197. /// 證件號
  198. /// </summary>
  199. public string IdCardNum
  200. {
  201. get
  202. {
  203. return _IdCardNum;
  204. }
  205. set
  206. {
  207. Set(() => IdCardNum, ref _IdCardNum, value);
  208. }
  209. }
  210. private TakeGoodsWay _TakeGoodsWay;
  211. public TakeGoodsWay TakeGoodsWay
  212. {
  213. get
  214. {
  215. return _TakeGoodsWay;
  216. }
  217. set
  218. {
  219. Set(() => TakeGoodsWay, ref _TakeGoodsWay, value);
  220. }
  221. }
  222. #region 是否可以修改
  223. private bool _isEnableToWrite = false;
  224. /// <summary>
  225. /// 是否可以修改
  226. /// </summary>
  227. public bool IsEnableToWrite
  228. {
  229. get
  230. {
  231. return _isEnableToWrite;
  232. }
  233. set
  234. {
  235. Set(() => IsEnableToWrite, ref _isEnableToWrite, value);
  236. }
  237. }
  238. #endregion
  239. #region 当前账号提货人信息
  240. private DepositPersonalInfoRspModel _currentDepositPersonalInfo;
  241. /// <summary>
  242. /// 当前账号提货人信息
  243. /// </summary>
  244. public DepositPersonalInfoRspModel CurrentDepositPersonalInfo
  245. {
  246. get
  247. {
  248. return _currentDepositPersonalInfo;
  249. }
  250. set
  251. {
  252. Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value);
  253. }
  254. }
  255. #endregion
  256. #endregion "Public Properties To Get/Set "
  257. #region "=========公共命令/Public Commands"
  258. #region 取消选中Command
  259. /// <summary>
  260. /// 取消选中
  261. /// </summary>
  262. private RelayCommand unSelectCommand;
  263. public RelayCommand UnSelectCommand
  264. {
  265. get
  266. {
  267. return unSelectCommand ?? (unSelectCommand = new RelayCommand(
  268. () =>
  269. {
  270. //SettlementSelectedOutStore();
  271. }));
  272. }
  273. }
  274. #endregion
  275. #region 提交确定Command
  276. /// <summary>
  277. /// 提交确定
  278. /// </summary>
  279. public RelayCommand<Window> OKCommand
  280. {
  281. get
  282. {
  283. return new RelayCommand<Window>((dialog) =>
  284. {
  285. CurrentSelectedOutStore = new List<OutStoreReqDetailModel>();
  286. CurrentSelectedOutStore.Add(new OutStoreReqDetailModel() { WRId = (_itemWarehouse.WRID), StoreOutQty = ((_itemWarehouse.Qty - _itemWarehouse.FreezeQty - _itemWarehouse.PayQty)) });
  287. OKButtonEnabled = false;
  288. string errorMsg = string.Empty;
  289. bool validateBool = Validated(ref errorMsg); ////内容验证
  290. if (validateBool)
  291. {
  292. IsBusy = true;
  293. _openWindow = dialog;
  294. var newOrder = new OutStoreReqModel()
  295. {
  296. //申请
  297. OperateType = (int)TakaGoodsOperateType.Apply,
  298. RecievePerson = RecievePerson,
  299. RecieveAddress = string.IsNullOrWhiteSpace(RecieveAddress) ? "--" : RecieveAddress.Trim(),
  300. PhoneNum = PhoneNum.Trim(),
  301. IdCardNum = IdCardNum.Trim(),
  302. TakeGoodsWay =TakeGoodsWay,
  303. OutStoreDetail = CurrentSelectedOutStore
  304. };
  305. if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  306. UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  307. {
  308. newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  309. }
  310. else
  311. {
  312. newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.AccountId;
  313. }
  314. try
  315. {
  316. _deliveryService.SubmitOutStoreReq(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  317. }
  318. finally
  319. {
  320. }
  321. }
  322. else
  323. {
  324. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  325. OKButtonEnabled = true;
  326. }
  327. });
  328. }
  329. }
  330. #endregion
  331. #region 窗口取消Command
  332. /// <summary>
  333. /// 窗口取消
  334. /// </summary>
  335. public RelayCommand<Window> CancelCommand
  336. {
  337. get
  338. {
  339. return new RelayCommand<Window>((dialog) =>
  340. {
  341. dialog.DialogResult = false;
  342. });
  343. }
  344. }
  345. #endregion
  346. #endregion "Public Commands"
  347. #region "=========私有方法/Private Methods"
  348. /// <summary>
  349. /// 检查收货人信息
  350. /// </summary>
  351. private void CheckRecievePersonInfo()
  352. {
  353. if (_itemWarehouse != null)
  354. {
  355. RecieveAddress = _itemWarehouse.address;
  356. RecievePerson = _itemWarehouse.personname;
  357. PhoneNum = _itemWarehouse.telphone;
  358. IdCardNum = _itemWarehouse.IdCardNum;
  359. TakeGoodsWay = _itemWarehouse.TakeGoodsWay == TakeGoodsWay.Express?TakeGoodsWay.Express:TakeGoodsWay.Self;
  360. return;
  361. }
  362. IsEnableToWrite = false;
  363. if (string.IsNullOrEmpty(RecievePerson))
  364. {
  365. //读取登录人基本信息
  366. GetDepositPersonalInfo();
  367. IsEnableToWrite = true;
  368. }
  369. }
  370. /// <summary>
  371. /// 获取交割提货个人信息
  372. /// </summary>
  373. private void GetDepositPersonalInfo()
  374. {
  375. var accountid = UserManager.CurrentTradeAccount.AccountId;
  376. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  377. //{
  378. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  379. //}
  380. var ReqModel = new DepositPersonalInfoReqModel();
  381. ReqModel.accountId = (long)accountid;
  382. IsBusy = true;
  383. //交割提货个人信息查询
  384. _deliveryService.SearchDepositPersonalInfoReq(ReqModel, QueryDepositPersonalInfoSuccess, QueryDepositPersonalInfoCallBack);
  385. }
  386. /// <summary>
  387. /// 交割提货个人信息-成功返回
  388. /// </summary>
  389. /// <param name="orders"></param>
  390. protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel)
  391. {
  392. TakeGoodsWay = TakeGoodsWay.Self;
  393. if (itemModel != null)
  394. {
  395. CurrentDepositPersonalInfo = itemModel;
  396. if (CurrentDepositPersonalInfo != null)
  397. {
  398. RecieveAddress = CurrentDepositPersonalInfo.address;
  399. RecievePerson = CurrentDepositPersonalInfo.personName;
  400. PhoneNum = CurrentDepositPersonalInfo.telphone;
  401. }
  402. }
  403. IsBusy = false;
  404. }
  405. /// <summary>
  406. /// 获取交割提货个人信息失败返回
  407. /// </summary>
  408. /// <param name="errorEntity"></param>
  409. private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity)
  410. {
  411. IsBusy = false;
  412. }
  413. /// <summary>
  414. /// 提交提货成功返回
  415. /// </summary>
  416. /// <param name="order"></param>
  417. private void EntrurstSuccessCallBack(OutStoreRspModel order)
  418. {
  419. IsBusy = false;
  420. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  421. {
  422. OKButtonEnabled = true;
  423. //提货成功
  424. MessageBoxHelper.ShowSuccess(Client_Resource.Order_TakaDeliveryGoods_Success_Result,
  425. Client_Resource.UI2014_Tips);
  426. if (_openWindow != null)
  427. {
  428. _openWindow.Close();
  429. this.Cleanup();
  430. }
  431. }));
  432. //刷新正常单
  433. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  434. }
  435. /// <summary>
  436. /// 提货委托失败返回
  437. /// </summary>
  438. /// <param name="errorEntity"></param>
  439. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  440. {
  441. IsBusy = false;
  442. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  443. {
  444. OKButtonEnabled = true;
  445. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  446. if (_openWindow != null)
  447. {
  448. _openWindow.Close();
  449. this.Cleanup();
  450. }
  451. }));
  452. }
  453. #endregion "Private Methods"
  454. #region "=========其它方法/Other Methods"
  455. /// <summary>
  456. /// 数据验证
  457. /// </summary>
  458. /// <param name="msg"></param>
  459. /// <returns></returns>
  460. public bool Validated(ref string msg)
  461. {
  462. if (string.IsNullOrWhiteSpace(RecievePerson))
  463. {
  464. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecievePerson + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
  465. return false;
  466. }
  467. if (TakeGoodsWay == TakeGoodsWay.Express && string.IsNullOrWhiteSpace(RecieveAddress))
  468. {
  469. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecieveAddress + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
  470. return false;
  471. }
  472. if (string.IsNullOrWhiteSpace(PhoneNum))
  473. {
  474. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNum + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
  475. return false;
  476. }
  477. if (!string.IsNullOrWhiteSpace(PhoneNum) && !PhoneNum.StartsWith("1") || PhoneNum.Length != 11 || !ValidationHelper.IsMobile(PhoneNum))
  478. {
  479. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNumErrFormat;
  480. return false;
  481. }
  482. if (String.IsNullOrWhiteSpace(IdCardNum) || !ValidationHelper.IsIDcard(IdCardNum.Trim()))
  483. {
  484. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_IDCardNumErrFormat;
  485. return false;
  486. }
  487. return true;
  488. }
  489. #endregion "Other Methods"
  490. }
  491. }