
layui.use(['form', 'layer', 'jquery', 'laydate'], function () {
  var form = layui.form,
    layer = parent.layer === undefined ? layui.layer : parent.layer,
    $ = layui.jquery,
    laydate = layui.laydate;

  //监听提交
  form.on('submit(SubmitData)', function (data) {

    
    //所有表单数据
    var dataArr = new Array();
    dataArr = data.field;
    
    
    console.log(data.field)
    var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,20}');
    var pwd1 = $("#pwd1").val();
    var pwd2 = $("#pwd2").val();
    console.log($("input[name='F_Password']").val().length)
    if ((!pwdRegex.test(pwd1))&&($("input[name='F_Password']").val().length<20)) {
      layui.layer.alert("您的密码复杂度太低", {
        icon: 2
      });
      $(".passIcon").show()
      return false;
    }

    if (pwd1 != pwd2) {
      layui.layer.alert("两次密码不一致!", {
        icon: 2
      });
      return false;
    }

    //启用标志
    if (dataArr["F_SeatFlag"] == "on") {
      dataArr["F_SeatFlag"] = 1;
    }
    else {
      dataArr["F_SeatFlag"] = 0;
    }
    dataArr['F_Password'] = $.md5(pwd2)
    console.log(JSON.stringify(dataArr))

    $.ajax({
      url: "/SystemManage/SaveUserData",
      type: "post",
      async: false,//同步请求
      contentType: "application/json",
      dataType: "text",
      cache: false,
      data: JSON.stringify(dataArr),
      // data: dataArr,
      success: function (thisResult, result) {

        if (thisResult == "True") {
          layer.open({
            content: '保存成功'
            , btn: ['确定']
            , yes: function (index, layero) {
              layer.close(index);
              ////刷新父窗体

              var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
              parent.layer.close(thisindex);
            }
            , cancel: function () {
              var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
              parent.layer.close(thisindex);

            }
          });

          return false;
        } else {
          layui.layer.alert("保存失败!", {
            icon: 2
          });

          return false;
        }

      },
      error: function (error) {
        return false;
      }
    });
    return false;
  });

})

