未成年设置

    checkPatient(e) {
      let identityCard = e.replace(/\s+/g, "");
      let len = identityCard.length;
      var strBirthday = "";
      if (len == 18) {
        strBirthday =
          identityCard.substr(6, 4) +
          "/" +
          identityCard.substr(10, 2) +
          "/" +
          identityCard.substr(12, 2);
      }
      if (len == 15) {
        strBirthday =
          "19" +
          identityCard.substr(6, 2) +
          "/" +
          identityCard.substr(8, 2) +
          "/" +
          identityCard.substr(10, 2);
      }
      let birthDate = new Date(strBirthday);
      let nowDateTime = new Date();
      var age = nowDateTime.getFullYear() - birthDate.getFullYear();
      if (
        nowDateTime.getMonth() < birthDate.getMonth() ||
        (nowDateTime.getMonth() == birthDate.getMonth() &&
          nowDateTime.getDate() < birthDate.getDate())
      ) {
        age--;
      }
      if (age < 18) {
        this.$MX.alert.show({
          title: "提示",
          content: "您尚未成年,本项目不包含未成年人入组",
          onHide: () => {
           
            this.$router.push("/Home");
          },
        });
        return;
      }
     
    },

你可能感兴趣的:(前端网页小项目,vue.js)