<template>
  <el-dialog
    v-model="props.show"
    title=""
    width="720"
    style="border-radius: 24px"
    :before-close="handleClose"
  >
    <div class="login-dialog">
      <div class="login-top">
        <div class="info">个人用户</div>
        <div class="switch-info">切换为企业用户>></div>
      </div>
      <el-form
        ref="formRef"
        :model="state.loginForm"
        :rules="state.loginRules"
        label-width="0"
        class="demo-dynamic"
      >
        <el-form-item label="" prop="Phone">
          <el-input v-model="state.loginForm.Phone" size="large" placeholder="请输入手机号">
            <template #prefix>
              <img src="../../assets/img/Phone.png" alt="" />
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="" prop="Code">
          <el-input v-model="state.loginForm.Code" size="large" placeholder="请输入验证码">
            <template #prefix>
              <img src="../../assets/img/pwd.png" alt="" />
            </template>
            <template #suffix>
              <el-button type="primary" link :disabled="state.disabled">获取验证码</el-button>
            </template>
          </el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" style="width: 100%; margin-top: 46px" @click="onConfirm"
        >登录/注册</el-button
      >
    </div>
    <div class="agree-with">
      <el-checkbox v-model="state.agreeWith" label="" size="large" text-color="#ffffff">
        <template #default>
          <div style="color: #999999">
            同意南山就业帮
            <span style="color: #409eff" @click.prevent="open">《南山就业帮用户服务协议》</span>
            及
            <span style="color: #409eff" @click.prevent="open">《个人信息保护政策》</span>
          </div>
        </template>
      </el-checkbox>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  }
})

const emits = defineEmits(['update:show'])

const formRef = ref()
const state = reactive({
  loginForm: {
    Phone: '',
    Code: ''
  },
  loginRules: {
    Phone: [
      { required: true, message: '请输入手机号', trigger: 'blur' },
      {
        pattern: /^1[3|4|5|6|7|8][0-9]\d{8}$/,
        message: '手机号码格式不正确',
        trigger: 'blur'
      }
    ],
    Code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  },
  disabled: false,
  agreeWith: false
})

const onConfirm = () => {
  formRef.value?.validate((valid: boolean, fields: any) => {
    if (valid) {
      console.log(state.loginForm)
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}

const open = () => {
  console.log('open')
}

const handleClose = () => {
  formRef.value?.resetFields()
  emits('update:show', false)
}
</script>

<style lang="scss" scoped>
.login-dialog {
  padding: 0 130px;
  .login-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 64px;
    .info {
      font-size: 32px;
      font-weight: 500;
      color: #000000;
    }
    .switch-info {
      color: #265ea4;
      cursor: pointer;
    }
  }
}
.agree-with {
  display: flex;
  align-items: center;
  margin-top: 24px;
  margin-bottom: 50px;
  padding-left: 130px;
}
</style>
