index.js 2.87 KB
import {
    getMalls,
} from "../../../api/login";
import {
    getPatrolGateList
} from "../../../api/tour.js";
import _ from 'underscore';
Page({
    /**
     * 组件的初始数据
     */
    data: {
        mallList: [],
        activeMall: [],
        gateId: '',
        navHeight: getApp().globalData.navHeight,
        type:''
    },
    onReady() {
        this.getMalls()
    },
    onLoad(option){
       let type = option.type;
       this.setData({
           type
       });
    },
    goBack(){
       wx.switchTab({
          url: '/pages/home/index'
       }) 
    },
    onChange(evt) {
        this.setData({
            activeMall: evt.detail
        }, () => {
            this.loadGates(evt.detail[evt.detail.length - 1]);
        })
    },
    loadGates(mallId) {
        getPatrolGateList({
            mallId
        }).then(res => {
            let mallObj = _.findWhere(this.data.mallList, {
                id: mallId
            });
            if (!res.data || !res.data.list||res.data.list.length==0) {
                mallObj.empty = true;
                //this.triggerEvent('gateChange',{});
            } else {
                mallObj.gates = res.data.list;
                let gateObj = res.data.list[0];
                //this.triggerEvent('gateChange',{id:gateObj.id,name:gateObj.name,mallId:gateObj.mallId});
            }
            this.setData({
                mallList: this.data.mallList
            }, () => {

            })
        })
    },
    backBtn() {
        this.triggerEvent('back');
    },
    // 获取门店列表
    getMalls: function () {
        const {
            accountId,
            atoken
        } = this.data
        getMalls({
            url: '/report/malls',
            accountId: wx.getStorageSync('accountId')
        }).then((malls) => {
            const data = malls.data;
            this.setData({
                mallList: data
            }, () => {
                let mallId = wx.getStorageSync('mallId');
                if (!mallId) {
                    mallId = data[0].id;
                    wx.setStorageSync('mallId', mallId);
                }
                this.onChange({
                    detail: [mallId]
                });
            });
        })
    },
    selectGate(evt) {
        let {
            id,
            channelid,
            name,
            mallid,
            mallname,
            platform
        } = evt.currentTarget.dataset;
        this.setData({
            gateId: id
        }, () => {
            wx.redirectTo({
                url: `/pages/tour/webview/index?type=${this.data.type}&id=${id}&channelid=${channelid}&platform=${platform}&mallId=${mallid}&name=${name}&mallName=${mallname}&type=${this.data.type}`,
            })
            // this.triggerEvent('gateChange', {
            //     id,
            //     name,
            //     mallId
            // });
        })

    }
});