collect.js 5.13 KB
// pages/reserveNew/collect.js
import App from '../../utils/api';
Page({
    /**
     * 页面的初始数据
     */
    data: {
        barHeight: '', //状态栏+导航栏高度
        checkType: '', //城市筛选1 美食筛选2
        cateList: [], //美食列表
        seachList: [{
                id: '1',
                title: '全部城市',
                check: false,
            },
            {
                id: '2',
                title: '美食筛选',
                check: false,
            }
        ],
        cityList: [{
                id: '1',
                name: '全部城市',
                check: true,
            },
            {
                id: '2',
                name: '北京市',
                check: false,
            },
            {
                id: '3',
                name: '天津市',
                check: false,
            },
            {
                id: '4',
                name: '唐山市',
                check: false,
            }
        ],
        sellerInfo: [{
            "id": "8",
            "sellername": "石府大酒店",
            "is_parking": "1",
            "average": "85",
            "cate": [
                "中餐",
                "京菜鲁菜",
                "淮扬菜"
            ],
            "juli": '300m',
            'shoucang': '0',
            "seller_image": "http://libpc.colorcun.com/20250313162436_f5f597ea863038dbfbe3ee31287a915a",
        }]
    },
    modal: '',
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.modal = this.selectComponent("#seachModal");
        this.getCates()
    },
    // 选择筛选
    checkDish(e) {
        let activeId = e.currentTarget.dataset['id'];
        const {
            data
        } = this;
        const list = data.checkType == '1' ? data.cityList : data.cateList;
        const idx = list.findIndex(item => item.id === activeId);
        if (idx !== -1) {
            if (data.checkType == '1') {
                list.forEach((item, i) => {
                    if (i != idx) {
                        item.check = false;
                    } else {
                        item.check = true;
                    }
                })
                let seachList = data.seachList
                seachList[0].title = data.cityList[idx].name;
                this.setData({
                    seachList
                })
                this.modal.closeModal()
            } else {
                list[idx].check = !list[idx].check;
            }
        }
        this.setData({
            [data.checkType === '1' ? 'cityList' : 'cateList']: list,
        });
    },
    // 重置
    resetFun() {
        let cateList = this.data.cateList;
        cateList.forEach(i => {
            i.check = false;
        })
        this.setData({
            cateList,
        });
    },
    // 筛选点确定
    submitFun() {
        const result1 = this.data.cateList.filter(item => item.check).map(item => item.id).join(',');
        console.log('选择的菜品id', result1);
        this.modal.closeModal()
    },
    // 切换筛选
    checkSeachFun(e) {
        let type = e.currentTarget.dataset['type'];
        let seachList = this.data.seachList;
        let i = type == '1' ? 0 : 1;
        let idx = type == '1' ? 1 : 0
        let check = seachList[i].check
        if (check) {
            seachList[i].check = false
            seachList[idx].check = false
            this.modal.closeModal()
        } else {
            seachList[i].check = true
            seachList[idx].check = false
            this.modal.showModal()
        }
        this.setData({
            checkType: type,
            seachList
        })
    },
    // 获取美食列表
    getCates() {
        App.Reserve.GetCustomerConfig().then(res => {
            let cateList = res.data.cate;
            cateList.forEach(i => {
                i.check = false;
            })
            this.setData({
                cateList,
            })
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        //导航栏自适应
        let systemInfo = wx.getSystemInfoSync();
        let reg = /ios/i;
        let pt = 20; //导航状态栏上内边距
        let h = 44; //导航状态栏高度
        if (reg.test(systemInfo.system)) {
            pt = systemInfo.statusBarHeight;
            h = 44;
        } else {
            pt = systemInfo.statusBarHeight;
            h = 48;
        }
        this.setData({
            barHeight: pt + h,
        })
        this.modal.closeModal()
        this.getCates()
    },

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

    },

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

    },

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

    },

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

    },

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

    }
})