using BBWY.Client.APIServices; using BBWY.Client.Models.PackTask; using BBWY.Common.Models; using BBWY.Controls; using GalaSoft.MvvmLight.Command; using Microsoft.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Windows; using System.Linq; using AutoMapper.Internal; using WebSocketSharp; namespace BBWY.Client.ViewModels.TotalPackTask { public class ShopPackTaskTotalViewModel : BaseVM, IDenpendency { private readonly PackTaskService packTaskService; private bool isLoading; private DateTime startDate; private DateTime endDate; private int pageIndex = 1; private int pageSize = 15; private int orderCount; private string searchTaskId; private string searchSkuId; private ObservableCollection packTaskTotalList; public ObservableCollection PackTaskTotalList { get => packTaskTotalList; set { Set(ref packTaskTotalList, value); } } public string SearchSkuId { get => searchSkuId; set { Set(ref searchSkuId, value); } } public string SearchTaskId { get => searchTaskId; set { Set(ref searchTaskId, value); } } public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } public DateTime StartDate { get => startDate; set { Set(ref startDate, value); } } public DateTime EndDate { get => endDate; set { Set(ref endDate, value); } } public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } } public int PageSize { get => pageSize; set { Set(ref pageSize, value); } } public int OrderCount { get => orderCount; set { Set(ref orderCount, value); } } private decimal totalPackDiscountFees; /// /// 总打包费用 /// public decimal TotalPackDiscountFees { get => totalPackDiscountFees; set { Set(ref totalPackDiscountFees, value); } } private decimal totalConsumableFees; /// /// 总耗材费 /// public decimal TotalConsumableFees { get => totalConsumableFees; set { Set(ref totalConsumableFees, value); } } private decimal totalFees; /// /// 总耗材费 /// public decimal TotalFees { get => totalFees; set { Set(ref totalFees, value); } } public ICommand SetSearchDateCommand { get; set; } public ICommand SearchTaskTotalCommand { get; set; } public ICommand ExportCommand { get; set; } public ICommand OrderPageIndexChangedCommand { get; set; } //public IList departmentList; //ShopService shopService; public ShopPackTaskTotalViewModel(PackTaskService packTaskService, GlobalContext globalContext) { this.packTaskService = packTaskService; SearchTaskTotalCommand = new RelayCommand(() => { SearchTask(1); }); StartDate = DateTime.Now; EndDate = DateTime.Now; SetSearchDateCommand = new RelayCommand(d => { EndDate = d == 1 ? DateTime.Now.Date.AddDays(-1) : DateTime.Now; StartDate = DateTime.Now.Date.AddDays(d * -1); PageIndex = 1; Task.Factory.StartNew(() => LoadOrder(1)); //点击日期查询订单 }); OrderPageIndexChangedCommand = new RelayCommand(p => { LoadOrder(p.PageIndex); }); ExportCommand = new RelayCommand(Export); SearchTaskTotal(); this.globalContext = globalContext; } GlobalContext globalContext; private void Export() { SaveFileDialog save = new SaveFileDialog(); save.Filter = "csv files(*.csv)|*.csv"; var result = save.ShowDialog(); if (result == null || !result.Value) { return; } string fileName = save.FileName; Task.Factory.StartNew(() => { IsLoading = true; var res = packTaskService.ShopTotalV3(SearchSkuId, SearchTaskId, globalContext.User.Shop.ShopId.ToString(), StartDate, EndDate, null, null, 0, 0);//获取全部数据 if (res.Success) { //string title = "任务ID,日期,是否结清,部门,店铺,对接人,sku名称,sku数量,增值服务,打包服务,耗材服务,原价,促销折扣,结算价格,对接备注"; string title = "任务ID,日期,是否结清,所属部门,所属店铺,包装数量,收货数量,耗材明细,耗材总价,工序类型,工序套餐,工序单价,包装原价,包装折扣系数,包装折扣价,包装赔付费用,实际打包费用,总收费"; var excelList = res.Data.ShopTotals.Select(x => x.ToString()).ToList(); excelList.Insert(0, title); System.IO.File.WriteAllLines(fileName, excelList, Encoding.UTF8); } IsLoading = false; }); } private void SearchTaskTotal() { PackTaskTotalList = new ObservableCollection(); Task.Factory.StartNew(() => { IsLoading = true; var res = packTaskService.ShopTotalV3(SearchSkuId, SearchTaskId, globalContext.User.Shop.ShopId.ToString(), StartDate, EndDate, null, null, PageIndex, PageSize); if (res != null && res.Success) { OrderCount = res.Data.TotalCount; TotalConsumableFees = res.Data.TotalConsumableFees; TotalPackDiscountFees = res.Data.TotalPackDiscountFees; TotalFees = TotalConsumableFees + TotalPackDiscountFees; foreach (var shopTotal in res.Data.ShopTotals) { if (!shopTotal.ProcessComboName.IsNullOrEmpty()) shopTotal.FeesItemResponse = new Models.APIModel.Response.PackTask.FeesItemResponse { AllFees = shopTotal.AllFees.Value, PackFees = shopTotal.PackDisCountFees.Value, TaskId = shopTotal.TaskId, ProcessTypeName = shopTotal.ProcessTypeName, ProcessComboName = shopTotal.ProcessComboName, ConsumableFees = shopTotal.ConsumableFees, ConsumableList = shopTotal.ConsumableList, ProcessComboPrice = shopTotal.ProcessComboPrice, ProcessComboTaskCount = shopTotal.ProcessComboTaskCount, DiscountFoctor = shopTotal.DiscountFactor, ActualPackFees = shopTotal.ActualPackFees, CompensateFees = shopTotal.CompensateFees, }; App.Current.Dispatcher.Invoke(() => { PackTaskTotalList.Add(shopTotal); }); } } IsLoading = false; }); } private void LoadOrder(int pageIndex) { SearchTask(pageIndex); } private void SearchTask(int pageIndex) { PageIndex = pageIndex; SearchTaskTotal(); } } }