bszn.js 4.26 KB
$(function () {
    layui.use('element', function () {
        var element = layui.element;
    });
    layui.use('element', function () {
        var element = layui.element;
        //监听Tab切换,以改变地址hash值
        element.on('tab(navtab)', function () {
            if (this.getAttribute('lay-id') == 1) {
                $("body,html").animate({ scrollTop: $(".tudi").offset().top });
                $(".online_business h2").removeClass('titleActive')
                $(".tudi .online_business h2").addClass('titleActive')
            } else if (this.getAttribute('lay-id') == 2) {
                $("body,html").animate({ scrollTop: $(".jianzhu").offset().top });
                $(".online_business h2").removeClass('titleActive')
                $(".jianzhu .online_business h2").addClass('titleActive')
            } else if (this.getAttribute('lay-id') == 3) {
                $("body,html").animate({ scrollTop: $(".linmu").offset().top });
                $(".online_business h2").removeClass('titleActive')
                $(".linmu .online_business h2").addClass('titleActive')
            } else if (this.getAttribute('lay-id') == 4) {
                $("body,html").animate({ scrollTop: $(".qita").offset().top });
                $(".online_business h2").removeClass('titleActive')
                $(".qita .online_business h2").addClass('titleActive')
            } else {
                $("body,html").animate({ scrollTop: 0 });
                $(".online_business h2").removeClass('titleActive')
            }
        });
        element.on('tab(navtab1)', function () {
            if (this.getAttribute('lay-id') == 1) {
                $("body,html").animate({ scrollTop: $(".tudi1").offset().top });
                $(".navtab1  h2").removeClass('titleActive')
                $(".tudi1 .navtab1 h2").addClass('titleActive')
            } else if (this.getAttribute('lay-id') == 2) {
                $("body,html").animate({ scrollTop: $(".jianzhu1").offset().top });
                $(".navtab1 h2").removeClass('titleActive')
                $(".jianzhu1 .navtab1 h2").addClass('titleActive')
            } else if (this.getAttribute('lay-id') == 3) {
                $("body,html").animate({ scrollTop: $(".linmu1").offset().top });
                $(".navtab1 h2").removeClass('titleActive')
                $(".linmu1 .navtab1 h2").addClass('titleActive')
            } else {
                $("body,html").animate({ scrollTop: 0 });
                $(".navtab1 h2").removeClass('titleActive')
            }
        });
    });
    layui.use('util', function () {
        let util = layui.util;
        //执行
        util.fixbar({
            bar1: true,
            bar2: true,
            top: true
            , click: function (type) {
                console.log(type);
                if (type === 'bar1') {
                    alert('点击了bar1')
                }
            }
        });
    })
    addTabs('#bszn')
    _initData()
});
//config的设置是全局的
layui.config({
    base: '../../staticJs/'
}).extend({ //设定模块别名
    common: 'cityCommon'
});

$(document).on("click", ".area_list li", function (e) {
    $(".area_list li").removeClass("active2")
    $(this).addClass("active2");
    _businessList($(this).attr("data-id"))
})

layui.use(['form', 'common'], function () {
    var common = layui.common,
        form = layui.form;
    //三级地址联动
    common.showCity('province', 'city');
    //区域选择
    form.on('select(selectCity)', function (data) {
        return false;
    });
});
// 初始化数据
function _initData() {
    var area_list = $(".area_list");
    area_list.empty();
    var li
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/cms/district/queryAllDistrict",//路径  
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理
            if (result.code == 200 && result.data != null) {
                let data = result.data[0].children[0].children
                for (var i = 0; i < data.length; i++) {
                    li = '<li data-id="' + data[i].id + '">' + data[i].name + '</li>';
                    area_list.append(li);
                }

            }
        }
    })
}