/**
 * [OElove] (C)2010-2099 oelove.com  biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/11/18 by BO $
*/
$(function () {
    function Rz() {
        this.clickIdcard();
    }
    Rz.prototype = {
      //验证身份证
      clickIdcard:function() {
          var _this = this;
          $(document).on("click", "[f='but_submit_idcard']", function(){
              _this.obj_id = $(this).attr('id');
              var truename = $("#truename").val();
              var idnumber = $("#idnumber").val();
              var paper1 = $("#img1_url").val();
              var paper2 = $("#img2_url").val();
              if (truename == '') {
                  OEUI.message.msg({
                      text: '请填写真实姓名'
                  });
                  return false;
              }
              if (idnumber == '') {
                  OEUI.message.msg({
                      text: '请填写身份证号'
                  });
              }
              if (paper1 == '') {
                  OEUI.message.msg({
                      text: '请上传身份证正面'
                  });
                  return false;
              }
              if (paper2 == '') {
                  OEUI.message.msg({
                      text: '请上传身份证反面'
                  });
                  return false;
              }
              
              var paper3 = $("#img3_url").val();
              if (typeof(paper3) == "undefined") {
                  paper3 = "";
              }
              else {
                  if (paper3 == '') {
                      OEUI.message.msg({
                          text: '请上传手持身份证'
                      });
                      return false;
                  }
              }
      
              if (!$("#"+_this.obj_id).hasClass("forbid_submit")) {
                  $("#"+_this.obj_id).addClass("forbid_submit");
                  var loading = OEUI.loading({
                      el: '#'+_this.obj_id,
                      width: 30,
                      height: 30
                  });
                  loading.show();
              
                  $.ajax({
                      type: "POST",
                      url: _this.api_url,
                      cache: false,
                      data: {
                          a:"idrz", truename:truename, idnumber:idnumber, 
                          paper1:paper1, paper2:paper2, paper3:paper3
                      },
                      dataType: "json",
                      success: function(data) {
                          var response = data.response;
                          var result = data.result;
                          if (response == '1') {
                              window.parent.OEUI.message.msg({
                                  text: '提交成功，请等待审核'
                              });
                              window.parent.idRzDialog && window.parent.idRzDialog.remove();
                          }
                          else {
                              if (result == '') {
                                  result = '提交失败，请检查';
                              }
                              OEUI.message.msg({
                                  text: result
                              });
                          }
                          $("#"+_this.obj_id).removeClass("forbid_submit");
                          loading.remove();
                      },
                      error: function() {
                          $("#"+_this.obj_id).removeClass("forbid_submit");
                          loading.remove();
                          OEUI.message.msg({
                              text: '系统繁忙，请稍后再试'
                          });
                      }
                  });
              
              }
          });
      }
    }
    new Rz();
});