<template>
  <div class="box">
    <div class="mine">
      <el-upload
          class="avatar-uploader"
          action="https://9miao.fun:6838/prod-api/common/alibabaUpload"
          :show-file-list="false"
          :headers="headerObj"
          :on-success="handleAvatarSuccess"
        >
          <img v-if="user.avatar" :src="user.avatar" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>

      <div class="msg">
        <div class="item">
          <p>昵称</p>
          <input
            type="text"
            placeholder="请输入昵称"
            v-model="user.nicekname"
          />
        </div>

        <div class="item">
          <p>性别</p>
          <div class="radio">
            <el-radio v-model="user.sex" label="male">男</el-radio>
            <el-radio v-model="user.sex" label="nv">女</el-radio>
          </div>
        </div>

        <div class="item">
          <p>手机号</p>
          <input
            type="text"
            placeholder="请输入手机号"
            v-model="user.phonenumber"
          />
        </div>

        <div class="btn">
          <p @click="save">保存</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { apiServe } from "@/api/api.js";
export default {
  name: "WenhuaWebuiMine",

  data() {
    return {
      cdata: {},
      headerObj: {
        // "Content-Type": "application/json",
        saToken: localStorage.getItem("token"),
      },
      imageUrl:'',
      user: {
        phonenumber: "",
        nicekname: "",
        avatar: "",
        sex: "",
      },
    };
  },

  mounted() {
    this.cdata.token = localStorage.getItem("token");
    this.searchUser();
  },

  methods: {
    handleSelect(e){

    },
    handleAvatarSuccess(res, file) {
       console.log(res);
       this.user.avatar  =res.url
      //  this.imageUrl= URL.createObjectURL(file.raw);
      //  this.list.avatar = this.imageUrl
    },
    searchUser() {
      apiServe.admin(this.cdata).then((res) => {
        console.log(res);
        this.user = res.data.data;
        this.imageUrl = res.data.data.avatar;
        localStorage.setItem("userid", res.data.data.id);
        localStorage.setItem("img", res.data.data.avatar);
      });
    },
    save() {
      apiServe.editAdmin(this.user).then((res) => {
        console.log(res);
        this.$router.push("/index");
        this.$message({
          message: "个人信息保存成功!",
          type: "success",
        });
      });
    },
  },
};
</script>

<style scoped lang="less">
.box::v-deep {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .mine {
    width: 1000px;
    margin-top: 50px;
    border-radius: 10px;
    border: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 30px 0;

    .msg {
      width: 800px;
      border-radius: 10px;

      .btn {
        display: flex;
        flex-direction: column;
        // background-color: rgba(242, 242, 242, 1);
        justify-content: center;
        align-items: center;

        p {
          width: 150px;
          height: 35px;
          font-size: 14px;
          text-align: center;
          line-height: 35px;
          background-color: rgba(22, 155, 213, 1);
          color: #ffffff;
          border-radius: 5px;
          //   padding: 20px;
        }
      }

      .item {
        display: flex;
        flex-direction: column;
        background-color: rgba(242, 242, 242, 1);

        // justify-content: center;
        align-items: center;
        margin-top: 20px;
        padding: 20px 30px 0;
        box-sizing: border-box;
        margin-bottom: 50px;

        p {
          width: 100%;
          text-align: left;
          // margin-top: 20px;
        }

        .radio {
          width: 100%;
          display: flex;
          margin-top: 20px;
          padding-bottom: 20px;
        }

        input {
          width: 100%;
          height: 35px;
          margin: 10px 0 20px;
          padding-left: 15px;
          box-sizing: border-box;
          border-radius: 5px;
          border: 1px solid #ffffff !important;
        }
      }
    }
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>