// pages/cart/cart.js
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
const app=getApp();
var qqmapsdk;
Page({

        /**
         * 页面的初始数据
         */
        data: {
                city: '',
                imgUrls: [
                        1, 2, 2
                ],
                num: 3,
                count:1,
                erji:3,
                current_index: 0,
                showad: true, //首页广告控制显示
                popup_state: false,
                nav: 0,
                flag: false,
                all: false,
                currentIndex: 0,
                hotList:[],
                category:[],
                photo:[],
                banner:{},
                special:[],
                state:0,
                product_item:[],
                cookCategory:[],
                goods:[],
                two_banner:"",
                select:[],
                select_item:[],
                id:0,
                currnetindexs:0,
                mainindex:0,
                main:0
        },
        //切换筛选id
        changeId(e){
                console.log(e)
                let id=e.currentTarget.dataset.id;
            
                this.setData({
                        id:id,
                        currnetindexs:e.currentTarget.dataset.index,
                        mainindex: e.currentTarget.dataset.indexs,
                        main: e.currentTarget.dataset.indexs,
                });

                console.log(this.data.mainindex);
                console.log(this.data.main)
        },
   
        //操作筛选
        operation_all(){
                this.setData({
                        all:!this.data.all
                });
        },
        //关闭筛选
        close_all(){
                this.setData({
                        flag: !this.data.flag
                });
                let url ='/wxapp/product/getProductSku';
                app.post(url).then(r=>{
                        console.log(r);
                });
        },
        //关闭全部分类
        cancel_both_category(){
                this.setData({
                        all:!this.data.all
                });
        },
        //   热卖
        hotList() {
                let url = '/portal/index/index';
                app.post(url).then(r => {
                        console.log(r);
                        this.setData({
                                hotList: r.gohi,
                                category: r.categories,
                                special: r.special,
                                banner:r.welcome,
                                select: r.screen,
                                product_item:r.recommended
                        })
                })
        },
        //获取分类菜谱
        category(){
                let url ='/portal/index/getCookBookByCategory';
                let params={
                        id:this.data.nav
                };
                app.post(url,params).then(r=>{
                        console.log(r);
                        for(var i=0;i<r.categories.length;i++){
                                if (r.categories[i].id===this.data.nav){
                                        var two_banner=r.categories[i].more.banner;
                                        this.setData({
                                                two_banner: two_banner,
                                                select:r.screen,
                                        }); 
                                }
                        }
                       let goods=r.list.goods;
                       this.setData({
                               goods:goods
                       });
                });
        },
        //切换导航
        changeNav1() {
                this.setData({
                        nav: 0
                });
                this.hotList();
        },
        changeNav2(e) {
                let id=e.currentTarget.dataset.id;
                this.setData({
                      nav:id
                });
                this.category();
        },
        //筛选
        select() {
                this.setData({
                        flag: !this.data.flag
                });
        },
        //重置筛选完成
        close_success(){
                this.setData({
                        flag:!this.data.flag
                });
        },
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function(options) {
                qqmapsdk = new QQMapWX({
                        key: 'KLXBZ-KAFCF-6LVJZ-JQAAL-NCI65-XTF52'
                });
                this.getaddress();
                this.hotList();
               this.category();
        },
        active_btn(e) {
                this.setData({
                        current_index: 1
                })
        },
        getaddress() {
                var that = this
                wx.getLocation({
                        type: 'gcj02', //返回可以用于wx.openLocation的经纬度
                        success: function(res) {
                                var latitude = res.latitude
                                var longitude = res.longitude
                                qqmapsdk.reverseGeocoder({
                                        location: {
                                                latitude: latitude,
                                                longitude: longitude
                                        },
                                        success: function(res) {
                                                var ctiy = res.result.address_component.district
                                                that.setData({
                                                        city: ctiy
                                                })
                                        },
                                        fail: function(res) {

                                        },
                                        complete: function(res) {

                                        }
                                });
                        }
                })

        },
        //中间实现凹凸
        // handle_aotu:function(e){
        //   console.log(e);
        //   this.setData({
        //     // currentIndex: e.detail.current
        //   })
        // },
        // 跳转至详情
        get_contant() {
                wx.navigateTo({
                        url: '../../pages/my/big/big',
                })
        },
        // 跳转商品详情
        get_goodsDetial() {
                wx.navigateTo({
                        url: '/pages/index/goodsDetial/goodsDetial',
                })
        },
        toMessage() {
                wx.navigateTo({
                        url: '/pages/my/activityInformation/activityInformation',
                })
        },
        chooseAdress() {
                wx.navigateTo({
                        url: '/pages/my/selectAddress/selectAddress',
                })
        },
        search() {
                wx.navigateTo({
                        url: '/pages/my/serach/serach',
                })
        },
        //控制广告
        show_ad() {
                this.setData({
                        showad: false
                })
        },
        //广告页的跳转
        goad() {

        },


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

        },

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

        },

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

        },

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

        },

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

        },

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

        },

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

        }
})