<!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="taskNo"/>
                            </li>
                            <li>
                                <label>范围类型：</label>
                                <select name="scopeType" th:with="type=${@dict.getType('ams_inventory_scope_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>仓库：</label>
                                <select name="warehouseId">
                                    <option value="">所有</option>
                                    <option th:each="warehouse : ${warehouseList}" th:value="${warehouse.warehouseId}"
                                            th:text="${warehouse.warehouseCode + ' - ' + warehouse.warehouseName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>位置：</label>
                                <select name="locationId">
                                    <option value="">所有</option>
                                    <option th:each="location : ${locationList}" th:value="${location.locationId}"
                                            th:text="${location.locationCode + ' - ' + location.locationName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>类别：</label>
                                <select name="categoryId">
                                    <option value="">所有</option>
                                    <option th:each="category : ${categoryList}" th:value="${category.categoryId}"
                                            th:text="${category.categoryCode + ' - ' + category.categoryName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>负责人：</label>
                                <input type="text" name="ownerUserName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="taskStatus" th:with="type=${@dict.getType('ams_inventory_task_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>下发时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="params[beginIssueTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="params[endIssueTime]"/>
                            </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="asset:task:add">
                    <i class="fa fa-plus"></i> 新增任务
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="asset: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('asset:task:edit')}]];
        var removeFlag = [[${@permission.hasPermi('asset:task:remove')}]];
        var issueFlag = [[${@permission.hasPermi('asset:task:issue')}]];
        var resultFlag = [[${@permission.hasPermi('asset:task:result')}]];
        var confirmFlag = [[${@permission.hasPermi('asset:task:confirm')}]];
        var closeFlag = [[${@permission.hasPermi('asset:task:close')}]];
        var scopeTypeDatas = [[${@dict.getType('ams_inventory_scope_type')}]];
        var taskStatusDatas = [[${@dict.getType('ams_inventory_task_status')}]];
        var prefix = ctx + "asset/task";

        $(function() {
            $.table.init({
                url: prefix + "/list",
                viewUrl: prefix + "/view/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "盘点任务",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'taskId',
                    title: '任务ID',
                    visible: false
                },
                {
                    field: 'taskNo',
                    title: '任务号'
                },
                {
                    field: 'scopeType',
                    title: '范围类型',
                    formatter: function(value) {
                        return $.table.selectDictLabel(scopeTypeDatas, value);
                    }
                },
                {
                    field: 'warehouseName',
                    title: '仓库'
                },
                {
                    field: 'locationName',
                    title: '位置'
                },
                {
                    field: 'categoryName',
                    title: '资产类别'
                },
                {
                    field: 'ownerUserName',
                    title: '负责人'
                },
                {
                    field: 'taskStatus',
                    title: '状态',
                    formatter: function(value) {
                        return $.table.selectDictLabel(taskStatusDatas, value);
                    }
                },
                {
                    field: 'issueTime',
                    title: '下发时间'
                },
                {
                    field: 'finishTime',
                    title: '完成时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.view(\'' + row.taskId + '\')"><i class="fa fa-eye"></i>查看</a> ');
                        if (row.taskStatus === "DRAFT") {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.taskId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-primary btn-xs ' + issueFlag + '" href="javascript:void(0)" onclick="issueTask(\'' + row.taskId + '\')"><i class="fa fa-upload"></i>下发</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.taskId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        } else if (row.taskStatus === "ISSUED" || row.taskStatus === "INVENTORYING") {
                            actions.push('<a class="btn btn-primary btn-xs ' + resultFlag + '" href="javascript:void(0)" onclick="openResult(\'' + row.taskId + '\')"><i class="fa fa-list"></i>结果</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + closeFlag + '" href="javascript:void(0)" onclick="closeTask(\'' + row.taskId + '\')"><i class="fa fa-ban"></i>关闭</a> ');
                        } else if (row.taskStatus === "PENDING_RESULT_CONFIRM") {
                            actions.push('<a class="btn btn-primary btn-xs ' + confirmFlag + '" href="javascript:void(0)" onclick="confirmTask(\'' + row.taskId + '\')"><i class="fa fa-check"></i>确认</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + closeFlag + '" href="javascript:void(0)" onclick="closeTask(\'' + row.taskId + '\')"><i class="fa fa-ban"></i>关闭</a> ');
                        }
                        return actions.join('');
                    }
                }]
            });
        });

        function issueTask(taskId) {
            $.modal.confirm("下发后将按当前范围生成盘点明细快照，是否继续？", function() {
                $.operate.post(prefix + "/issue/" + taskId, {});
            });
        }

        function openResult(taskId) {
            $.modal.openOptions({
                title: "录入盘点结果",
                url: prefix + "/result/" + taskId,
                width: "1200",
                height: "720"
            });
        }

        function confirmTask(taskId) {
            $.modal.confirm("确认后只完成盘点任务，不会自动调整资产台账，也不会写资产履历，是否继续？", function() {
                $.operate.post(prefix + "/confirm/" + taskId, {});
            });
        }

        function closeTask(taskId) {
            $.modal.confirm("关闭后任务不可继续盘点，是否继续？", function() {
                $.operate.post(prefix + "/close/" + taskId, {});
            });
        }
    </script>
</body>
</html>
