liujie
2026-04-20 f80d57a352069f27af6ea2b442380c44208e05a3
ManagementYKDTravel/guns-admin/src/main/webapp/static/modular/system/tLine/tLine_info.js
@@ -3,6 +3,15 @@
 */
var TLineInfoDlg = {
    tLineInfoData : {},
    destinationLayerIndex: null,
    destinationEditRow: null,
    destinationMap: null,
    destinationMouseTool: null,
    destinationFenceOverlay: null,
    destinationDefaultPointMarker: null,
    destinationSelectPointMode: false,
    destinationAutoComplete: null,
    destinationPlaceSearch: null,
    validateFields: {
        name: {
            validators: {
@@ -177,6 +186,10 @@
        Feng.error("请至少设置一条班次设置");
        return;
    }
    var destArr = TLineInfoDlg.collectDestinationArr();
    if(destArr === false){
        return;
    }
    $(e).attr('disabled','disabled'); //点击后就禁用,若想再次点击需刷新页面;
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tLine/add", function(data){
@@ -196,6 +209,7 @@
    ajax.set("endSiteId",endSiteId);
    ajax.set("subArr",JSON.stringify(subArr));
    ajax.set("shuArr",JSON.stringify(shuArr));
    ajax.set("destArr",JSON.stringify(destArr));
    ajax.start();
}
@@ -242,6 +256,10 @@
        Feng.error("请至少设置一条班次设置");
        return;
    }
    var destArr = TLineInfoDlg.collectDestinationArr();
    if(destArr === false){
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tLine/update", function(data){
        if(data.status == 200){
@@ -259,6 +277,7 @@
    ajax.set("endSiteId",endSiteId);
    ajax.set("subArr",JSON.stringify(subArr));
    ajax.set("shuArr",JSON.stringify(shuArr));
    ajax.set("destArr",JSON.stringify(destArr));
    ajax.start();
}
@@ -628,6 +647,460 @@
    }
}
TLineInfoDlg.collectDestinationArr = function () {
    var destArr = [];
    var mainCount = 0;
    $(".destinationValueClass").each(function () {
        var item = {
            time: $(this).find("input[name='destinationTimeValue']").val(),
            fenceType: $(this).find("input[name='destinationFenceTypeValue']").val(),
            coordinate: $(this).find("input[name='destinationCoordinateValue']").val(),
            defaultPointLon: $(this).find("input[name='destinationDefaultPointLonValue']").val(),
            defaultPointLat: $(this).find("input[name='destinationDefaultPointLatValue']").val(),
            name: $(this).find("input[name='destinationNameValue']").val(),
            price5: $(this).find("input[name='destinationPrice5Value']").val(),
            price7: $(this).find("input[name='destinationPrice7Value']").val(),
            state: $(this).find("input[name='destinationStateValue']").val(),
            isMain: $(this).find("input[name='destinationIsMainValue']").val()
        };
        if (item.isMain == "1") {
            mainCount++;
        }
        destArr.push(item);
    });
    if (mainCount > 1) {
        Feng.error("最多只能设置一个主要目的地");
        return false;
    }
    return destArr;
}
TLineInfoDlg.escapeHtml = function (str) {
    return (str || "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
TLineInfoDlg.escapeAttr = function (str) {
    return TLineInfoDlg.escapeHtml(str).replace(/"/g, "&quot;");
}
TLineInfoDlg.openDestinationDialog = function () {
    if ($(".destinationValueClass").length >= 3) {
        Feng.error("最多只能添加3个目的地");
        return;
    }
    TLineInfoDlg.destinationEditRow = null;
    TLineInfoDlg.resetDestinationForm();
    TLineInfoDlg.openDestinationLayer("添加目的地");
}
TLineInfoDlg.openDestinationLayer = function (title) {
    TLineInfoDlg.destinationLayerIndex = layer.open({
        type: 1,
        title: title,
        area: ['1000px', '760px'],
        btn: ['保存', '取消'],
        content: $("#destinationDialogContent"),
        success: function () {
            $("#destinationDialogContent").show();
            TLineInfoDlg.initDestinationMap();
            setTimeout(function () {
                if (TLineInfoDlg.destinationMap) {
                    TLineInfoDlg.destinationMap.resize();
                    TLineInfoDlg.destinationMap.setFitView();
                }
            }, 100);
        },
        yes: function (index) {
            TLineInfoDlg.saveDestination(index);
        },
        end: function () {
            $("#destinationDialogContent").hide();
            TLineInfoDlg.destinationSelectPointMode = false;
            if (TLineInfoDlg.destinationMouseTool) {
                TLineInfoDlg.destinationMouseTool.close();
            }
        }
    });
}
TLineInfoDlg.resetDestinationForm = function () {
    $("#destinationEditIndex").val("");
    $("#destinationName").val("");
    $("#destinationPrice5").val("");
    $("#destinationPrice7").val("");
    $("#destinationAddressKeyword").val("");
    $("#destinationCoordinate").val("");
    $("#destinationDefaultPointLon").val("");
    $("#destinationDefaultPointLat").val("");
    $("#destinationDefaultPointText").text("");
    $("#destinationFenceType1").prop("checked", true);
    $("#destinationState1").prop("checked", true);
    $("#destinationIsMain0").prop("checked", true);
    TLineInfoDlg.destinationFenceTypeChange(1);
    TLineInfoDlg.clearDestinationFence();
}
TLineInfoDlg.destinationFenceTypeChange = function (type) {
    if (type == 1) {
        $("#destinationFenceTip").text("圆形围栏默认点为圆心");
    } else {
        $("#destinationFenceTip").text("多边形围栏需要确认一个默认点");
    }
}
TLineInfoDlg.initDestinationMap = function () {
    if (TLineInfoDlg.destinationMap) {
        return;
    }
    TLineInfoDlg.destinationMap = new AMap.Map("destinationMapContainer", {
        resizeEnable: true,
        zoom: 13
    });
    TLineInfoDlg.destinationMouseTool = new AMap.MouseTool(TLineInfoDlg.destinationMap);
    TLineInfoDlg.destinationMouseTool.on('draw', function (e) {
        var type = $("input[name='destinationFenceType']:checked").val();
        TLineInfoDlg.clearDestinationFence();
        TLineInfoDlg.destinationFenceOverlay = e.obj;
        if (type == "1") {
            var center = e.obj.getCenter();
            var radius = e.obj.getRadius();
            if (radius > 5000) {
                Feng.error("圆形围栏半径不能大于5000米");
                TLineInfoDlg.clearDestinationFence();
                return;
            }
            var coordinate = center.lng + "," + center.lat + ";" + radius;
            $("#destinationCoordinate").val(coordinate);
            $("#destinationDefaultPointLon").val(center.lng);
            $("#destinationDefaultPointLat").val(center.lat);
            TLineInfoDlg.setDestinationDefaultPointMarker(center.lng, center.lat, true);
        } else {
            var path = e.obj.getPath();
            var coordinate = TLineInfoDlg.pathToCoordinate(path);
            $("#destinationCoordinate").val(coordinate);
        }
    });
    TLineInfoDlg.destinationMap.on('click', function (e) {
        if (!TLineInfoDlg.destinationSelectPointMode) {
            return;
        }
        var fenceType = $("input[name='destinationFenceType']:checked").val();
        if (fenceType != "2") {
            Feng.info("圆形围栏默认点为圆心,无需单独设置");
            TLineInfoDlg.destinationSelectPointMode = false;
            return;
        }
        $("#destinationDefaultPointLon").val(e.lnglat.getLng());
        $("#destinationDefaultPointLat").val(e.lnglat.getLat());
        TLineInfoDlg.setDestinationDefaultPointMarker(e.lnglat.getLng(), e.lnglat.getLat(), false);
        TLineInfoDlg.destinationSelectPointMode = false;
        Feng.success("默认点设置成功");
    });
    TLineInfoDlg.destinationAutoComplete = new AMap.Autocomplete({
        city: "",
        input: "destinationAddressKeyword"
    });
    TLineInfoDlg.destinationPlaceSearch = new AMap.PlaceSearch({
        map: TLineInfoDlg.destinationMap,
        pageSize: 1,
        pageIndex: 1,
        citylimit: false
    });
    AMap.event.addListener(TLineInfoDlg.destinationAutoComplete, "select", function (e) {
        if (!e.poi || !e.poi.location) {
            return;
        }
        var lon = e.poi.location.lng;
        var lat = e.poi.location.lat;
        TLineInfoDlg.destinationMap.setCenter([lon, lat]);
        TLineInfoDlg.destinationMap.setZoom(15);
        $("#destinationDefaultPointLon").val(lon);
        $("#destinationDefaultPointLat").val(lat);
        TLineInfoDlg.setDestinationDefaultPointMarker(lon, lat, false);
    });
}
TLineInfoDlg.searchDestinationAddress = function () {
    var keyword = $("#destinationAddressKeyword").val();
    if (!keyword) {
        Feng.info("请输入地址关键词");
        return;
    }
    if (!TLineInfoDlg.destinationPlaceSearch) {
        return;
    }
    TLineInfoDlg.destinationPlaceSearch.search(keyword, function (status, result) {
        if (status !== "complete" || !result || !result.poiList || result.poiList.count <= 0) {
            Feng.error("未找到相关地址");
            return;
        }
        var poi = result.poiList.pois[0];
        if (!poi || !poi.location) {
            Feng.error("地址定位失败");
            return;
        }
        var lon = poi.location.lng;
        var lat = poi.location.lat;
        TLineInfoDlg.destinationMap.setCenter([lon, lat]);
        TLineInfoDlg.destinationMap.setZoom(15);
        $("#destinationDefaultPointLon").val(lon);
        $("#destinationDefaultPointLat").val(lat);
        TLineInfoDlg.setDestinationDefaultPointMarker(lon, lat, false);
    });
}
TLineInfoDlg.pathToCoordinate = function (path) {
    var arr = [];
    for (var i = 0; i < path.length; i++) {
        arr.push(path[i].lng + "," + path[i].lat);
    }
    return arr.join(";");
}
TLineInfoDlg.selectDestinationDefaultPoint = function () {
    var fenceType = $("input[name='destinationFenceType']:checked").val();
    if (fenceType == "1") {
        Feng.info("圆形围栏默认点为圆心,无需单独设置");
        return;
    }
    TLineInfoDlg.destinationSelectPointMode = true;
    Feng.info("请在地图上点击设置默认点");
}
TLineInfoDlg.startDrawDestinationFence = function () {
    TLineInfoDlg.initDestinationMap();
    var type = $("input[name='destinationFenceType']:checked").val();
    TLineInfoDlg.clearDestinationFence();
    if (type == "1") {
        TLineInfoDlg.destinationMouseTool.circle({
            fillColor: '#00b0ff',
            strokeColor: '#80d8ff'
        });
    } else {
        TLineInfoDlg.destinationMouseTool.polygon({
            fillColor: '#00b0ff',
            strokeColor: '#80d8ff'
        });
    }
}
TLineInfoDlg.clearDestinationFence = function () {
    if (TLineInfoDlg.destinationFenceOverlay) {
        TLineInfoDlg.destinationMap.remove(TLineInfoDlg.destinationFenceOverlay);
        TLineInfoDlg.destinationFenceOverlay = null;
    }
    if (TLineInfoDlg.destinationDefaultPointMarker) {
        TLineInfoDlg.destinationMap.remove(TLineInfoDlg.destinationDefaultPointMarker);
        TLineInfoDlg.destinationDefaultPointMarker = null;
    }
    $("#destinationCoordinate").val("");
    $("#destinationDefaultPointLon").val("");
    $("#destinationDefaultPointLat").val("");
    $("#destinationDefaultPointText").text("");
}
TLineInfoDlg.setDestinationDefaultPointMarker = function (lon, lat, auto) {
    if (!TLineInfoDlg.destinationMap) {
        return;
    }
    if (TLineInfoDlg.destinationDefaultPointMarker) {
        TLineInfoDlg.destinationMap.remove(TLineInfoDlg.destinationDefaultPointMarker);
    }
    TLineInfoDlg.destinationDefaultPointMarker = new AMap.Marker({
        map: TLineInfoDlg.destinationMap,
        position: new AMap.LngLat(lon, lat)
    });
    var text = "默认点:" + lon + "," + lat;
    if (auto) {
        text += "(圆心)";
    }
    $("#destinationDefaultPointText").text(text);
}
TLineInfoDlg.validateDestinationForm = function () {
    var name = $("#destinationName").val();
    if (!name) {
        Feng.error("请填写目的地名称");
        return false;
    }
    var priceReg = /^(0|[1-9]\d{0,6})(\.\d{1,2})?$/;
    var price5 = $("#destinationPrice5").val();
    var price7 = $("#destinationPrice7").val();
    if (!priceReg.test(price5)) {
        Feng.error("5座车费用格式不正确");
        return false;
    }
    if (!priceReg.test(price7)) {
        Feng.error("7座车费用格式不正确");
        return false;
    }
    var coordinate = $("#destinationCoordinate").val();
    if (!coordinate) {
        Feng.error("请先设置目的地围栏");
        return false;
    }
    var fenceType = $("input[name='destinationFenceType']:checked").val();
    var defaultPointLon = $("#destinationDefaultPointLon").val();
    var defaultPointLat = $("#destinationDefaultPointLat").val();
    if (fenceType == "2" && (!defaultPointLon || !defaultPointLat)) {
        Feng.error("多边形围栏必须设置默认点");
        return false;
    }
    if ($("input[name='destinationIsMain']:checked").val() == "1") {
        var sameMainCount = 0;
        $(".destinationValueClass").each(function () {
            if ($(this).find("input[name='destinationIsMainValue']").val() == "1") {
                if (!TLineInfoDlg.destinationEditRow || this != TLineInfoDlg.destinationEditRow[0]) {
                    sameMainCount++;
                }
            }
        });
        if (sameMainCount > 0) {
            Feng.error("已存在主要目的地,请先调整后再保存");
            return false;
        }
    }
    return true;
}
TLineInfoDlg.saveDestination = function (layerIndex) {
    if (!TLineInfoDlg.validateDestinationForm()) {
        return;
    }
    var data = {
        time: getNowFormatDate(),
        fenceType: $("input[name='destinationFenceType']:checked").val(),
        coordinate: $("#destinationCoordinate").val(),
        defaultPointLon: $("#destinationDefaultPointLon").val(),
        defaultPointLat: $("#destinationDefaultPointLat").val(),
        name: $("#destinationName").val(),
        price5: $("#destinationPrice5").val(),
        price7: $("#destinationPrice7").val(),
        state: $("input[name='destinationState']:checked").val(),
        isMain: $("input[name='destinationIsMain']:checked").val()
    };
    if (TLineInfoDlg.destinationEditRow) {
        TLineInfoDlg.destinationEditRow.replaceWith(TLineInfoDlg.buildDestinationRowHtml(data));
    } else {
        $("#destinationValue").append(TLineInfoDlg.buildDestinationRowHtml(data));
    }
    layer.close(layerIndex);
}
TLineInfoDlg.buildDestinationRowHtml = function (data) {
    var fenceTypeText = data.fenceType == "1" ? "圆形围栏" : "多边形围栏";
    var stateText = data.state == "1" ? "启用" : "关闭";
    var isMainText = data.isMain == "1" ? "是" : "否";
    var nameHtml = TLineInfoDlg.escapeHtml(data.name);
    var coordinateAttr = TLineInfoDlg.escapeAttr(data.coordinate);
    var nameAttr = TLineInfoDlg.escapeAttr(data.name);
    return '<tr class="destinationValueClass">' +
        '<td style="text-align: center;">' +
        '<input type="hidden" name="destinationTimeValue" value="' + TLineInfoDlg.escapeAttr(data.time) + '">' +
        '<input type="hidden" name="destinationFenceTypeValue" value="' + data.fenceType + '">' +
        '<input type="hidden" name="destinationCoordinateValue" value="' + coordinateAttr + '">' +
        '<input type="hidden" name="destinationDefaultPointLonValue" value="' + TLineInfoDlg.escapeAttr(data.defaultPointLon) + '">' +
        '<input type="hidden" name="destinationDefaultPointLatValue" value="' + TLineInfoDlg.escapeAttr(data.defaultPointLat) + '">' +
        '<input type="hidden" name="destinationNameValue" value="' + nameAttr + '">' +
        '<input type="hidden" name="destinationPrice5Value" value="' + TLineInfoDlg.escapeAttr(data.price5) + '">' +
        '<input type="hidden" name="destinationPrice7Value" value="' + TLineInfoDlg.escapeAttr(data.price7) + '">' +
        '<input type="hidden" name="destinationStateValue" value="' + data.state + '">' +
        '<input type="hidden" name="destinationIsMainValue" value="' + data.isMain + '">' +
        fenceTypeText + '</td>' +
        '<td style="text-align: center;">' + nameHtml + '</td>' +
        '<td style="text-align: center;">' + TLineInfoDlg.escapeHtml(data.price5) + '</td>' +
        '<td style="text-align: center;">' + TLineInfoDlg.escapeHtml(data.price7) + '</td>' +
        '<td style="text-align: center;">' + stateText + '</td>' +
        '<td style="text-align: center;">' + isMainText + '</td>' +
        '<td style="text-align: center;">' +
        '<button type="button" onclick="TLineInfoDlg.editDestination(this)">编辑</button> ' +
        '<button type="button" onclick="TLineInfoDlg.deleteDestination(this)">删除</button>' +
        '</td></tr>';
}
TLineInfoDlg.editDestination = function (btn) {
    var $row = $(btn).closest("tr");
    TLineInfoDlg.destinationEditRow = $row;
    TLineInfoDlg.resetDestinationForm();
    $("#destinationName").val($row.find("input[name='destinationNameValue']").val());
    $("#destinationPrice5").val($row.find("input[name='destinationPrice5Value']").val());
    $("#destinationPrice7").val($row.find("input[name='destinationPrice7Value']").val());
    $("#destinationCoordinate").val($row.find("input[name='destinationCoordinateValue']").val());
    $("#destinationDefaultPointLon").val($row.find("input[name='destinationDefaultPointLonValue']").val());
    $("#destinationDefaultPointLat").val($row.find("input[name='destinationDefaultPointLatValue']").val());
    var fenceType = $row.find("input[name='destinationFenceTypeValue']").val();
    var state = $row.find("input[name='destinationStateValue']").val();
    var isMain = $row.find("input[name='destinationIsMainValue']").val();
    $("input[name='destinationFenceType'][value='" + fenceType + "']").prop("checked", true);
    $("input[name='destinationState'][value='" + state + "']").prop("checked", true);
    $("input[name='destinationIsMain'][value='" + isMain + "']").prop("checked", true);
    TLineInfoDlg.destinationFenceTypeChange(parseInt(fenceType, 10));
    TLineInfoDlg.openDestinationLayer("编辑目的地");
    setTimeout(function () {
        TLineInfoDlg.restoreDestinationMapFence();
    }, 150);
}
TLineInfoDlg.restoreDestinationMapFence = function () {
    TLineInfoDlg.initDestinationMap();
    TLineInfoDlg.clearDestinationFence();
    var fenceType = $("input[name='destinationFenceType']:checked").val();
    var coordinate = $("#destinationCoordinate").val();
    if (!coordinate) {
        return;
    }
    if (fenceType == "1") {
        var arr = coordinate.split(";");
        if (arr.length != 2) {
            return;
        }
        var centerArr = arr[0].split(",");
        if (centerArr.length != 2) {
            return;
        }
        var center = new AMap.LngLat(parseFloat(centerArr[0]), parseFloat(centerArr[1]));
        var radius = parseFloat(arr[1]);
        TLineInfoDlg.destinationFenceOverlay = new AMap.Circle({
            center: center,
            radius: radius,
            fillColor: '#00b0ff',
            strokeColor: '#80d8ff'
        });
        TLineInfoDlg.destinationMap.add(TLineInfoDlg.destinationFenceOverlay);
        TLineInfoDlg.setDestinationDefaultPointMarker(center.getLng(), center.getLat(), true);
        TLineInfoDlg.destinationMap.setFitView();
    } else {
        var pointsArr = coordinate.split(";");
        var points = [];
        for (var i = 0; i < pointsArr.length; i++) {
            var point = pointsArr[i].split(",");
            if (point.length == 2) {
                points.push([parseFloat(point[0]), parseFloat(point[1])]);
            }
        }
        if (points.length > 0) {
            TLineInfoDlg.destinationFenceOverlay = new AMap.Polygon({
                path: points,
                fillColor: '#00b0ff',
                strokeColor: '#80d8ff'
            });
            TLineInfoDlg.destinationMap.add(TLineInfoDlg.destinationFenceOverlay);
            var lon = $("#destinationDefaultPointLon").val();
            var lat = $("#destinationDefaultPointLat").val();
            if (lon && lat) {
                TLineInfoDlg.setDestinationDefaultPointMarker(parseFloat(lon), parseFloat(lat), false);
            }
            TLineInfoDlg.destinationMap.setFitView();
        }
    }
}
TLineInfoDlg.deleteDestination = function (btn) {
    $(btn).closest("tr").remove();
}
/**
 * 添加公司
 */