<!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">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>商品名称：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <p>所属公司id：</p>
                                <input type="text" name="companyId"/>
                            </li>
                            <li>
                                <p>所属类型id：</p>
                                <input type="text" name="typeId"/>
                            </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="$.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.addFull()" shiro:hasPermission="goods:info:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="goods:info: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('goods:info:edit')}]];
        var putawayFlag = [[${@permission.hasPermi('goods:info:putaway')}]];
        var removeFlag = [[${@permission.hasPermi('goods:info:remove')}]];
        var putawayDict = [[${@dict.getType('goods_putaway')}]];
        var prefix = ctx + "goods/info";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "商品基础详情",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '上架标志',
                    visible: false
                },
                {
                    field : 'name', 
                    title : '商品名称'
                },
                {
                    field : 'companyId',
                    visible: false
                },
                {
                    field : 'companyName',
                    title : '所属公司'
                },
                {
                    field : 'typeName',
                    title : '所属类型',
                },
                {
                    field : 'typeId', 
                    title : '所属类型id',
                    visible: false
                },
                {
                    field : 'price', 
                    title : '一口价'
                },
                {
                    field : 'cover', 
                    title : '封面图片',
                    formatter: function(value, row, index) {
                        // 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
                        // 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
                        return $.table.imageView(value,250,250);
                    }
                },
                {
                    field : 'producedTime', 
                    title : '生产日期'
                },
                {
                    field : 'weight', 
                    title : '单重'
                },
                {
                    field : 'putawayFlag',
                    title: '上架标志',
                    width: '10%',
                    align: "left",
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(putawayDict, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        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>');
                        if(row.putawayFlag=="0"){
                            actions.push('<a class="btn btn-primary btn-xs ' + putawayFlag + '" onclick="putaway('+row.id+',1)" shiro:hasPermission="goods:info:putaway"><i class="fa fa-edit"></i> 上架</a>');
                        }else if(row.putawayFlag=="1"){
                            actions.push('<a class="btn btn-warning btn-xs ' + putawayFlag + '" onclick="putaway('+row.id+',0)" shiro:hasPermission="goods:info:putaway"><i class="fa fa-download"></i> 下架</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function putaway(id,putaway){
            var data = new FormData();
            data.append("id", id);
            data.append("putawayFlag", putaway);
            $.ajax({
                type: "POST",
                url: prefix + "/putaway",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.table.refresh()
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            })
        }

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