let Parse = getApp().Parse;
const company = getApp().globalData.company;
const rechText = require('../../../../../utils/rech-text');
const dateF = require('../../../../../utils/date')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: "",
        goods: {},
        shopstore: {},
        score: 3,
        comments: null,
    },

    submit() {
        let id = this.data.id
        // let uid = this.data.shopstore.
        console.log(id);
        wx.navigateTo({
            url: '/nova-tourism/pages/gourmet/store-package/goods-details/submit/index?id=' + id
        });
    },


    async getComments() {
        let Order = new Parse.Query('ShopOrder')
        Order.equalTo("goods", this.data.id);
        Order.include("user");
        Order.include("goods");
        Order.greaterThanOrEqualTo("status", 800);
        Order.ascending('updatedAt')
        Order.notEqualTo('hiddenComment', true)
        Order.limit(10)
        Order.find().then(res => {
            let comments = []
            res.forEach(item => {
                let activitys = item.toJSON()
                activitys.time = dateF.formatTime("YYYY-mm-dd HH:MM:SS", activitys.goods.updatedAt)
                comments.push(activitys)
            })


            this.setData({
                comments
            }),
                console.log(this.data.comments)
        })
    },
    phone() {
        let phone = this.data.goods.shopStore.mobile
        console.log(phone);
        wx.makePhoneCall({
            phoneNumber: phone
        })

    },
    async getShopgoods() {
        let id = this.data.id
        let ShopStore = new Parse.Query('ShopGoods')
        ShopStore.include('shopStore')
        let shopstore = await ShopStore.get(id)
        shopstore = shopstore.toJSON()
        if (shopstore.details) {
            shopstore.details = rechText.formatRichText(shopstore.details)
        }

        this.setData({
            goods: shopstore
        })
        console.log(this.data.goods);

    },


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

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: `${this.data.goods.name}`,

        }
    }

})