RiskControlNoticeViewModel.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using GalaSoft.MvvmLight.Ioc;
  4. using Muchinfo.PC.Common.Extensions;
  5. using Muchinfo.MTPClient.Account.Views;
  6. using Muchinfo.MTPClient.Data.Model;
  7. using Muchinfo.MTPClient.Infrastructure.Utilities;
  8. using Muchinfo.MTPClient.IService;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. using System.Windows.Controls;
  13. namespace Muchinfo.MTPClient.Account.ViewModels
  14. {
  15. public class RiskControlNoticeViewModel : ViewModelBase
  16. {
  17. private const int PageSize = 8;
  18. public RiskControlNoticeViewModel()
  19. {
  20. }
  21. public RiskControlNoticeViewModel(System.Collections.ObjectModel.ObservableCollection<Announcement> riskList)
  22. {
  23. RiskMessages = riskList;
  24. }
  25. /// <summary>
  26. /// 风控通知集合
  27. /// </summary>
  28. private ObservableCollection<Announcement> _riskMessages = new ObservableCollection<Announcement>();
  29. /// <summary>
  30. /// 风控通知集合
  31. /// </summary>
  32. public ObservableCollection<Announcement> RiskMessages
  33. {
  34. get
  35. {
  36. return _riskMessages;
  37. }
  38. set
  39. {
  40. Set(() => RiskMessages, ref _riskMessages, value);
  41. RaisePropertyChanged(() => RiskMessages);
  42. if (RiskMessages != null && RiskMessages.Count > 0)
  43. {
  44. if (RiskMessages.Count % PageSize == 0)
  45. {
  46. TotalPageCount = RiskMessages.Count / PageSize;
  47. }
  48. else
  49. {
  50. TotalPageCount = RiskMessages.Count / PageSize + 1;
  51. }
  52. RaisePropertyChanged(() => CurrentPageMessages);
  53. }
  54. else
  55. {
  56. TotalPageCount = 0;
  57. CurrentPageIndex = 0;
  58. }
  59. }
  60. }
  61. public void InsertNewRisk(Announcement newAnnouncement)
  62. {
  63. if (RiskMessages != null)
  64. {
  65. RiskMessages.Insert(0, newAnnouncement);
  66. if (RiskMessages.Count % PageSize == 0)
  67. {
  68. TotalPageCount = RiskMessages.Count / PageSize;
  69. }
  70. else
  71. {
  72. TotalPageCount = RiskMessages.Count / PageSize + 1;
  73. }
  74. RaisePropertyChanged(() => CurrentPageMessages);
  75. }
  76. else
  77. {
  78. TotalPageCount = 0;
  79. CurrentPageIndex = 0;
  80. }
  81. }
  82. public ObservableCollection<Announcement> CurrentPageMessages
  83. {
  84. get
  85. {
  86. var query = RiskMessages.Skip((_currentPageIndex - 1) * PageSize).Take(PageSize);
  87. ObservableCollection<Announcement> temp = new ObservableCollection<Announcement>();
  88. foreach (Announcement an in query)
  89. {
  90. temp.Add(an);
  91. }
  92. return temp;
  93. }
  94. set
  95. {
  96. RaisePropertyChanged(() => CurrentPageMessages);
  97. }
  98. }
  99. /// <summary>
  100. /// 当前选中风控通知
  101. /// </summary>
  102. private Announcement _currentRiskMessage;
  103. public Announcement CurrentRiskMessage
  104. {
  105. get
  106. {
  107. return _currentRiskMessage;
  108. }
  109. set
  110. {
  111. Set(() => CurrentRiskMessage, ref _currentRiskMessage, value);
  112. RaisePropertyChanged(() => CurrentRiskTitle);
  113. RaisePropertyChanged(() => CurrentRiskContent);
  114. RaisePropertyChanged(() => CurrentRiskLevel);
  115. if (CurrentRiskMessage != null)
  116. {
  117. if (CurrentRiskMessage.ReadStatus == 0)
  118. {
  119. Task.Factory.TryStartNew(() =>
  120. {
  121. var announcementService = SimpleIoc.Default.GetInstance<IAnnouncementService>();
  122. announcementService.ModifyBulletinNotifyStatus(UserManager.CurrentTradeAccount, CurrentRiskMessage);
  123. });
  124. CurrentRiskMessage.ReadStatus = 1;
  125. RaisePropertyChanged(() => CurrentRiskMessage);
  126. }
  127. }
  128. }
  129. }
  130. private int _currentPageIndex = 1;
  131. public int CurrentPageIndex
  132. {
  133. get
  134. {
  135. if (_totalPageCount == 0)
  136. {
  137. _currentPageIndex = 0;
  138. }
  139. if (_totalPageCount != 0 && _currentPageIndex == 0)
  140. {
  141. _currentPageIndex = 1;
  142. }
  143. return _currentPageIndex;
  144. }
  145. set
  146. {
  147. Set(() => CurrentPageIndex, ref _currentPageIndex, value);
  148. RaisePropertyChanged(() => CurrentPageIndex);
  149. RaisePropertyChanged(() => CurrentPageMessages);
  150. }
  151. }
  152. private int _totalPageCount = 0;
  153. public int TotalPageCount
  154. {
  155. get
  156. {
  157. return _totalPageCount;
  158. }
  159. set
  160. {
  161. Set(() => TotalPageCount, ref _totalPageCount, value);
  162. RaisePropertyChanged(() => TotalPageCount);
  163. RaisePropertyChanged(() => CurrentPageIndex);
  164. }
  165. }
  166. public string CurrentRiskTitle
  167. {
  168. get
  169. {
  170. if (CurrentRiskMessage != null)
  171. {
  172. return CurrentRiskMessage.Title;
  173. }
  174. else
  175. {
  176. return "";
  177. }
  178. }
  179. }
  180. public string CurrentRiskContent
  181. {
  182. get
  183. {
  184. if (CurrentRiskMessage != null)
  185. {
  186. return CurrentRiskMessage.Content;
  187. }
  188. else
  189. {
  190. return "";
  191. }
  192. }
  193. }
  194. public int CurrentRiskLevel
  195. {
  196. get
  197. {
  198. if (CurrentRiskMessage != null)
  199. {
  200. return CurrentRiskMessage.RiskLevel;
  201. }
  202. else
  203. {
  204. return 0;
  205. }
  206. }
  207. }
  208. private bool _isBusy;
  209. /// <summary>
  210. /// 是否忙等待
  211. /// </summary>
  212. public bool IsBusy
  213. {
  214. get { return _isBusy; }
  215. set { Set(() => IsBusy, ref _isBusy, value); }
  216. }
  217. public RelayCommand<RiskControlNoticeView> ClosedCommand
  218. {
  219. get
  220. {
  221. return new RelayCommand<RiskControlNoticeView>((v) => v.Close());
  222. }
  223. }
  224. //下一页
  225. public RelayCommand NextCommand
  226. {
  227. get
  228. {
  229. return new RelayCommand(() =>
  230. {
  231. if (CurrentPageIndex <= TotalPageCount - 1)
  232. {
  233. CurrentPageIndex += 1;
  234. }
  235. });
  236. }
  237. }
  238. public RelayCommand PrevCommand
  239. {
  240. get
  241. {
  242. return new RelayCommand(() =>
  243. {
  244. if (CurrentPageIndex > 1)
  245. {
  246. CurrentPageIndex -= 1;
  247. }
  248. });
  249. }
  250. }
  251. public RelayCommand<TextBox> QueryCommand
  252. {
  253. get
  254. {
  255. return new RelayCommand<TextBox>((v) =>
  256. {
  257. int index;
  258. if (int.TryParse(v.Text, out index))
  259. {
  260. if (index >= 1 && index <= TotalPageCount)
  261. {
  262. CurrentPageIndex = index;
  263. }
  264. }
  265. });
  266. }
  267. }
  268. /// <summary>
  269. /// 加载数据
  270. /// </summary>
  271. public void LoadRiskMessages()
  272. {
  273. var tradeCacheData = UserManager.GetTradeCacheData((UserManager.CurrentTradeAccount.AccountId));
  274. IsBusy = true;
  275. Task.Factory.TryStartNew(() =>
  276. {
  277. //RiskMessages = UserManager.GetMessageNoticeOrders(UserManager.CurrentTradeAccount, true);
  278. RiskMessages = tradeCacheData.MessageNoticeOrders;
  279. }, () => IsBusy = false);
  280. }
  281. }
  282. }