combine.php 4.44 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;


?>

<div class="panel panel-default">
    <div id="warning"></div>
    <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">
                <input type="text" class="form-control" name="needbindmodel" id="needbindmodel"/>
            </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 type="text" class="form-control" name="bindtomodel" id="bindtomodel"/>
            </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/combine")?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
    </div>
</div>

<script type="text/javascript" src="<?=Url::toRoute('/exts/base/1.0.0/ui/typeahead/bootstrap3-typeahead.min.js')?>" ></script>
<script>
    var searchItemUrl = "<?=Url::toRoute('/device/model/search-model')?>";
   $(document).ready(function(){
       $("#save").bind("click",function(){
           var needbindmodel = $("#needbindmodel").val();
           var bindtomodel = $("#bindtomodel").val();

           if (needbindmodel == ""){
               alertWaringMsg("请填写需要合并的设备型号");
               $("#needbindmodel").focus();
               return false;
           }
           if (bindtomodel == ""){
               alertWaringMsg("请填写合并到的设备型号");
               $("#bindtomodel").focus();
               return false;
           }
           if (needbindmodel == bindtomodel){
               alertWaringMsg("需要合并设备型号和合并到的设备型号不能相同");
               $("#bindtomodel").focus();
               return false;
           }
           $.ajax({
               type: "post",
               url: "<?=Url::toRoute("/device/model/do-combine")?>",
               dataType:"json",
               data: $.csrf({"needbindmodel":needbindmodel,"bindtomodel":bindtomodel}),
               success:function(msg){
                   alert(msg['msg']);
                   if (msg['status'] == 1){
                       location.href="<?php echo Url::toRoute('/device/model/index'); ?>";
                   }
               },
               error:function(msg){
               }
           });
       });
       $('#needbindmodel,#bindtomodel').typeahead({
           minLength: 2,
           source: function(query, process) {
               var parameter = {query: query};
               $.post(searchItemUrl, parameter, function (res) {
                   var data = [];
                   var iList = res.list;
                   for(i in iList){
                       var tItem = iList[i];
                       data.push(JSON.stringify(tItem));
                   }
                   process(data);
               },'json');
           },
           highlighter: function(item) {
               var itemObject = JSON.parse(item);
               var title = itemObject.model;
               return  title ;
           },
           updater: function(item) {
               var itemObject = JSON.parse(item);
               var title = itemObject.model;
               selectItemInfo(itemObject);
               return title;
           }
       });
       function selectItemInfo(item){
           $('#deviceParentCat').val(item.model);
       }
       //显示警告信息
       function alertWaringMsg(showmsg){
           var htmltext = "<div class='alert alert-warning' style='margin-bottom:0px;display:block" +
               "'>" +
               "        <a href='#' class='close' data-dismiss='alert'>" +
               "            &times;" +
               "        </a>" +
               " <strong>提示!</strong>"+showmsg+"。" +
               "    </div>";
           $("#warning").html(htmltext);
       }
   });
</script>