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

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

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



    },
    onReady: function () {

    },

    onShow: function () {
        let that = this;
        that.getList();
        that.getaddredss()
        // 获取经纬度
        wx.getLocation({
            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
                    })    
                })

                
            },
        })
        
        // 获取时间点
        var time = util.formathour(new Date());
        this.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;
        let url = '/index/second/startClock';
        let head = {
            'XX-Token': wx.getStorageSync('token')
        }
        let d = {
            id: that.data.id,
            long: that.data.latitude,
            lat: that.data.longitude

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

        }).catch((err) => {

        })

    },

    // 下岗打卡
    getEnd() {

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


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

        }).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 () {

    },

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

    },

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

    },

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

    },

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

    }
})