<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=360, user-scalable=0"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title></title>
    <style></style>
    <link rel="stylesheet" href="{{ theme }}/css/bootstrap.min.css">
    <link rel="stylesheet" href="{{ theme }}/css/star-rating.min.css">
    <script src="{{ theme }}/js/jquery.min.js"></script>
    <script src="{{ theme }}/js/star-rating.min.js"></script>
    <script>
        $(document).ready(function () {
            var score = 0;
            $('#score').rating({
                min: 0,
                max: 5,
                step: 0.5,
                size: 'xs',
                showClear: false,
                showCaption: false,
                hoverEnabled: false,
                starCaptions: function (data) {
                    console.log(data);
                    score = data;
                    $(this).val(score);
                }
            });
            var scoreForm = $('#scoreForm');
            scoreForm.submit(function () {
                if (score > 0) {
                    $.ajax({
                        type: 'POST',
                        url: '{{ url }}/wp-admin/admin-ajax.php/',
                        data: 'action=add_score&' + scoreForm.serialize(),
                        success: function (data) {
                            if (data.code == 2000) {
                                alert('评分成功');
                            }else{
                                alert('不能重复评分');
                            }
                        }
                    });
                } else {
                    alert('请选择评分');
                }
                return false;
            });
        });
    </script>
</head>
<body>
<form id="scoreForm" method="post">
    <br>
    <label for="score">评分</label>
    <input type="hidden" id="score" name="score" value="0">
    <input type="hidden" name="user_id" value="{{ user_id }}">
    <input type="hidden" name="consultant_id" value="{{ consultant_id }}">
    <br>

    <p class="submit">
        <input type="submit" id="score_submit" value="提交">
    </p>
</form>
</body>
</html>