<!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="repairNo"/>
                            </li>
                            <li>
                                <label>资产编码：</label>
                                <input type="text" name="assetCode"/>
                            </li>
                            <li>
                                <label>资产名称：</label>
                                <input type="text" name="assetName"/>
                            </li>
                            <li>
                                <label>报修人：</label>
                                <input type="text" name="reportUserName"/>
                            </li>
                            <li class="select-time">
                                <label>报修时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginReportTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endReportTime]"/>
                            </li>
                            <li>
                                <label>维修方：</label>
                                <select name="repairerType" th:with="type=${@dict.getType('ams_repairer_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="orderStatus" th:with="type=${@dict.getType('ams_repair_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否超期：</label>
                                <select name="params[overdueFlag]">
                                    <option value="">所有</option>
                                    <option value="Y">已超期</option>
                                    <option value="N">未超期</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-success" onclick="$.operate.add()" shiro:hasPermission="asset:repair:add">
                    <i class="fa fa-plus"></i> 新增报修
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="asset:repair: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:repair:edit')}]];
        var removeFlag = [[${@permission.hasPermi('asset:repair:remove')}]];
        var submitFlag = [[${@permission.hasPermi('asset:repair:submit')}]];
        var confirmFlag = [[${@permission.hasPermi('asset:repair:confirm')}]];
        var rejectFlag = [[${@permission.hasPermi('asset:repair:reject')}]];
        var startFlag = [[${@permission.hasPermi('asset:repair:start')}]];
        var finishFlag = [[${@permission.hasPermi('asset:repair:finish')}]];

        var repairerTypeDatas = [[${@dict.getType('ams_repairer_type')}]];
        var orderStatusDatas = [[${@dict.getType('ams_repair_status')}]];
        var prefix = ctx + "asset/repair";

        $(function() {
            var options = {
                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: 'repairId',
                    title: '维修单ID',
                    visible: false
                },
                {
                    field: 'repairNo',
                    title: '报修单号'
                },
                {
                    field: 'assetCode',
                    title: '资产编码'
                },
                {
                    field: 'assetName',
                    title: '资产名称'
                },
                {
                    field: 'categoryName',
                    title: '资产类别'
                },
                {
                    field: 'specModel',
                    title: '规格型号',
                    visible: false
                },
                {
                    field: 'brand',
                    title: '品牌',
                    visible: false
                },
                {
                    field: 'reportUserName',
                    title: '报修人'
                },
                {
                    field: 'faultDesc',
                    title: '故障描述',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 15);
                    }
                },
                {
                    field: 'reportTime',
                    title: '报修时间'
                },
                {
                    field: 'expectedFinishTime',
                    title: '预计完成时间',
                    visible: false
                },
                {
                    field: 'repairerType',
                    title: '维修方',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(repairerTypeDatas, value) || "-";
                    }
                },
                {
                    field: 'repairUserName',
                    title: '维修人'
                },
                {
                    field: 'repairOrgName',
                    title: '维修单位',
                    visible: false
                },
                {
                    field: 'repairStartTime',
                    title: '开始时间',
                    visible: false
                },
                {
                    field: 'repairFinishTime',
                    title: '完成时间'
                },
                {
                    field: 'repairCost',
                    title: '维修费用'
                },
                {
                    field: 'orderStatus',
                    title: '单据状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'rejectReason',
                    title: '驳回原因',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.view(\'' + row.repairId + '\')"><i class="fa fa-eye"></i>查看</a> ');

                        if (row.orderStatus === "DRAFT") {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.repairId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-primary btn-xs ' + submitFlag + '" href="javascript:void(0)" onclick="submitRepair(\'' + row.repairId + '\')"><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.repairId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        } else if (row.orderStatus === "PENDING_CONFIRM") {
                            actions.push('<a class="btn btn-primary btn-xs ' + confirmFlag + '" href="javascript:void(0)" onclick="confirmRepair(\'' + row.repairId + '\')"><i class="fa fa-check"></i>确认受理</a> ');
                            actions.push('<a class="btn btn-warning btn-xs ' + rejectFlag + '" href="javascript:void(0)" onclick="rejectRepair(\'' + row.repairId + '\')"><i class="fa fa-reply"></i>驳回</a>');
                        } else if (row.orderStatus === "WAIT_REPAIR") {
                            actions.push('<a class="btn btn-primary btn-xs ' + startFlag + '" href="javascript:void(0)" onclick="startRepair(\'' + row.repairId + '\')"><i class="fa fa-wrench"></i>开始维修</a>');
                        } else if (row.orderStatus === "REPAIRING") {
                            actions.push('<a class="btn btn-primary btn-xs ' + finishFlag + '" href="javascript:void(0)" onclick="finishRepair(\'' + row.repairId + '\')"><i class="fa fa-check-square-o"></i>完成维修</a>');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function submitRepair(repairId) {
            $.modal.confirm("提交后报修单不可再修改或删除，是否继续？", function() {
                $.operate.post(prefix + "/submit/" + repairId, {});
            });
        }

        function confirmRepair(repairId) {
            $.modal.confirm("您确定要受理该报修申请吗？", function() {
                $.operate.post(prefix + "/confirm/" + repairId, {});
            });
        }

        function rejectRepair(repairId) {
            layer.prompt({ title: "请输入驳回原因", formType: 2, maxlength: 500 }, function(text, index) {
                layer.close(index);
                $.operate.post(prefix + "/reject/" + repairId, { rejectReason: text });
            });
        }

        function startRepair(repairId) {
            $.modal.open("开始资产维修", prefix + "/start/" + repairId, "800", "500");
        }

        function finishRepair(repairId) {
            $.modal.open("完成资产维修", prefix + "/finish/" + repairId, "800", "500");
        }
    </script>
</body>
</html>
