You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
7.5 KiB
213 lines
7.5 KiB
2 years ago
|
using BBWY.Client.APIServices;
|
||
|
using BBWY.Client.APIServices.QiKu;
|
||
|
using BBWY.Client.Models.APIModel;
|
||
|
using BBWY.Common.Models;
|
||
|
using BBWY.Controls;
|
||
|
using GalaSoft.MvvmLight.Command;
|
||
|
using Microsoft.Win32;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows;
|
||
|
using System.Windows.Input;
|
||
|
|
||
|
namespace BBWY.Client.ViewModels.PackerTask
|
||
|
{
|
||
|
public class PackerSalaryViewModel:BaseVM,IDenpendency
|
||
|
{
|
||
|
public PackUserService packUserService;
|
||
|
public PackTaskService packTaskService;
|
||
|
private bool isLoading;
|
||
|
private DateTime startTime;
|
||
|
private DateTime endTime;
|
||
|
private int pageIndex = 1;
|
||
|
private int pageSize = 20;
|
||
|
private int orderCount;
|
||
|
private List<PackerDaySalary> packUserSalaryList;
|
||
|
|
||
|
private string searchUserName;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 总工资
|
||
|
/// </summary>
|
||
|
public decimal totalSalary;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 总任务数
|
||
|
/// </summary>
|
||
|
public int totalTaskCount;
|
||
|
/// <summary>
|
||
|
/// 总件数
|
||
|
/// </summary>
|
||
|
public int totalSkuItemCount;
|
||
|
|
||
|
public int TotalTaskCount { get => totalTaskCount; set { Set(ref totalTaskCount, value); } }
|
||
|
public int TotalSkuItemCount { get => totalSkuItemCount; set { Set(ref totalSkuItemCount, value); } }
|
||
|
|
||
|
public decimal TotalSalary { get => totalSalary; set { Set(ref totalSalary, value); } }
|
||
|
|
||
|
public string SearchUserName { get => searchUserName; set { Set(ref searchUserName, value); } }
|
||
|
public List<PackerDaySalary> PackUserSalaryList { get => packUserSalaryList; set { Set(ref packUserSalaryList, value); } }
|
||
|
|
||
|
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
|
||
|
|
||
|
public DateTime StartTime { get => startTime; set { Set(ref startTime, value); } }
|
||
|
|
||
|
public DateTime EndTime { get => endTime; set { Set(ref endTime, 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); } }
|
||
|
|
||
|
public ICommand SearchPackUserSalaryCommand { get; set; }
|
||
|
|
||
|
public ICommand ExportCommand { get; set; }
|
||
|
|
||
|
public ICommand OrderPageIndexChangedCommand { get; set; }
|
||
|
|
||
|
public ICommand SetSearchDateCommand { get; set; }
|
||
|
|
||
|
public PackerSalaryViewModel(PackTaskService packTaskService, PackUserService packUserService)
|
||
|
{
|
||
|
this.packTaskService = packTaskService;
|
||
|
|
||
|
OrderPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
|
||
|
{
|
||
|
LoadOrder(p.PageIndex);
|
||
|
});
|
||
|
|
||
|
SearchPackUserSalaryCommand = new RelayCommand(SearchPackUserSalary);
|
||
|
|
||
|
StartTime = DateTime.Now;
|
||
|
EndTime = DateTime.Now;
|
||
|
SearchPackUserSalary();
|
||
|
SetSearchDateCommand = new RelayCommand<int>(d =>
|
||
|
{
|
||
|
EndTime = d == 1 ? DateTime.Now.Date.AddDays(-1) : DateTime.Now;
|
||
|
StartTime = DateTime.Now.Date.AddDays(d * -1);
|
||
|
PageIndex = 1;
|
||
|
Task.Factory.StartNew(() => LoadOrder(1)); //点击日期查询订单
|
||
|
});
|
||
|
ExportCommand = new RelayCommand(Export);
|
||
|
this.packUserService = packUserService;
|
||
|
LoadOrder(1);
|
||
|
}
|
||
|
|
||
|
private void LoadOrder(int pageIndex)
|
||
|
{
|
||
|
PageIndex = pageIndex;
|
||
|
SearchPackUserSalary();
|
||
|
}
|
||
|
private void SearchPackUserSalary()
|
||
|
{
|
||
|
PackUserSalaryList = new List<PackerDaySalary> ();
|
||
|
Task.Factory.StartNew(() =>
|
||
|
{
|
||
|
IsLoading = true;
|
||
|
try
|
||
|
{
|
||
|
var res = packUserService.SearchPackerSalary(StartTime.Date, EndTime.Date, PageIndex, PageSize);
|
||
|
if (res != null && res.Success)
|
||
|
{
|
||
|
OrderCount = res.Data.TotalCount;
|
||
|
TotalSalary = res.Data.TotalSalary;
|
||
|
TotalSkuItemCount = res.Data.TotalSkuItemCount;
|
||
|
TotalTaskCount = res.Data.TotalTaskCount;
|
||
|
App.Current.Dispatcher.Invoke(() =>
|
||
|
{
|
||
|
PackUserSalaryList = res.Data.PackerDaySalaries;
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//foreach (var packUserSalary in res.Data.PackUserSalaries)
|
||
|
//{
|
||
|
// App.Current.Dispatcher.Invoke(() =>
|
||
|
// {
|
||
|
// PackUserSalaryList.Add(packUserSalary);
|
||
|
// });
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
App.Current.Dispatcher.Invoke(() =>
|
||
|
{
|
||
|
PackUserSalaryList = new List<PackerDaySalary>();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
|
||
|
MessageBox.Show(ex.Message);
|
||
|
}
|
||
|
|
||
|
|
||
|
IsLoading = false;
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
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.TotalPackUserSalary(SearchUserName, StartTime, EndTime, 0, 0);//获取全部数据
|
||
|
if (res.Success)
|
||
|
{
|
||
|
//string title = "任务ID,日期,是否结清,部门,店铺,对接人,sku名称,sku数量,增值服务,打包服务,耗材服务,原价,促销折扣,结算价格,对接备注";
|
||
|
List<string> exportList = new List<string>();
|
||
|
string title = "日期,花名,总收益";
|
||
|
if (res.Data.TotalCount > 0)
|
||
|
{
|
||
|
foreach (var item in res.Data.PackUserSalaries[0].IncomeItems)
|
||
|
{
|
||
|
title += $",{item.Name}";
|
||
|
}
|
||
|
exportList.Add(title);
|
||
|
|
||
|
foreach (var packUserSalary in res.Data.PackUserSalaries)
|
||
|
{
|
||
|
List<string> rowList = new List<string>();
|
||
|
rowList.Add(packUserSalary.Date.ToString("yyyy-MM-dd"));
|
||
|
rowList.Add(packUserSalary.PackUserName);
|
||
|
rowList.Add(packUserSalary.TotalIncome.ToString("0.00"));
|
||
|
foreach (var incomeItem in packUserSalary.IncomeItems)
|
||
|
{
|
||
|
rowList.Add(incomeItem.TotalPrice.ToString());
|
||
|
}
|
||
|
|
||
|
exportList.Add(string.Join(",", rowList));
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
//var excelList = res.Data.ShopTotals.Select(x => x.ToString()).ToList();
|
||
|
//excelList.Insert(0, title);
|
||
|
System.IO.File.WriteAllLines(fileName, exportList, Encoding.UTF8);
|
||
|
}
|
||
|
IsLoading = false;
|
||
|
|
||
|
});
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|