| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Microsoft.Practices.ServiceLocation;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.DTO;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Helper;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Sale;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.Sale.Views;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- namespace Muchinfo.MTPClient.Sale.ViewModels
- {
- public class QuerySaleGoodsViewModel : ViewModelBase
- {
- private ISaleService _saleService;
- private long _goodsGroupId;
- //申购中的商品
- private ObservableCollection<SaleGoods> purchaseGoodsList;
- //战略投资者商品
- private List<StrategicInvestor> strategicInvestors;
- #region 构造函数
- public QuerySaleGoodsViewModel()
- {
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.RefrashSaleGoodsCommand, RegisterMethod);
- }
- #endregion
- #region 成员变量
- private SaleGoods _currentDataGridItem;
- /// <summary>
- /// 当前选中DataGridItem
- /// </summary>
- public SaleGoods CurrentDataGridItem
- {
- get { return _currentDataGridItem; }
- set
- {
- Set(() => CurrentDataGridItem, ref _currentDataGridItem, value);
- SendCurrentGoods(_currentDataGridItem);
- }
- }
- /// <summary>
- /// 发行商品
- /// </summary>
- private List<SaleGoods> _saleGoodsList;
- public List<SaleGoods> SaleGoodsList
- {
- get { return _saleGoodsList; }
- set { Set(() => SaleGoodsList, ref _saleGoodsList, value); }
- }
- private List<QuoteGoods> _quoteGoodsList;
- public List<QuoteGoods> QuoteGoodsList
- {
- get { return _quoteGoodsList; }
- set { Set(() => QuoteGoodsList, ref _quoteGoodsList, value); }
- }
- private string _goodCode = string.Empty;
- /// <summary>
- /// 商品代码
- /// </summary>
- public string GoodCode
- {
- get
- {
- return _goodCode.Trim();
- }
- set
- {
- Set(() => GoodCode, ref _goodCode, value);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 查询
- /// </summary>
- public RelayCommand SelectCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- QuerySaleGoods();
- });
- }
- }
- /// <summary>
- /// 重置
- /// </summary>
- public RelayCommand ResetCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- GoodCode = string.Empty;
- });
- }
- }
- /// <summary>
- /// 申购
- /// </summary>
- public RelayCommand DetailCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- if (CurrentDataGridItem == null)
- {
- //todo:提示无选择商品
- return;
- }
- var win = new SaleOrderFrame(CurrentDataGridItem)
- {
- Owner = Application.Current.MainWindow,
- WindowStartupLocation = WindowStartupLocation.CenterOwner
- };
- win.ShowDialog();
- });
- }
- }
- public void QuerySaleGoods()
- {
- QuoteGoodsList =
- CacheManager.CacheGoodsBaseInfos.Where((item) => item.GoodsParameters.SortId == _goodsGroupId)
- .ToList();
- if (UserManager.IsAccountLogin)
- {
- if (QuoteGoodsList == null || !QuoteGoodsList.Any())
- {
- SaleGoodsList = null;
- return;
- }
- var queryParamers = new List<QueryCommonParam>() {};
- var goodsIdString = string.Empty;
- foreach (var quoteGoods in QuoteGoodsList)
- {
- if ((quoteGoods.ContainsGoodsSrc & (int) GoodsFromScr.Trade) > 0) ///只查询交易的商品
- {
- goodsIdString += quoteGoods.GoodsParameters.GoodsId + ",";
- }
- }
- goodsIdString = goodsIdString.TrimEnd(',');
- if (!string.IsNullOrEmpty(goodsIdString))
- {
- queryParamers.Add(new QueryCommonParam() {ParamKey = "goodsIds", ParamValue = goodsIdString});
- _saleService.QueryAccountSaleGoodsRpt(QueryStatement.SearchSaleGoods, queryParamers, QuerySuccess,
- QueryErrorFunc);
- }
- }
- else ////游客登录
- {
- if (UserManager.BrownSaleGoodses == null)
- {
- var quoteDataServie = SimpleIoc.Default.GetInstance<IQuoteDataService>();
- quoteDataServie.QuerySaleGoodsParam(QuoteQuerySaleParamSuccess, QueryErrorFunc);
- }
- else
- {
- SetCurrentSaleGoods();
- }
- }
- }
- /// <summary>
- /// 设置发售商品显示内容
- /// </summary>
- private void SetCurrentSaleGoods()
- {
- if (QuoteGoodsList == null || !QuoteGoodsList.Any()||UserManager.BrownSaleGoodses==null || !UserManager.BrownSaleGoodses.Any())
- {
- SaleGoodsList = null;
- return;
- }
- int index = 1;
- var goodsList = new List<SaleGoods>();
- foreach (var quoteGoodse in QuoteGoodsList)
- {
- var goods= UserManager.BrownSaleGoodses.FirstOrDefault((item) => item.GoodsId == quoteGoodse.GoodsId);
-
- if (goods != null)
- {
- goods.OrderNumber = index;
- goods.GoodsName = quoteGoodse.Name;
- goods.GoodsCode = quoteGoodse.GoodsCode;
- goods.AgreeUnit = quoteGoodse.GoodsParameters.AgreeUnit;
- goods.GoodsId = quoteGoodse.GoodsId;
-
- goods.RunStepsDisplay = goods.RunSteps.Discription();
- goods.GoodsCodeColor = quoteGoodse.GoodsCodeColor;
- goods.GoodsNameColor = quoteGoodse.NameColor;
- goods.DefaultColor = quoteGoodse.DefaultColor;
- goods.IsBrownMode = true;
- goodsList.Add(goods);
- index++;
- }
- }
- SaleGoodsList = goodsList;
- }
- /// <summary>
- /// 查询发售商品参数回应
- /// </summary>
- /// <param name="goodses"></param>
- private void QuoteQuerySaleParamSuccess(List<SaleGoods> goodses )
- {
- if (goodses != null && goodses.Any())
- {
- UserManager.BrownSaleGoodses = goodses;
- SetCurrentSaleGoods();
- }
-
- }
- //private void QuoteQuerySaleError(ErrorEntity error)
- //{
- // ErrorManager.ShowReturnError(error, Client_Resource.UI2014_Tips, true);
- //}
- /// <summary>
- /// 查询申购 的商品
- /// </summary>
- /// <param name="saleGoodses"></param>
- public void QuerySuccess(List<SaleGoods> saleGoodses)
- {
- if (saleGoodses == null || !saleGoodses.Any()) return;
- var saleGoodsList = new List<SaleGoods>();
- var dicSaleGoods = saleGoodses.ToDictionary((item) => item.GoodsId);
- int index = 1;
- foreach (var quoteGoods in QuoteGoodsList)
- {
- if (quoteGoods == null || quoteGoods.ContainsGoodsSrc == (int)GoodsFromScr.Brown) continue;
- var saleGoods = new SaleGoods(quoteGoods)
- {
- OrderNumber = index,
- AgreeUnitString = CacheManager.TradeGoodsUnit.Where(x => x.UNITID == quoteGoods.GoodsParameters.AgreeUnitType).Select(x => x.GOODSUNITNAME).FirstOrDefault()
- };
- if (CacheManager.TradeGoodsFeeRules != null)
- {
- var rule = CacheManager.TradeGoodsFeeRules.FirstOrDefault(z => z.Key == quoteGoods.GoodsId).Value;
- if (rule != null && rule.GoodsRules != null)
- {
- var minKey = (int)eTradeRule.TRADERULE_SPPT;
- var maxKey = (int)eTradeRule.TRADERULE_SPPT;
- var maxHolderKey = (int)eTradeRule.TRADERULE_SPPT;
- ////单笔最小申购数量
- if (rule.GoodsRules.ContainsKey(minKey))
- {
- long minLot = 1;
- long.TryParse(rule.GoodsRules[minKey].FeeValue + string.Empty, out minLot);
- saleGoods.PerMinSubQty = minLot;
- }
- ////单笔最大申购数量
- if (rule.GoodsRules.ContainsKey(maxKey))
- {
- long maxLot = 10;
- long.TryParse(rule.GoodsRules[maxKey].FeeValue + string.Empty, out maxLot);
- saleGoods.PerMaxSubQty = maxLot;
- }
- ////最大可申购数量
- if (rule.GoodsRules.ContainsKey(maxHolderKey))
- {
- long Qty = long.MaxValue;
- long.TryParse(rule.GoodsRules[maxHolderKey].FeeValue + string.Empty, out Qty);
- //saleGoods.Qty = Qty;
- }
- }
- }
- ////todo:测试用
- if (saleGoods.PerMinSubQty == 0) saleGoods.PerMinSubQty = 10;
- if (saleGoods.PerMaxSubQty == 0) saleGoods.PerMaxSubQty = 1000;
- if (dicSaleGoods.ContainsKey(quoteGoods.GoodsId))
- {
- saleGoods.Planissueqty = dicSaleGoods[quoteGoods.GoodsId].Planissueqty;
- saleGoods.ApplyStartTime = dicSaleGoods[quoteGoods.GoodsId].ApplyStartTime;
- saleGoods.ApplyEndTime = dicSaleGoods[quoteGoods.GoodsId].ApplyEndTime;
- }
- //只显示申购中和待申购状态的商品
- if (saleGoods.RunSteps == eRunStep.RUNSTEP_BIDDINGPRICE || saleGoods.RunSteps == eRunStep.RUNSTEP_BIDDINGCONTINUOUS)
- {
- saleGoodsList.Add(saleGoods);
- index++;
- }
- }
- SaleGoodsList = saleGoodsList;
- CacheManager.SaleGoodses[_goodsGroupId] = SaleGoodsList;
- //默认选择第一个
- CurrentDataGridItem = SaleGoodsList.FirstOrDefault();
- }
- /// <summary>
- /// 错误处理
- /// </summary>
- /// <param name="error">错误内容</param>
- private void QueryErrorFunc(ErrorEntity error)
- {
- SaleGoodsList = null;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(error, Client_Resource.UI2014_Tips, true);
- }));
- }
- private void RegisterMethod(bool obj)
- {
- this.SelectCommand.Execute(null);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="goodsGroupId"></param>
- public void InitQuery(long goodsGroupId)
- {
- _goodsGroupId = goodsGroupId;
- _saleService = ServiceLocator.Current.GetInstance<ISaleService>();
- QuerySaleGoods();
- }
- /// <summary>
- /// 发当前商品
- /// </summary>
- /// <param name="saleGoods">发售商品</param>
- private void SendCurrentGoods(SaleGoods saleGoods)
- {
- if (saleGoods == null) return;
- var quoteGoods= CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.GoodsId == saleGoods.GoodsId);
- if (quoteGoods == null) return;
- var goodsDTO = new QuoteGoodsDTO(quoteGoods);
-
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(goodsDTO, MessengerTokens.SelectGoodsChange);
- }
- #endregion
- }
- }
|