Newer
Older
import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {AppService} from "../../../../service/http.service";
import {Geolocation} from "@ionic-native/geolocation";
import * as moment from "moment";
import {HomeService} from "../../home.service";
import {CommonService} from "../../../../provide/common.service";
@IonicPage()
@Component({
selector: 'page-duty-sign-up',
templateUrl: 'duty-sign-up.html',
})
export class DutySignUpPage {
id;
signState;
signStatus = 'fail';
//市委组织部坐标
mainLat = 31.205033; //纬度
// mainLat = 31.231871; //纬度test 31.231871, 121.393319
mainLng = 121.444888; //经度
// mainLng = 121.393319; //经度test
nowDay;
constructor(public navCtrl: NavController, public navParams: NavParams,public homeSer:HomeService,
public commonSer:CommonService,
public appService: AppService, public geolocation: Geolocation) {
}
ionViewDidLoad() {
this.nowDay = moment().format('l');
this.homeSer.myScheduleOfToday().subscribe(
(res)=>{
if(res){
this.signInfo = res.json();
}else{
this.commonSer.toast('暂无值班')
}
}
)
}
//签到
signIn() {
const data = {
id: this.signInfo.id, //值班记录id,
address: '上海市委组织部' //签到地址
};
this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/signIn', data)
.subscribe((res) => {
})
}
//签退
signBack() {
this.calcuDistance();
const data = {
id:this.signInfo.id, //值班记录id,
address:'上海市委组织部' //签到地址
};
this.appService.ObserverHttpGet('/wisdomgroup/schedule/signOut',data)
.subscribe((res)=>{
})
}
//计算距离
calcuDistance() {
this.geolocation.getCurrentPosition().then((resp) => {
const distance = this.getDisance(this.mainLat, this.mainLng, resp.coords.latitude, resp.coords.longitude);
if(distance < 1000){
this.signIn();
}else{
this.commonSer.toast('距离太远,无法签到');
}
}).catch((error) => {
console.log(error);
});
}
getDisance(lat1, lng1, lat2, lng2) {
let radLat1 = this.toRad(lat1);
let radLat2 = this.toRad(lat2);
let deltaLat = radLat1 - radLat2;
let deltaLng = this.toRad(lng1) - this.toRad(lng2);
let dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
dis = dis * 6378137;
dis = Math.round(dis * 10) / 10;
return dis;
}
toRad(d) {
return d * Math.PI / 180;
}
}