index.php 14.1 KB
<?php

use yii\helpers\Url;
use app\ht\widgets\LinkPager;


$this->title = '故障管理';
$this->params['breadcrumbs'][] = '设备管理';
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="panel panel-default">
    <div id="warning"></div>
    <div class="panel-body">
        <form action="" method="get" class="filter-form">
            <table width="100%">
                <tbody>
                <tr>
                    <td class="text-right" style="width:10%"><b>所属设备类型:</b></td>
                    <td class="form-inline" style="width:30%">
                        <select class="form-control" id="deviceParentCat" name="deviceParentCat">
                            <option value="">--请选择一级分类--</option>
                            <?php foreach ($deviceCatParentList as $deviceCatParent) :?>
                                <option value="<?=$deviceCatParent['id'] ?>" <?php if ($gets['cat_pid'] == $deviceCatParent['id']){ echo "selected"; } ?>><?=$deviceCatParent['name'] ?></option>
                            <?php endforeach;?>
                        </select>&nbsp;&nbsp;
                        <select class="form-control" id="deviceChildCat" name="deviceChildCat">
                            <option value="">--选择二级分类--</option>
                        </select>
                        <input type="hidden" value="<?=$gets['cat_id'] ?>" id="hid_cat_id">
                    </td>
                    <td class="text-right" style="width:8%"><b>故障名称:</b></td>
                    <td class="form-inline" style="width:20%">
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="faultName" name="faultName" value="<?=$gets['faultName']?>">
                        </div>
                    </td>
                    <td class="text-right" style="width:8%"><b>是否常见:</b></td>
                    <td class="form-inline" style="width:24%">
                        <div class="col-sm-5">
                            <select id="selsiscommon" name="selsiscommon" class="form-control form-inline">
                                <option value=""> -- 全部 --</option>
                                <option value="1" <?php if ($gets['selsiscommon'] == 1){ echo 'selected';}?>> 常见 </option>
                                <option value="2" <?php if ($gets['selsiscommon'] == 2){ echo 'selected';}?>> 不常见</option>
                            </select>
                        </div>
                    </td>
                </tr>
                <tr class="search">
                    <td colspan="6" class="text-center">
                        <button type="submit" class="btn btn-primary" id="search"><i class="glyphicon glyphicon-search"></i> 查 询  </button>
                        <a class="btn btn-default" href="<?=Url::toRoute("/device/fault/index")?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <a href="<?php echo Url::toRoute('/device/fault/create'); ?>" class="btn btn-success pull-left">添加故障</a>&nbsp;&nbsp;
        <a href="<?php echo Url::toRoute('/device/fault/batch-create'); ?>" class="btn btn-success">批量添加故障</a>
<!--        <a href="--><?php //echo Url::toRoute('/device/fault/check'); ?><!--" class="btn btn-warning">维修方案报价检查</a>&nbsp;&nbsp;&nbsp;&nbsp;-->
        <a href="javascript:void(0);" id="saveOrder" class="btn btn-primary">保存排序</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="<?php echo Url::toRoute('/device/fault/clear-computer-data'); ?>" class="btn btn-danger" style="visibility: hidden;">清理电脑故障数据</a>
        <div class="clearfix"></div>
    </div>

    <div  class="panel-body">
        <?php if (!empty($deviceFaultlList)) : ?>
            <table class="table table-striped table-bordered"  id="brand-table">
                <thead>
                <tr>
                    <th style="width:5%;" class="text-center align-middle hqy-all-select"><?php echo $sort['id']  ?></th>
                    <th style="width:25%;">所属设备分类</th>
                    <th style="width:30%;">故障名称</th>
                    <th style="width:10%;">是否常见</th>
                    <th style="width:10%;"><?php echo $sort['sort_order']  ?></th>
                    <th style="width:30%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($deviceFaultlList as $deviceFault) : ?>
                    <tr>
                        <td class="text-center align-middle hqy-row-select"><?=$deviceFault['id'] ?></td>
                        <td >
                            <?= $deviceFault['cat_name'] ?>
                        </td>
                        <!--<td >
                            <?/*= $deviceFault['name'] */?>
                        </td>-->
                        <td><?php if ($deviceFault['id']){?>
                                <a href="javascript:void();" data-type="textarea" data-pk="<?=$deviceFault['id']?>"
                                   data-url="<?php echo Url::toRoute(['/device/fault/update-info']); ?>"
                                   data-title="修改故障名称" data-name="name" data-value="<?=$deviceFault['name']?>" class="remark">
                                    <?=$deviceFault['name']?>
                                </a>
                            <?php }?>
                        </td>
                        <!--<td >
                            <?/*=empty($deviceFault['is_common']) ? "不常见":"常见" */?>
                        </td>-->
                        <td>
                            <a href="javascript:void();"
                               data-type="select" data-pk="<?php echo $deviceFault['id']  ?>" data-url="<?php echo Url::toRoute(['/device/fault/update-info']); ?>"
                               data-title="故障是否常见修改" data-name="iscommon" data-value="<?php echo $deviceFault['is_common']  ?>" class="ajax-is-key">
                                <?=empty($deviceFault['is_common']) ? "不常见":"常见" ?>
                            </a>
                        </td>
                        <td >
                            <input type="text" name="devicefaultorder" id="sortorder_<?php echo $deviceFault['id']  ?>" data-val="<?php echo $deviceFault['id']  ?>" size="15" value="<?=empty($deviceFault['sort_order']) ? 1:$deviceFault['sort_order']; ?>" />
                        </td>
                        <td >
                            <a href="<?php echo Url::toRoute(['/device/fault/update', 'id' => $deviceFault['id']])  ?>">编辑</a> &nbsp;|&nbsp;
                            <a  onclick="confirmRedirect('<?php echo Url::toRoute(['/device/fault/delete', 'id' => $deviceFault['id']])  ?>')" title="删除" href="javascript:void(0)">删除</a> &nbsp;|&nbsp;
                            <a href="<?php echo Url::toRoute(['/device/repair/index', 'catId' => $deviceFault['device_cat_id'],'faultId'=>$deviceFault['id']])  ?>">维修方案管理</a>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php else : ?>
            <p class="text-center">
                没有找到数据
            </p>
        <?php endif; ?>
    </div>

    <div class="panel-footer">
        <div class="hqy-panel-pager">
            <?= LinkPager::widget([
                'pagination' => $pages,
            ]); ?>
            <div class="clearfix"></div>
        </div>
    </div>
</div>

<script>
    // 全部选中
    seajs.use("base/1.0.0/unit/utils/utils-1.0.0",function  (a) {
        a.hqySelectRow('brand-table', 'warning');
    })

    //关闭
    $("#batch-disable").click(function() {
        var ids = "";
        $("input[name='selection[]']").each(function() {
            if ($(this).prop("checked") == true) {
                var id = $(this).attr("value");
                ids = ids + id + ",";
            }
        });

        if (ids == "") {
            alert('请选择品牌')
            return false;
        }

        var url = "<?php echo Url::toRoute('/device/brand/batch-disable'); ?>?ids=" + ids;
        $('#url4').val(url);//给会话中的隐藏属性URL赋值
        $('#myModal4').modal();
    });

    function batchDisableSubmit(url){
        var url=$.trim($("#url4").val());//获取会话中的隐藏属性URL
        window.location.href=url;

    }

    $(document).ready(function(){
        function loadDeviceCat(){
            var pid = $("#deviceParentCat").val();
            if (pid == ""){
                $("#deviceChildCat").html("<option value=''>--请选择二级分类--</option>");
                return false;
            }
            $.ajax({
                type: "post",
                url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
                dataType:"json",
                data: $.csrf({"parentId":pid}),
                success:function(msg){
                    if (msg['status'] == 1){
                        var data = eval(msg['modelList']);
                        var html = "<option value=''>--请选择二级分类--</option>";
                        var cat_id = $("#hid_cat_id").val();
                        for(var s in data){
                            if (parseInt(cat_id) == parseInt(data[s]['id'])){
                                html = html +"<option value='"+data[s]['id']+"' selected=\"selected\">"+data[s]['name']+"</option>";
                            }else{
                                html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
                            }
                        }
                        $("#deviceChildCat").html(html);
                    }else{
                        showToast("加载失败");
                    }
                },
                error:function(msg){
                    //提示确认失败
                    showToast("加载异常");
                }
            });
        }

        loadDeviceCat();
        //获取子级分类
        $("#deviceParentCat").bind("change",function(){
            loadDeviceCat();
        });

        $("#saveOrder").click(function () {
            var updateorderstr = ""; // 更新主键
            var failflag = true; //失败标志
            $("input[name='devicefaultorder']").each(function (e) {
                var val= 1;
                if ($(this).val()!="")
                {
                    if (isNaN($(this).val())){
                        alertWaringMsg("排序提交的值应该为数字");
                        $(this).focus();
                        failflag = false;
                    }
                    val = $(this).val()
                }
                updateorderstr +=($(this).attr("data-val")+","+val+"|");
            });
            if (failflag == false){
                return false;
            }
            if (updateorderstr !="") {
                updateorderstr = updateorderstr.substring(0, updateorderstr.length - 1);
                $.ajax({
                    type: "post",
                    url: "<?=Url::toRoute("/device/fault/update-order")?>",
                    dataType: "json",
                    data: $.csrf({"updatestr": updateorderstr}),
                    success: function (msg) {
                        if (msg['status'] == 1) {
                            alertWaringMsg(msg['msg']);
                        } else {
                            alertWaringMsg(msg['msg']);
                        }
                    },
                    error: function (msg) {
                    }
                });
            }
        });
    });
    seajs.use("base/1.0.0/ui/editable/js/editable-1.0.0",function  () {
        $(document).ready(function() {
            $('.remark').editable(
                {
                    type: 'text',
                    emptytext: '请输入',
                    success: function(response, newValue) {
                        json = eval('('+response+')');
                        alertWaringMsg(json.msg);
                    }
                }
            );
            $('.ajax-is-key').editable({
                source: [
                    {value: 0, text: '不常见'},
                    {value: 1, text: '常见'}
                ],
                success: function(response, newValue) {
                    json = eval('('+response+')');
                    alertWaringMsg(json.msg);
                }
            });
        });
    });

    //显示警告信息
    function alertWaringMsg(showmsg){
        var htmltext = "<div class='alert alert-info' style='margin-bottom:0px;display:block'>" +
            "        <a href='#' class='close' data-dismiss='alert'>" +
            "            &times;" +
            "        </a>" +
            " <strong>提示!</strong>"+showmsg+"。" +
            "    </div>";
        $("#warning").html(htmltext);
        var setID= setTimeout(
            function () {
                $("#warning").html("");
            }, 2000
        );
    }
</script>

<!-- 模态框(Modal) -->
<div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel4" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">关闭</button>
                <h4 class="modal-title" id="myModalLabel4">
                    提示
                </h4>
            </div>
            <div class="modal-body">
                确定禁用所选品牌吗?
            </div>
            <div class="modal-footer">
                <input type="hidden" id="url4"/>

                <a  onclick="batchDisableSubmit()" class="btn btn-primary" data-dismiss="modal">确定</a>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>