<template>
  <div class="bg-F5">
    <div class="topDiv">
      <div class="container">
        <span class="title">{{ $t("title") }}</span>
        <span class="line"></span>
        <span class="info">{{
          $t("page.views.account.findPassword.title")
        }}</span>
      </div>
    </div>
    <div class="bg">
      <div class="container  ">
        <img :src="require(`@assets/loginbg_${$i18n.locale}.png`)" />
        <div class="loginDiv">
          <div class="x-title">
            {{ $t("page.views.account.findPassword.title") }}
          </div>
          <el-form :model="form" :rules="rules" class="form" ref="form">
            <el-form-item class="formItem" prop="loginAccount">
              <img class="icon" src="@assets/user.png" alt="" />
              <el-input
                v-model="form.loginAccount"
                prefix-icon="x-el-icon-user"
                :placeholder="
                  `${$t(`inputPlaceholder`)}${$t(`form.loginAccount`)}`
                "
              />
            </el-form-item>

            <el-form-item class="formItem" prop="phone">
              <img class="icon" src="@assets/phone.png" alt="" />
              <el-input
                v-model="form.phone"
                prefix-icon="x-el-icon-lock"
                :placeholder="`${$t(`inputPlaceholder`)}${$t(`form.phone`)}`"
              />
            </el-form-item>
            <el-form-item class="formItem yzm" prop="validateCode">
              <img class="icon" src="@assets/yz.png" alt="" />
              <el-input
                v-model="form.validateCode"
                prefix-icon="icon-yzm"
                :placeholder="
                  `${$t(`inputPlaceholder`)}${$t(`form.validateCode`)}`
                "
              />
              <div class="getyzm">{{ $t("form.getValidateCode") }}</div>
            </el-form-item>
            <el-form-item class="formItem" prop="loginPassword">
              <img class="icon" src="@assets/lock.png" alt="" />
              <el-input
                v-model="form.loginPassword"
                prefix-icon="x-el-icon-lock"
                :placeholder="
                  `${$t(`inputPlaceholder`)}${$t(
                    `page.views.account.findPassword.loginPassword`
                  )}`
                "
                show-password
              />
            </el-form-item>

            <el-button class="loginBtn" @click="validate">{{
              $t("page.views.account.findPassword.submit")
            }}</el-button>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
import user from "@/store/modules/user";
import { RegAccount } from "@/utils";
import { ElForm } from "element-ui/types/form";
import i18n from "@/lang";
@Component
export default class extends Vue {
  private verifyImg = "";
  private form = {
    loginAccount: "",
    loginPassword: "",
    validateCode: "",
    phone: ""
  };
  private rules = {
    loginAccount: [
      {
        required: true,
        message: `${i18n.t(`inputPlaceholder`)}${i18n.t(`form.loginAccount`)}`,
        trigger: "blur"
      },
      {
        validator: (rule: any, value: string, callback: any) =>
          callback(
            RegAccount.test(value)
              ? undefined
              : new Error(`${i18n.t("form.RegAccount")}`)
          ),
        trigger: "blur"
      }
    ],
    loginPassword: [
      {
        required: true,
        message: `${i18n.t(`inputPlaceholder`)}${i18n.t(
          `page.views.account.findPassword.loginPassword`
        )}`,
        trigger: "blur"
      },
      {
        validator: (rule: any, value: string, callback: any) =>
          callback(
            RegAccount.test(value)
              ? undefined
              : new Error(`${i18n.t("form.RegAccount")}`)
          ),
        trigger: "blur"
      }
    ],
    phone: [
      {
        required: true,
        message: `${i18n.t(`inputPlaceholder`)}${i18n.t(`form.phone`)}`,
        trigger: "blur"
      },
      {
        validator: (rule: any, value: string, callback: any) =>
          callback(
            /^1[3|4|5|7|8][0-9]\d{8}$/.test(value)
              ? undefined
              : new Error(`${i18n.t("form.validatePhone")}`)
          ),
        trigger: "blur"
      }
    ],
    validateCode: [
      {
        required: true,
        message: `${i18n.t(`inputPlaceholder`)}${i18n.t(`form.validateCode`)}`,
        trigger: "blur"
      }
    ]
  };

  validate() {
    (this.$refs.form as ElForm).validate(x => x && this.submit());
  }

  async submit() {
    const [err] = await this.$post("/member/info/resetPassword", this.form);
    if (err) return;
    this.$message.success(`${this.$i18n.t("message.success.findPassword")}`);
    (this.$refs.form as ElForm).resetFields();
    this.$router.push("/login");
  }
}
</script>
<style lang="scss" scoped>
.bg-F5 {
  .topDiv {
    height: 9rem;
    line-height: 9rem;
    background: #fff;
    .title {
      font-size: 2.2rem;
      font-weight: bold;
      color: #fd5522;
    }
    .line {
      display: inline-block;
      height: 3rem;
      width: 0.1rem;
      background: #e5e5e5;
      margin: 0 2rem;
      vertical-align: middle;
    }
    .info {
      font-size: 1.8rem;
      font-weight: bold;
      color: #666;
    }
  }

  .bg {
    background: #84ccc9;
    padding: 75px 0;
    .container {
      overflow: hidden;
      > img {
        margin-left: 180px;
        margin-top: 50px;
        float: left;
      }
      .loginDiv {
        // width: 320px;
        // height: 338px;
        overflow: hidden;
        margin-left: 218px;
        float: left;
        background: #fff;

        box-sizing: border-box;
        border-radius: 0.4rem;
        box-shadow: 2px 2px 12px #ddd;
        .x-title {
          margin-top: 20px;
        }
        .form {
          padding: 15px 20px;
          .formItem {
            height: 40px;
            line-height: 40px;
            box-sizing: border-box;
            border-radius: 4px;
            margin-bottom: 20px;
            position: relative;
            .icon {
              position: absolute;
              left: 10px;
              top: 50%;
              transform: translateY(-50%);
              z-index: 1;
              width: 12px;
            }
          }
          .loginBtn {
            width: 100%;
            background: #fd5522;
            color: #fff;
            border-color: #fd5522;
          }
        }
      }
      .getyzm {
        height: 40px;
        line-height: 40px;
        width: 100px;
        font-size: 14px;
        color: #fd5522;
        text-align: center;
        float: right;
        background: #ffded5;
        border-radius: 0.4rem;
        cursor: pointer;
      }
      .xieyi {
        color: #fd5522;
      }
    }
  }
}
</style>
<style lang="scss">
.formItem.yzm {
  .el-input {
    width: 200px;
  }
  .verifyImg {
    height: 40px;
    width: 108px;
    margin-left: 10px;
    vertical-align: middle;
  }
}
</style>
