// pages/foodDetail/foodDetail.js

import request from '../../utils/request'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        shopTitle: '', //店铺名
        foodList:[],    //美食照片路径
        shopDescribe: '', //商铺简介
        heat: '', //商铺热度
        dish:'',    //招牌菜
        shopPhone: '', //商铺电话
        shopAddress: '', //商铺地址
        shopLatitude: 0, //商铺纬度
        shopLongtitude: 0 //商铺经度
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        // 获取上一个页面传过来的美食店铺id
        // console.log(options.id);
        let id = options.id
        await request('/front/merchant/' + id) //更新浏览量
        let imagePath = await request('/front/findAllMerchantFilesPath/' + id) //获取店铺照片
        // console.log(imagePath);
        let result = await request('/front/merchantAndCallout') //获取店铺列表
        // console.log(result);
        for (let i = 0; i < result.length; i++) {
            if (result[i].id == id) {
                this.setData({
                    shopTitle: result[i].title,
                    shopDescribe: result[i].describes,
                    heat: result[i].viewCount,
                    dish:result[i].dish,
                    shopPhone: result[i].phone,
                    shopAddress: result[i].location,
                    shopLatitude: result[i].latitude,
                    shopLongtitude: result[i].longitude
                })
            }
        }
        let foodList = this.data.foodList
        for(let j = 0;j < imagePath.length;j++){
            foodList[j] = imagePath[j].iconPath
        }
        this.setData({
            foodList
        })
        // console.log(this.data.shopAddress);
    },

    //点击预览图片
    toPreviewImage() {
        let foodList = this.data.foodList
        wx.previewImage({
            urls: foodList // 需要预览的图片 http 链接列表
        })
    },

    // “去这里”按钮功能
    toFoodAddress() {
        let latitude = parseFloat(this.data.shopLatitude)
        let longtitude = parseFloat(this.data.shopLongtitude)
        // console.log(latitude); 
        // console.log(longtitude);
        wx.openLocation({
            latitude: latitude,
            longitude: longtitude,
            name: this.data.shopTitle
        })
    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})