| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Data.Model.Delivery;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- 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 System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- namespace Muchinfo.MTPClient.Delivery.ViewModels
- {
- /// <summary>
- /// 提货申请
- /// </summary>
- public class TakaDeliveryGoodsApplyViewModel : ViewModelBase
- {
- #region "=========私有成员/Private Data Members"
- protected IDeliveryService _deliveryService;
- private Window _openWindow;
- #endregion "Private Data Members"
- #region "=========构造函数/Constructor/Initialization"
- public TakaDeliveryGoodsApplyViewModel()
- {
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- InitData();
- }
- #endregion "Constructor/Initialization"
- #region "=========接口重写/Interface implementation Or override"
- #endregion "Interface implementation Or override"
- #region "=========公共属性/Public Properties To Get/Set "
- #region 当前账号提货人信息
- private DepositPersonalInfoRspModel _currentDepositPersonalInfo;
- /// <summary>
- /// 当前账号提货人信息
- /// </summary>
- public DepositPersonalInfoRspModel CurrentDepositPersonalInfo
- {
- get
- {
- return _currentDepositPersonalInfo;
- }
- set
- {
- Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value);
- }
- }
- #endregion
- #region 标题
- public string Title
- {
- get
- {
- return Resources.Client_Resource.Resources_Service_SubmitOutStoreReq;
- }
- }
- #endregion
- #region 是否忙
- private bool _isBusy;
- /// <summary>
- /// 是否忙
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- #endregion
- #region 按钮是否可用
- private bool _oKButtonEnabled = true;
- /// <summary>
- ///按钮是否可用
- /// </summary>
- public bool OKButtonEnabled
- {
- get
- {
- return _oKButtonEnabled;
- }
- set
- {
- Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
- }
- }
- #endregion
- #region 当前选择仓库
- private TakaDeliveryGoodsApplyModel _currentWarehouse = null;
- /// <summary>
- /// Sets and gets the CurrentWarehouse property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public TakaDeliveryGoodsApplyModel CurrentWarehouse
- {
- get
- {
- return _currentWarehouse;
- }
- set
- {
- Set(() => CurrentWarehouse, ref _currentWarehouse, value);
-
- }
- }
- #endregion
- #region 仓库列表
- private List<TakaDeliveryGoodsApplyModel> _warehouseList = new List<TakaDeliveryGoodsApplyModel>();
- /// <summary>
- /// 仓库列表
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public List<TakaDeliveryGoodsApplyModel> WarehouseList
- {
- get
- {
- return _warehouseList;
- }
- set
- {
- Set(() => WarehouseList, ref _warehouseList, value);
- }
- }
- #endregion
- #region 收货人
- private string _RecievePerson = string.Empty;
- /// <summary>
- /// 收货人
- /// </summary>
- public string RecievePerson
- {
- get
- {
- return _RecievePerson;
- }
- set
- {
- Set(() => RecievePerson, ref _RecievePerson, value);
- }
- }
- #endregion
- #region 收货地址
- private string _RecieveAddress = string.Empty;
- /// <summary>
- /// 收货地址
- /// </summary>
- public string RecieveAddress
- {
- get
- {
- return _RecieveAddress;
- }
- set
- {
- Set(() => RecieveAddress, ref _RecieveAddress, value);
- }
- }
- #endregion
- #region 联系方式
- private string _PhoneNum = string.Empty;
- /// <summary>
- /// 联系方式
- /// </summary>
- public string PhoneNum
- {
- get
- {
- return _PhoneNum;
- }
- set
- {
- Set(() => PhoneNum, ref _PhoneNum, value);
- }
- }
- #endregion
- #region 提货方式
- private TakeGoodsWay _takeGoodsWay;
- /// <summary>
- /// 提货方式
- /// </summary>
- public TakeGoodsWay TakeGoodsWay
- {
- get { return _takeGoodsWay; }
- set { Set(() => TakeGoodsWay, ref _takeGoodsWay, value); }
- }
- #endregion
- #region 身份证
- private string _idCardNum;
- /// <summary>
- /// 身份证号
- /// </summary>
- public string IdCardNum
- {
- get { return _idCardNum; }
- set { Set(() => IdCardNum, ref _idCardNum, value); }
- }
- #endregion
- #region 所有提货仓单ListSource
- public List<TakaDeliveryGoodsApplyModel> TempTakaDeliveryGoodsOrderList = new List<TakaDeliveryGoodsApplyModel>();
- private List<TakaDeliveryGoodsApplyModel> _allTakaDeliveryGoodsOrderList= new List<TakaDeliveryGoodsApplyModel>();
- /// <summary>
- /// 所有提货仓单ListSource
- /// </summary>
- public List<TakaDeliveryGoodsApplyModel> AllTakaDeliveryGoodsOrderList
- {
- get { return _allTakaDeliveryGoodsOrderList; }
- set { Set(() => AllTakaDeliveryGoodsOrderList, ref _allTakaDeliveryGoodsOrderList, value); }
- }
- #endregion
- #region 当前勾选单据
- private List<OutStoreReqDetailModel> _currentSelectedOutStore = null;
- /// <summary>
- /// 当前勾选的提货单据LIST
- /// </summary>
- public List<OutStoreReqDetailModel> CurrentSelectedOutStore
- {
- get
- {
- return _currentSelectedOutStore;
- }
- set
- {
- Set(() => CurrentSelectedOutStore, ref _currentSelectedOutStore, value);
- }
- }
- #endregion
- #endregion "Public Properties To Get/Set "
- #region "=========公共命令/Public Commands"
- #region 窗口取消Command
- /// <summary>
- /// 窗口取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- #endregion
- #region 选中Command
- /// <summary>
- /// 选中
- /// </summary>
- private RelayCommand selectCommand;
- public RelayCommand SelectCommand
- {
- get
- {
- return selectCommand ?? (selectCommand = new RelayCommand(
- () =>
- {
- SettlementSelectedOutStore();
- }));
- }
- }
- #endregion
- #region 取消选中Command
- /// <summary>
- /// 取消选中
- /// </summary>
- private RelayCommand unSelectCommand;
- public RelayCommand UnSelectCommand
- {
- get
- {
- return unSelectCommand ?? (unSelectCommand = new RelayCommand(
- () =>
- {
- SettlementSelectedOutStore();
- }));
- }
- }
- #endregion
- #region 提交确定Command
- /// <summary>
- /// 提交确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- OKButtonEnabled = false;
- string errorMsg = string.Empty;
- bool validateBool = Validated(ref errorMsg); ////内容验证
- if (validateBool)
- {
- IsBusy = true;
- _openWindow = dialog;
- var newOrder = new OutStoreReqModel()
- {
- //申请
- OperateType = (int) TakaGoodsOperateType.Apply,
- RecievePerson = RecievePerson,
- RecieveAddress = string.IsNullOrWhiteSpace(RecieveAddress) ? "-" : RecieveAddress,
- PhoneNum = PhoneNum,
- OutStoreDetail = CurrentSelectedOutStore,
- TakeGoodsWay=TakeGoodsWay,
- OperatorID = UserManager.CurrentTradeAccount.AccountId,
- IdCardNum = IdCardNum,
- };
- if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
- UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
- {
- newOrder.AccountID = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- }
- else
- {
- newOrder.AccountID = UserManager.CurrentTradeAccount.AccountId;
- }
- _deliveryService.SubmitOutStoreReq(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
- }
- else
- {
- MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
- OKButtonEnabled = true;
- }
- });
- }
- }
- #endregion
- #region 出库选择-发生改变-发送命令
- private RelayCommand _warehouseSelectionChangedCommand;
- /// <summary>
- /// Gets the WarehouseSelectionChangedCommand.
- /// </summary>
- public RelayCommand WarehouseSelectionChangedCommand
- {
- get
- {
- return _warehouseSelectionChangedCommand
- ?? (_warehouseSelectionChangedCommand = new RelayCommand(
- () =>
- {
- #region 处理事件ChangedEvent
- FilteOutStoreOrderListByCombox();
- #endregion
- }));
- }
- }
- #endregion
- #endregion "Public Commands"
- #region "=========私有方法/Private Methods"
- /// <summary>
- /// 处理选择提货
- /// </summary>
- private void SettlementSelectedOutStore()
- {
-
- _currentSelectedOutStore = new List<OutStoreReqDetailModel>();
- var sourceList = AllTakaDeliveryGoodsOrderList.ToList().FindAll(p => p.IsSelected == true);
- if (sourceList != null && sourceList.Count == 1) ///选择一条数据时显示
- {
- RecieveAddress = sourceList[0].Address;
- RecievePerson = sourceList[0].PersonName;
- PhoneNum = sourceList[0].Telphone;
- TakeGoodsWay = sourceList[0].TakeGoodsWay;
- IdCardNum = sourceList[0].IdCardNum;
- }
- long tempDeliveryGoodsId=0;
- for (int i = 0; i < sourceList.Count(); i++)
- {
- _currentSelectedOutStore.Add(new OutStoreReqDetailModel() { WRId = (sourceList[i].WRID), StoreOutQty = ((sourceList[i].Qty - sourceList[i].FreezeQty -sourceList[i].PayQty)) });
- if (tempDeliveryGoodsId == 0)
- {
- tempDeliveryGoodsId = sourceList[i].DeliveryGoodsId;
- }
- }
- #region 只能提取相同的交割商品[注销]
- //if (sourceList.Count() > 0)
- //{
- // var sourceListSame = AllTakaDeliveryGoodsOrderList.ToList().FindAll(p => p.IsSelected != true && p.DeliveryGoodsId != tempDeliveryGoodsId);
- // for (int i = 0; i < sourceListSame.Count(); i++)
- // {
- // sourceListSame[i].IsEnabled = false;
- // }
- //}
- //else
- //{
- // var sourceListAll = AllTakaDeliveryGoodsOrderList.ToList();
- // for (int i = 0; i < sourceListAll.Count(); i++)
- // {
- // sourceListAll[i].IsEnabled = true;
- // }
- //}
- #endregion
-
- IsEnableButtonEvent();
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- private void InitData()
- {
- var accountid = UserManager.CurrentTradeAccount.AccountId;
- //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
- //{
- // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- //}
- IsBusy = true;
- _deliveryService.QueryTakaDeliveryGoodsOrdersAppy(accountid, MarketOrderSuccess, QueryErrorCallback);
- //赋默赋值给下拉列表
- _warehouseList.Add(new TakaDeliveryGoodsApplyModel() { WareHouseName = Client_Resource.DeliveryMatchView_AllWareHouse });
- CurrentWarehouse = _warehouseList.FirstOrDefault();//默认选择
- IsEnableButtonEvent();
- //读取登录人基本信息
- GetDepositPersonalInfo();
- #region 测试数据
- //for (int i = 0; i < 5; i++)
- //{
- // _allTakaDeliveryGoodsOrderList.Add(new TakaDeliveryGoodsApplyModel() { WRID = 10003 + i, WRCode = DateTime.Now.ToShortTimeString(),WareHouseName="仓库"+i });
- //}
- //TempTakaDeliveryGoodsOrderList = _allTakaDeliveryGoodsOrderList;
- //BindingWarehouseComBoxList(_allTakaDeliveryGoodsOrderList);
- #endregion
-
- }
- /// <summary>
- /// 获取交割提货个人信息
- /// </summary>
- private void GetDepositPersonalInfo()
- {
- var accountid = UserManager.CurrentTradeAccount.AccountId;
- //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
- //{
- // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- //}
- var ReqModel = new DepositPersonalInfoReqModel();
- ReqModel.accountId = (long)accountid;
- IsBusy = true;
- //交割提货个人信息查询
- _deliveryService.SearchDepositPersonalInfoReq(ReqModel, QueryDepositPersonalInfoSuccess, QueryDepositPersonalInfoCallBack);
- }
- /// <summary>
- /// 交割提货个人信息-成功返回
- /// </summary>
- /// <param name="orders"></param>
- protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel)
- {
- if (itemModel != null)
- {
- CurrentDepositPersonalInfo = itemModel;
- if (CurrentDepositPersonalInfo != null)
- {
- RecieveAddress = CurrentDepositPersonalInfo.address;
- RecievePerson = CurrentDepositPersonalInfo.personName;
- PhoneNum = CurrentDepositPersonalInfo.telphone;
- }
- }
- IsBusy = false;
- }
- /// <summary>
- /// 获取交割提货个人信息失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- }
- /// <summary>
- /// 过滤出库数据BY下拉列表
- /// </summary>
- private void FilteOutStoreOrderListByCombox()
- {
- #region 重置勾选单据
- var sourceList = AllTakaDeliveryGoodsOrderList.ToList().FindAll(p => p.IsSelected == true);
- for (int i = 0; i < sourceList.Count(); i++)
- {
- sourceList[i].IsSelected = false;
- }
- #endregion
- AllTakaDeliveryGoodsOrderList = TempTakaDeliveryGoodsOrderList;//回归数据
- if (_currentWarehouse.WareHouseName != Client_Resource.DeliveryMatchView_AllWareHouse)//全部仓库
- {
- AllTakaDeliveryGoodsOrderList = AllTakaDeliveryGoodsOrderList.Where(x => x.WareHouseName == _currentWarehouse.WareHouseName).ToList();
- }
- }
- /// <summary>
- /// 触发提交按钮是否可用
- /// </summary>
- private void IsEnableButtonEvent()
- {
- if (_currentSelectedOutStore != null && _currentSelectedOutStore.Any() && _currentSelectedOutStore.Count() > 0)
- {
- OKButtonEnabled = true;
- }
- else
- {
- OKButtonEnabled = false;
- }
- }
- /// <summary>
- /// 绑定-仓库-下拉列表数据
- /// </summary>
- /// <param name="itemList"></param>
- private void BindingWarehouseComBoxList(List<TakaDeliveryGoodsApplyModel> itemList)
- {
- if (itemList != null && itemList.Any())
- {
- foreach (var item in itemList)
- {
- //绑定-仓库-下拉列表数据
- if (!WarehouseList.Exists(x => x.WareHouseName == item.WareHouseName))
- {
- WarehouseList.Add(item);
- }
- }
- }
- }
- /// <summary>
- /// 查询成功返回
- /// </summary>
- /// <param name="orders"></param>
- protected void MarketOrderSuccess(List<TakaDeliveryGoodsApplyModel> orders)
- {
-
-
- UpdateItemSource(orders);
- IsBusy = false;
- }
- /// <summary>
- /// 查询失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- public void QueryErrorCallback(ErrorEntity errorEntity)
- {
- IsBusy = false;
- //var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
- //MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
- // base.QueryErrorCallback();
- }
- /// <summary>
- /// 更新数据源-绑定数据源
- /// </summary>
- /// <param name="orders"></param>
- private void UpdateItemSource(List<TakaDeliveryGoodsApplyModel> orders)
- {
- if (orders != null)
- {
- foreach (var item in orders)
- {
- #region 合约单位转换
- var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == item.GoodsUnitId);
- if (goodsUnit != null)
- {
- item.GoodsUnitIdDisplay = goodsUnit.GOODSUNITNAME;
- }
- #endregion
- #region 是否可以提货逻辑
- //可用数量 = 注册数量-冻结数量-兑付数量
- var canTakeGoodsNum = item.Qty - item.FreezeQty - item.PayQty;
- //正常状态 且 可用数量大于零 可以提货
- if (canTakeGoodsNum > 0 && item.Status == eWRStatus.Normal)
- {
- item.CanTakeGoods = Visibility.Visible;
- }
- #endregion
- }
- AllTakaDeliveryGoodsOrderList = TempTakaDeliveryGoodsOrderList = orders.Where(x => x.Status == eWRStatus.Normal && x.CanTakeGoods == Visibility.Visible).ToList();//所有单据
- BindingWarehouseComBoxList(AllTakaDeliveryGoodsOrderList);
- }
- }
- /// <summary>
- /// 提交提货成功返回
- /// </summary>
- /// <param name="order"></param>
- private void EntrurstSuccessCallBack(OutStoreRspModel order)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- OKButtonEnabled = true;
- //提货成功
- MessageBoxHelper.ShowSuccess(Client_Resource.Order_TakaDeliveryGoods_Success_Result,
- Client_Resource.UI2014_Tips);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }));
- //刷新正常单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
- }
- /// <summary>
- /// 提货委托失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void EntrurstErrorCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- OKButtonEnabled = true;
- ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }));
- }
- #endregion "Private Methods"
- #region "=========其它方法/Other Methods"
-
- /// <summary>
- /// 数据验证
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- public bool Validated(ref string msg)
- {
- if (RecievePerson.Trim() == "")
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecievePerson + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
- return false;
- }
- if (TakeGoodsWay == TakeGoodsWay.Express && RecieveAddress.Trim() == "")
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecieveAddress + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
- return false;
- }
- if (PhoneNum.Trim() == "")
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNum + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
- return false;
- }
- if (PhoneNum.Trim() != "" && !PhoneNum.StartsWith("1") || PhoneNum.Length != 11 || !ValidationHelper.IsMobile(PhoneNum))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNumErrFormat;
- return false;
- }
- if (string.IsNullOrWhiteSpace(IdCardNum) || !ValidationHelper.IsIDcard(IdCardNum.Trim()))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_IDCardNumErrFormat;
- return false;
- }
-
- return true;
- }
- #endregion "Other Methods"
-
-
- }
- }
|