<!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="dept-form">
                <div class="select-list">
                    <ul>
                        <li>
                            商品名称：<input type="text" name="goodsName"/>
                        </li>
                        <li>
                            类目状态：<select name="status" th:with="type=${@dict.getType('goods_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"/>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.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>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:goods:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-success" onclick="addTemplate()" shiro:hasPermission="goods:goods:add">
                <i class="fa fa-plus"></i> 模版发单
            </a>
            <!--            <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:goods:edit">-->
            <!--                <i class="fa fa-edit"></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 addFlag = [[${@permission.hasPermi('goods:goods:add')}]];
    var editFlag = [[${@permission.hasPermi('goods:goods:edit')}]];
    var removeFlag = [[${@permission.hasPermi('goods:goods:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "goods/goods"

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "商品",
            columns: [
                {
                    checkbox: true
                }, {
                    field: 'goodsCode',
                    title: '商品编码',
                    align: "left"
                }, {
                    field: 'goodsName',
                    title: '商品名称',
                    align: "left"
                // }, {
                //     field: 'goodsPrice',
                //     title: '价格',
                //     align: "left"
                // }, {
                //     field: 'discountsPrice',
                //     title: '优惠价',
                //     align: "left"
                // }, {
                //     field: 'groupPrice',
                //     title: '团购价',
                //     align: "left"
                }, {
                    field: 'goodsSort',
                    title: '排序',
                    align: "left"
                }, {
                    field: 'status',
                    title: '状态',
                    align: "left",
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas, item.status);
                    }
                }, {
                    field: 'goodsImgUrl',
                    title: '图片',
                    align: "left"
                // }, {
                //     field: 'goodsNumber',
                //     title: '商品库存',
                //     align: "left"
                }, {
                    field: 'createTime',
                    title: '创建时间',
                    align: "left"
                }, {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.status === 1) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="enable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-up"></i>上架</a> ');
                        }
                        if (row.status === 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="disable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-down"></i>下架</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.goodsStandards(\'' + row.goodsId + '\')"><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.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function enable(goodsId) {
        $.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" +  0);
    }

    function disable(goodsId) {
        $.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" +  1);
    }

    function addTemplate(){
        var url = "goods/standard/addTemplate";
        $.modal.openTab("模版添加", url, true);
    }

</script>
</body>
</html>