<extend name="Public/manage" />
<block name="head">
    <link href="__CSS__/pagination.css" rel="stylesheet">
    <link href="__CSS__/icon.css" rel="stylesheet">
    <link href="__CSS__/user_zxy.css" rel="stylesheet">
    <script src="__JS__/bootstrap-select.min.js"></script>
    <script src="__JS__/VMenu.js"></script>
    <script src="__JS__/zh-cn.js"></script>
    <script src="__JS__/echarts-all.js"></script>
    <script src="__JS__/chart.js"></script>
    <script src="__JS__/jquery.tablesorter.js"></script>
    <script src="__JS__/string.js"></script>
    <script src="__JS__/pagination.js"></script>
    <script src="__JS__/datacommon.js"></script>
    <script src="__JS__/retain.js"></script>
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<script type="text/javascript" src="__ADDONS__/UploadImages.js"></script>
	<link rel="stylesheet" href="__ADDONS__/UploadImages.css">
	<style>
		.mrc_colum_ml {margin-left: 122px;}
	</style>
</block>
<block name="location">
	<a class="z_nav" href="{:U('Apply/company')}">账号中心</a>
	<a class="z_nav curt_nav" href="{:U('Apply/company')}">基本信息</a>
</block>
<block name="body" >
        <div class="matter_right_content">
		<notempty name="data.status">
            <div class="title" style="margin-bottom: 20px;">
                <style>.form-group{margin-bottom:0;}</style>
                <span style="display: block;width: 100%;text-align: center;font-size: 16px;color: {$data['status'] == 1 ? 'green' : 'red'}">
                <switch name="data.status">
                    <case value="-1">您的认证信息已经提交平台审核,我们会在3个工作日内完成审核请耐心等待...</case>
                    <case value="1">您的认证信息已通过平台审核,现在可以进入管理中心<a href="{:U('Game/add')}" style="color:#5A90EE;text-decoration: underline;">创建游戏</a>啦!</case>
                    <case value="3">很抱歉的通知您,您的认证信息未通过审核,请修改后重新提交,如有疑问请联系我们。</case>
                </switch>
                </span>
            </div>
		</notempty>
            <form id="editForm" action="{:U('Apply/company')}" class="form-horizontal" method="post" novalidate="novalidate">

                <empty name="data.nature">
                    <div class="form-group clearfix">
                        <label class="mrc_left mrc control-label"><span class="must_red">*</span> 开发者类型</label>
                        <div class="mrc_right4_3_3 mrc input-format" style="margin-top: 8px">
							<label class="nature custom_lable" >
								<input class="form_control" type="radio" name="nature" placeholder="请填写开发者名称" value="1" checked="checked">
								<i class="lable_icon"></i>
								<span class="lable_text">公司</span>
							</label>
							<label class="nature custom_lable" >
								<input class="form_control" type="radio" name="nature" placeholder="请填写开发者名称" value="2" >
								<i class="lable_icon"></i>
								<span class="lable_text">个人</span>
							</label>
							<span style="color: #999;">(开发者类型一经填写不可修改)</span>
                            <div class="show-form-info" style="margin: -8px 1px 0px -5px">
                                <eq name="data.nature" value="1">公司</eq>
                                <eq name="data.nature" value="2">个人</eq>
                            </div>
                        </div>



                        <div class="clearfix"></div>
                        <div class="mrc_colum_ml input-status"></div>
                    </div>
                    <else />
                    <div class="form-group clearfix ">
                        <label class="mrc_left mrc control-label"><span class="must_red">*</span> 开发者类型</label>
                        <div class="mrc_right4_3_3 mrc input-format" style="margin-top: 8px">
                            <div class="show-form-info" style="margin: -8px 1px 0px -5px">
                                <eq name="data.nature" value="1">公司</eq>
                                <eq name="data.nature" value="2">个人</eq>
								<span style="color: #999;">(开发者类型一经填写不可修改)</span>
                            </div>
                        </div>



                        <div class="clearfix"></div>
                        <div class="mrc_colum_ml input-status"></div>
                    </div>
                </empty>
                <div class="form-group clearfix">
					<label class="mrc_left mrc control-label"><span class="must_red">*</span>开发者名称</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " style="display: block;" name="nickname" placeholder="请填写开发者名称" value="{$data.nickname}" >

                    </div>
                    <div class="show-form-info">{$data.nickname}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 公司名称</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " name="corporate_name" placeholder="请填写公司与营业执照上一致" value="{$data.corporate_name}" >
                    </div>
                    <div class="show-form-info">{$data.corporate_name}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 公司地址</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " name="address" placeholder="请填写公司地址" value="{$data.address}" >

                    </div>
                    <div class="show-form-info">{$data.address}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>

                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 营业执照注册号</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " name="identity" placeholder="请填写营业执照注册号" value="{$data.identity}" >

                    </div>
                    <div class="show-form-info">{$data.identity}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 资质证明</label>
                    <div class="mrc_right2_2 mrc input-format">

                      <div class="upload-img-box"> 
							<notempty name="data.prove_img">
                                <img id="prove_img upload-pre-item" src="{:get_cover($data['prove_img'],'path')}" data-id="{$data['prove_img']}" class="imgDiff upload-pre-item">
								<span class="btn-close btn-close-prove_img hide" title="删除图片"></span>
                                <else />
                                <img id="prove_img upload-pre-item" src='__IMG__/default.png' class="imgDiff upload-pre-item">
                            </notempty>
                        </div>
						 <input type="file" id="upload_picture_prove" class="user_file">
                        <input type="hidden" name="prove_img" value="{$data.prove_img}" class="form-control " id="cover_id_prove_img" />
						
                        <p class="imgTips " style="margin-top: 10px">
                            <span>请上传营业执照(或三证合一)扫描件,文件大小不超过2M,仅限 .jpg 或 .jpeg 或 .png 格式</span>
                        </p>
                    </div>
                    <div class="zwm_example">示例图</div>
                    <div class="mrc_right2_2 mrc sample_graph clearfix ">
                        <a href="__IMG__/default_card_yy.png" target="_blank">
                            <img  src="__IMG__/default_dever_yy.png" class="imgDiff">
                        </a>
                    </div>
										<div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                
                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 联系人</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " name="link_man" placeholder="请填写联系人" value="{$data.link_man}" >

                    </div>
                    <div class="show-form-info">{$data.link_man}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 联系电话</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " name="mobile_phone" placeholder="请填写联系电话" value="{$data.mobile_phone}" >

                    </div>
                    <div class="show-form-info">{$data.mobile_phone}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label"><span class="must_red">*</span> 邮箱</label>
                    <div class="mrc_right4_3_3 mrc input-format">
                        <input type="text" class="form-control " name="email" placeholder="请填写邮箱" value="{$data.email}" >

                    </div>
                    <div class="show-form-info">{$data.email}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">
                    <label class="mrc_left mrc control-label">QQ号</label>
                    <div class="mrc_right4_3_3 mrc noLeft input-format">
                        <input type="text" class="form-control " name="qq" placeholder="请填写QQ号" value="{$data.qq}" >

                    </div>
                    <div class="show-form-info">{$data.qq}</div>
                    <div class="clearfix"></div>
                    <div class="mrc_colum_ml input-status"></div>
                </div>
                <div class="form-group clearfix">
                    <div class="mrc_colum_ml mrc_colum4_1_6 mrc btn_case">
                        <input type="hidden" name="nature" value="1" >
                        <input type="submit" class="btn btn_primary user_btn " id="saveButton" value="保存" >
                        <input type="button" class="btn btn_primary user_btn hidden" id="editButton" value="编辑" >
                        &nbsp;&nbsp;<a id="cancelEdit" href="#" class="btn btn_default hidden">取消</a>
                    </div>
                </div>
            </form>

        </div>
       <in name="data.status" value="-1,1">
			<script>
				 $(".btn_case").hide();
			</script>
		</in>
        <script>
            var dever_from = "";

            $(document).ready(function(){
			
			//删除图片
$('.btn-close-prove_img').click(function(event) {
    event.preventDefault();
    $(this).parent().html('<img id="prove_img upload-pre-item" src="__IMG__/default.png" class="imgDiff upload-pre-item">');
							
    picsbox = $("#upload_picture_prove_img").siblings('.upload-img-box');
    picArr = [];
    for (var i = 0; i < picsbox.children().length ; i++) {
        picArr.push(picsbox.children('.upload-pre-item:eq('+i+')').find('img').attr('data-id'));
    };

    //console.log(picStr);
    var picStr = picArr.join(',');
		if($.trim(picStr.replace(',','')).length<1) {
			$('#cover_id_prove_img').closest('.input-format').siblings('.input-status').html('<small id="cover_id_prove_img-error" class="error">资质证明不能为空</small>');
		}
    $('#cover_id_prove_img').val(picStr);
});
             

                //上传图片
                /* 初始化上传插件 */
                $("#upload_picture_prove").uploadify({
					"height"          : 22,
                    "swf"             : "__STATIC__/uploadify/uploadify.swf",
                    "fileObjName"     : "download",
                    "buttonText"      : "上传图标",
                    "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                    "width"           : 65,
					'buttonClass'     : 'user_file',
                    'removeTimeout'   : 1,
                    'fileTypeExts'    : '*.jpg; *.jpeg; *.png;',
                    "onUploadSuccess" : upload_picture_prove,
                'onFallback' : function() {
                    alert('未检测到兼容版本的Flash.');
                }
            });
                 function upload_picture_prove(file, data){
                    var data = $.parseJSON(data);
                    var src = '';
                    if(data.status){
                        $("#cover_id_prove_img").val(data.id);
                        src = data.url || '__ROOT__' + data.path;
                        $("#cover_id_prove_img").parent().find('.upload-img-box').html(
                            '<img style="width: 210px;height: 310px" src="' + src + '"/><span class="btn-close btn-close-prove_img" title="删除图片"></span>'
                        );
						$('#cover_id_prove_img').closest('.input-format').siblings('.input-status').html('');
						
						$('.btn-close-prove_img').click(function (event) {
							event.preventDefault();
							$(this).parent().html('<img id="prove_img upload-pre-item" src="__IMG__/default.png" class="imgDiff upload-pre-item">');
							picsbox = $("#upload_picture_prove_img").siblings('.upload-img-box');
							picArr = [];
							for (var i = 0; i < picsbox.children().length; i++) {
								picArr.push(picsbox.children('.upload-pre-item:eq(' + i + ')').find('img').attr('data-id'));
							}
							;
							
							picStr = picArr.join(',');
							if($.trim(picStr.replace(',','')).length<1) {
								$('#cover_id_prove_img').closest('.input-format').siblings('.input-status').html('<small id="cover_id_prove_img-error" class="error">资质证明不能为空</small>');
							}
							$('#cover_id_prove_img').val(picStr);
						});
						
						
						
                    } else {
                        alert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        },1500);
                    }
                }

                /**
                 * 新增验证方法
                 */

                $.validator.addMethod("checkmobile_phone", function(value, element) {
                    var mobile_phone = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
                    var tel = /^\d{3,4}-?\d{7,9}$/;
                    return mobile_phone.test(value)||tel.test(value);
                }, '联系电话格式不正确。手机参考格式:13666668888。座机参考格式: 010-66668888。');
                $.validator.addMethod("checkL", function(value, element) {
                    if(value.length!=18){
                        return false;
                    }else{return true;}
                }, '营业执照注册号格式不正确');
                $.validator.addMethod("checkEmail", function(value, element){
                    var email = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+(\.[a-zA-Z]{2,3})+$/;
                    return email.test(value);
                }, "邮箱不合法!");

            $.validator.addMethod("checkQQWechat", function(value, element){
                var qq = $("input[name='qq']").val();
                var wechat = $("input[name='wx']").val();

                if(qq == "" && wechat == ""){
                    return false;
                }else{
                    return true;
                }
            }, "QQ和微信请至少填写一项!");


            $("#editButton").click(function(event){
                event.preventDefault();
                $("input").prop("readonly", false);
                $(".hide").removeClass("hide");
                $(".show-form-info").addClass("hide");
                $("select").prop("disabled", false);
                $("input[type='radio']").parent("label").removeClass("disabled");
                $("#cancelEdit").removeClass("hidden").show();
                $("#saveButton").removeClass("hidden").show();
                $("#editButton").hide();
                $(".user_file").removeClass("hidden").show();

                $('#ADDTOPICBLB').addClass('hide');
                $('.uploadify').removeClass("hidden").show();
                $(".nature_show").addClass("show");
            });


            // 取消修改
            $("#cancelEdit").click(function(event){
                $("input").prop("readonly", true);
                $("select").prop("disabled", true);
                $(".form-control").addClass("hide");
                $(".show-form-info").removeClass("hide");
                $("#re_dever_bank_account").addClass("hide");
                //$("#editButton").val("修改信息");
                $("#editButton").removeClass("hidden").show();
                $("#saveButton").addClass("hidden").hide();
                $(this).hide();
                $("small").remove();
                event.preventDefault();
                $(".nature").addClass("hide");
                $('.uploadify').addClass('hide');
            });

                //定义规则
                formValidate = {
                    ignore:[],
                    rules: {
					    nickname: {
                            required: true,
                        },
                        firstname: "required",
                        corporate_name: {
                            required: true
                        },
                        codenum: {
                            required: false//dever_from != 'TOPICBLB' ? true : false  //专题 公司信息 不必填
                        },
                        identity: {
                            required: dever_from != 'TOPICBLB' ? true : false,
                            checkL:true
                        },
                        link_man: {
                            required: true
                        },
                        mobile_phone: {
                            required: true,
                            checkmobile_phone: true
                        },
                        email: {
                            required: true,
                            checkEmail: true
                        },
                        address: {
                            required: true,
                        },
                        qq: {
                            checkQQWechat: true,
                        },
                        nickname: {
                            required: true,
                        },
                        prove_img: {
                            required: true,
                        },
                    },
                    //定义错误消息
                    messages: {
                        corporate_name: {
                            required: "公司名称不能为空"
                        },
                        codenum: {
                            required: "组织机构代码不能为空"
                        },
                        identity: {
                            required: "营业执照注册号不能为空",
                            checkL:"营业执照注册号格式不正确",
                        },
                        link_man: {
                            required: "联系人不能为空"
                        },
                        mobile_phone: {
                            required: "联系电话不能为空",
                        },
                        email: {
                            required: "邮箱不能为空",
                            checkEmail: '邮箱格式不对'
                        },
                        address: {
                            required: "公司地址不能为空",
                        },
                        nickname: {
                            required: "开发者名称不能为空",
                        },
                        prove_img: {
                            required: "资质证明不能为空",
                        },
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit({
													type:'post',
													url:"{:U('Apply/company')}",
													data:$("#editForm").serializeArray(),
													success:function(result) {
														layer.msg(result.info,{time:2000},function(){
																location.href="{:U('Apply/apply')}";
														})
													},
													error : function(xhr, status, err) {			
														layer.msg("服务器有误,请稍后再试");
													}
												});
											return false;
                    },
                }

                // 表单验证
                $("#editForm").validate(formValidate);
                <empty name="data">
                    $("#editButton").click();
                <else />
                $("#cancelEdit").click();
                </empty>

            });

            $("input[name='nature']").change(function () {
                var val = $(this).val();
                if(val == 1){
                    location.href = "{:U('Apply/company')}";
                }else{
                    location.href = "{:U('Apply/personal')}";
                }
            });


            $.VMenu.show('#menu');
            $.VMenu.open('m1.1');
        </script>
    </body>
</block>