const Parse = getApp().Parse;
const company = getApp().globalData.company
const dateF = require('../../../utils/date')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: "",
        order: null,
        orderTime: null,
    },
    async getShopOrder() {
        let id = this.data.id
        console.log(id);
        let ShopOrder = new Parse.Query('ShopOrder')
        ShopOrder.include('goods')
        ShopOrder.include('shopStore')
        let shopOrder = await ShopOrder.get(id)
        let orderTime = dateF.formatTime("YYYY-mm-dd HH:MM:SS", shopOrder.createdAt)
        this.setData({
            order: shopOrder.toJSON(),
            orderTime: orderTime
        })
        console.log(this.data.order);
    },
    async submit() {
        let id = this.data.id
        let shopOrder
        let ShopOrder = new Parse.Query("ShopOrder")
        shopOrder = await ShopOrder.get(id)
        shopOrder.set("status", 400)
        shopOrder.save().then(res => {
            console.log(res)
            wx.showToast({
                title: '核销成功',
                icon: 'none'
            })

        })
        wx.navigateBack({
            delta: 1,

        });

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let id = options.id
        this.setData({ id: id })
        this.getShopOrder()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

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

    },

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

    },

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

    },

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

    }
})