<template>
  <div id="userTop">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="one" @click.native="back">
          <van-col span="24" class="image">
            <van-image :src="icon"></van-image>
          </van-col>
          <van-col span="24" class="other">
            <van-col span="24" class="otherInfo">
              {{ userInfo.phone || '游客' }}
            </van-col>
            <van-col span="24" class="otherInfo">
              {{ userInfo.name || '游客123456' }}
            </van-col>
          </van-col>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
var moment = require('moment');
export default {
  name: 'userTop',
  props: {},
  components: {},
  data: function () {
    return {
      icon: require('@a/icon.jpg'),
      userInfo: {},
    };
  },
  created() {
    this.searchUser();
  },
  methods: {
    // 查询用户
    searchUser() {
      if (this.user) {
        this.$set(this, `userInfo`, this.user);
      } else {
        let data = {
          name: '游客',
          phone: moment(new Date()).valueOf(),
        };
        this.$set(this, `userInfo`, data);
      }
    },
    // 返回个人中心
    back() {
      this.$router.push({ path: '/account/index' });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    background: url('~@/assets/userbj.jpg');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    .image {
      text-align: center;
      padding: 10px 0 10px 0;
      .van-image {
        width: 66px;
        height: 66px;
        /deep/.van-image__img {
          border-radius: 90px;
        }
      }
    }
    .other {
      text-align: center;
      .otherInfo {
        font-size: 16px;
        color: #000;
        font-weight: bold;
        margin: 0 0 5px 0;
      }
    }
  }
}
</style>
