瀏覽代碼

修改bug

wangxin 5 年之前
父節點
當前提交
065776eb2a

+ 2 - 2
pages/clock/clock-tongji/index.js

@@ -105,8 +105,8 @@ Page({
     })
   },
   day(e) {
-    let { year, month, day } = e.detail
-    const search_date = [year, month, day].map(val => {
+    let { year, month, date } = e.detail
+    const search_date = [year, month, date].map(val => {
       const number = val.toString()
       return number[1] ? number : '0' + number
     }).join('-')

+ 1 - 0
pages/clock/clock-tongji/list.js

@@ -14,6 +14,7 @@ Page({
    */
   data: {
     avatar: wx.getStorageSync('userInfo').avatarUrl,
+    name: wx.getStorageSync('userInfo').nickName,
     imgServerUrl,
     mouthNext: `${imgServerUrl}/images/clock/clock-arrow-righr-disabled.png`,
     mouthLast: `${imgServerUrl}/images/clock/clock-arrow-left.png`,

+ 1 - 1
pages/clock/clock-tongji/list.wxml

@@ -9,7 +9,7 @@
       <image class="avatar-icon" src="{{imgServerUrl}}/images/clock/clock-approving-icon.png" wx:else></image>
     </view>
     <view class="header-info">
-      <view>铁锤</view>
+      <view>{{name}}</view>
       <view class="approveStatus {{approveStatus === 3 ? '' : 'approveStatus-color'}}">
         {{approveStatus === 3 ? '开心工作认证用户' : '认证信息审核中'}}</view>
     </view>

+ 20 - 6
pages/clock/clock.js

@@ -6,6 +6,7 @@ import {
 import {
   imgServerUrl
 } from '../../config/config.js'
+import { transformFromWGSToGCJ } from '../../utils/util'
 Page({
 
   /**
@@ -38,7 +39,7 @@ Page({
     todayMoney: 0,
     sumDuration: 0,
     sumMoney: 0,
-    wsPunchClockId: null
+    wsPunchClockId: ''
   },
   toRule() {
     wx.navigateTo({
@@ -48,12 +49,12 @@ Page({
   getLocation() {
     return new Promise(reslove => {
       wx.getLocation({
-        type: 'gcj02 ',
         success: data => {
-          reslove(data)
+          const { latitude, longitude } = transformFromWGSToGCJ(data.latitude, data.longitude)
+          reslove(Object.assign(data, { latitude, longitude }))
         },
         fail: res => {
-          console.log(res)
+          reslove(res)
         }
       })
     })
@@ -63,7 +64,19 @@ Page({
       wx.getSetting({
         success: async res => {
           if (res.authSetting['scope.userLocation']) {
-            reslove(await this.getLocation())
+            const data = await this.getLocation()
+            const info = wx.getSystemInfoSync()
+            if (data.errMsg.indexOf('system permission denied') !== -1 || info.locationEnabled === false) {
+              wx.showModal({
+                content: '无法使用打卡功能',
+                title: '微信未开启系统定位功能',
+                showCancel: false,
+              })
+              reject()
+            } else {
+              console.log(data)
+              reslove(data)
+            }
           } else {
             wx.authorize({
               scope: 'scope.userLocation',
@@ -125,7 +138,7 @@ Page({
     }
   },
   clock(longitude, latitude) {
-    savePunchClock({ longitude, latitude, clockType: this.data.clockType }).then(data => {
+    savePunchClock({ longitude, latitude, clockType: this.data.clockType, wsPunchClockId: this.data.wsPunchClockId }).then(data => {
       wx.showToast({
         title: '打卡成功',
         success: () => {
@@ -170,6 +183,7 @@ Page({
   },
   async load() {
     const data = await this.location()
+    console.log(data)
     punchClockNeedInfo({ longitude: data.longitude, latitude: data.latitude }).then(data => {
       // punchClockNeedInfo({ longitude: 120.353312, latitude: 31.535582 }).then(data => {
       let {

+ 4 - 4
pages/clock/clock.wxml

@@ -1,7 +1,7 @@
 <!--pages/clock/clock.wxml-->
 <wxs src="./clock.wxs" module="clock"></wxs>
 <view class="container">
-  <view class="no-authentication" wx:if="{{approveStatus === 0}}">
+  <view class="no-authentication" wx:if="{{approveStatus === 2}}">
     <view class="header">
       <image src="{{imgServerUrl}}/images/clock/clock-bg.png" class="no-authentication-bg" mode="widthFixed"></image>
     </view>
@@ -22,7 +22,7 @@
     </view>
     <image bindtap="toRule" src="{{imgServerUrl}}/images/clock/clock-video.png" class="video"></image>
   </view>
-  <view class="no-pass" wx:elif="{{approveStatus === 2}}">
+  <view class="no-pass" wx:elif="{{approveStatus === 0}}">
     <view class="header">
       <image src="{{imgServerUrl}}/images/clock/clock-bg.png" class="no-pass-bg" mode="widthFixed"></image>
     </view>
@@ -36,7 +36,7 @@
         前往认证
       </navigator>
     </view>
-    <image src="{{imgServerUrl}}/images/clock/clock-video.png" class="video"></image>
+    <image  bindtap="toRule" src="{{imgServerUrl}}/images/clock/clock-video.png" class="video"></image>
   </view>
   <view class="pass" wx:else>
     <view class="pass-header">
@@ -107,7 +107,7 @@
       <view class="prepayable">
         <text>当日可预支工资:</text>
         <view>
-          <text class="prepayable-number">37.0</text>
+          <text class="prepayable-number">{{clock.toFixed(todayMoney)}}</text>
           <text class="prepayable-unit">元</text>
         </view>
       </view>

+ 15 - 15
utils/http.js

@@ -2,12 +2,13 @@ var config = require('../config/config.js')
 import {
   showToast
 } from '../utils/tips.js'
+import { Loading } from './loading'
+const _loading = new Loading();
 const noRelaunch = [
   'pages/interview-registration/index'
 ]
 //model状态
 let model = true;
-let loading = true;
 //服务器地址
 const apiUrl = config.apiUrl;
 /**
@@ -40,17 +41,16 @@ const getData = (data) => {
  * 封装http 请求方法
  */
 const http = (params) => {
+  _loading.showLoading({
+    mask: true,
+    title: '加载中...',
+    success: () => {
+      console.log('loding start')
+    }
+  })
   //返回promise 对象
   return new Promise((resolve, reject) => {
-    if (loading) {
-      loading = false;
-      wx.showLoading({
-        title: 'loading',
-        mask: true
-      });
-    }
     const pages = getCurrentPages();
-
     wx.request({
       url: apiUrl + params.url, //服务器url+参数中携带的接口具体地址
       data: getData(params.data || {}), //请求参数
@@ -61,11 +61,11 @@ const http = (params) => {
       dataType: params.dataType, //返回的数据格式,默认为JSON,特殊格式可以在调用的时候传入参数
       responseType: params.responseType, //响应的数据类型
       success: function (res) {
-        wx.hideLoading({
+        _loading.hideLoading({
           success: () => {
-            loading = true
+            console.log('loding end')
           }
-        });
+        })
         if (res.statusCode == 200) {
           var errorCode = res.data.errcode
           if (errorCode == 0) {
@@ -189,11 +189,11 @@ const http = (params) => {
         }
       },
       fail: function (e) {
-        wx.hideLoading({
+        _loading.hideLoading({
           success: () => {
-            loading = true
+            console.log('loding end')
           }
-        });
+        })
         wx.showToast({
           icon: "none",
           title: "网络异常",

+ 25 - 0
utils/loading.js

@@ -0,0 +1,25 @@
+class Loading {
+	constructor() {
+		this.load_arr = []
+	}
+	showLoading(options) {
+		if (!this.load_arr.length) {
+			options ? wx.showLoading({
+				...options
+			}) : wx.showLoading()
+		}
+		this.load_arr.push(true)
+	}
+	hideLoading(options) {
+		this.load_arr.pop();
+		if (!this.load_arr.length) {
+			options ? wx.hideLoading({
+				...options
+			}) : wx.hideLoading()
+		}
+	}
+}
+
+module.exports = {
+	Loading: Loading
+}

+ 60 - 1
utils/util.js

@@ -73,6 +73,64 @@ function testPhone(data) {
   const phone_zz = /^1[3-9]\d{9}$/;
   return phone_zz.test(data)
 }
+/**
+ *  判断经纬度是否超出中国境内
+ */
+function isLocationOutOfChina(latitude, longitude) {
+  if (longitude < 72.004 || longitude > 137.8347 || latitude < 0.8293 || latitude > 55.8271)
+    return true;
+  return false;
+}
+
+function transformLatWithXY(x, y) {
+  var pi = 3.14159265358979324;
+  var lat = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
+  lat += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
+  lat += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
+  lat += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
+  return lat;
+}
+
+function transformLonWithXY(x, y) {
+  var pi = 3.14159265358979324;
+  var lon = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
+  lon += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
+  lon += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
+  lon += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
+  return lon;
+}
+
+function isContains(point, p1, p2) {
+  return (point.latitude >= Math.min(p1.latitude, p2.latitude) && point.latitude <= Math.max(p1.latitude, p2.latitude)) && (point.longitude >= Math.min(p1.longitude, p2.longitude) && point.longitude <= Math.max(p1.longitude, p2.longitude));
+}
+
+/** 
+ * 将WGS-84(国际标准)转为GCJ-02(火星坐标): 
+ */ 
+function transformFromWGSToGCJ(latitude, longitude) { 
+  var lat = ""; 
+  var lon = ""; 
+  var ee = 0.00669342162296594323; 
+  var a = 6378245.0; 
+  var pi = 3.14159265358979324; 
+    if (isLocationOutOfChina(latitude, longitude)) { 
+  lat = latitude; 
+  lon = longitude; 
+  } 
+  else { 
+  var adjustLat = transformLatWithXY(longitude - 105.0, latitude - 35.0); 
+  var adjustLon = transformLonWithXY(longitude - 105.0, latitude - 35.0); 
+  var radLat = latitude / 180.0 * pi; 
+  var magic = Math.sin(radLat); 
+  magic = 1 - ee * magic * magic; 
+  var sqrtMagic = Math.sqrt(magic); 
+  adjustLat = (adjustLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); 
+  adjustLon = (adjustLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); 
+  latitude = latitude + adjustLat; 
+  longitude = longitude + adjustLon; 
+  } 
+  return { latitude: latitude, longitude: longitude }; 
+    }
 module.exports = {
   formatTime: formatTime,
   formatNumber,
@@ -80,5 +138,6 @@ module.exports = {
   argusToTimestamp,
   formateYM,
   formatetime,
-  testPhone
+  testPhone,
+  transformFromWGSToGCJ
 }