88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
using Acr.UserDialogs;
|
|
using Rg.Plugins.Popup.Pages;
|
|
using Rg.Plugins.Popup.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Threading;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Xaml;
|
|
using XXCpzs.helper;
|
|
using XXCpzs.Models;
|
|
using XXCpzs.ViewModels;
|
|
|
|
namespace XXCpzs.Views
|
|
{
|
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
|
public partial class PageLogin : PopupPage
|
|
{
|
|
LoginViewModel ViewModel;
|
|
private int Uid;
|
|
private PageMain pageMain;
|
|
public PageLogin(PageMain pageMain)
|
|
{
|
|
InitializeComponent();
|
|
this.pageMain = pageMain;
|
|
this.BindingContext = ViewModel = new LoginViewModel(pageMain.companyId);
|
|
}
|
|
|
|
void OnBumenPickerSelectedIndexChangedAsync(object sender, EventArgs e)
|
|
{
|
|
var picker = (Picker)sender;
|
|
int selectedIndex = picker.SelectedIndex;
|
|
if (selectedIndex != -1)
|
|
{
|
|
DepartmentItem buMen = ViewModel.BuMenItems[selectedIndex] as DepartmentItem;
|
|
Dictionary<string, string> _body = new Dictionary<string, string>{
|
|
{ "companyId", pageMain.companyId.ToString() },{"departmentId", buMen.id.ToString() }
|
|
};
|
|
|
|
List<UserItem> buMens = HttpHelper.RefreshData<UserItem>(04, RestSharp.Method.POST, _body);
|
|
ViewModel.UserItems = new ObservableCollection<UserItem>();
|
|
foreach (var item in buMens)
|
|
{
|
|
ViewModel.UserItems.Add(item);
|
|
}
|
|
UserPicker.ItemsSource = ViewModel.UserItems;
|
|
}
|
|
}
|
|
|
|
private void UserPicker_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
var picker = (Picker)sender;
|
|
int selectedIndex = picker.SelectedIndex;
|
|
|
|
if (selectedIndex != -1)
|
|
{
|
|
this.Uid = ViewModel.UserItems[selectedIndex].uid;
|
|
}
|
|
}
|
|
|
|
async void Button_ClickedAsync(object sender, EventArgs e)
|
|
{
|
|
UserDialogs.Instance.ShowLoading("正在登录,请稍后!");
|
|
new Thread(new ThreadStart(async () =>
|
|
{
|
|
Dictionary<string, string> _body = new Dictionary<string, string>{
|
|
{ "Uid", this.Uid.ToString() },{"Password", UserPass.Text.Trim() }
|
|
};
|
|
var Result = HttpHelper.Refresh<UserInfo>("login", _body);
|
|
if (Result.Code == 200)
|
|
{
|
|
|
|
Device.BeginInvokeOnMainThread(() =>{
|
|
UserInfo LoginResult = Result.Data;
|
|
pageMain.Loginback(LoginResult);
|
|
UserDialogs.Instance.HideLoading();
|
|
});
|
|
await PopupNavigation.Instance.PopAsync();
|
|
}
|
|
else
|
|
{
|
|
await DisplayAlert("访问出错", Result.Msg, "OK");
|
|
//Button_ClickedAsync(sender, e);
|
|
}
|
|
})).Start();
|
|
}
|
|
}
|
|
} |