index.js 6.81 KB
// packageEquity/pages/parking/index/index.js
const STATUS = [{
    label: '空闲', value: 1, name: 'idleStatusCount'
},
{
    label: '占用', value: 2, name: 'occupyStatusCount'
},
{
    label: '未知', value: 0, name: 'unknowStatusCount'
}
]
Page({

    /**
     * 页面的初始数据
     */
    data: {
        animationData: {},
        drawerHeight: 456, // 当前抽屉的高度
        touchStartY: 0, // 触摸起始位置
        touchMoveY: 0, // 触摸移动位置
        drawerExpanded: false, // 抽屉是否展开的标志
        isRotate: false,
        boxHeight: 456,
        scale: 16,
        markers: [],
        STATUS,
        tabIndex: '',
        customCalloutMarkerIds: [],
        num: 1,
    },
    touchStart(event) {
        this.setData({
            touchStartY: event.touches[0].clientY
        });
    },

    touchMove(event) {
        const { touchStartY, drawerHeight } = this.data;
        const touchMoveY = event.touches[0].clientY;

        const diffY = touchMoveY - touchStartY;
        const newDrawerHeight = Math.max(drawerHeight - diffY, 0); // 根据实际需求设置抽屉的最小高度

        const animation = wx.createAnimation({
            duration: 0
        });

        animation.height(newDrawerHeight + 'rpx').step();

        this.setData({
            animationData: animation.export(),
            drawerHeight: newDrawerHeight
        });
    },

    touchEnd() {
        const { drawerHeight } = this.data;
        const { windowHeight } = wx.getSystemInfoSync();

        if (drawerHeight > windowHeight * 0.5) {
            // 抽屉高度大于屏幕高度的一半时,展开抽屉
            this.expandDrawer();
        } else {
            // 否则收起抽屉
            this.collapseDrawer();
        }
    },

    expandDrawer() {
        // const animation = wx.createAnimation({
        //     duration: 300,
        //     timingFunction: 'ease-out'
        // });

        // animation.height('100%').step();

        this.setData({
            drawerHeight: 850,
            drawerExpanded: true
        });
    },

    collapseDrawer() {
        this.setData({
            drawerHeight: 456,
        });
    },
    pullH() {
        const { boxHeight } = this.data
        this.setData({ boxHeight: boxHeight == 850 ? 456 : 850 })
    },
    getCarPosition(latitude, longitude) {
        const normalCallout = {
            id: 0,
            latitude,
            longitude,
            width: 32,
            height: 32,
            iconPath: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/wuye/home/parking/location.png',
        }
        const { markers } = this.data
        this.setData({
            latitude, longitude,
            markers: [normalCallout, ...markers],
        })
    },
    handleRefresh() {
        this.parkingSpaceList()
        this.setData({ isRotate: true })
        setTimeout(() => {
            this.setData({ isRotate: false })
        }, 1000)
    },
    getAllParking() { 
        let {
        merchantId
      } = wx.p.storage.get('merchant_info')
        wx.p.api.equityApi.parkingSpaceList({ locateFlag: 1,merchantId }).then(res => {
            const normalCallout = [], list = res.responseList || [];
            list.forEach((item, index) => {
                normalCallout.push({
                    id: item.id,
                    latitude: item.parkingAddressLat,
                    longitude: item.parkingAddressLng,
                    width: 32,
                    height: 32,
                    iconPath: `https://img02.glsx.com.cn/weapp/resource/miniprogram/wuye/home/parking/${item.parkingStatus == 1 ? 'idle' : item.parkingStatus == 2 ? 'occupy' : 'unknown'}.png`,
                    callout: {
                        content: `${item.parkingArea}-${item.parkingBuilding}-${item.parkingFloor} >`,
                        color: '#666',
                        fontSize: 10,
                        borderWidth: 1,
                        borderRadius: 22,
                        borderColor: '#FFFFFF',
                        padding: 6,
                        display: 'BYCLICK',
                        textAlign: 'center'
                    },
                })
            })
            const { markers } = this.data
            this.setData({ markers: [...normalCallout, ...markers], isEmpty: normalCallout.length })
        })
    },
    parkingSpaceList() {
        let { tabIndex } = this.data ,{
        merchantId
      } = wx.p.storage.get('merchant_info')
        wx.p.api.equityApi.parkingSpaceList({ locateFlag: 1, parkingStatusList: tabIndex === ''?null:[tabIndex],merchantId }).then(res => {
            const list = res.responseList || [];
            this.setData({ carList: list, parking: res })
        })
    },
    /**
    * 点击冒泡
    */
    callouttap(e) {
        wx.p.router.go('/packageEquity/pages/parking/detail/detail', { id: e.markerId })
    },
    tolower() {
        console.log(88)
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.parkingSpaceList()
        this.getAllParking()
        wx.getLocation({
            type: 'gcj02',
            success: res => {
                this.getCarPosition(res.latitude, res.longitude)
            }
        })
    },
    controltap(e) {
        // 创建 map 上下文 MapContext 对象。建议使用 wx.createSelectorQuery 获取 context 对象
        // 获取地图,map要与wxml页面的id名一致。注意:不需要#符号
        let mpCtx = wx.createMapContext('myMap')
        // 将地图中心移置当前定位点,此时需设置地图组件 show-location 为true。'2.8.0' 起支持将地图中心移动到指定位置。
        mpCtx.moveToLocation()
        console.log(mpCtx)
        // 将地图缩放值改为初始值
        this.setData({
            scale: 16
        })
    },
    markertap(e) {
    },
    selectTab(e) {
        let { index } = e.currentTarget.dataset,{tabIndex} = this.data;
        if(tabIndex === index) index = ''
        this.setData({ tabIndex:index }, () => {
            this.parkingSpaceList()
        })
    },
    jump(e) {
        const { id } = e.currentTarget.dataset
        wx.p.router.go('/packageEquity/pages/parking/detail/detail', { id })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})