lineSelect.html 11.1 KB
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta name="renderer" content="webkit"/>
    <meta charset="utf-8"/>
    <title>选择线路</title>
    <link rel="stylesheet" href="/real_control_v2/assets/plugins/uikit-2.27.1/css/uikit.gradient.min.css"/>
    <link rel="stylesheet"
          href="/real_control_v2/assets/plugins/uikit-2.27.1/components/form-advanced.gradient.min.css"/>

    <link rel="stylesheet"
          href="/real_control_v2/assets/plugins/uikit-2.27.1/components/sortable.gradient.min.css"/>

    <style type="text/css">

        ::-webkit-scrollbar {
            width: 16px;
            height: 16px;
        }

        ::-webkit-scrollbar-track, ::-webkit-scrollbar-thumb {
            border-radius: 999px;
            border: 5px solid transparent;
        }

        ::-webkit-scrollbar-track {
            box-shadow: 1px 1px 5px rgba(0, 0, 0, .2) inset;
        }

        ::-webkit-scrollbar-thumb {
            min-height: 20px;
            background-clip: content-box;
            box-shadow: 0 0 0 5px rgba(0, 0, 0, .2) inset;
        }

        ::-webkit-scrollbar-corner {
            background: transparent;
        }

        input[type="checkbox"] {
            vertical-align: bottom;
        }

        .line-btn-list {
            padding: 0 15px 15px 15px;
            height: 180px;
            overflow: auto;
        }

        .line-btn-list-selected {
            padding: 0 15px 15px 15px;
            height: 35px;
            overflow: auto;
        }

        .line-btn-list span.line-item {
            border: 1px solid #e0dfdf;
            padding: 4px 9px;
            margin: 5px;
            -webkit-user-select: none;
            user-select: none;
            display: inline-block;
            cursor: default;
            transition: all .1s;
        }

        .line-btn-list span.line-item.active {
            background: #5E96D2;
            border: 1px solid #5E96D2;
            box-shadow: 0px 3px 4px 0 rgba(111, 172, 237, 0.3), 0px 3px 5px 0 rgba(111, 172, 237, 0.3);
            color: #ffffff;
        }

        input.i-cbox[type=checkbox] {
            vertical-align: middle;
            margin-top: -3px;
        }

        .line-btn-list span.line-item.active input.i-cbox[type=checkbox] {
            border: 0;
        }

        .line-btn-list span.line-item.active input.i-cbox[type=checkbox]:checked:before {
            color: #86f78b;
        }

        .uk-panel-title {
            text-indent: 15px;
        }

        .line-btn-list-selected span.line-item {
            padding: 4px 9px;
            margin: 2px;
            color: #fff;
            background: #5e96d2;
            box-shadow: 0px 3px 4px 0 rgba(111, 172, 237, 0.3), 0px 3px 5px 0 rgba(111, 172, 237, 0.3);
            user-select: none;
            display: inline-block;
            cursor: move;
            border-radius: 5px;
        }

        #lineSearchInput {
            width: 300px;
            box-shadow: 0px 3px 4px 0 rgba(217, 226, 235, 0.3), 0px 3px 5px 0 rgba(200, 217, 236, 0.3);
            height: 35px;
        }

        #submitBtn{
            border-radius: 0;
            border-color: #00aff2;
            transition: all .3s;
        }

        #submitBtn:disabled{
            border-color: #ebe9e9;
        }
    </style>
</head>

<body>
<div class="wrapper ng-scope">
    <div class="dialog dialog-shadow">
        <form class="uk-form" style="width: 100%;">
            <div class="uk-grid">

                <div class="uk-width-medium-1-1">
                    <div class="uk-panel uk-panel-divider">
                        <div class="uk-form-row">
                            <div class="uk-form-icon" style="margin: 15px;">
                                <i class="uk-icon-search"></i>
                                <input type="text" placeholder="搜索线路..." id="lineSearchInput">
                            </div>
                        </div>
                        <h3 class="uk-panel-title">待选择的线路</h3>
                        <div class="line-btn-list">
                        </div>
                    </div>
                    <div class="uk-panel uk-panel-divider">
                        <h3 class="uk-panel-title">已选择的线路</h3>
                        <div class="line-btn-list-selected uk-sortable" data-uk-sortable data-uk-observe>
                        </div>
                        <button disabled class="uk-button uk-button-primary uk-button-large uk-width-1-1" type="button" id="submitBtn">确定
                        </button>
                    </div>
                </div>

            </div>
        </form>

    </div>
</div>

<script>
    delete window.exports;
    delete window.module;
</script>
<!-- jQuery -->
<script src="/metronic_v4.5.4/plugins/jquery.min.js"></script>
<script src="/real_control_v2/assets/plugins/uikit-2.27.1/uikit.min.js"></script>
<script src="/real_control_v2/assets/plugins/uikit-2.27.1/components/sortable.min.js"></script>
<script src="/assets/plugins/pinyin.js"></script>
<script src="/real_control_v2/js/common.js"></script>

<!-- EventProxy  -->
<script src="/assets/js/eventproxy.js"></script>
<script>
    if (typeof(process) == 'undefined' || !process) {
        alert('不支持当前环境!!');
    }

    const ipcMain = require('electron').ipcRenderer

    !function () {
        var all = {};
        //线路编码映射
        var lineIdMap = {};
        var storage = window.localStorage;

        var auth;
        gb_common.$get('/line/all', {destroy_eq: 0}, function (list) {

            //用户分配的线路
            $.get('/realControAuthority/findByCurrentUser', function (t) {
                auth = t;
                var newArray = [], authArray = t.lineCodeStr.split(',');

                $.each(list, function () {
                    if (this.lineCode && authArray.indexOf(this.lineCode) != -1) {
                        newArray.push(this);
                    }
                });

                var htmlStr = '';
                $.each(newArray, function () {
                    htmlStr += '<span class="line-item" data-name="' + this.name + '" data-code="' + this.lineCode + '">' +
                            ' <input class="i-cbox" type="checkbox"> ' + this.name +
                            '</span>';

                    //拼音首字母
                    this.camelChars = pinyin.getCamelChars(this.name);
                    //全拼
                    this.fullChars = pinyin.getFullChars(this.name).toUpperCase();

                    lineIdMap[this.lineCode] = this;
                });
                all = list;

                $('.line-btn-list').html(htmlStr);

                $('.line-btn-list .line-item').on('click', function () {
                    var box = $(this).find('input[type=checkbox]')[0];
                    if ($(this).hasClass('active')) {
                        $(this).removeClass('active');
                        box.checked = false;

                        removeSelected(this);
                    }
                    else {
                        $(this).addClass('active');
                        box.checked = true;

                        addSelected(this);
                    }
                });
            });
        });


        $('#lineSearchInput').on('input', function () {
            var t = $(this).val().toUpperCase();
            if (!t) {
                $('.line-btn-list .line-item').show();
                return;
            }

            var rs = [];
            $.each(all, function () {
                if (this.camelChars.indexOf(t) != -1
                        || this.fullChars.indexOf(t) != -1
                        || this.name.indexOf(t) != -1) {
                    rs.push(this.lineCode);
                }
            });

            $('.line-btn-list .line-item').hide().each(function () {
                var code = $(this).data('code') + '';
                if (rs.indexOf(code) != -1)
                    $(this).show();
            });
        });

        function addSelected(that) {
            $('.line-btn-list-selected').append('<span class="line-item" data-code="' + $(that).data('code') + '">' + $(that).data('name') + '</span>');

            $('#submitBtn').removeAttr('disabled');
        }

        function removeSelected(that) {
            var code = $(that).data('code');
            $('.line-btn-list-selected .line-item[data-code='+code+']').remove();

            if($('.line-btn-list-selected .line-item').length == 0){
                $('#submitBtn').attr('disabled', 'disabled');
            }
        }

        function error(rs) {
            return rs.status == 'ERROR' || rs.status == 500;
        }

        /**
         * 确定
         */
        $('#submitBtn').on('click', function () {
            var ep = EventProxy.create('car2DeviceId', 'routes', 'checkLineConfig', function () {
                ipcMain.send('webPageGotoControl');
            });

            var lsData = [], codeStr='', code;
            $('.line-btn-list-selected .line-item').each(function () {
                code = $(this).data('code');
                lsData.push(lineIdMap[code]);
                codeStr += (code + ',');
            });
            //将选择的线路信息写入localstorage
            storage.setItem('lineControlItems', JSON.stringify(lsData));

            //缓存车辆自编号和设备号对照
            $.get('/gps/Car2DeviceId', function (rs) {
                storage.setItem('car2DeviceId', JSON.stringify(rs));
                ep.emitLater('car2DeviceId');
            });

            //监控模式还是主调模式
            storage.setItem('operationMode', auth.pattern);

            //缓存线路路由
            codeStr = codeStr.substr(0, codeStr.length - 1);
            $.get('/realMap/multiRouteByLine', {codeStr: codeStr}, function (rs) {
                for(var key in rs){
                    storage.setItem(key, JSON.stringify(rs[key]));
                }
                ep.emitLater('routes');
            });

            //检查线路配置信息
            $.ajax({
                url: '/lineConfig/check',
                traditional: true,
                data: {codeArray: codeStr.split(',')},
                method: 'POST',
                success: function (rs) {
                    if (rs.status == 0){
                        ep.emitLater('checkLineConfig');
                    }
                    else if (rs.status == 1){
                        initLineConfig(rs.not, function () {
                            ep.emitLater('checkLineConfig');
                        });
                    }
                }
            });
        });


        function initLineConfig(arr, cb) {
            var i = 0;
            (function () {
                if (i >= arr.length) {
                    cb && cb();
                    return;
                }
                var f = arguments.callee
                        , lineCode = arr[i];

                $.post('/lineConfig/init/' + lineCode, function (rs) {
                    if (rs == 1) {
                        i++;
                        f();
                    }
                });
            })();
        }
    }();
</script>
</body>
</html>