repair_plan_set.php 9.25 KB
<?php

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

$this->title = '维修方案设置';
$this->params['breadcrumbs'][] = '设备管理';
$this->params['breadcrumbs'][] = ['label' => '故障设置', 'url' => ['/device/fault/faultset?type=0&mid='.$gets['model_id']."&title=".$gets['info']]];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="panel panel-default">
    <div class="panel-heading bg-success">
        <?=$gets['info'] ?> &nbsp;&nbsp;>&nbsp;&nbsp;<?=$fault['name'] ?>
    </div>
    <div class="panel-heading">
        <?php if ($gets['type'] == 1): ?>
            <a class="btn btn-danger pull-left" id="batch_del">批量删除</a>
        <?php else: ?>
            <a class="btn btn-success pull-left" id="batch_add">批量添加</a>
        <?php endif; ?>
        <input type="hidden" value="<?=$gets['model_id'] ?>" id="model_id">
        <input type="hidden" value="<?=$gets['fault_id'] ?>" id="fault_id">
        <div class="clearfix"></div>
    </div>

    <div  class="panel-body">
        <ul id="countryTab" class="nav nav-tabs" style="margin-bottom: 20px">
            <li <?php if ($gets['type'] == 1){ echo "class=\"active\"" ;} ?> ><a href="<?=Url::toRoute(['/device/fault/repair-plan-set', 'type' =>1, 'modelDeviceFaultId'=> $gets['modelDeviceFaultId']])?>" >已添加维修方案</a></li>
            <li <?php if ($gets['type'] == 2){ echo "class=\"active\"" ;} ?> ><a href="<?=Url::toRoute(['/device/fault/repair-plan-set', 'type'=>2, 'modelDeviceFaultId'=> $gets['modelDeviceFaultId']])?>" >未添加维修方案</a></li>
        </ul>

        <?php if (!empty($list)) : ?>
            <table class="table table-striped table-bordered"  id="brand-table">
                <thead>
                <tr>
                    <th style="width:5%;" class="text-center align-middle hqy-all-select"><input type="checkbox" class="select-on-check-all" name="selection_all" value="1"></th>
                    <th style="width:50%;">方案名称</th>
                    <th style="width:20%;">故障原因</th>
                    <th style="width:25%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php if ($gets['type'] == 1): ?>
                    <?php foreach ($list as $p) : ?>
                        <tr>
                            <td class="text-center align-middle hqy-row-select"><input type="checkbox" name="selection[]" value="<?=$p['model_price_id'] ?>"></td>
                            <td ><?=$p['name'] ?></td>
                            <td ><?=$p['reason'] ?></td>
                            <td >
                                <button class="btn btn-danger btn_fault_models_replan_del" model_price_id="<?=$p['model_price_id'] ?>" >删除</button> &nbsp;&nbsp;
                                <button class="btn btn-primary btn_repair_plan_setting" model_price_id="<?=$p['model_price_id'] ?>">设置价格</button>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <?php foreach ($list as $p) : ?>
                        <tr >
                            <td class="text-center align-middle hqy-row-select"><input type="checkbox" name="selection[]" value="<?=$p['id'] ?>"></td>
                            <td ><?=$p['name'] ?></td>
                            <td ><?=$p['reason'] ?></td>
                            <td >
                                <button class="btn btn-success btn_fault_models_replan_add" repair_plan_id="<?=$p['id'] ?>"  model_id="<?=$p['model_id'] ?>" >添加</button>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
                </tbody>
            </table>
        <?php else : ?>
            <p class="text-center">
                没有找到数据
            </p>
        <?php endif; ?>
    </div>

    <div class="panel-footer">
        <div class="hqy-panel-pager">

            <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_del").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/fault/fault-repair-plan-del'); ?>";
        $('#url4').val(url);//给会话中的隐藏属性URL赋值
        $('#ids').val(ids);
        $('#modal_content').text("确定要删除吗?");
        $('#myModal4').modal();
    });

    //添加
    $("#batch_add").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/fault/fault-repair-plan-add'); ?>";
        $('#url4').val(url);//给会话中的隐藏属性URL赋值
        $('#ids').val(ids);
        $('#modal_content').text("确定要添加吗?");
        $('#myModal4').modal();
    });

    function batchDisableSubmit(){
        var url=$.trim($("#url4").val());//获取会话中的隐藏属性URL
        var model_id = $("#model_id").val();
        var ids = $.trim($("#ids").val());
        ids = ids.length > 0 ? ids.substring(0,(ids.length-1)):ids;
        $.ajax({
            type: "post",
            url: url,
            dataType:"json",
            data: $.csrf({"ids":ids,"model_id":model_id}),
            success:function(msg){
                alert(msg['msg']);
                if (msg['status'] == 1){
                    location.reload();
                }else{
                }
            },
            error:function(msg){
            }
        });
    }

    $(document).ready(function () {
        //添加维修方案报价
        $(".btn_fault_models_replan_add").bind("click",function(){
            var repair_plan_id = $(this).attr("repair_plan_id");
            var model_id = $(this).attr("model_id");
            var thiz = $(this);
            $.ajax({
                type: "post",
                url: "fault-repair-plan-add",
                dataType:"json",
                data: $.csrf({"ids":repair_plan_id,"model_id":model_id}),
                success:function(msg){
                    alert(msg['msg']);
                    if (msg['status'] == 1){
                        thiz.parents('tr').remove();
                    }else{
                    }
                },
                error:function(msg){
                }
            });
        });

        //执行删除维修方案报价
        $(".btn_fault_models_replan_del").bind("click",function(){
            var model_price_id = $(this).attr("model_price_id");
            //var model_id = $(this).attr("model_id");
            if (model_price_id == null || model_price_id == ""){
                alert("删除失败,请刷新后再试");
                return false;
            }
            var thiz = $(this);
            if (confirm("你确定要删除此维修方案吗?")){
                $.ajax({
                    type: "post",
                    url: "fault-repair-plan-del",
                    dataType:"json",
                    data: $.csrf({"ids":model_price_id}),
                    success:function(msg){
                        alert(msg['msg']);
                        if (msg['status'] == 1){
                            thiz.parents('tr').remove();
                        }else{
                        }
                    },
                    error:function(msg){
                    }
                });
            }

        });

        //跳转到定价页面
        $(".btn_repair_plan_setting").bind("click",function () {
            location.href = "./repair-plan-price-set?modelsRepairPlanPricesId="+$(this).attr("model_price_id");
        });
    });


</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" id="modal_content">

            </div>
            <div class="modal-footer">
                <input type="hidden" id="url4"/>
                <input type="hidden" id="ids"/>
                <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>