<template>
  <p class="inquire-button-one" @click="upDataClick">提交</p>
</template>

<script>
  import { addUserStudent,putUserStudent } from "@/api/system/user_student";
  export default {
    name: 'addPageSubPagePublic',
    methods:{
      upDataClick(){
        let self = this;
        self.$parent.$refs["form"].validate(valid => {
          if (valid) {
            if(self.$parent.form.email){
              let re = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
              if(!re.test(self.$parent.form.email)){
                self.msgError('请输入正确的邮箱地址')
                return
              }
            }
            if(self.$parent.propsData.userId){
              //编辑
              self.$parent.form.userId = self.$parent.propsData.userId
              putUserStudent(self.$parent.form).then(response => {
                if(response.code==200){
                  self.msgSuccess(response.msg)
                  self.$parent.outPageButton()
                }else if(response.code==205){
                  self.$confirm(response.msg, "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                  }).then(() => {
                    //  确定
                    self.$router.push({ path: '/comprehensive/laboratoryManagement/accessAuthorization' });
                  }).catch(function() {
                    //  取消
                    self.$parent.outPageButton();
                  });
                }

              });
            }else{
              //新增
              addUserStudent(self.$parent.form).then(response => {
                if(response.code==200){
                  self.msgSuccess(response.msg)
                  self.$parent.outPageButton()
                }else if(response.code==205){
                  self.$confirm(response.msg, "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                  }).then(() => {
                    //  确定
                    self.$router.push({ path: '/comprehensive/laboratoryManagement/accessAuthorization' });
                  }).catch(function() {
                    //  取消
                    self.$parent.outPageButton();
                  });
                }

              });
            }
          }
        })
      },
    }
  }
</script>

<style scoped>

</style>
