index.php 6.29 KB
<?php
use yii\helpers\Url;
use app\ht\widgets\LinkPager;

$this->title = '回访问题设置';
$this->params['breadcrumbs'][] = '平台设置';
$this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['#']];
?>

<div class="panel panel-default">
    <div class="panel-heading">
        <a href="<?php echo Url::toRoute('/setting/repair-order-questions/create'); ?>" class="btn btn-success pull-left">添加</a>
        &nbsp;&nbsp;
        <a href="javascript:void(0)" class="btn btn-success sort-table">执行排序</a>
        <div class="clearfix"></div>
    </div>

    <div  class="panel-body">
        <?php if (!empty($dataList)) : ?>
            <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:25%;">问题</th>
                    <th style="width:15%;">类型</th>
                    <th style="width:15%;">排序</th>
                    <th style="width:15%;">添加时间</th>
                    <th style="width:35%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($dataList as $item) : ?>
                    <tr id="tr-<?= $item['id'] ?>">
                        <td class="text-center align-middle hqy-row-select"><?= $item['id'] ?></td>
                        <td >
                            <?= $item['title'] ?> <br/>
                            <?= $item['optionsStr']?>
                        </td>
                        <td >
                            <?php if ($item['type'] == 1) {echo "单选";} elseif ($item['type'] == 2) {echo "多选";} elseif ($item['type'] == 3) {echo "多行输入";} else {echo "单行输入";} ?>
                        </td>
                        <td >
                            <input style="width: 50px;" type="number" class="sort-input" value="<?= $item['sort_order'] ?>" data-id="<?= $item['id'] ?>" name="sort-<?= $item['id'] ?>" />
                        </td>
                        <td>
                            <?=Yii::$app->formatter->asTime($item['created_at'],"yyyy-MM-dd HH:mm:ss"); ?>
                        </td>
                        <td >
                            <button class="btn btn-info btn-sm btn_edit" aid="<?=$item['id'] ?>">编辑</button> &nbsp;&nbsp;
                            <?php if ($item['is_deleted'] == 1): ?>
                                <button class="btn btn-warning btn-sm btn_reset" aid="<?=$item['id'] ?>">恢复</button> &nbsp;&nbsp;
                            <?php else: ?>
                                <button class="btn btn-danger btn-sm btn_delete" aid="<?=$item['id'] ?>">删除</button> &nbsp;&nbsp;
                            <?php endif; ?>

                        </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>
    $(document).ready(function () {
        $(".btn_edit").bind("click", function () {
            location.href = "<?=Url::toRoute(['/setting/repair-order-questions/update'])?>?Id=" + $(this).attr("aid");
        });
        $(".btn_delete").bind("click", function () {
            if (confirm("你是否确认删除?")) {
                var Id = $(this).attr("aid");
                if (Id == "") {
                    alert("缺少必要参数不能被删除!");
                    return false;
                }
                $.ajax({
                    type: "post",
                    url: "do-delete",
                    dataType: "json",
                    data: $.csrf({"Id": Id}),
                    success: function (msg) {
                        alert(msg['msg']);
                        if (msg['status'] == 1) {
                            window.location.reload();
                        } else {
                            alert("删除失败");
                        }
                    }, error: function (msg) {

                    }
                });
            }
        });

        $(".btn_reset").bind("click", function () {
            if (confirm("你是否确认恢复?")) {
                var Id = $(this).attr("aid");
                if (Id == "") {
                    alert("缺少必要参数不能被删除!");
                    return false;
                }
                $.ajax({
                    type: "post",
                    url: "do-reset",
                    dataType: "json",
                    data: $.csrf({"Id": Id}),
                    success: function (msg) {
                        alert(msg['msg']);
                        if (msg['status'] == 1) {
                            window.location.reload();
                        } else {
                            alert("恢复失败");
                        }
                    }, error: function (msg) {

                    }
                });
            }
        });

        $(".sort-table").bind("click", function () {
            if (confirm("你是否执行排序?")) {
                var sort_json = {};
                $(".sort-input").each(function () {
                    id = $(this).attr('data-id');
                    val = $(this).val();
                    if (val == null || val == '')val = 0;
                    sort_json[id] = val;
                });

                $.ajax({
                    type: "post",
                    url: "do-sort",
                    dataType: "json",
                    data: sort_json,
                    success: function (msg) {
                        alert(msg['msg']);
                        if (msg['status'] == 1) {
                            window.location.reload();
                        } else {
                            alert("执行失败");
                        }
                    }, error: function (msg) {

                    }
                });
            }
        });
    });
</script>