<!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>
                            <label>艺人ID：</label>
                            <input type="text" name="artistId" placeholder="请输入艺人ID"/>
                        </li>
                        <li>
                            <label>艺人名称：</label>
                            <input type="text" name="artistName" placeholder="请输入艺人名称"/>
                        </li>
                        <li>
                            <label>艺人类型：</label>
                            <select name="artistType">
                                <option value="">全部</option>
                                <option value="1">音乐人</option>
                                <option value="2">艺术家</option>
                                <option value="3">厂牌</option>
                                <option value="4">品牌方</option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>入驻时间：</label>
                            <input type="text" class="time-input" id="beginDate" name="beginDate" placeholder="开始日期"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endDate" name="endDate" placeholder="结束日期"/>
                        </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.add()" shiro:hasPermission="kylin:artist:create">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var updateFlag = [[${@permission.hasPermi('kylin:artist:update')}]];
    var removeFlag = [[${@permission.hasPermi('kylin:artist:delete')}]];
    var detailFlag = [[${@permission.hasPermi('kylin:artist:detail')}]];

    var prefix = ctx + "kylin/artist";
    $(function () {
        var options = {
            url: prefix + "/list",
            updateUrl: prefix + "/update/{id}",
            createUrl: prefix + "/create",
            removeUrl: prefix + "/delete",
            detailUrl: prefix + "/detail/{id}",
            modalName: "艺人",
            columns: [
                {
                    field: 'artistId',
                    title: '艺人ID'
                },
                {
                    field: 'avatarUrl',
                    title: '艺人头像',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value, "80", "80");
                    }
                },
                {
                    field: 'artistName',
                    title: '艺人名称'
                },
                {
                    field: 'artistTypeName',
                    title: '艺人类型',
                },
                {
                    field: 'createdAt',
                    title: '艺人入驻时间',
                    formatter: function(value, row, index) {
                        if (value) {
                            var date = new Date(value);
                            return date.getFullYear() + '-' +
                                String(date.getMonth() + 1).padStart(2, '0') + '-' +
                                String(date.getDate()).padStart(2, '0') + ' ' +
                                String(date.getHours()).padStart(2, '0') + ':' +
                                String(date.getMinutes()).padStart(2, '0') + ':' +
                                String(date.getSeconds()).padStart(2, '0');
                        }
                        return '';
                    }
                },
                {
                    field: 'performanceCount',
                    title: '关联演出',
                    formatter: function(value, row, index) {
                        return value || 0;
                    }
                },
                {
                    field: 'productCount',
                    title: '关联商品',
                    formatter: function(value, row, index) {
                        return value || 0;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.artistId + '\')"><i class="fa fa-eye"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + updateFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.artistId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
        };

        $.table.init(options);
        
        // 初始化日期选择器
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            
            // 开始日期
            laydate.render({
                elem: '#beginDate',
                format: 'yyyy-MM-dd',
                type: 'date',
                done: function(value, date){
                    // 可以在这里添加日期选择后的逻辑
                }
            });
            
            // 结束日期
            laydate.render({
                elem: '#endDate',
                format: 'yyyy-MM-dd',
                type: 'date',
                done: function(value, date){
                    // 可以在这里添加日期选择后的逻辑
                }
            });
        });
    });
    
    // 单条删除
    function removeArtist(id) {
        $.operate.remove(id, "删除后该艺人信息将无法被引用，也无法找回，确认要将该艺人删除吗？");
    }
</script>
</body>
</html>
