<!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>任务名称：</label>
                            <input type="text" name="name"/>
                        </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="system:task:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:task:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:task:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:task:export">
                <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 editFlag = [[${@permission.hasPermi('system:task:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:task:remove')}]];
    var prefix = ctx + "system/playlet/task";

    $(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: '任务主键id',
                    visible: false
                },
                {
                    field: 'taskId',
                    title: '任务id'
                },
                {
                    field: 'itemName',
                    title: '短剧名称'
                },
                {
                    field: 'name',
                    title: '任务名称'
                },
                {
                    title: '抖音',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return dyStatusTools(row);
                    }
                },
                {
                    title: '快手',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return ksStatusTools(row);
                    }
                },
                {
                    title: '视频',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return dspStatusTools(row);
                    }
                },
                {
                    field: 'peopleNumber',
                    title: '参与人数'
                },
                {
                    field: 'commissionRate',
                    title: '提成比例'
                },
                {
                    field: 'taskUrl',
                    title: '任务链接',
                    formatter: function(value) {
                        if (value != null && value !== ''){return '<a target="_blank" href="' + value+ '" download="false">任务链接<a/>';}
                        else {return '<a>无<a/>'}
                    }
                },
                {
                    field: 'taskDiskUrl',
                    title: '网盘链接',
                    formatter: function(value) {
                        if (value != null && value !== ''){return '<a target="_blank" href="' + value+ '" download="false">网盘链接<a/>';}
                        else {return '<a>无<a/>'}
                    }
                },
                {
                    field: 'startTime',
                    title: '任务开始时间'
                },
                {
                    field: 'endTime',
                    title: '任务结束时间'
                },
                {
                    field: 'baseBonus',
                    title: '基础奖金',
                    visible: false
                },
                {
                    field: 'totalBonus',
                    title: '任务总奖金',
                    visible: false
                },
                {
                    field: 'state',
                    title: '任务状态',
                    visible: false
                },
                {
                    field: 'taskContent',
                    title: '任务介绍',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><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.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function dyStatusTools(row) {
        if (row.dyStatus === '01') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableDy(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableDy(\'' + row.id + '\')"></i> ';
        }
    }

    function enableDy(id) {
        $.modal.confirm("确认要上架抖音平台吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "dyStatus": "02" });
        })
    }

    /* 上架抖音 */
    function disableDy(id) {
        $.modal.confirm("确认下架抖音平台吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "dyStatus": "01" });
        })
    }

    function ksStatusTools(row) {
        if (row.ksStatus === '01') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableKs(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableKs(\'' + row.id + '\')"></i> ';
        }
    }

    function enableKs(id) {
        $.modal.confirm("确认要上架快手平台吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "ksStatus": "02" });
        })
    }

    /* 上架快手 */
    function disableKs(id) {
        $.modal.confirm("确认下架快手平台吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "ksStatus": "01" });
        })
    }

    function dspStatusTools(row) {
        if (row.dspStatus === '01') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableDsp(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableDsp(\'' + row.id + '\')"></i> ';
        }
    }

    function enableDsp(id) {
        $.modal.confirm("确认要上架视频平台吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "dspStatus": "02" });
        })
    }

    /* 上架抖音 */
    function disableDsp(id) {
        $.modal.confirm("确认下架视频平台吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "dspStatus": "01" });
        })
    }

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