| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.PC.Common.Extensions;
- using Muchinfo.MTPClient.Account.Views;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- namespace Muchinfo.MTPClient.Account.ViewModels
- {
- public class RiskControlNoticeViewModel : ViewModelBase
- {
- private const int PageSize = 8;
- public RiskControlNoticeViewModel()
- {
- }
- public RiskControlNoticeViewModel(System.Collections.ObjectModel.ObservableCollection<Announcement> riskList)
- {
- RiskMessages = riskList;
- }
- /// <summary>
- /// 风控通知集合
- /// </summary>
- private ObservableCollection<Announcement> _riskMessages = new ObservableCollection<Announcement>();
- /// <summary>
- /// 风控通知集合
- /// </summary>
- public ObservableCollection<Announcement> RiskMessages
- {
- get
- {
- return _riskMessages;
- }
- set
- {
- Set(() => RiskMessages, ref _riskMessages, value);
- RaisePropertyChanged(() => RiskMessages);
- if (RiskMessages != null && RiskMessages.Count > 0)
- {
- if (RiskMessages.Count % PageSize == 0)
- {
- TotalPageCount = RiskMessages.Count / PageSize;
- }
- else
- {
- TotalPageCount = RiskMessages.Count / PageSize + 1;
- }
- RaisePropertyChanged(() => CurrentPageMessages);
- }
- else
- {
- TotalPageCount = 0;
- CurrentPageIndex = 0;
- }
- }
- }
- public void InsertNewRisk(Announcement newAnnouncement)
- {
- if (RiskMessages != null)
- {
- RiskMessages.Insert(0, newAnnouncement);
- if (RiskMessages.Count % PageSize == 0)
- {
- TotalPageCount = RiskMessages.Count / PageSize;
- }
- else
- {
- TotalPageCount = RiskMessages.Count / PageSize + 1;
- }
- RaisePropertyChanged(() => CurrentPageMessages);
- }
- else
- {
- TotalPageCount = 0;
- CurrentPageIndex = 0;
- }
- }
- public ObservableCollection<Announcement> CurrentPageMessages
- {
- get
- {
- var query = RiskMessages.Skip((_currentPageIndex - 1) * PageSize).Take(PageSize);
- ObservableCollection<Announcement> temp = new ObservableCollection<Announcement>();
- foreach (Announcement an in query)
- {
- temp.Add(an);
- }
- return temp;
- }
- set
- {
- RaisePropertyChanged(() => CurrentPageMessages);
- }
- }
- /// <summary>
- /// 当前选中风控通知
- /// </summary>
- private Announcement _currentRiskMessage;
- public Announcement CurrentRiskMessage
- {
- get
- {
- return _currentRiskMessage;
- }
- set
- {
- Set(() => CurrentRiskMessage, ref _currentRiskMessage, value);
- RaisePropertyChanged(() => CurrentRiskTitle);
- RaisePropertyChanged(() => CurrentRiskContent);
- RaisePropertyChanged(() => CurrentRiskLevel);
- if (CurrentRiskMessage != null)
- {
- if (CurrentRiskMessage.ReadStatus == 0)
- {
- Task.Factory.TryStartNew(() =>
- {
- var announcementService = SimpleIoc.Default.GetInstance<IAnnouncementService>();
- announcementService.ModifyBulletinNotifyStatus(UserManager.CurrentTradeAccount, CurrentRiskMessage);
- });
- CurrentRiskMessage.ReadStatus = 1;
- RaisePropertyChanged(() => CurrentRiskMessage);
- }
- }
- }
- }
- private int _currentPageIndex = 1;
- public int CurrentPageIndex
- {
- get
- {
- if (_totalPageCount == 0)
- {
- _currentPageIndex = 0;
- }
- if (_totalPageCount != 0 && _currentPageIndex == 0)
- {
- _currentPageIndex = 1;
- }
- return _currentPageIndex;
- }
- set
- {
- Set(() => CurrentPageIndex, ref _currentPageIndex, value);
- RaisePropertyChanged(() => CurrentPageIndex);
- RaisePropertyChanged(() => CurrentPageMessages);
- }
- }
- private int _totalPageCount = 0;
- public int TotalPageCount
- {
- get
- {
- return _totalPageCount;
- }
- set
- {
- Set(() => TotalPageCount, ref _totalPageCount, value);
- RaisePropertyChanged(() => TotalPageCount);
- RaisePropertyChanged(() => CurrentPageIndex);
- }
- }
- public string CurrentRiskTitle
- {
- get
- {
- if (CurrentRiskMessage != null)
- {
- return CurrentRiskMessage.Title;
- }
- else
- {
- return "";
- }
- }
- }
- public string CurrentRiskContent
- {
- get
- {
- if (CurrentRiskMessage != null)
- {
- return CurrentRiskMessage.Content;
- }
- else
- {
- return "";
- }
- }
- }
- public int CurrentRiskLevel
- {
- get
- {
- if (CurrentRiskMessage != null)
- {
- return CurrentRiskMessage.RiskLevel;
- }
- else
- {
- return 0;
- }
- }
- }
- private bool _isBusy;
- /// <summary>
- /// 是否忙等待
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- public RelayCommand<RiskControlNoticeView> ClosedCommand
- {
- get
- {
- return new RelayCommand<RiskControlNoticeView>((v) => v.Close());
- }
- }
- //下一页
- public RelayCommand NextCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- if (CurrentPageIndex <= TotalPageCount - 1)
- {
- CurrentPageIndex += 1;
- }
- });
- }
- }
- public RelayCommand PrevCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- if (CurrentPageIndex > 1)
- {
- CurrentPageIndex -= 1;
- }
- });
- }
- }
- public RelayCommand<TextBox> QueryCommand
- {
- get
- {
- return new RelayCommand<TextBox>((v) =>
- {
- int index;
- if (int.TryParse(v.Text, out index))
- {
- if (index >= 1 && index <= TotalPageCount)
- {
- CurrentPageIndex = index;
- }
- }
- });
- }
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadRiskMessages()
- {
- var tradeCacheData = UserManager.GetTradeCacheData((UserManager.CurrentTradeAccount.AccountId));
- IsBusy = true;
- Task.Factory.TryStartNew(() =>
- {
- //RiskMessages = UserManager.GetMessageNoticeOrders(UserManager.CurrentTradeAccount, true);
- RiskMessages = tradeCacheData.MessageNoticeOrders;
- }, () => IsBusy = false);
- }
- }
- }
|