<!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="coupon-form">
                    <div class="select-list">
                        <ul>
                            <input type="hidden" name="couType" th:value="${couType}"/>
                            <li>
                                <input type="text" name="title" placeholder="请输入商品名称"/>
                            </li>
                            <li>
                                状态：
                                <select name="state" id="">
                                    <option value="">全部</option>
                                    <option value="">上架中</option>
                                    <option value="">待上架</option>
                                    <option value="">已下架</option>
                                </select>
                            </li>
                            <li>
                                类型：
                                <select name="type" id="">
                                    <option value="">全部</option>
                                    <option value="">券</option>
                                    <option value="">商品</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="$.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-warning" th:onclick="$.operate.addTab(1)">
		            <i class="fa fa-download"></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 dicCouponBusiType = [[${@dict.getType('zhengzai_coupon_busi_type')}]];
        var dicCouponBindType = [[${@dict.getType('zhengzai_coupon_bind_type')}]];
        var prefix = ctx + "stone/item";
        var prefix2 = ctx;
        var couType = [[${couType}]];
        var simpleTypeDataList = [{
            id: 1,
            simpleName: '5元'
        }, {
            id: 2,
            simpleName: '10元'
        }, {
            id: 3,
            simpleName: '25元'
        }, {
            id: 4,
            simpleName: '35元'
        }]
        $(function () {
            var options = {
                url: prefix2 + "stone/item/list",
                createUrl: prefix + "/integralStoreEdit",
                detailUrl: prefix + "/integralStoreEdit/${id}",
                removeUrl: prefix2 + "cancel/{id}",
                updateUrl: prefix + "/integralStoreEdit?id={id}",
                // exportUrl: prefix + "/export",
                sortName: "createdAt",
                sortOrder: "desc",
                modalName: "商品",
                columns: [
                    {
                        field: '',
                        title: '序号',
                        formatter: function (value, row, index) {
                            return index + 1
                        }
                    },
                    {
                        field: 'targetTitle',
                        title: '商品名称'
                    },
                    {
                        field: 'status',
                        title: '状态',
                        formatter: function(value, row, index) {
                            if (value == 1) {
                                return "不限"
                            } else if (value == 2) {
                                return "定时"
                            } else {
                                return "下线"
                            }
                        }
                    },
                    {
                        field: 'simpleType',
                        title: '优惠券分类',
                        formatter: function(value, row, index) {
                            if (value == 0) {
                                return '无条件';
                            } else {
                                for (var i in simpleTypeDataList) {
                                    if (simpleTypeDataList[i].id == value) {
                                        return simpleTypeDataList[i].simpleName;
                                    }
                                }
                            }
                        }
                    },
                    {
                        field: 'busiType',
                        title: '类型',
                        formatter: function(value, row, index) {
                            return '券'
                        }
                    },
                    {
                        field: 'score',
                        title: '所需积分'
                    },
                    {
                        field: 'limitCount',
                        title: '每人限兑次数'
                    },
                    {
                        field: 'generalSurplus',
                        title: '已兑换数量'
                    },
                    {
                        field: 'generalTotal',
                        title: '剩余库存'
                    },
                    {
                        field: 'createdAt',
                        title: '创建时间'
                    },
                    {
                        title: '操作',
                        // align: 'center',
                        formatter: function (value, row, index) {
                            let dataArr = [];
                            if (row.status == 7) {
                                return `<span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.editTab('${row.itemId}')">编辑</span>
                                <span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openShelvesModal('${row.itemId}', 1, '确定下架此商品吗？')">上架</span>
                                <span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openShelvesModal('${row.itemId}', '-1', '确定删除此商品吗？')">删除</span>`
                            } else {
                                return `<span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.editTab('${row.itemId}')">编辑</span>
                                <span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openShelvesModal('${row.itemId}', 7, '确定下架此商品吗？')">下架</span>
                                <span class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openShelvesModal('${row.itemId}', '-1', '确定删除此商品吗？')">删除</span>`
                            }
                        }
                    }]
            };
            $.table.init(options);
        });
        /* 查看码列表 */
        function couponCodeList(couponId) {
            var url = 'candy/coupon/code?couponId=' + couponId;
            $.modal.openTab("积分明细列表", url);
        }
        function openShelvesModal(id, status, notice) {
            $.modal.confirm(notice, function() {
                $.ajax({
                    type: 'put',
                    url: '/stone/item/change/status',
                    data: {
                        itemId: id,
                        status
                    },
                    success:function(e) {
                        layer.msg("操作成功！")
                        $("button[name=refresh]").click()
                    }
                })
            });
        }
    </script>
</body>
</html>