const Parse = getApp().Parse;
const company = getApp().globalData.company
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        meal: null,
        goods: null,
        room: null,
    },
    async getShopOrder() {
        let ShopOrder = new Parse.Query('ShopOrder')
        ShopOrder.equalTo('company', company)
        ShopOrder.equalTo('user', Parse.User.current().id)
        ShopOrder.equalTo('status', 800)
        ShopOrder.exists('score')
        ShopOrder.equalTo('type', 'meal')
        ShopOrder.include('shopStore')
        let shopOrder = await ShopOrder.find()
        let listJSON = []
        if (shopOrder && shopOrder.length > 0) {
            shopOrder.forEach(c => {
                listJSON.push(c.toJSON())
            })
        }
        this.setData({
            meal: listJSON
        })
        console.log(this.data.meal);
    },
    look(e) {
        let id = e.currentTarget.dataset.item.objectId
        console.log(id);
        wx.navigateTo({
            url: '/nova-tourism/pages/my/comments/look/index?id=' + id
        });
    },
    looks(e) {
        let id = e.currentTarget.dataset.item.objectId
        console.log(id);
        wx.navigateTo({
            url: '/nova-tourism/pages/my/comments/look2/index?id=' + id
        });
    },
    onChange(event) {
        active = event.detail.name
        this.setData({ active: active })
    },
    async getGoods() {
        let ShopOrder = new Parse.Query('ShopOrder')
        ShopOrder.equalTo('company', company)
        ShopOrder.equalTo('user', Parse.User.current().id)
        ShopOrder.equalTo('status', 800)
        ShopOrder.exists('score')
        ShopOrder.equalTo('type', 'goods')
        ShopOrder.include('shopStore')
        let shopOrder = await ShopOrder.find()
        let listJSON = []
        if (shopOrder && shopOrder.length > 0) {
            shopOrder.forEach(c => {
                listJSON.push(c.toJSON())
            })
        }
        this.setData({
            goods: listJSON
        })
        console.log(this.data.goods);
    },
    async getRoom() {
        let ShopOrder = new Parse.Query('RoomOrder')
        ShopOrder.equalTo('company', company)
        ShopOrder.equalTo('user', Parse.User.current().id)
        ShopOrder.equalTo('status', 800)
        ShopOrder.exists('score')
        ShopOrder.include('room')
        let shopOrder = await ShopOrder.find()
        let listJSON = []
        if (shopOrder && shopOrder.length > 0) {
            shopOrder.forEach(c => {
                listJSON.push(c.toJSON())
            })
        }
        this.setData({
            room: listJSON
        })
        console.log(this.data.room);
    },
    onChange(event) {
        let active = event.detail.name
        this.setData({ active: active })
    },
    async submit(e) {
        let that = this
        let id = e.currentTarget.dataset.item.objectId
        console.log(id);
        wx.showModal({
            title: '提示',
            content: '是否删除评论',
            success(res) {
                that.confirm(id)
                if (res.confirm) {
                    console.log('确定')

                } else if (res.cancel) {
                    console.log('取消')
                    return
                }
            }
        })
    },
    async submits(e) {
        let that = this
        let id = e.currentTarget.dataset.item.objectId
        console.log(id);
        wx.showModal({
            title: '提示',
            content: '是否删除评论',
            success(res) {
                that.confirms(id)
                if (res.confirm) {
                    console.log('确定')

                } else if (res.cancel) {
                    console.log('取消')
                    return
                }
            }
        })
    },
    async confirms(id) {
        let shopOrder
        let query = new Parse.Query("RoomOrder")
        shopOrder = await query.get(id)
        console.log(shopOrder);
        shopOrder.set("content", null)
        shopOrder.set("images", null)
        shopOrder.set("score", null)
        shopOrder.save().then(res => {
            console.log(res)
            wx.showToast({
                title: '删除成功',
                icon: 'none'
            })
            wx.navigateBack({
                delta: 1,

            });

        })
        console.log(shopOrder);
    },
    async confirm(id) {
        let shopOrder
        let query = new Parse.Query("ShopOrder")
        shopOrder = await query.get(id)
        console.log(shopOrder);
        shopOrder.set("content", null)
        shopOrder.set("images", null)
        shopOrder.set("score", null)
        shopOrder.save().then(res => {
            console.log(res)
            wx.showToast({
                title: '删除成功',
                icon: 'none'
            })
            wx.navigateBack({
                delta: 1,

            });

        })
        console.log(shopOrder);
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            activeColor:getApp().globalData.activeColor || '#229293'
        })
        this.getShopOrder()
        this.getGoods()
        this.getRoom()
    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})