<!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="col-sm-12 search-collapse">
                <form id="formId" class="form-horizontal m-t">
                    <div class="form-group">
                        <div style="margin-left: 15px; width: 100px; float: left;">
                            <label class="control-label">商品分类：</label>
                        </div>
                        <div style="width: 150px; float: left;">
                            <select name="prodClass" class="form-control m-b" th:with="prodClasses=${@product.getProdClasses()}" >
                                <option value="">所有</option>
                                <option th:each="prodClass : ${prodClasses}" th:text="${prodClass.className}" th:value="${prodClass.prodClassId}"></option>
                            </select>
                        </div>
                        <div style="margin-left: 15px; width: 100px; float: left;">
                            <label class="control-label">商品名称：</label>
                        </div>
                        <div style="width: 150px; float: left;">
                            <input type="text" class="form-control" name="prodName">
                        </div>
                        <div style="margin-left: 15px; width: 100px; float: left;">
                            <label class="control-label">文创名称：</label>
                        </div>
                        <div style="width: 150px; float: left;">
                            <input type="text" class="form-control" name="ipName">
                        </div>
                        <div style="margin-left: 15px; width: 100px; float: left;">
                            <label class="control-label">设计师名称：</label>
                        </div>
                        <div style="width: 150px; float: left;">
                            <input type="text" class="form-control" name="designerName">
                        </div>
                        <div style="margin-left: 15px; width: 100px; float: left;">
                            <label class="control-label">商品描述：</label>
                        </div>
                        <div style="width: 150px; float: left;">
                            <input type="text" class="form-control" name="description">
                        </div>
                        <div style="margin-left: 15px; width: 100px; float: left;">
                            <label class="control-label">商品状态：</label>
                        </div>
                        <div style="width: 150px; float: left;">
                            <input type="text" class="form-control" name="prodStatus">
                        </div>
                        <div style="margin-left: 15px; float: left;">
                            <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="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </div>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="master:product:prod:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="master:product:prod:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="master:product:prod: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>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('master:product:prod:edit')}]];
        var removeFlag = [[${@permission.hasPermi('master:product:prod:remove')}]];
        var approveFlag = [[${@permission.hasPermi('master:product:prod:approve')}]];
        var editAttrFlag = [[${@permission.hasPermi('master:product:prod:viewAttrs')}]];
        var editTagFlag = [[${@permission.hasPermi('master:product:prod:editTag')}]];
        var prefix = ctx + "master/product/prod";
        var prodStatuses = [[${@dict.getType('prod_status')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "推荐商品",
                columns: [
                    {
                        field: 'prodName',
                        title: '商品名称'
                    },
                    {
                        field: 'prodClass',
                        title: '商品分类'
                    },
                    {
                        field: 'ipName',
                        title: '文创品牌'
                    },
                    {
                        field: 'designerName',
                        title: '设计师名称'
                    },
                    {
                        field: 'prodStatus',
                        title: '商品状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(prodStatuses, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            if (row.prodStatus === 'SAVED') {
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><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.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                                actions.push('<a class="btn btn-warning btn-xs ' + editAttrFlag + '" href="javascript:void(0)" onclick="editAttr(\'' + row.id + '\')"><i class="fa fa-at"></i>编辑属性</a> ');
                                actions.push('<a class="btn btn-info btn-xs ' + editTagFlag + '" href="javascript:void(0)" onclick="editTag(\'' + row.id + '\')"><i class="fa fa-info"></i>编辑标签</a> ');
                                actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editPic(\'' + row.id + '\')"><i class="fa fa-file-picture-o"></i>商品图片</a> ');
                            }
                            if (row.prodStatus === 'SUBMITTED') {
                                actions.push('<a class="btn btn-warning btn-xs ' + approveFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.id + '\')"><i class="fa fa-thumbs-o-up"></i>审核</a> ');
                                actions.push('<a class="btn btn-warning btn-xs ' + approveFlag + '" href="javascript:void(0)" onclick="reject(\'' + row.id + '\')"><i class="fa fa-thumbs-o-down"></i>驳回</a>');
                            }
                            return actions.join('');
                        }
                    }
                ]
            };
            $.table.init(options);
        });

        function editAttr(id) {
            $.modal.openTab("商品属性信息",ctx + "master/product/prodAttr/" + id);
        }

        function editTag(id) {
            $.modal.openTab("商品标签信息", ctx + "master/product/prodTag/editTag/" + id);
        }

        function editPic(id) {
            $.modal.openTab("商品图片信息", ctx + "master/product/prodPic/editPic/" + id);
        }

        function approve(id) {
            $.modal.confirm("确认同意该商品的申请吗？", function() {
                $.operate.post(prefix + "/approve", {"id": id});
            });
        }

        function reject(id) {
            $.modal.confirm("确认驳回该商品的申请吗？", function() {
                $.operate.post(prefix + "/reject/", {"id": id});
            });
        }
    </script>
</body>
</html>