<!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('素材信息列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 素材分组
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="openGroup()" title="管理素材分组"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i>
                </button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">

    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>所属商户：</p>
                                <select id="merchantId" class="form-control" name="merchantId">
                                    <option value="">------全部------</option>
                                    <option th:each="post:${mts}"
                                            th:value="${post.merchantId}"
                                            th:text="${post.merchantName}"></option>
                                </select></li>
                            <li style="display:none;">
                                <p>分组id：</p>
                                <input type="text" name="groupId" id="groupId"/>
                            </li>
                            <li>
                                <p>素材名称：</p>
                                <input type="text" name="materialName"/>
                            </li>
                            <li>
                                <p>素材类型：</p>
                                <select name="materialType" th:with="type=${@dict.getType('csm_material_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>审核状态：</p>
                                <select name="auditState" th:with="type=${@dict.getType('cms_audit_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>可用状态：</p>
                                <select name="useState" th:with="type=${@dict.getType('sms_use_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre();"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()"
                   shiro:hasPermission="bussiness_cms:material:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
                   shiro:hasPermission="bussiness_cms:material:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
                   shiro:hasPermission="bussiness_cms:material:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    function resetPre() {
        $.form.reset();
        $("#merchantId").val($("#merchantId").val()).trigger("change");
    }

    var editFlag = [[${@permission.hasPermi('bussiness_cms:material:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bussiness_cms:material:remove')}]];
    var materialTypeDatas = [[${@dict.getType('csm_material_type')}]];
    var auditStateDatas = [[${@dict.getType('cms_audit_state')}]];
    var useStateDatas = [[${@dict.getType('sms_use_state')}]];
    var prefix = ctx + "bussiness_cms/material";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryMaterialGroupTree();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "素材信息",
            sortName: "createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'materialId',
                    title: '素材id',
                    visible: false
                },
                {
                    field: 'merchantName',
                    title: '所属商户',
                    formatter: function (value) {
                        if (!value)
                            return '系统商户';
                        return value;
                    }
                },
                {
                    field: 'materialName',
                    title: '素材名称'
                },
                {
                    field: 'groupName',
                    title: '所属分组',
                    align: 'left'
                },
                {
                    field: 'savePath',
                    title: '素材图片',
                    formatter: function (value) {
                        if (value) {
                            value = ctx + "profile" + value;
                            return "<img src='"
                                + value
                                + "' style='height: 36px;' target='_blank' tile='点击查看' onclick='$.operate.alertPic(\""
                                + value
                                + "\")'></img>";
                        }
                    }
                },
                {
                    field: 'materialType',
                    title: '素材类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(materialTypeDatas, value);
                    }
                },
                {
                    field: 'materialDescription',
                    title: '素材描述'
                },

                {
                    field: 'auditState',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(auditStateDatas, value);
                    }
                },
                {
                    field: 'auditReason',
                    title: '审核意见'
                },
                {
                    field: 'useState',
                    title: '可用状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(useStateDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.materialId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.materialId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryMaterialGroupTree();
    });

    function queryMaterialGroupTree() {
        var url = ctx + "bussiness_cms/materialgroup/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#groupId").val(treeNode.id);
            $.table.search();
        }
    }

    /* 打开分组管理 */
    function openGroup() {
        var url = ctx + "bussiness_cms/materialgroup";
        $.modal.openTab("素材组别管理", url);
    }
</script>
</body>
</html>