<template>
  <el-form
    :label-position="'right'"
    label-width="120px"
    :model="accountForm"
    :rules="formRules"
    ref="accountRef"
    style="max-width: 90%">
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="accountForm.phone"/>
    </el-form-item>
    <el-form-item label="账号" prop="account">
      <el-input v-model="accountForm.account" />
    </el-form-item>
    <el-form-item label="验证码" prop="code">
      <div class="msg-code">
        <el-input
          v-model="accountForm.code"
          placeholder="请输入"
          style="860px"
        >
        </el-input>
        <div class="yzm_img">
            <el-button type="primary" @click="sendSms" style="width: 100%;height: 34px;">
              发送验证码
            </el-button>
        </div>
      </div> 
    </el-form-item>
  </el-form>
</template>

<script setup>
import { reactive, ref, onBeforeMount, onMounted, computed } from "vue";
import axios from "@/request/http.js";
import { ElMessage } from "element-plus";
const props = defineProps({

});
const accountForm = reactive({
  phone: "",
  account: "",
  code: ""
});


const formRules = reactive({
  phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
  account: [
    { required: true, message: "请输入账号", trigger: "blur" },
  ],
  code: [
    { required: true, message: "请输入验证码", trigger: "blur" },
  ],
});

const accountRef = ref(null);
const emit = defineEmits(["action"]);
const submitForm = async () => {
  if (!accountRef) return;
  await accountRef.value.validate((valid, fields) => {
    if (valid) {
      emit("action", accountForm);
    } else {
      emit("action", null);
    }
  });
};

const clearForm = () => {
  if (!accountRef) return;
  accountRef.value.resetFields();
};

const setForm = (data) => {
  Object.assign(accountForm, data);
};

const sendSms = () => {
  
}

onBeforeMount(() => {

});

onMounted(() => {});

defineExpose({ submitForm, clearForm, setForm });
</script>

<style lang="scss" scoped>
.msg-code {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  .yzm_img {
    flex: 1;
    margin-left: 20px;
  }
}
</style>
