type-detail.js 7.1 KB
// pages/index/type-detail/type-detail.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        is_showSort: false,
        is_showSelect: false,
        currentSort: null,
        currentSelect: 0,
        start_time_date: '',//app.nowDate(),
        end_time_date: '',//app.nowDate(),
        cate: [],
        score: 1,//(1智能排序,2最具人气,3距离最近)
        sort: [{id: 2, name: '最具人气'}, {id: 3, name: '距离最近'}],//(1智能排序,2最具人气,3距离最近)
        select_id: '',//分类id
        is_all: true,
        list: [],
        page_number:1,
        hasMore:true,
    },
    goPostDetail(e) {
        const id = +e.currentTarget.dataset.id;
        const type = +e.currentTarget.dataset.type;
        console.log('type', type);
        if(type === 1) { //1是活动,2是拼餐
            wx.navigateTo({
                url: '/pages/activity/detail/detail?id=' + id,
            })
        }else {
            wx.navigateTo({
                url: '/pages/meal/detail/detail?id=' + id,
            })
        }
    },
    //搜索
    search() {
        wx.navigateTo({
            url: '/pages/search/search',
        })
    },
    //点击智能排序按钮
    clickSort() {
        let that = this;
        that.setData({
            // down: !that.data.down,
            is_showSort: !that.data.is_showSort,
            is_showSelect: false
            // showrent_mask: false
        })
    },
    //点击筛选按钮
    clickSelect() {
        let that = this;
        that.setData({
            // down: !that.data.down,
            is_showSelect: !that.data.is_showSelect,
            is_showSort: false,
            // showrent_mask: false
        })
    },
    //点击蒙层关闭排序和筛选框
    closeMask() {
        let that = this;
        that.setData({
            // showrent_mask: false,
            is_showSort: false,
            is_showSelect: false,
        });
        wx.showLoading({
            title: '加载中',
        });
        that.initList();
        that.getTypeList();
    },
    //保持筛选列表开启
    openMask() {
        this.setData({is_showSelect: true,})
    },
    //点击最具人气/距离最近
    chooseSort(e) {
        const current = e.currentTarget.dataset.index;
        this.setData({
            // sort_id: this.data.sort[current].id,
            currentSort: current,
            is_showSort: false,
            score: this.data.sort[current].id,//参数
            // down: !this.data.down,
        });
        // this.initPortalPost();
        wx.showLoading({
            title: '加载中',
        });
        this.initList();
        this.getTypeList()
    },
    //选择开始时间
    changeStartTime: function (e) {
        console.log('picker发送选择改变,携带值为', e.detail.value)
        this.setData({
            start_time_date: e.detail.value,
            is_showSelect: true,
            // is_birth_change: true,
        })
    },
    //选择结束时间
    changeEndTime: function (e) {
        console.log('picker发送选择改变,携带值为', e.detail.value)
        this.setData({
            end_time_date: e.detail.value,
            is_showSelect: true,
            // is_birth_change: true,
        })
    },
    //选择全部分类
    chooseAll() {
        this.setData({is_all: true, is_showSelect: false, current_type: null,score:'',});
        this.initList();
        this.getTypeList();
    },
    //选择分类
    chooseType(e) {
        const current = e.currentTarget.dataset.index;
        const id = e.currentTarget.dataset.id;
        console.log('select_id', id);
        this.setData({current_type: current, is_all: false, is_showSelect: false, is_showSort: false,select_id:id});
        wx.showLoading({
          title: '加载中',
        });
        this.initList();
        this.getTypeList();
    },
    initList() {
        this.setData({
            list: [],
            page_number:1,
            hasMore:true,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log('options', options);
        this.setData({select_id:+options.id?+options.id:''});
        wx.setNavigationBarTitle({title:options.name})
    },

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

    },
    //获取首页分类列表
    getTypeList() {
        const self = this;
        console.log('city',self.data.city);
        let url = '/portal/Index/cate';
        let params = {
            lat: self.data.latitude,
            lng: self.data.longitude,
            addr: self.data.city,	  //    浮点型	必填	-	-	用户位置名称
            keyword: '',  //	浮点型	非必填	-	-	搜索关键字
            score: self.data.score,    //	浮点型	非必填	-	-	排序(1智能排序,2最具人气,3距离最近)
            startTime: self.data.start_time_date,//	浮点型	非必填	-	-	筛选开始时间
            endTime: self.data.end_time_date,  //	浮点型	非必填	-	-	筛选结束时间
            type: self.data.select_id,     //	浮点型	非必填	-	-	筛选类型
        };
        let header = {
            "token": wx.getStorageSync('token')
        };
        app.post(url, params, {}).then((res) => {
            console.log('获取分类列表', res);
            if (+res.code === 1) {
                self.setData({
                    list: res.data.active,
                    cate: res.data.cate,
                });
            }
            wx.hideLoading()
        })

    },
    getCity() {
        const self = this;
        let url = '/portal/Index/findCity';
        let params = {
            lat: self.data.latitude,
            lng: self.data.longitude,
        };
        let header = {
            "token": wx.getStorageSync('token')
        };
        app.post(url, params, {}).then((res) => {
            console.log('获取城市', res);
            if (+res.code === 1) {
                self.setData({
                    city: res.data.city.city,
                });
                self.getTypeList();
            }
        })
    },
    //获取地理位置
    getLocation() {
        const self = this;
        wx.getLocation({
            type: 'wgs84',
            altitude: 'true',
            success(res) {
                console.log('获取地理位', res);
                self.setData({latitude: res.latitude, longitude: res.longitude});
                self.getCity();
            }
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        const self = this;
        self.getLocation();
    },

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

    },

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

    },

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

    },

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

    },

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

    }
})