index.php 10.9 KB
<?php

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


$this->title = '型号管理';
$this->params['breadcrumbs'][] = '设备管理';
$this->params['breadcrumbs'][] = ['label' => '设备列表', 'url' => ['/device/device/index']];
$this->params['breadcrumbs'][] = $this->title;

?>
<style>
    .filter-form .form-group{margin-right:15px}
</style>
<script src="<?= Yii::$app->request->baseUrl . "/exts/combo-select/js/jquery.combo.select.js"?>"></script>
<link rel="stylesheet" type="text/css" href="<?= Yii::$app->request->baseUrl . "/exts/combo-select/css/combo.select.css"?>" />
<div class="panel panel-default">
    <div class="panel-body">
        <form action="" method="get" class="filter-form form-inline">
                <div class="form-group">
                    <label for="brand">所属品牌:</label>

                        <select class="form-control" id="brand" name="brand">
                            <option value="0">--请选择品牌--</option>
                            <?php foreach ($brandList as $brand) : ?>
                                <option value="<?=$brand['id'] ?>" <?php if (intval($gets['brandId']) == intval($brand['id'])){ echo  "selected=\"selected\"";} ?> ><?=$brand['chinese_name'] . '(' . $brand['english_name'] . ')' ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                <div class="form-group">
                    <label for="catGroup">所属设备类型:</label>
                    <div id="catGroup" class="form-control" style="border:0;padding:0;">
                        <select class="form-control" id="deviceParentCat" name="deviceParentCat"><option value="0">--请选择分类--</option></select>&nbsp;&nbsp;
                        <select class="form-control" id="deviceChildCat" name="deviceChildCat"><option value="0">--请选择二级分类--</option></select>
                        </div>
                </div>

                 <div class="form-group">
                        <label for="model_id">型号名称</label>
                        <input id="model_id" type="text" class="form-control" name="title" value="<?=$gets['title']?>" />
                </div>

                <div class="form-group">
                    <div style="width:100%;">
                        <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/model/index")?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
                        <input type="hidden" value="<?=$gets['cateId'] ?>" id="hiddenCateId">
                        <input type="hidden" value="<?=$gets['catePid'] ?>" id="hiddenCatePid">
                    </div>
                </div>
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <a href="<?php echo Url::toRoute('/device/model/create'); ?>" class="btn btn-success pull-left">添加型号</a>&nbsp;
        <a href="<?php echo Url::toRoute('/device/model/batch-create'); ?>" class="btn btn-success">批量添加型号</a>&nbsp;
        <a href="<?php echo Url::toRoute('/device/model/combine'); ?>" class="btn btn-danger">合并型号</a>
        <div class="clearfix"></div>
    </div>

    <div  class="panel-body">
        <?php if (!empty($modelList)) : ?>
            <table class="table table-striped table-bordered"  id="brand-table">
                <thead>
                <tr>
                    <th style="width:5%;" class="text-center align-middle hqy-all-select">ID</th>
                    <th style="width:20%;">型号名称</th>
                    <th style="width:20%;">所属品牌</th>
                    <th style="width:20%;">所属设备分类</th>
                    <th style="width:35%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($modelList as $model) : ?>
                    <tr>
                        <td class="text-center align-middle hqy-row-select"><?= $model['id'] ?></td>
                        <td >
                            <?= $model['model'] ?>
                        </td>
                        <td >
                            <?= $model['chinese_name'] ?>
                        </td>
                        <td >
                            <?= $model['cat_name'] ?>
                        </td>
                        <td >
                            <a href="<?php echo Url::toRoute(['/device/model/update', 'id' => $model['id'],"info"=>$model['chinese_name']."-".$model['model']])  ?>">编辑</a> &nbsp;|&nbsp;
                            <a  onclick="confirmRedirect('<?php echo Url::toRoute(['/device/model/delete', 'id' => $model['id']])  ?>')" title="删除" href="javascript:void(0)">删除</a>&nbsp;|&nbsp;
                            <a href="<?php echo Url::toRoute(['/device/fault/faultset', 'mid' => $model['id'],'title'=>$model['chinese_name'].'-'.$model['cat_name'].'-'.$model['model'] ])  ?>">故障设置</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(){
        $('#brand').comboSelect().bind("change", function () {
            var brandId = $(this).val();
            if (brandId == 0){
                return false;
            }
            $("#hiddenBrand").val(brandId);
            $.ajax({
                type: "post",
                url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
                dataType:"json",
                data: $.csrf({"brandId":brandId,"parentId":0}),
                success:function(msg){
                    if (msg['status'] == 1){
                        var data = eval(msg['modelList']);
                        var html = "<option value='0'>--请选择分类--</option>";
                        var hiddenCatePid = $("#hiddenCatePid").val();
                        for(var s in data){
                            if (hiddenCatePid != null && hiddenCatePid != "" && parseInt(hiddenCatePid) == 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>";
                            }

                        }
                        $("#deviceParentCat").html(html);
                        $("#deviceParentCat").trigger("change");
                    }else{
                        //提示确认失败
                        showToast("加载失败");
                    }
                },
                error:function(msg){
                    //提示确认失败
                    showToast("加载异常");
                }
            });

        });

        //获取子级分类
        $("#deviceParentCat").bind("change",function(){
            var pid = $(this).val();
            var brandId = $("#hiddenBrand").val();
            $.ajax({
                type: "post",
                url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
                dataType:"json",
                data: $.csrf({"brandId":brandId,"parentId":pid}),
                success:function(msg){
                    if (msg['status'] == 1){
                        var data = eval(msg['modelList']);
                        var html = "<option value='0'>--请选择二级分类--</option>";
                        var hiddenCataId = $("#hiddenCateId").val();
                        for(var s in data){
                            if (hiddenCataId != null && hiddenCataId != "" && parseInt(hiddenCataId) == 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("加载异常");
                }
            });
        });


        var brand = $("#brand").val();
        if (brand != null && brand != ""){
            //var hiddenCataId = $("#hiddenCateId").val();
            //if (hiddenCataId != 0){
                $("#brand").trigger("change");
            //}

        }
    });
</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>