<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('快递模版列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="kylin:expressModule:create">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var updateFlag = [[${@permission.hasPermi('kylin:expressModule:create')}]];
    var isOnlineFlag = [[${@permission.hasPermi('kylin:expressModule:isOnline')}]];

    var prefix = ctx + "kylin/expressModule";

    $(function () {
        var options = {
            url: prefix + "/list",
            updateUrl: prefix + "/update/{id}",
            createUrl: prefix + "/create",
            modalName: "快递模版",
            columns: [{
                checkbox: true
            },
                {
                    field: 'title',
                    title: '快件产品名称'
                },
                {
                    field: 'productCode',
                    title: '产品编码'
                },
                {
                    field: 'agingType',
                    title: '时效类型'
                },
                {
                    field: '',
                    title: '快递预估价',
                    formatter: function (value, row, index) {
                        return row.estimatePriceMin + ' ~ ' + row.estimatePriceMax;
                    }
                },
                {
                    field: 'isOnline',
                    title: '状态',
                    formatter: function (value, row) {
                        var isOnline = row.isOnline;
                        if (row.isOnline == 1) {
                            isOnline = "未上线";
                        } else {
                            isOnline = "已上线";
                        }
                        return isOnline;
                    }
                },
                {
                    field: 'createdAt',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + updateFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.moduleId + '\')"></i>编辑</a> ');
                        actions.push(`<a class="btn btn-danger btn-xs ${isOnlineFlag}" href="javascript:void(0)" onclick="openModal('${row.moduleId}','${row.isOnline}')"></i>上下线</a> `);
                        return actions.join('');
                    }
                }]
        };

        $.table.init(options);

    });
    function openModal(id, data) {
        let title = '';
        let lineId = null;
        if (data == 1) {
            title = '上线';
            lineId = 2
        } else {
            title = '下线';
            lineId = 1
        }
        $.modal.confirm(`确定要${title}此活动吗`, function() {
            $.ajax({
                type: 'put',
                url: '/kylin/expressModule/isOnline',
                data: {moduleId: id, isOnline: lineId},
                success:function(e) {
                    $("button[name=refresh]").click();
                }
            })
        });
    }
</script>
</body>
</html>