<template>
  <div class="login-container">
    <div class="logo">
      <el-image :src="logo" style="width: 180px"></el-image>
    </div>
    <div class="form-wrap">
      <div class="header">
        <span class="t1">注册</span>
        <div class="mt50">
          <el-radio-group v-model="type" size="large">
            <el-radio-button :label="1">餐饮版</el-radio-button>
            <el-radio-button :label="2">商超版</el-radio-button>
            <el-radio-button :label="3">快餐版</el-radio-button>
            <el-radio-button :label="4">美业版</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <el-form
        ref="formRef"
        :model="form"
        :rules="rules"
        label-position="top"
        size="large"
        hide-required-asterisk
      >
        <el-form-item label="店铺名称" prop="shopName">
          <el-input
            v-model="form.shopName"
            placeholder="请输入店铺名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input
            v-model="form.phone"
            placeholder="请输入注册手机号"
          ></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="code">
          <el-input v-model="form.code" placeholder="请输入验证码"></el-input>
        </el-form-item>
        <el-form-item label="登录密码" prop="password">
          <el-input
            v-model="form.password"
            type="password"
            placeholder="请输入登录密码"
          ></el-input>
        </el-form-item>
        <el-form-item label="确认登录密码" prop="repassword">
          <el-input
            v-model="form.repassword"
            type="password"
            placeholder="请重复输入登录密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="submitHandle"
            >注册</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button plain style="width: 100%" @click="router.back()">
            返回
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import logo from "@/assets/logo.png";
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();

const type = ref(1);

const formRef = ref(null);

const form = reactive({
  shopName: "",
  phone: "",
  code: "",
  password: "",
  repassword: "",
});
const repasswordPass = (rule, value, callback) => {
  if (!form.repassword) {
    callback(new Error("请重复输入登录密码"));
  } else if (form.password !== form.repassword) {
    callback(new Error("两次密码输入不一致"));
  } else {
    callback();
  }
};
const rules = reactive({
  shopName: [
    {
      required: true,
      message: "请输入店铺名称",
      trigger: "blur",
    },
  ],
  phone: [
    {
      required: true,
      message: "请输入注册手机号",
      trigger: "blur",
    },
  ],
  code: [
    {
      required: true,
      message: "请输入验证码",
      trigger: "blur",
    },
  ],
  password: [
    {
      required: true,
      message: "请输入登录密码",
      trigger: "blur",
    },
  ],
  repassword: [
    {
      validator: repasswordPass,
      trigger: "blur",
    },
  ],
});

// 提交
const submitHandle = () => {
  formRef.value.validate((valid) => {
    if (valid) {
    }
  });
};
</script>

<style scoped lang="scss">
.login-container {
  display: flex;
  height: 100vh;
  .logo {
    flex: 1;
    height: inherit;
    background-color: var(--el-color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .form-wrap {
    flex: 1;
    height: inherit;
    padding: 50px;
  }
  .reg-wrap {
    display: flex;
    justify-content: flex-end;
    padding-bottom: 100px;
  }
  .header {
    display: flex;
    flex-direction: column;
    padding-bottom: 50px;
    .t1 {
      font-size: 52px;
      color: #999;
    }
    .t2 {
      font-size: 24px;
      color: #999;
    }
  }
}
.version {
  padding-top: 50px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
</style>
