const app = getApp()
const util = require("../../../utils/util");
const api = require('../../../api/api.js');
const user = require('../../../utils/user.js');
const map=require('../../../utils/map');
import moment from 'moment'



Page({
  data: {
		 detailId:'',
		 qrCodeUrl:'',
		 status:''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      if(options.serviceId){
				this.setData({
					serviceId:options.serviceId
				});
				// this.getQrCode()
			}
  }, 
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  this.getQrCode()
	},
	goBack(){
		wx.navigateBack();
	},
getQrCode(){
	wx.showLoading({
		title: '加载中...',
	});
	util.request(api.serviceOrderAcceptanceCheck, {
		serviceId:this.data.serviceId
	}, 'GET').then(res => {
		wx.hideLoading();
		if (res.errno === 0) {
			this.setData({
				qrCodeUrl:res.data.qrCodeUrl,
				status:res.data.status
			});
		
		}
	}).catch(err => {
		wx.hideLoading();
	});
},
sendFinish(){
	this.finishOrder();
	this.sendSms();
},
checkFinish(){
	this.finishOrder(true);
},
finishOrder(flag){
	console.log(flag);
	let that=this;
	wx.getLocation({
    type: 'wgs84',
    success: function (res) { 
			console.log(res);
      var lat = res.latitude;
			var lng= res.longitude; 
			wx.showLoading({
				title: '加载中...',
			});
			util.request(api.finishServiceOrder, {
				serviceId:that.data.serviceId,
				latlng:lng+','+lat,
				address:'',
			}, 'GET').then(res2 => {
				console.log(res2);
				wx.hideLoading();
				if (res2.errno == 0) {
			    if(flag){
						wx.navigateTo({
							url: '/pages/problem/list/list?bookTradeNo=' + that.data.serviceId,
						})
					}
				}else{
					wx.showToast({
						title: res2.errmsg,
						icon: 'none',
					});
				}
			}).catch(err => {
				wx.hideLoading();
			});
		},
    fail: function (res) {
      console.log('fail' + JSON.stringify(res))
    }
  })	
	// map.getLocation().then((res)=>{
	// 	 console.log(res);
	// }).catch((res)=>{
	// 	console.log('fail' + JSON.stringify(res))
	// });

},
sendSms(){
	wx.showLoading({
		title: '加载中...',
	});
	util.request(api.smsEvaluate, {
		serviceId:this.data.serviceId
	}, 'GET').then(res => {
		wx.hideLoading();
		if (res.errno === 0) {

		}
	}).catch(err => {
		wx.hideLoading();
	});
},
  onHide: function () {

  },

  onUnload: function () {

  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})