using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2017/3/14 16:19:23 //Author //Description Create //---------------------------------------------------------------- using System.Threading.Tasks; using System.Windows; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Bank.Views; using Muchinfo.MTPClient.CustomException; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Bank; using Muchinfo.MTPClient.Data.Model.Config; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Infrastructure.Windows; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using Muchinfo.PC.Common.Bosn; using Muchinfo.PC.Common.Extensions; using Muchinfo.PC.Common.Helpers; namespace Muchinfo.MTPClient.Bank.ViewModels { public class BankSignQueryViewModel : QueryPanelModelBase { private bool _isBusy; /// /// 是否忙,显示等待控件 /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } private IBankService _bankService; private List _signingBanks; /// /// 签约银行信息 /// public List SigningBanks { get { return _signingBanks; } set { Set(() => SigningBanks, ref _signingBanks, value); } } private SigningBank _currentSigningBank; /// /// 当前选中签约银行 /// public SigningBank CurrentSigningBank { get { return _currentSigningBank; } set { Set(() => CurrentSigningBank, ref _currentSigningBank, value); } } public BankSignQueryViewModel() { _bankService = SimpleIoc.Default.GetInstance(); RefreshContent(); } /// /// 查询签约信息回应 /// /// private void SearchBankCustomerSignCallback(List list) { //#if DEBUG // list.Add(new SigningBank() // { // AccountCode =UserManager.CurrentTradeAccount.AccountCode, // AccountName = UserManager.CurrentTradeAccount.CustomerName, // ExchId = "111", // CusBankID = 38, // AccountType = UserManager.CurrentTradeAccount.AccountType, // Name = "民生市场通", // BankAccount = "44587857854755788985", // AppDateTime = ApplicationParameter.ServerTimeNow.ToString("yyyy-MM-dd HH:mm"), // BankId = 438+string.Empty, // BankCardType = 2, // CredentialType = eCardType.IDCARD, // CredentialNumber="447858785693561255", // SignStatusType = SignStatus.SignStatus_Signed, // }); //#endif var BandIDList = ApplicationParameter.CusBankNetSign.Split(','); foreach (var signingBank in list) { if (BandIDList.Contains(signingBank.CusBankID + string.Empty)) { signingBank.IsShowUnSignBtn = false; } signingBank.IsConfingCard = ApplicationParameter.IsConfigShowBingCard == 1; } IsBusy = false; if (ApplicationParameter.NewBankPlatform == 1) ////新银行平台 { SigningBanks = list.Where((item) => item.ShowCancelSign == 0).ToList() ; } else { SigningBanks = new List(list.Where((item) => item.ShowCancelSign == 0 && item.SignStatusType == SignStatus.SignStatus_Signed)); } } public void ErrorCallback(ErrorEntity error) { IsBusy = false; System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true); })); } /// /// 解约操作 /// public RelayCommand TerminationCommand { get { return new RelayCommand(() => { if (CurrentSigningBank == null) return; if (!string.IsNullOrEmpty(CurrentSigningBank.CancleSignShowField)) { //根据当前所选签约银行,配置输入字段 string[] CancleSignShowField = this.CurrentSigningBank.CancleSignShowField.Split(','); if (CancleSignShowField.Contains(((int) ShowFieldStatus.ShowField_Draw_IdentifyCode) + string.Empty) || CancleSignShowField.Contains(((int) ShowFieldStatus.ShowField_IdentifyCode) + string.Empty)) { ///需要密码或电话验证码弹出 var signView = new TerminationSignView(CurrentSigningBank, CancleSignShowField){Owner = Application.Current.MainWindow,WindowStartupLocation = WindowStartupLocation.CenterOwner}; signView.ShowDialog(); return; } } var result = MessageBoxHelper.ShowQuestion(string.Format(Client_Resource .Bank_UnSignTips , CurrentSigningBank.CusBankName), Client_Resource.APP_Tips); if (MessageBoxResult.Yes == result) { CurrentSigningBank.CurrentTime = ApplicationParameter.ServerTimeNow; CurrentSigningBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId; //CurrentSigningBank.AccountCode = UserManager.CurrentTradeAccount.AccountCode; //CurrentSigningBank.CustomerName = UserManager.CurrentTradeAccount.CustomerName; CurrentSigningBank.AccountType = UserManager.CurrentTradeAccount.AccountType; IsBusy = true; _bankService.BankCaneclSign(CurrentSigningBank, UnSignBankCallback, ErrorCallback); } }); } } private RelayCommand _UnBingCardCommand; /// /// 解绑银行卡 /// public RelayCommand UnBingCardCommand { get { return _UnBingCardCommand ?? (_UnBingCardCommand = new RelayCommand((sign) => { if (sign != null) { var result= MessageBoxHelper.ShowQuestion( Muchinfo.MTPClient.Resources.Client_Resource .Tips_BankUnBindCardComfrim, Muchinfo.MTPClient.Resources.Client_Resource .APP_Tips); if (result == MessageBoxResult.Yes) { IsBusy = true; _bankService.BankUnBindBankCard(sign, BankUnBindCardSuccess, ErrorCallback); } } })); } } private void BankUnBindCardSuccess(BankUnBindResult bankResult) { IsBusy = false; System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (bankResult.ReturnCode == 0) { //switch (bankResult.Status) //{ // case BankDealStatus.BankDealStatus__Succeed: if (string.IsNullOrWhiteSpace(bankResult.WebAddress)) { MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource .Tips_BankunBindCardSuccess, Muchinfo.MTPClient.Resources.Client_Resource .APP_Tips); } // break; //case BankDealStatus.BankDealStatus__Pend: // MessageBoxHelper.ShowSuccess( // Muchinfo.MTPClient.Resources.Client_Resource // .Bank_BankTerminationInfoSubmit_Wait, // Muchinfo.MTPClient.Resources.Client_Resource // .APP_Tips); // break; // case BankDealStatus.BankDealStatus__BankWebComfirm: else { try { IPHelper.OpenWebAddress(bankResult.WebAddress); } catch (Exception) { throw new MuchinfoException(ExceptionManager.OpenIEError); } finally { var messageBox = new MsgAlter(bankResult.WebAddress, Client_Resource.Tips_BankunBindCardWebComfrim) { Owner = System.Windows.Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; messageBox.Show(); } } // break; // } } else { var errorEntriy = new ErrorEntity() { ReturnCode = bankResult.ReturnCode, ReturnDesc = bankResult.ReturnDesc, RequestFunc = Client_Resource.Function_BankUnBindBankCard }; ErrorManager.ShowReturnError(errorEntriy, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips, true); } })); } private RelayCommand _BankBingCardCommand; /// /// 绑银行卡 /// public RelayCommand BankBingCardCommand { get { return _BankBingCardCommand ?? (_BankBingCardCommand = new RelayCommand((sign) => { if (sign != null) { var bindCard = new BindCardView(sign) { ShowInTaskbar = false, Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; bindCard.ShowDialog(); RefreshContent(); } })); } } /// /// 解约操作 /// public RelayCommand SignCommand { get { return new RelayCommand(() => { var sign = new BankSigningView() { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; sign.ShowDialog(); }); } } /// /// 修改手机号 /// public RelayCommand ModifyPhoneCommand { get { return new RelayCommand(() => { var sign = new MotifyPhoneView(CurrentSigningBank) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; sign.ShowDialog(); }); } } /// /// 查询资金信息 /// public RelayCommand BalanceCommand { get { return new RelayCommand(() => { if (CurrentSigningBank == null) return; var queryBank = new BankBalanceView(CurrentSigningBank) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; queryBank.ShowDialog(); }); } } private void UnSignBankCallback(BankSignResult result) { IsBusy = false; var bankDealStatus = result; RefreshContent(); System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (result.ReturnCode == 0) { switch (bankDealStatus.Status) { case BankDealStatus.BankDealStatus__Succeed: MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource .Bank_TerminationSuccess, Muchinfo.MTPClient.Resources.Client_Resource .Bank_BankTerminationTips); break; case BankDealStatus.BankDealStatus__Pend: MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource .Bank_BankTerminationInfoSubmit_Wait, Muchinfo.MTPClient.Resources.Client_Resource .Bank_BankTerminationTips); break; case BankDealStatus.BankDealStatus__BankWebComfirm: try { IPHelper.OpenWebAddress(bankDealStatus.WebAddress); } catch (Exception) { throw new MuchinfoException(ExceptionManager.OpenIEError); } finally { var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankUnSignWebComfrim) { Owner = System.Windows.Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; messageBox.Show(); } break; } } else { ErrorManager.ShowReturnError(bankDealStatus.ReturnCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips); } })); } #region public override void RegisterMessage() { RefreshContent(); //当选择时刷新 MessengerHelper.DefaultRegister(this, MessengerTokens.SignNotify, (e) => { RefreshContent(); }); } /// /// 取消注册 /// public override void UnRegisterMessage() { MessengerHelper.DefaultUnregister(this, MessengerTokens.SignNotify); base.UnRegisterMessage(); } public override void RefreshContent() { var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} IsBusy = true; _bankService.QueryBankCustomerSignInfo(accountid, SearchBankCustomerSignCallback, ErrorCallback); } #endregion } }