<template>
    <div class="home_wrapper">
    <van-nav-bar
      title="用户信息维护"
      left-arrow
      placeholder
      safe-area-inset-top
      @click-left="onClickLeft"
    />

      <van-form @submit="onSubmit">
      <div class="main">
        <p class="title"><i></i>用户信息</p>
        <van-field
          required
          :rules="[{ required: true }]"
          v-model="form.nickName"
          label="用户昵称"
          placeholder="请输入"
          input-align="right"
          label-width="auto"
        />
        <van-field
          required
          :rules="[
            { required: true },
            {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur'
            }
            ]"
          v-model="form.phonenumber"
          label="手机号码"
          placeholder="请输入"
          input-align="right"
          label-width="auto"
        />
        <van-field
          required
          :rules="[
            { required: true },
            {
            type: 'email',
            message: '请输入正确的邮箱地址',
            trigger: ['blur', 'change']
            }
          ]"
          v-model="form.email"
          label="邮箱"
          placeholder="请输入"
          input-align="right"
          label-width="auto"
        />
        <van-field
          required
          :rules="[{ required: true }]"
          label="性别"
          input-align="right"
          label-width="auto"
        >
          <van-radio-group slot="input" v-model="form.sex" direction="horizontal">
            <van-radio name="0">男</van-radio>
            <van-radio name="1">女</van-radio>
          </van-radio-group>
        </van-field>
      </div>

      <van-button round block type="primary" native-type="submit" class="subClass">提交</van-button>
      </van-form>

    </div>
</template>

<script>
  // import { getMenuApp } from "@/api/app/index";
  import Cookies from "js-cookie";
  import { getUserProfile } from "@/api/system/user"
  import { updateUserProfile } from "@/api/system/user"
  export default {
    name: "appUserInfo",
    data() {
      return {
        form: {},
        user: {},
      };
    },
    created() {

      this.getUser()
    },
    methods: {
      onClickLeft(){
        history.back(-1);
      },
      getUser() {
        getUserProfile().then(response => {
          this.form = response.data
          this.roleGroup = response.roleGroup
          this.postGroup = response.postGroup
        })
      },
      onSubmit() {
        updateUserProfile(this.form).then(response => {
          this.$modal.msgSuccess("修改成功")
          setTimeout(function(){
            history.back(-1);
          },2000)
        })
      },

    },
  };
</script>

<style scoped lang="scss">
  p{margin: 0;}
  .home_wrapper{
    width: 100vw;
    min-height: 100vh;
    background: #F6F9FB;
    padding-bottom: 5vh;
  }
  .van-nav-bar{
    background: linear-gradient( 173deg, #91E2D3 0%, #CDFCF0 100%);
    ::v-deep.van-icon{
      color: #000000;
    }
  }
  .main{
    width: 94%;
    margin: 3vw auto;
    padding: 3vw;
    background-color: #ffffff;
    border-radius: 10px;
    overflow: hidden;

  }
  .title{
    display: flex;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
    i{
      width: 5px;
      height: 20px;
      display: block;
      background-color: #29D2AF;
      margin-right: 10px;
    }
  }
  .subClass{
    background: linear-gradient( 270deg, #53E4A5 0%, #24DBDB 100%);
    border-radius: 50px 50px 50px 50px;
    border: none;
    width: 90%;
    margin: 3vw auto;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 18px;
  }

</style>
