index.js 7.83 KB
// pages/reserveNew/index.js
import App from '../../utils/api';
Page({
    /**
     * 页面的初始数据
     */
    data: {
        displayModal: false, //更多的弹框
        customItem: '全部',
        region: ['北京市', '北京市', '东城区'],
        activeId: '1', //选择的tab
        barHeight: '', //状态栏+导航栏高度
        checkType: '1',
        cateList: [],
        seachList: [{
                id: '1',
                title: '美食筛选',
                check: true,
            },
            {
                id: '2',
                title: '包间筛选',
                check: false,
            }
        ],
        roomList: [{
                id: '1',
                name: '2人间',
                check: false,
            },
            {
                id: '2',
                name: '4人间',
                check: false,
            },
            {
                id: '3',
                name: '6人间',
                check: false,
            },
            {
                id: '4',
                name: '8人间',
                check: false,
            },
            {
                id: '5',
                name: '10人间',
                check: false,
            },
            {
                id: '6',
                name: '12人间',
                check: false,
            },
            {
                id: '7',
                name: '15人间',
                check: false,
            },
            {
                id: '8',
                name: '20人间',
                check: false,
            },
            {
                id: '9',
                name: '特大包间',
                check: false,
            }
        ],
        tabList: [{
                title: '订过',
                id: '1'
            },
            {
                title: '去过',
                id: '2'
            },
            {
                title: '好友订过',
                id: '3'
            },
            {
                title: '我有券',
                id: '4'
            },
            {
                title: '更多',
                id: '5'
            }
        ],
        sellerInfo: [{
                "id": "8",
                "sellername": "石府大酒店",
                "is_parking": "1",
                "average": "85",
                "cate": [
                    "中餐",
                    "京菜鲁菜",
                    "淮扬菜"
                ],
                "juli": '300m',
                'shoucang': '0',
                "seller_image": "http://libpc.colorcun.com/20250313162436_f5f597ea863038dbfbe3ee31287a915a",
            },
            {
                "id": "8",
                "sellername": "石府大酒店",
                "is_parking": "1",
                "average": "85",
                "cate": [
                    "中餐",
                    "京菜鲁菜",
                    "淮扬菜"
                ],
                "juli": '300m',
                'shoucang': '1',
                "seller_image": "http://libpc.colorcun.com/20250313162436_f5f597ea863038dbfbe3ee31287a915a",
            },
            {
                "id": "8",
                "sellername": "石府大酒店",
                "is_parking": "1",
                "average": "85",
                "cate": [
                    "中餐",
                    "京菜鲁菜",
                    "淮扬菜"
                ],
                "juli": '300m',
                'shoucang': '1',
                "seller_image": "http://libpc.colorcun.com/20250313162436_f5f597ea863038dbfbe3ee31287a915a",
            },
            {
                "id": "8",
                "sellername": "石府大酒店",
                "is_parking": "1",
                "average": "85",
                "cate": [
                    "中餐",
                    "京菜鲁菜",
                    "淮扬菜"
                ],
                "juli": '300m',
                'shoucang': '1',
                "seller_image": "http://libpc.colorcun.com/20250313162436_f5f597ea863038dbfbe3ee31287a915a",
            }
        ]
    },
    modal: '',
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.modal = this.selectComponent("#seachModal"); //通过给组件所起的id调用组件
    },
    // 选择筛选
    checkDish(e) {
        let activeId = e.currentTarget.dataset['id'];
        const {
            data
        } = this;
        const list = data.checkType == '1' ? data.cateList : data.roomList;
        const idx = list.findIndex(item => item.id === activeId);
        if (idx !== -1) {
            list[idx].check = !list[idx].check;
        }
        this.setData({
            [data.checkType === '1' ? 'cateList' : 'roomList']: list,
            checkList: list,
        });
    },
    // 重置
    resetFun() {
        let data = this.data;
        let list = data.checkType == '1' ? data.cateList : data.roomList;
        list.forEach(i => {
            i.check = false;
        })
        this.setData({
            [data.checkType === '1' ? 'cateList' : 'roomList']: list,
            checkList: list,
        });
    },
    // 筛选点确定
    submitFun() {
        const result1 = this.data.cateList.filter(item => item.check).map(item => item.id).join(',');
        const result2 = this.data.roomList.filter(item => item.check).map(item => item.id).join(',');
        console.log('result1result1result1-------', result1);
        console.log('result2result2-----------', result2);
        this.modal.closeModal()
    },
    // 切换tab
    checkTabFun(e) {
        let activeId = e.currentTarget.dataset['id'];
        let displayModal = this.data.displayModal
        if (activeId == '5') {
            if (displayModal) {
                this.modal.closeModal()
            } else {
                this.modal.showModal()
            }
        }
        this.setData({
            activeId,
            displayModal: !displayModal
        })
    },
    checkSeachFun(e) {
        let type = e.currentTarget.dataset['type'];
        let checkList = type == '1' ? this.data.cateList : this.data.roomList
        this.setData({
            checkType: type,
            checkList
        })
    },
    // 获取美食列表
    getCates() {
        App.Reserve.GetCustomerConfig().then(res => {
            let cateList = res.data.cate;
            cateList.forEach(i => {
                i.check = false;
            })
            this.setData({
                cateList,
                checkList: cateList
            })
        })
    },
    bindRegionChange(e) {
        console.log('picker发送选择改变,携带值为', e.detail.value)
        this.setData({
            region: e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    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() {

    }
})