85 lines
2.9 KiB
C#
85 lines
2.9 KiB
C#
using Plugin.Permissions;
|
|
using Plugin.Permissions.Abstractions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Xaml;
|
|
using XXCpzs.helper;
|
|
using XXCpzs.Models;
|
|
using XXCpzs.ViewModels;
|
|
using ZXing.Mobile;
|
|
|
|
namespace XXCpzs.Views
|
|
{
|
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
|
public partial class PageSale : ContentPage
|
|
{
|
|
private SaleViewModel ViewModel;
|
|
private int deviceId = 1;
|
|
private UserInfo userInfo;
|
|
|
|
public PageSale(UserInfo userInfo)
|
|
{
|
|
InitializeComponent();
|
|
this.userInfo = userInfo;
|
|
this.BindingContext = ViewModel = new SaleViewModel();
|
|
}
|
|
private async void ButtonCustomerSelect_Clicked(object sender, EventArgs e)
|
|
{
|
|
await Navigation.PushModalAsync(new NavigationPage(new PageCustomerSelect(userInfo)));
|
|
}
|
|
private async void Button_ClickedAsync(object sender, EventArgs e)
|
|
{
|
|
if (userInfo != null && ViewModel.CustomerId != 0 && SerialNumber.Text != null)
|
|
{
|
|
Dictionary<string, string> _body = new Dictionary<string, string>{
|
|
{"Sn", SerialNumber.Text},
|
|
{"Uid", userInfo.uid.ToString()},
|
|
{"CustomerId", ViewModel.CustomerId.ToString()},
|
|
{"deviceId", this.deviceId.ToString()}
|
|
};
|
|
var request = await HttpHelper.RequestPost(16, _body);
|
|
if (request.Code == 200){
|
|
ViewModel.Items.Add(new ResultModel() { Code = request.Code, Data = request.Data, Msg = request.Msg });
|
|
}
|
|
else{
|
|
await DisplayAlert("访问出错", request.Msg, "OK");
|
|
}
|
|
}
|
|
}
|
|
private async void OnScan(object sender, EventArgs e)
|
|
{
|
|
if (this.ViewModel.CustomerId == 0)
|
|
{
|
|
await DisplayAlert("注意", "请选择产品 购买的客户", "OK"); return;
|
|
}
|
|
if (await CheckPerssion())
|
|
{
|
|
var scanner = new MobileBarcodeScanner();
|
|
var result = await scanner.Scan();
|
|
if (result != null)
|
|
{
|
|
SerialNumber.Text = result.Text;
|
|
Button_ClickedAsync(sender, e);
|
|
}
|
|
}
|
|
}
|
|
private async Task<bool> CheckPerssion()
|
|
{
|
|
var current = CrossPermissions.Current;
|
|
//检查权限
|
|
var status = await current.CheckPermissionStatusAsync(Permission.Camera);
|
|
if (status != PermissionStatus.Granted)
|
|
{
|
|
var result = await current.RequestPermissionsAsync(Permission.Camera);
|
|
status = result[Permission.Camera];
|
|
}
|
|
return status == PermissionStatus.Granted;
|
|
}
|
|
|
|
}
|
|
} |