BankSignQueryViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. //----------------------------------------------------------------
  7. //Module Name: $safeprojectname$
  8. //Purpose:
  9. //CopyRight: Muchinfo
  10. //History:
  11. //----------------------------------------------------------------
  12. //DateTime 2017/3/14 16:19:23
  13. //Author
  14. //Description Create
  15. //----------------------------------------------------------------
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using GalaSoft.MvvmLight;
  19. using GalaSoft.MvvmLight.Command;
  20. using GalaSoft.MvvmLight.Ioc;
  21. using Muchinfo.MTPClient.Bank.Views;
  22. using Muchinfo.MTPClient.CustomException;
  23. using Muchinfo.MTPClient.Data;
  24. using Muchinfo.MTPClient.Data.Enums;
  25. using Muchinfo.MTPClient.Data.Model.Account;
  26. using Muchinfo.MTPClient.Data.Model.Bank;
  27. using Muchinfo.MTPClient.Data.Model.Config;
  28. using Muchinfo.MTPClient.Infrastructure.Helpers;
  29. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  30. using Muchinfo.MTPClient.Infrastructure.Utilities;
  31. using Muchinfo.MTPClient.Infrastructure.Windows;
  32. using Muchinfo.MTPClient.IService;
  33. using Muchinfo.MTPClient.Resources;
  34. using Muchinfo.PC.Common.Bosn;
  35. using Muchinfo.PC.Common.Extensions;
  36. using Muchinfo.PC.Common.Helpers;
  37. namespace Muchinfo.MTPClient.Bank.ViewModels
  38. {
  39. public class BankSignQueryViewModel : QueryPanelModelBase
  40. {
  41. private bool _isBusy;
  42. /// <summary>
  43. /// 是否忙,显示等待控件
  44. /// </summary>
  45. public bool IsBusy
  46. {
  47. get { return _isBusy; }
  48. set { Set(() => IsBusy, ref _isBusy, value); }
  49. }
  50. private IBankService _bankService;
  51. private List<SigningBank> _signingBanks;
  52. /// <summary>
  53. /// 签约银行信息
  54. /// </summary>
  55. public List<SigningBank> SigningBanks
  56. {
  57. get { return _signingBanks; }
  58. set { Set(() => SigningBanks, ref _signingBanks, value); }
  59. }
  60. private SigningBank _currentSigningBank;
  61. /// <summary>
  62. /// 当前选中签约银行
  63. /// </summary>
  64. public SigningBank CurrentSigningBank
  65. {
  66. get
  67. {
  68. return _currentSigningBank;
  69. }
  70. set
  71. {
  72. Set(() => CurrentSigningBank, ref _currentSigningBank, value);
  73. }
  74. }
  75. public BankSignQueryViewModel()
  76. {
  77. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  78. RefreshContent();
  79. }
  80. /// <summary>
  81. /// 查询签约信息回应
  82. /// </summary>
  83. /// <param name="list"></param>
  84. private void SearchBankCustomerSignCallback(List<SigningBank> list)
  85. {
  86. //#if DEBUG
  87. // list.Add(new SigningBank()
  88. // {
  89. // AccountCode =UserManager.CurrentTradeAccount.AccountCode,
  90. // AccountName = UserManager.CurrentTradeAccount.CustomerName,
  91. // ExchId = "111",
  92. // CusBankID = 38,
  93. // AccountType = UserManager.CurrentTradeAccount.AccountType,
  94. // Name = "民生市场通",
  95. // BankAccount = "44587857854755788985",
  96. // AppDateTime = ApplicationParameter.ServerTimeNow.ToString("yyyy-MM-dd HH:mm"),
  97. // BankId = 438+string.Empty,
  98. // BankCardType = 2,
  99. // CredentialType = eCardType.IDCARD,
  100. // CredentialNumber="447858785693561255",
  101. // SignStatusType = SignStatus.SignStatus_Signed,
  102. // });
  103. //#endif
  104. var BandIDList = ApplicationParameter.CusBankNetSign.Split(',');
  105. foreach (var signingBank in list)
  106. {
  107. if (BandIDList.Contains(signingBank.CusBankID + string.Empty))
  108. {
  109. signingBank.IsShowUnSignBtn = false;
  110. }
  111. signingBank.IsConfingCard = ApplicationParameter.IsConfigShowBingCard == 1;
  112. }
  113. IsBusy = false;
  114. if (ApplicationParameter.NewBankPlatform == 1) ////新银行平台
  115. {
  116. SigningBanks = list.Where((item) => item.ShowCancelSign == 0).ToList() ;
  117. }
  118. else
  119. {
  120. SigningBanks = new List<SigningBank>(list.Where((item) => item.ShowCancelSign == 0 && item.SignStatusType == SignStatus.SignStatus_Signed));
  121. }
  122. }
  123. public void ErrorCallback(ErrorEntity error)
  124. {
  125. IsBusy = false;
  126. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  127. {
  128. ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true);
  129. }));
  130. }
  131. /// <summary>
  132. /// 解约操作
  133. /// </summary>
  134. public RelayCommand TerminationCommand
  135. {
  136. get
  137. {
  138. return new RelayCommand(() =>
  139. {
  140. if (CurrentSigningBank == null) return;
  141. if (!string.IsNullOrEmpty(CurrentSigningBank.CancleSignShowField))
  142. {
  143. //根据当前所选签约银行,配置输入字段
  144. string[] CancleSignShowField = this.CurrentSigningBank.CancleSignShowField.Split(',');
  145. if (CancleSignShowField.Contains(((int) ShowFieldStatus.ShowField_Draw_IdentifyCode) +
  146. string.Empty) ||
  147. CancleSignShowField.Contains(((int) ShowFieldStatus.ShowField_IdentifyCode) + string.Empty))
  148. {
  149. ///需要密码或电话验证码弹出
  150. var signView = new TerminationSignView(CurrentSigningBank, CancleSignShowField){Owner = Application.Current.MainWindow,WindowStartupLocation = WindowStartupLocation.CenterOwner};
  151. signView.ShowDialog();
  152. return;
  153. }
  154. }
  155. var result =
  156. MessageBoxHelper.ShowQuestion(string.Format(Client_Resource
  157. .Bank_UnSignTips , CurrentSigningBank.CusBankName),
  158. Client_Resource.APP_Tips);
  159. if (MessageBoxResult.Yes == result)
  160. {
  161. CurrentSigningBank.CurrentTime = ApplicationParameter.ServerTimeNow;
  162. CurrentSigningBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId;
  163. //CurrentSigningBank.AccountCode = UserManager.CurrentTradeAccount.AccountCode;
  164. //CurrentSigningBank.CustomerName = UserManager.CurrentTradeAccount.CustomerName;
  165. CurrentSigningBank.AccountType = UserManager.CurrentTradeAccount.AccountType;
  166. IsBusy = true;
  167. _bankService.BankCaneclSign(CurrentSigningBank, UnSignBankCallback, ErrorCallback);
  168. }
  169. });
  170. }
  171. }
  172. private RelayCommand<SigningBank> _UnBingCardCommand;
  173. /// <summary>
  174. /// 解绑银行卡
  175. /// </summary>
  176. public RelayCommand<SigningBank> UnBingCardCommand
  177. {
  178. get
  179. {
  180. return _UnBingCardCommand ?? (_UnBingCardCommand = new RelayCommand<SigningBank>((sign) =>
  181. {
  182. if (sign != null)
  183. {
  184. var result= MessageBoxHelper.ShowQuestion(
  185. Muchinfo.MTPClient.Resources.Client_Resource
  186. .Tips_BankUnBindCardComfrim,
  187. Muchinfo.MTPClient.Resources.Client_Resource
  188. .APP_Tips);
  189. if (result == MessageBoxResult.Yes)
  190. {
  191. IsBusy = true;
  192. _bankService.BankUnBindBankCard(sign, BankUnBindCardSuccess, ErrorCallback);
  193. }
  194. }
  195. }));
  196. }
  197. }
  198. private void BankUnBindCardSuccess(BankUnBindResult bankResult)
  199. {
  200. IsBusy = false;
  201. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  202. {
  203. if (bankResult.ReturnCode == 0)
  204. {
  205. //switch (bankResult.Status)
  206. //{
  207. // case BankDealStatus.BankDealStatus__Succeed:
  208. if (string.IsNullOrWhiteSpace(bankResult.WebAddress))
  209. {
  210. MessageBoxHelper.ShowSuccess(
  211. Muchinfo.MTPClient.Resources.Client_Resource
  212. .Tips_BankunBindCardSuccess,
  213. Muchinfo.MTPClient.Resources.Client_Resource
  214. .APP_Tips);
  215. }
  216. // break;
  217. //case BankDealStatus.BankDealStatus__Pend:
  218. // MessageBoxHelper.ShowSuccess(
  219. // Muchinfo.MTPClient.Resources.Client_Resource
  220. // .Bank_BankTerminationInfoSubmit_Wait,
  221. // Muchinfo.MTPClient.Resources.Client_Resource
  222. // .APP_Tips);
  223. // break;
  224. // case BankDealStatus.BankDealStatus__BankWebComfirm:
  225. else
  226. {
  227. try
  228. {
  229. IPHelper.OpenWebAddress(bankResult.WebAddress);
  230. }
  231. catch (Exception)
  232. {
  233. throw new MuchinfoException(ExceptionManager.OpenIEError);
  234. }
  235. finally
  236. {
  237. var messageBox = new MsgAlter(bankResult.WebAddress,
  238. Client_Resource.Tips_BankunBindCardWebComfrim)
  239. {
  240. Owner = System.Windows.Application.Current.MainWindow,
  241. WindowStartupLocation = WindowStartupLocation.CenterOwner
  242. };
  243. messageBox.Show();
  244. }
  245. }
  246. // break;
  247. // }
  248. }
  249. else
  250. {
  251. var errorEntriy = new ErrorEntity()
  252. {
  253. ReturnCode = bankResult.ReturnCode,
  254. ReturnDesc = bankResult.ReturnDesc,
  255. RequestFunc = Client_Resource.Function_BankUnBindBankCard
  256. };
  257. ErrorManager.ShowReturnError(errorEntriy,
  258. Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips, true);
  259. }
  260. }));
  261. }
  262. private RelayCommand<SigningBank> _BankBingCardCommand;
  263. /// <summary>
  264. /// 绑银行卡
  265. /// </summary>
  266. public RelayCommand<SigningBank> BankBingCardCommand
  267. {
  268. get
  269. {
  270. return _BankBingCardCommand ?? (_BankBingCardCommand = new RelayCommand<SigningBank>((sign) =>
  271. {
  272. if (sign != null)
  273. {
  274. var bindCard = new BindCardView(sign) { ShowInTaskbar = false, Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner };
  275. bindCard.ShowDialog();
  276. RefreshContent();
  277. }
  278. }));
  279. }
  280. }
  281. /// <summary>
  282. /// 解约操作
  283. /// </summary>
  284. public RelayCommand SignCommand
  285. {
  286. get
  287. {
  288. return new RelayCommand(() =>
  289. {
  290. var sign = new BankSigningView() { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner };
  291. sign.ShowDialog();
  292. });
  293. }
  294. }
  295. /// <summary>
  296. /// 修改手机号
  297. /// </summary>
  298. public RelayCommand ModifyPhoneCommand
  299. {
  300. get
  301. {
  302. return new RelayCommand(() =>
  303. {
  304. var sign = new MotifyPhoneView(CurrentSigningBank) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner };
  305. sign.ShowDialog();
  306. });
  307. }
  308. }
  309. /// <summary>
  310. /// 查询资金信息
  311. /// </summary>
  312. public RelayCommand BalanceCommand
  313. {
  314. get
  315. {
  316. return new RelayCommand(() =>
  317. {
  318. if (CurrentSigningBank == null) return;
  319. var queryBank = new BankBalanceView(CurrentSigningBank) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner };
  320. queryBank.ShowDialog();
  321. });
  322. }
  323. }
  324. private void UnSignBankCallback(BankSignResult result)
  325. {
  326. IsBusy = false;
  327. var bankDealStatus = result;
  328. RefreshContent();
  329. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  330. {
  331. if (result.ReturnCode == 0)
  332. {
  333. switch (bankDealStatus.Status)
  334. {
  335. case BankDealStatus.BankDealStatus__Succeed:
  336. MessageBoxHelper.ShowSuccess(
  337. Muchinfo.MTPClient.Resources.Client_Resource
  338. .Bank_TerminationSuccess,
  339. Muchinfo.MTPClient.Resources.Client_Resource
  340. .Bank_BankTerminationTips);
  341. break;
  342. case BankDealStatus.BankDealStatus__Pend:
  343. MessageBoxHelper.ShowSuccess(
  344. Muchinfo.MTPClient.Resources.Client_Resource
  345. .Bank_BankTerminationInfoSubmit_Wait,
  346. Muchinfo.MTPClient.Resources.Client_Resource
  347. .Bank_BankTerminationTips);
  348. break;
  349. case BankDealStatus.BankDealStatus__BankWebComfirm:
  350. try
  351. {
  352. IPHelper.OpenWebAddress(bankDealStatus.WebAddress);
  353. }
  354. catch (Exception)
  355. {
  356. throw new MuchinfoException(ExceptionManager.OpenIEError);
  357. }
  358. finally
  359. {
  360. var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankUnSignWebComfrim)
  361. {
  362. Owner = System.Windows.Application.Current.MainWindow,
  363. WindowStartupLocation = WindowStartupLocation.CenterOwner
  364. };
  365. messageBox.Show();
  366. }
  367. break;
  368. }
  369. }
  370. else
  371. {
  372. ErrorManager.ShowReturnError(bankDealStatus.ReturnCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips);
  373. }
  374. }));
  375. }
  376. #region
  377. public override void RegisterMessage()
  378. {
  379. RefreshContent();
  380. //当选择时刷新
  381. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.SignNotify, (e) =>
  382. {
  383. RefreshContent();
  384. });
  385. }
  386. /// <summary>
  387. /// 取消注册
  388. /// </summary>
  389. public override void UnRegisterMessage()
  390. {
  391. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.SignNotify);
  392. base.UnRegisterMessage();
  393. }
  394. public override void RefreshContent()
  395. {
  396. var accountid = UserManager.CurrentTradeAccount.AccountId;
  397. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  398. //{
  399. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  400. //}
  401. IsBusy = true;
  402. _bankService.QueryBankCustomerSignInfo(accountid, SearchBankCustomerSignCallback, ErrorCallback);
  403. }
  404. #endregion
  405. }
  406. }