商家预约并签到

    技术2022-07-17  77

    const $api = require('../../../utils/api.js').API

    const pointFun = require('../../../utils/pointMap.js').IsPtInPoly

    Page({

     

    /**

    * 页面的初始数据

    */

    data: {

    swiperPhoto:[

    {

    images:'/images/business.png'

    }, {

    images: '/images/business.png'

    }, {

    images: '/images/business.png'

    }

    ],

    latitude: "",

    longitude: "",

    // 区域假数据

    polygons: [{

    points: [{

    longitude: 117.265348,

    latitude: 38.907694

    }, {

    longitude: 117.365348,

    latitude: 38.917694

    }, {

    longitude: 117.365348,

    latitude: 38.917694

    },

    {

    longitude: 117.385348,

    latitude: 38.957694

    },

    {

    longitude: 117.375348,

    latitude: 38.927694

    }],

    strokeColor: '#6A79F1',

    fillColor: '',

    strokeStyle:'solid',

    strokeWidth: 2,

    zIndex: 1

    },

    {

    points: [{

    longitude: 111.818599,

    latitude: 34.707698

    }, {

    longitude: 108.985415,

    latitude: 34.441382

    },

    {

    longitude: 107.771193,

    latitude: 33.120195

    },

    {

    longitude: 110.78835,

    latitude: 32.778928

    }],

    // fillColor: "#ffff0033",

    // strokeColor: "#FFF",

    strokeColor: '#6A79F1',

    fillColor: '',

    strokeWidth: 2,

    zIndex: 1

    }],

    alertPosition:false,

    alreadyContent:false,

    onFullContent:false,

    buttonShow:false,

    ssingShow:false,

    successShow:false,

    stallInformation:{

    title:'',

    stallNumber:''

    },

    gridDetailList:{},

    cover:[],

    gridId:'',

    periodId:'',

    periodIdName:'',

    addClass:false,

    currTabIndex:0,

    arrPath:[]

     

    },

     

    /**

    * 生命周期函数--监听页面加载

    */

    onLoad: function (options) {

    var id = options.id

    this.setData({

    gridId:id

    })

    this.getGridDetail(id)

    $api.configuration({ code:'appointment_time' }).then(res => {

    console.log(res)

    this.setData({

    appointValue: res.data.data.value

    })

     

    })

    var title = 'stallInformation.title'

    var stallNumber = 'stallInformation.stallNumber'

    console.log(options)

    this.enterpriseDetail()

     

    },

    // 详情

    getGridDetail(id) {

    $api.getGridDetail({ id: id }).then(res => {

    if (res.data.success == true) {

    var imgArr = res.data.data.cover.split(',')

    this.setData({

    gridDetailList: res.data.data,

    cover: imgArr

    })

    this.data.gridDetailList.cover = res.data.data.cover.split(',')

    console.log('this.data.gridDetailList', this.data.gridDetailList)

    console.log('this.data.cover', this.data.cover)

    var points = []

    var obj = {}

    var arr = JSON.parse(res.data.data.path)

    this.setData({

    longitude: arr[0].lng,

    latitude: arr[0].lat,

    arrPath: arr

    })

    arr.forEach(val => {

    val.longitude = val.lng

    val.latitude = val.lat

    points.push(val)

    })

    obj = { points }

    obj.strokeColor = '#6A79F1',

    obj.fillColor = '',

    obj.strokeStyle = 'solid',

    obj.strokeWidth = 2,

    obj.zIndex = 1

    var arrayList = []

    arrayList.push(obj)

    this.setData({

    polygons: arrayList

    })

    var objList = {}

    console.log('objList', objList)

    // 当前时间

    let nowTime = new Date().getTime(); // 当前时间戳

    console.log('new Date()', new Date())

    let yeas = new Date().getFullYear() + " " + (new Date().getMonth() + 1) + " " + new Date().getDate()

    console.log('nowTime今天时间戳', nowTime);

    (this.data.gridDetailList.periodList).forEach((item, key) => {

    var beforeTime = Number(this.data.appointValue)

    item.beforeTimeAreaStart = new Date(yeas + ' ' + item.startTime).getTime() - 1000 * 60 * 60 * beforeTime // 前1小时时间戳

    console.log('item.beforeTimeAreaStart前1小时', new Date(item.beforeTimeAreaStart))

    item.timeAreaStart = new Date(yeas + ' ' + item.startTime).getTime() // 开始时间戳

    item.timeAreaEnd = new Date(yeas + ' ' + item.endTime).getTime() // 结束时间戳

    objList.periodId = item.id

    this.setData({

    periodIdName: item.id

    })

    var enterpriseDetail = wx.getStorageSync('enterprise')

    objList.enterpriseId = enterpriseDetail.id

    objList.gridId = this.data.gridDetailList.id

    console.log('nowTime 当前时间戳', nowTime)

    console.log('item.timeAreaStart开始时间戳', item.timeAreaStart)

    console.log('item.timeAreaEnd 结束时间戳', item.timeAreaEnd)

    // var mm = new Date(item.beforeTimeAreaStart)

    // var kk = new Date(yeas + ' ' + item.endTime)

    // console.log('today', new Date())

    // console.log('mm', mm)

    // console.log('kk', kk)

    if (((item.beforeTimeAreaStart < nowTime) && (nowTime < item.timeAreaEnd)) && (this.data.gridDetailList.remainingNumber !== 0)) {

    console.log('1111111111111111111预约按钮亮')

    $api.findAppointment(objList).then(res => {

    console.log(res.data.data)

    console.log(typeof res.data.data)

    // 没点预约

    if (res.data.data == '') {

    console.log('没有预约过')

    this.setData({

    buttonShow: true

    })

    } else {

    console.log('有预约过')

    this.setData({

    successAppointment: res.data.data,

    appointmentId: res.data.data.id,

    buttonShow: false

    })

    if (res.data.data.isSign == 0) {

    // 没签到

    // this.setData({

    // ssingShow: true

    // })

    // // 获取自己的所在的经纬度,定位

    wx.getLocation({

    type: 'gcj02',

    success: (res) => {

    console.log('获取地理位置', res)

    this.setData({

    longitude: res.longitude,

    latitude: res.latitude

    })

    this.data.arrPath.forEach(item => {

    item.latitude = item.lat

    item.longitude = item.lng

    })

    pointFun(res.latitude, res.longitude, this.data.arrPath)

    if (pointFun(res.latitude, res.longitude, this.data.arrPath) == true) {

    this.setData({

    ssingShow: true

    })

     

    } else {

    this.setData({

    ssingShow: false

    })

    }

    console.log('99999999999999999999', pointFun(res.latitude, res.longitude, this.data.arrPath))

    },

    })

     

    } else {

    // 已经签到

    this.setData({

    ssingShow: false

    })

    }

    }

    })

    console.log('item.id', item.id)

    console.log('点击预约')

    this.setData({

    periodTime: objList,

    })

    } else {

    console.log('1111111111111预约按钮灰')

    // wx.showToast({

    // title: '请按规定时间预约',

    // icon: 'none',

    // duration: 2000

    // })

    this.setData({

    buttonShow: false

    })

    return

    }

     

    })

    console.log('最终', this.data.gridDetailList)

    console.log('预约按钮颜色', this.data.buttonShow)

     

    }

    })

    },

    // 点击弹框内确定,关闭弹框

    sureTap() {

    console.log('eeee')

    this.setData({

    alertPosition:false

    })

    console.log(this.data.alertPosition)

    },

    timeTap(e) {

    console.log(e.currentTarget.dataset)

    this.setData({

    currTabIndex: e.currentTarget.dataset.index,

    periodId: e.currentTarget.dataset.id.id

    })

     

    },

    // 商家是否处罚

    enterpriseDetail() {

    var enterpriseId = wx.getStorageSync('enterprise').id

    $api.enterpriseFines(enterpriseId).then(res => {

    console.log(res)

    var fineList = res.data.data

    if (fineList.state == 2) {

    this.setData({

    buttonShow:false

    })

     

    } else {

    this.setData({

    buttonShow: true

    })

    }

     

    })

    },

     

    // 预约

    evaluationTab(e) {

    console.log(this.data.periodTime)

    // var businessApply = wx.getStorageSync('apply')

    var enterpriseDetail = wx.getStorageSync('enterprise')

    if (enterpriseDetail) {

    console.log('详情11', this.data.gridDetailList);

    var obj = {}

    var enterpriseDetail = wx.getStorageSync('enterprise')

    obj.enterpriseId = enterpriseDetail.id

    obj.gridId = this.data.gridDetailList.id

    obj.periodId = this.data.periodTime.periodId

    console.log('obj', obj)

    $api.appointmentAdd(obj).then(res => {

    console.log(res)

    this.setData({

    appointmentId : res.data.data.id

    })

    wx.showToast({

    title: res.data.message,

    icon: 'success',

    duration: 2000,

    success: res => {

    this.setData({

    buttonShow: false,

    ssingShow: true,

    })

    $api.getGridDetail({ id: obj.gridId }).then(res => {

    if (res.data.success) {

    this.setData({

    gridDetailList: res.data.data

    })

    }

    })

    }

    })

    })

    } else {

    wx.showToast({

    title: '请先申请摆摊',

    icon: 'success',

    duration: 3000,

    success:res => {

    wx.navigateTo({

    url: '/pages/managementInformation/applyStall/applyStall',

    })

    }

    })

    }

    },

    // 签到

    ssignTap() {

    console.log('签到id', this.data.appointmentId)

    // var id = this.data.successAppointment.id

    var id = this.data.appointmentId

    $api.appointmentSign({ id: id}).then(res => {

    console.log(res)

    this.setData({

    ssingShow: false

    })

    })

     

    },

    /**

    * 生命周期函数--监听页面初次渲染完成

    */

    onReady: function () {

     

    },

     

    /**

    * 生命周期函数--监听页面显示

    */

    onShow: function () {

     

    },

     

    /**

    * 生命周期函数--监听页面隐藏

    */

    onHide: function () {

     

    },

     

    /**

    * 生命周期函数--监听页面卸载

    */

    onUnload: function () {

     

    },

     

    /**

    * 页面相关事件处理函数--监听用户下拉动作

    */

    onPullDownRefresh: function () {

     

    },

     

    /**

    * 页面上拉触底事件的处理函数

    */

    onReachBottom: function () {

     

    },

     

    /**

    * 用户点击右上角分享

    */

    onShareAppMessage: function () {

     

    }

    })

    Processed: 0.010, SQL: 9