<!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 :: bootstrap-fileinput-css" />
    <style>
        .layui-layer-btn0 {
            padding: 0;
        }
        .paddings {
            padding: 0 !important;
        }
        .shadeCss,.layui-layer-shade {
            background-color: rgb(0, 0, 0, 0.5) !important;
        }
        .select-list ul {
            display: flex;
            justify-content: space-between;
        }
        .selectClassifyOne {
            display: flex;
            align-items: center;
            margin: 12px 0;
        }
        .selectClassifyOne span {
            width: 45px;
        }
        .gray-bg .fixed-table-toolbar {
            display: flex;
        }
        .gray-bg .fixed-table-toolbar .bs-bars {
            flex: 1;
        }
        .gray-bg .fixed-table-toolbar .bs-bars .btn-group-sm {
            display: flex;
            justify-content: space-between;
        }
        .leftSearchBox {
            display: flex;
            align-items: center;
        }
        .leftSearchBox input, .leftSearchBox select {
            width: 200px;
            height: 34px;
            margin-right: 12px;
        }
        .ibox-content {
            border-style: none;
            padding: 0;
        }
        .kv-hidden {
            display: none !important;
        }
    </style>
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="role-form">
                    <div class="select-list">
                        <ul>
                            <li class="leftSearchBox">
                                <input class="form-control" type="text" name="purchaseName" placeholder="请输入名字">
                                类型：<select class="type form-control" name="status" data-first-title="请选择">
                                    <option value="-1">全部</option>
                                    <option value="0">等待开始</option>
                                    <option value="1">活动中</option>
                                    <option value="2">活动结束</option>
                                    <option value="7">停用</option>
                                </select>
                                时间：<input type="text" class="layui-input form-control" id="test1" name="startTime" placeholder="请选择时间">
                                ~  
                                <input type="text" class="layui-input form-control" id="test1" name="endTime"  style="margin-left: 10px;" placeholder="请选择时间">
                                <li>
                                    <a id="searchBtns" 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="ceshi()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </li>
                            <li>
                                
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar">
                <div>
                    <a class="btn btn-primary" onclick="functionBtn(1)">
                        启用
                    </a>
                    <a class="btn btn-warning" onclick="functionBtn(2)">
                        停用
                    </a>
                    <!-- <a class="btn btn-danger" onclick="functionBtn(3)">
                        删除
                    </a> -->
                    <a class="btn btn-success" id="addActivity" th:onclick="$.operate.addTab()">
                        <i class="fa fa-plus"></i> 新增活动
                    </a>
                    <a class="btn btn-warning" id="button-open-11">
                        <i class="fa fa-download"></i> 导出Excel
                    </a>
                </div>
            </div>
            
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
            
        </div>
    </div>
    <th:block th:include="include :: footer"/>
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var dicCouponBusiType = [[${@dict.getType('zhengzai_coupon_busi_type')}]];
        var dicCouponBindType = [[${@dict.getType('zhengzai_coupon_bind_type')}]];
        var platformUrl = [[${platformUrl}]];
        var prefix = ctx + "candy/coupon/mgt";
        var prefix2 = ctx + "local";
        var viewMgtCouponFlag = [[${@permission.hasPermi('candy:coupon:mgt:detail')}]];
        var cancelMgtCouponFlag = [[${@permission.hasPermi('candy:coupon:mgt:cancel')}]];
        let rowData = {};
        var couType = [[${couType}]];
        $(function () {
            var options = {
                url: "/goblin/marketing/zhengzai/list",
                type: 'get',
                createUrl: prefix2 + "/addNewActivity",
                detailUrl: prefix2 + "/addNewActivity?id={id}",
                removeUrl: prefix + "/cancel/{id}",
                openTab: prefix2 + "/activityStoreList/id={id}",
                // exportUrl: prefix + "/export",
                onCheck: onCheck,
                // onCheckAll: onCheckAll,
                sortName: "createdAt",
                sortOrder: "desc",
                modalName: "活动",
                columns: [
                    {
                        radio: true
                    },
                    {
                        field: 'name',
                        title: '活动名称'
                    },
                    {
                        field: 'status',
                        title: '状态',
                        formatter: function(value, row, index) {
                            // $('.pull-right').hide()
                            if (value == -1) {
                                return '全部'
                            } else if (value == 0) {
                                return '等待开始'
                            } else if (value == 1) {
                                return '进行中'
                            } else if (value == 2) {
                                return '活动结束'
                            } else {
                                return '停用'
                            }
                        }
                    },
                    {
                        field: 'bindType',
                        title: '有效期',
                        formatter: function(value, row, index) {
                            return row.startTime + '  -  ' + row.endTime
                        }
                    },
                    {
                        field: 'createdAt',
                        title: '创建时间'
                    },
                    {
                        field: 'storeCount',
                        title: '店铺数量'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return `<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.detailTab('${row.selfMarketId}')">编辑活动</a>
                            <a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="goToStore_list('${row.name}','${row.selfMarketId}','${row.startTime}  -  ${row.endTime}')">查看详情</a>`
                        }
                    }]
            };
            $.table.init(options);
        });
        function ceshi () {
            $.form.reset();
            $("button[name=refresh]").click();
        }
        function functionBtn(type) {
            let status = '';
            if (type == 1) {
                status = 0;
            } else if (type == 2) {
                status = 7;
            } else {
                status = -1;
            }
            let data = {
                marketId: rowData.selfMarketId
            }
            data.status = status;
            promiseMethods('/goblin/marketing/zhengzai/status', 'post', data).then(res => {
                if (res.code == 0) {
                    if (type == 3) {
                        layer.msg('删除成功！')
                    } else {
                        layer.msg('修改状态成功！')
                    }
                    setTimeout(() => {
                        $("#searchBtns").click(); 
                    }, 500);
                }
            })
        }
        $("#button-open-11").click(function(){
            $("button[name=refresh]").click()
	    })
        function goToStore_list (name, id, time) {
            $.modal.openTab(name, prefix2 + "/activityStoreList?id=" + id + '&time=' + time + '&name=' + name)
        }
        function onCheck (row, $element) {
            rowData = row;
        }
        function onCheckAll (row, $element) {
            rowData = row;
        }
        function yes(index, layero) {
        }
        
        function del(id, status, notice) {
            $.modal.confirm(notice, function() {
                $.ajax({
                    type: 'put',
                    url: '/stone/item/change/status',
                    data: {
                        itemId: id,
                        status
                    },
                    success:function(e) {
                        layer.msg("操作成功！")
                        setTimeout(() => {
                            $("#searchBtns").click(); 
                        }, 1500);
                    }
                })
            });
        }
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#test1', //指定元素
                type: 'datetime'
            });
        });
        function promiseMethods(url,type,data,contentType) {
            return new Promise((resolve,reject)=>{
                $.ajax({
                    url,
                    type,
                    data,
                    contentType,
                    success:function(res) {
                        resolve(res);
                    }
                })
            })
        }
    </script>
</body>
</html>