create.php 5.78 KB
<?php

use yii\helpers\Url;


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


?>
<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"?>" />
<form action="<?php echo Url::toRoute(['/device/brand/do-add']); ?>" name="brandForm" id="brandForm" method="post" enctype="multipart/form-data">
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="form-group col-sm-12">
                <label for="skillName" class="col-sm-4 control-label text-right">分类:</label>
                <div class="col-sm-4 text-left form-inline">
                    <select class="form-control" id="deviceParentCat" name="deviceParentCat"></select>
                    <select class="form-control" id="deviceChildCat" name="deviceChildCat"></select>
                </div>
            </div>

            <div class="form-group col-sm-12">
                <label for="skillName" class="col-sm-4 control-label text-right">品牌:</label>
                <div class="col-sm-4 text-left">
                    <select class="form-control " id="brand" name="brand">
                        <option value="">--请选择品牌--</option>
                        <?php foreach ($brandList as $brand) : ?>
                            <option value="<?=$brand['id'] ?>" <?php if ($brand_id == $brand['id']){ echo "selected=\"selected\""; } ?> ><?=$brand['chinese_name'] ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="form-group col-sm-12">
                <label for="skillName" class="col-sm-4 control-label text-right">型号:</label>
                <div class="col-sm-4 text-left">
                    <input class="form-control" name="model" id="model">
                </div>
            </div>
        </div>

        <div class="panel-footer text-center">
            <button type="button" class="btn btn-primary" id="save">提&nbsp;&nbsp;交</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <a class="btn btn-default" href="<?=Url::toRoute("/device/model/create")?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
        </div>
    </div>

</form>

<script>
    $(document).ready(function(){
        $("#save").bind("click",function(){
            var deviceChildCat = $("#deviceChildCat").val();
            var brand_id = $("#brand").val();
            var model = $("#model").val();
            if (deviceChildCat == null || deviceChildCat == ""){
                alert("请选择二级分类");
                return false;
            }
            if (brand_id == null || brand_id == ""){
                alert("请选择品牌");
                return false;
            }
            if (model == null || model == ""){
                alert("请输入类型");
                return false;
            }


            $.ajax({
                type: "post",
                url: "do-add",
                dataType:"json",
                data: $.csrf({"brand_id":brand_id,"cat_id":deviceChildCat,"model":model}),
                success:function(msg){
                    alert(msg['msg']);
                    if (msg['status'] == 1){
                        location.href = "<?=Url::toRoute("/device/model/index")?>";
                    }else{
                    }
                },
                error:function(msg){
                }
            });
        });




        function loadDeviceParentCat(){
            $.ajax({
                type: "post",
                url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
                dataType:"json",
                data: $.csrf({"parentId":0}),
                success:function(msg){
                    if (msg['status'] == 1){
                        var data = eval(msg['modelList']);
                        var html = "";
                        for(var s in data){
                            html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
                        }
                        $("#deviceParentCat").html(html);

                        $("#deviceParentCat").trigger("change");
                    }else{
                        $("#deviceParentCat").html("<option value='0'>--无一级类型--</option>");
                        $("#deviceChildCat").html("<option value='0'>--无二级类型--</option>");
                    }
                },
                error:function(msg){
                }
            });
        }
        loadDeviceParentCat();


        //获取子级分类
        $("#deviceParentCat").bind("change",function(){
            var pid = $(this).val();
            $.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 = "";
                        for(var s in data){
                            html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
                        }
                        $("#deviceChildCat").html(html);

                    }else{
                    }
                },
                error:function(msg){
                }
            });
        });
        $('#brand').comboSelect();
    });
</script>