common-select.js 15.9 KB
/**
 * Created by atao on 2018/1/4.
 */
/**
 *目前返回的停车场字段如下:
 * latId:经度
 * lonId:纬度
 * type:停车场类型
 * code:停车场编码
 * name:停车场名称
 * areaId:服务点ID
 * areaName:服务点名称
 * berthsNum:停车场车位数
 *
 */
var commSelect = {

    //区域下拉框
    /**
     *
     * @param domStr
     * @param isNeedAll
     * @param plFilterFun
     * @param isIncludeRechargePlNo 是否包含App充值 默认否
     * plBusiType 1:自营,2:非自营 默认自营
     *
     */
    area_select: function (domStr, isNeedAll, plFilterFun, isIncludeRechargePlNo, plBusiType) {
        var plData = fn.getParkLot(plBusiType);
        $(domStr).empty();
        var html = '';
        var areaIds = [];
        $.each(plData, function (index, item) {
            var flag = true;
            if (undefined != plFilterFun && null != plFilterFun) {
                //过滤数据
                flag = plFilterFun(item)
            }
            if (areaIds.indexOf(item.areaId) > -1) {
                //如果上面存在了,说明已经添加了
                flag = false;
            }
            if (flag) {
                areaIds.push(item.areaId);
                html += "<option value='[\"" + item.areaId + "\"]'>" + item.areaName + "</option>";
            }

        });
        if (isIncludeRechargePlNo) {
            html = "<option value='[\"001\"]'>APP充值</option>" + html;
        }
        if (isNeedAll) {
            if (isIncludeRechargePlNo) {
                areaIds.push('001');
            }
            var areaIdsStr = JSON.stringify(areaIds);
            html = "<option value='" + areaIdsStr + " ' selected>所有办事处</option>" + html;
        }

        $(domStr).append(html);
        $(domStr).selectpicker('render');
        $(domStr).selectpicker('refresh');
    },
    /**
     * 停车场下拉框
     * @param domStr
     * @param isNeedAll
     * @param plFilterFun
     * @param isIncludeRechargePlNo
     * @param plBusiType 1:自营,2:非自营,3:全部  默认自营
     */
    plName_select: function (domStr, isNeedAll, plFilterFun, isIncludeRechargePlNo, plBusiType) {
        var plData = fn.getParkLot(plBusiType);
        $(domStr).empty();
        var html = '';
        var plNos = [];

        $.each(plData, function (index, item) {
            var flag = true;
            if (undefined != plFilterFun && null != plFilterFun) {
                //过滤数据
                flag = plFilterFun(item)
            }
            if (plNos.indexOf(item.areaId) > -1) {
                //如果上面存在了,说明已经添加了
                flag = false;
            }
            if (flag) {
                //如果不存在或者为空 ,则 取自营
                if (!plBusiType || plBusiType == null) {
                    plBusiType = 1;
                }


                //丹阳项目判断以下用户
                if (fn.getOrgId() == '10064') {
                    //丹阳特殊账户 ,非自营用户只看非自营车场
                    if ((item.plBusiType == 2) && ("10133" == fn.getUserId() || "10134" == fn.getUserId() || "10135" == fn.getUserId())) {
                        plNos.push(item.code);
                        html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                    } else if (plBusiType == 3) {
                        //加载全部
                        plNos.push(item.code);
                        html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                    } else if (plBusiType == item.plBusiType) {
                        plNos.push(item.code);
                        html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                    } else {
                        console.log('获取停车场未知的匹配项目:' + 'plBusiType=' + plBusiType + ';parklot.plBusiType=' + item.plBusiType);
                    }

                } else {
                    //生成环境项目
                    if (plBusiType == 3) {
                        //加载全部
                        plNos.push(item.code);
                        html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";

                    } else if (plBusiType == item.plBusiType) {
                        plNos.push(item.code);
                        html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                    } else {
                        console.log('获取停车场信息,未知的匹配项目:' + 'plBusiType=' + plBusiType + ';parklot.plBusiType=' + item.plBusiType);
                    }
                }
            }

        });
        if (isIncludeRechargePlNo) {
            html = "<option value='[\"001\"]'>APP充值</option>" + html;
        }
        if (isNeedAll) {
            if (isIncludeRechargePlNo) {
                plNos.push('001');
            }
            var plNosStr = JSON.stringify(plNos);
            html = "<option value='" + plNosStr + " ' selected>所有停车场</option>" + html;
        }
        $(domStr).append(html);
        $(domStr).selectpicker('render');
        // $(domStr).selectpicker('refresh');

    },
    /**
     * 区域,停车场级联下拉框
     * @param areaDomStr
     * @param plDomStr
     * @param plFilterFun
     * @param isIncludeRechargePlNo
     * @param plBusiType 1:自营,2:非自营 默认自营
     */
    area_Pl_LinkedSelect: function (areaDomStr, plDomStr, plFilterFun, isIncludeRechargePlNo, plBusiType) {
        if (isIncludeRechargePlNo == undefined || isIncludeRechargePlNo == '') {
            isIncludeRechargePlNo = false;
        }
        //区域下拉框
        commSelect.area_select(areaDomStr, true, plFilterFun, isIncludeRechargePlNo, plBusiType);
        //停车场下拉框
        commSelect.plName_select(plDomStr, true, plFilterFun, isIncludeRechargePlNo, plBusiType);

        //绑定区域下拉框变动的监听事件
        documentBindFunc.on('change', areaDomStr, function () {
            //停车场数据
            var areaValueArr = $(areaDomStr).val();
            areaValueArr = JSON.parse(areaValueArr);

            var areaValue = areaValueArr[0];
            for (var i = 0; i < areaValueArr.length; i++) {
                if (areaValueArr[i] == '001') {
                    areaValue = areaValueArr[i];
                }
            }
            var data = fn.getParkLot(plBusiType);
            $(plDomStr).empty();
            var html = '';
            var plNos = [];
            if (areaValue == '001' && isIncludeRechargePlNo) {
                plNos.push('001');
                html += "<option value='[\"001\"]'>APP充值</option>";
                if (areaValueArr.length > 1) {
                    $.each(data, function (index, item) {
                        var flag = true;
                        if (undefined != plFilterFun && null != plFilterFun) {
                            //过滤数据
                            flag = plFilterFun(item)
                        }
                        if (flag && (item.areaId == areaValue || areaValueArr.length > 1)) {
                            if (plBusiType != null && plBusiType == "3") {//加载全部
                                plNos.push(item.code);
                                html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                            } else {//只加载1:自营,
                                if (item.plBusiType != undefined && item.plBusiType != '2') {
                                    plNos.push(item.code);
                                    html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                                }
                            }
                        }

                    })
                }
            } else {
                $.each(data, function (index, item) {
                    var flag = true;
                    if (undefined != plFilterFun && null != plFilterFun) {
                        //过滤数据
                        flag = plFilterFun(item)
                    }
                    if (flag && (item.areaId == areaValue || areaValueArr.length > 1)) {
                        if (plBusiType != null && plBusiType == "3") {//加载全部
                            plNos.push(item.code);
                            html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                        } else {//只加载1:自营,
                            if (item.plBusiType != undefined && item.plBusiType != '2') {
                                plNos.push(item.code);
                                html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                            }
                        }
                    }

                })
            }

            var plNosStr = JSON.stringify(plNos);
            html = '<option value=' + plNosStr + ' selected>所有停车场</option>' + html;
            $(plDomStr).append(html);
            $(plDomStr).selectpicker('render');
            $(plDomStr).selectpicker('refresh');

        })


    },
    /**
     * 泊位区间下拉框
     * @param {Object} plDomStr
     * @param {Object} berthAreaDomStr
     * @param {Object} flag 是否加载全部
     */
    berthArea_select: function (plDomStr, berthAreaDomStr, flag) {
        $(berthAreaDomStr).empty();
        var req = {};
        var plNos = JSON.parse($(plDomStr).val());
        if (plNos == "" || plNos == undefined) {
            plNos = [-1];
        }
        req.plNos = plNos;
        //设置请求参数
        //条件查询
        req.baseRequest = {
            pageNum: 1,
            pageSize: 10000
        };
        req.sysCode = sysComm.sysCode;
        var easyUIOps = {
            method: 'post',
            async: false,
            url: dataUrl.util.queryTpPRegionAreaForPage(),
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (res) {
                //console.log(res)
                if (res.code == '8888') {
                    if (res.data.rows != null) {
                        var data = res.data.rows;
                        var parkAreaCodes = [];
                        var htmls = '';
                        var html = '';
                        for (var i = 0; i < data.length; i++) {
                            parkAreaCodes.push(data[i].parkAreaCode);
                            html += "<option value='[\"" + data[i].parkAreaCode + "\"]' >" + data[i].parkAreaName + "</option>";
                        }
                        var parkAreaCodesStr = JSON.stringify(parkAreaCodes);
                        htmls = '<option value=' + parkAreaCodesStr + ' selected>所有泊位区间</option>' + html;

                        $(berthAreaDomStr).empty();
                        if (flag) {
                            $(berthAreaDomStr).append(htmls);
                        } else {
                            $(berthAreaDomStr).append(html);
                        }
                        $(berthAreaDomStr).selectpicker('render');
                        $(berthAreaDomStr).selectpicker('refresh');
                    } else {
                        $(berthAreaDomStr).selectpicker('render');
                        $(berthAreaDomStr).selectpicker('refresh');
                        console.log(res);
                    }
                }
            }
        };
        sysAjax(easyUIOps);

    },
    /**
     * 区域,停车场、泊位区间级联下拉框
     * @param areaDomStr
     * @param plDomStr
     * @param berthAreaDomStr
     * @param plFilterFun
     * @param isIncludeRechargePlNo
     * @param plBusiType 1:自营,2:非自营 默认自营
     */
    area_Pl_BA_LinkedSelect: function (areaDomStr, plDomStr, berthAreaDomStr, plFilterFun, isIncludeRechargePlNo, plBusiType) {

        if (isIncludeRechargePlNo == undefined || isIncludeRechargePlNo == '') {
            isIncludeRechargePlNo = false;
        }
        //区域下拉框
        commSelect.area_select(areaDomStr, true, plFilterFun, isIncludeRechargePlNo, plBusiType);
        //停车场下拉框
        commSelect.plName_select(plDomStr, true, plFilterFun, isIncludeRechargePlNo, plBusiType);
        //泊位区间下拉框
        commSelect.berthArea_select(plDomStr, berthAreaDomStr, true);

        //绑定区域下拉框变动的监听事件
        documentBindFunc.on('change', plDomStr, function () {
            //泊位区间下拉框
            commSelect.berthArea_select(plDomStr, berthAreaDomStr, true);
        });
        //绑定区域下拉框变动的监听事件
        documentBindFunc.on('change', areaDomStr, function () {
            //停车场数据
            var areaValueArr = $(areaDomStr).val();
            areaValueArr = JSON.parse(areaValueArr);

            var areaValue = areaValueArr[0];
            for (var i = 0; i < areaValueArr.length; i++) {
                if (areaValueArr[i] == '001') {
                    areaValue = areaValueArr[i];
                }
            }
            var data = fn.getParkLot(plBusiType);
            $(plDomStr).empty();
            var html = '';
            var plNos = [];
            if (areaValue == '001' && isIncludeRechargePlNo) {
                plNos.push('001');
                html += "<option value='[\"001\"]'>APP充值</option>";
                if (areaValueArr.length > 1) {
                    $.each(data, function (index, item) {
                        var flag = true;
                        if (undefined != plFilterFun && null != plFilterFun) {
                            //过滤数据
                            flag = plFilterFun(item)
                        }
                        if (flag && (item.areaId == areaValue || areaValueArr.length > 1)) {
                            if (plBusiType != null && plBusiType == "3") {//加载全部
                                plNos.push(item.code);
                                html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                            } else {//只加载1:自营,
                                if (item.plBusiType != undefined && item.plBusiType != '2') {
                                    plNos.push(item.code);
                                    html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                                }
                            }
                        }

                    })
                }
            } else {
                $.each(data, function (index, item) {
                    var flag = true;
                    if (undefined != plFilterFun && null != plFilterFun) {
                        //过滤数据
                        flag = plFilterFun(item)
                    }
                    if (flag && (item.areaId == areaValue || areaValueArr.length > 1)) {
                        if (plBusiType != null && plBusiType == "3") {//加载全部
                            plNos.push(item.code);
                            html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                        } else {//只加载1:自营,
                            if (item.plBusiType != undefined && item.plBusiType != '2') {
                                plNos.push(item.code);
                                html += "<option value='[\"" + item.code + "\"]'>" + item.name + "</option>";
                            }
                        }
                    }

                })
            }

            var plNosStr = JSON.stringify(plNos);
            html = '<option value=' + plNosStr + ' selected>所有停车场</option>' + html;
            $(plDomStr).append(html);
            $(plDomStr).selectpicker('render');
            $(plDomStr).selectpicker('refresh');
            //泊位区间下拉框
            commSelect.berthArea_select(plDomStr, berthAreaDomStr, true);
        });
    },


}