myactivity_active.js 5.8 KB
const app = getApp()
var util = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: '',
        id: '',
        latitude: '',
        longitude: '',
        time: '',
        my_address: '',
        layerModel: false
    },

    onLoad: function (options) {
        // console.log(options)
        this.setData({
            id: options.id
        })



    },
    changeModalCancel() {
        // console.log('取消')
        this.setData({
            hiddenadd: !this.data.hiddenadd
        })
    },

    onReady: function () {

    },

    onShow: function () {
        let that = this;

        that.getList();
        // that.getaddredss()
        // 获取经纬度
        // this.locationAuth();

        wx.getLocation({
            isHighAccuracy:true,
            success: function (res) {
                console.log(res)
                that.setData({
                    latitude: res.latitude,
                    longitude: res.longitude
                })

                let url = '/index/second/getAddressInfo';
                let head = {
                    'XX-Token': wx.getStorageSync('token')
                }
                let d = {
                    lat: res.latitude,
                    lng: res.longitude
                }
                // console.log(d)
                app.post(url, d, head).then((res) => {
                    console.log(res);
                    that.setData({
                        my_address: res.address
                    })
                })


            },

            fail() {
                wx.showModal({
                    title: '提示',
                    content: '请打开手机定位功能',
                    showCancel: false

                })

            }


        })

        // 获取时间点
        this.data.timeInterval = setInterval(() => {
            var time = util.formathour(new Date());
            that.setData({
                time: time
            })
        })



    },



    // 详情列表
    getList() {

        let that = this;
        let url = '/index/second/clockInfo';
        let head = {
            'XX-Token': wx.getStorageSync('token')
        }
        let d = {
            id: that.data.id

        }
        console.log(d)
        app.post(url, d, head).then((res) => {
            that.setData({
                list: res
            })

        }).catch((err) => {

        })
    },

    // 上岗打卡
    getpunch() {
        let that = this;


        if (that.data.latitude == '') {
            wx.getSetting({
                success: (res) => {
                    console.log(res)
                    if (!res.authSetting['scope.userLocation']) {
                        //打开提示框,提示前往设置页面
                        this.setData({
                            layerModel: true
                        })
                    }
                }
            })

        } else {

            let url = '/index/second/startClock';
            let head = {
                'XX-Token': wx.getStorageSync('token')
            }
            let d = {
                id: that.data.id,
                long: that.data.longitude,
                lat: that.data.latitude

            }
            console.log(d)
            app.post(url, d, head).then((res) => {

                console.log(res)
                wx.showToast({
                    title: '上岗打卡成功',
                })
                setTimeout(() => {
                    that.getList()
                }, 1200)

            }).catch((err) => {

            })

        }




    },

    // 下岗打卡
    getEnd() {
        let that = this;
        if (that.data.latitude == '') {
            wx.getSetting({
                success: (res) => {
                    console.log(res)
                    if (!res.authSetting['scope.userLocation']) {
                        //打开提示框,提示前往设置页面
                        this.setData({
                            layerModel: true
                        })
                    }
                }
            })

        } else {

            let url = '/index/second/endClock';
            let head = {
                'XX-Token': wx.getStorageSync('token')
            }
            let d = {
                id: that.data.id,
                long: that.data.longitude,
                lat: that.data.latitude

            }
            console.log(d)
            app.post(url, d, head).then((res) => {
                console.log(res)
                wx.showToast({
                    title: '下岗打卡成功',
                })
                setTimeout(() => {
                    that.getList()
                }, 1200)

            }).catch((err) => {

            })

        }
    },
    // 获取当前地址
    // getaddredss() {

    //     let that = this;
    //     let url = '/index/second/clockInfo';
    //     let head = {
    //         'XX-Token': wx.getStorageSync('token')
    //     }
    //     let d = {
    //         id: that.data.id

    //     }
    //     app.post(url, d, head).then((res) => {
    //         that.setData({
    //            adddress: res
    //         })

    //     }).catch((err) => {

    //     })
    // },


    // 提示
    click: function (e) {
        this.setData({
            hiddenName: !this.data.hiddenName
        })
    },

    onHide: function () {
        clearInterval(this.data.timeInterval)
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

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

    },

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

    },

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

    }
})