{% load staticfiles %}

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="format-detection" content="telephone=no,email=no,address=no">
        <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
        <title>摄影师授权</title>

        <link href="//res.wx.qq.com/open/libs/weui/0.4.3/weui.min.css" rel="stylesheet" type="text/css" />

        <style>
            input:required:invalid {
                color: #E64340;
            }
            input:required:valid {
                color: rgb(0, 0, 0);
            }
        </style>
    </head>
    <body>
        <div class="container" >
            <div class="weui_cells_title">基本信息</div>
            <div class="weui_cells weui_cells_form">
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label for="" class="weui_label">姓名</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input id="name" class="weui_input" type="text" value="{{ lensman_info.name }}" placeholder="请输入姓名" {% if not modified %}disabled{% endif %}>
                    </div>
                </div>
                <div class="weui_cell weui_cell_select weui_select_after">
                    <div class="weui_cell_hd"><label for="" class="weui_label">性别</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <select id="sex" class="weui_select" name="select" {% if not modified %}disabled{% endif %}>
                            <option value="1" {% ifequal lensman_info.sex 1 %}selected{% endifequal %}>男</option>
                            <option value="0" {% ifequal lensman_info.sex 0 %}selected{% endifequal %}>女</option>
                        </select>
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label for="" class="weui_label">手机号</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input id="phone" class="weui_input" type="text" required="required" pattern="[0-9]{11}" value="{{ lensman_info.phone }}" placeholder="请输入手机号" {% if not modified %}disabled{% endif %}>
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label for="" class="weui_label">地址</label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input id="location" class="weui_input" type="text" value="{{ lensman_info.location }}" placeholder="请输入地址" {% if not modified %}disabled{% endif %}>
                    </div>
                </div>
            </div>

            {% if lensman_info %}
            <div class="weui_cells_title">审核状态</div>
            <div class="weui_cells">
                <div class="weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        <p>状态</p>
                    </div>
                    <div class="weui_cell_ft">
                        {% ifequal lensman_info.status -1 %}已拒绝{% endifequal %}
                        {% ifequal lensman_info.status 0 %}审核中{% endifequal %}
                        {% ifequal lensman_info.status 1 %}已激活{% endifequal %}
                        {% ifequal lensman_info.status 2 %}已禁用{% endifequal %}
                        {% ifequal lensman_info.status 3 %}已删除{% endifequal %}
                    </div>
                </div>
            </div>
            {% endif %}


            {% ifequal lensman_info.status -1 %}
            <div class="weui_cells_title">拒绝原因</div>
            <div class="weui_cells">
                <div class="weui_panel_bd">
                    <div class="weui_media_box weui_media_text">
                        <p class="weui_media_desc">{{ lensman_info.refused_reason|safe|linebreaks }}</p>
                    </div>
                </div>
            </div>
            {% endifequal %}

            <br>

            {% if modified %}<button id="submit" class="weui_btn weui_btn_warn">确认</button>{% endif %}

            <div class="weui_dialog_alert" id="dialog" style="display: none">
                <div class="weui_mask"></div>
                <div class="weui_dialog">
                    <div class="weui_dialog_hd"><strong id="title" class="weui_dialog_title">弹窗标题</strong></div>
                    <div id="content" class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
                    <div class="weui_dialog_ft">
                        <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
                    </div>
                </div>
            </div>

            <div id="toast" style="display: none;">
                <div class="weui_mask_transparent"></div>
                <div class="weui_toast">
                    <i class="weui_icon_toast"></i>
                    <p class="weui_toast_content">已完成</p>
                </div>
            </div>
        </div>

        <script src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
        <script>
            {% if modified %}
            $(function() {
                function getURLParameter(name) {
                  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
                }

                function show_error_dialog(title, content) {
                    $('#dialog #title').text(title);
                    $('#dialog #content').text(content);
                    $('#dialog').show();
                }

                function data_check() {
                    var unionid = getURLParameter('unionid');
                    if (!unionid) {
                        show_error_dialog('微信授权', '微信授权失败，请重新打开页面');
                        return false;
                    }

                    var name = $('#name').val();
                    if (!name) {
                        show_error_dialog('姓名', '姓名错误，请检查重新输入');
                        return false;
                    }

                    var phone_valid = $('#phone').is(':valid');
                    if (!phone_valid) {
                        show_error_dialog('手机号', '手机号错误，请检查重新输入');
                        return false;
                    }

                    var location = $('#location').val();
                    if (!location) {
                        show_error_dialog('地址', '地址错误，请检查重新输入');
                        return false;
                    }

                    return {
                        lensman_type: '{{ lensman_type }}',
                        unionid: unionid,
                        openid: getURLParameter('openid'),
                        name: name,
                        sex: $('#sex option:checked').val(),
                        phone: $('#phone').val(),
                        location: location,
                    }
                }

                $('#submit').click(function () {
                    var check_result = data_check();
                    if (check_result){
                        $.ajax({
                            type: 'POST',
                            url: 'l/submit',
                            data: check_result,
                            success: function(data) {
                                if (data.status == 200) {
                                    $('#toast').show();
                                    setTimeout(function () {
                                        $('#toast').hide();
                                    }, 1000);
                                    window.location.reload();
                                } else {
                                    show_error_dialog('错误', data.description);
                                }
                            }
                        })
                    }
                });

                $('#dialog .weui_btn_dialog').click(function () {
                    $('#dialog').hide();
                })
            });
            {% endif %}
        </script>
        <script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
        <script type="text/javascript" src="{% static 'pai2/js/jswe-0.0.4.js' %}"></script>
        <script>
            V.initWxData({
                imgUrl: "http://pai.ai/static/pai2/img/paiai_96_96.png",
                link: 'http://pai.ai/w/o?r=http%3A%2F%2Fpai.ai%2Fp%2Flensman',
                desc: "摄影师授权",
                title: "摄影师授权",
                timeLine: ""
            }, true);
            V.hideOptionMenu();
        </script>
    </body>
</html>