settings.vue 4.65 KB
Newer Older
1 2 3
<template>
  <div class="settings">
    <van-cell-group class="group-1">
leiqingsong's avatar
leiqingsong committed
4
      <van-cell title="用户名" :value="userName" />
5
      <van-cell is-link center title="头像" @click="onModefy">
leiqingsong's avatar
leiqingsong committed
6
        <img class="avatar-img" :src="imageBaseUrl + avatar" alt="头像" />
7 8 9
      </van-cell>
    </van-cell-group>
    <van-cell-group>
10
      <van-cell
11
        class="van-less"
12
        is-link
leiqingsong's avatar
leiqingsong committed
13
        title="推荐人邀请码"
14 15 16
        :value="inviteeCode"
        @click="fillInviterCode"
      />
17
      <van-cell is-link title="软件更新" value="版本v1.2" />
leiqingsong's avatar
leiqingsong committed
18
      <van-cell is-link title="用户协议" @click="jumpToInstructions" />
19
    </van-cell-group>
leiqingsong's avatar
leiqingsong committed
20

leiqingsong's avatar
leiqingsong committed
21
    <a href="redirect://xts.com/login_activity?hideBack=true">
leiqingsong's avatar
leiqingsong committed
22 23 24 25
      <van-button size="large" class="logout-btn" @click="logout"
        >退出登录</van-button
      >
    </a>
26 27 28 29 30 31

    <base-dialog
      base-dialog-title="推荐人邀请码"
      base-dialog-btn="提交"
      :base-dialog-show="inviteeCodeDialog"
      :base-dialog-show-close="true"
leiqingsong's avatar
leiqingsong committed
32
      @onClose="onCloseDialog"
33 34 35 36 37 38
      @onClick="onFillInviteeCode"
    >
      <div slot="content">
        <p class="content-tip">请输入您的推荐人邀请码</p>
        <van-field
          v-model="fillCode"
leiqingsong's avatar
leiqingsong committed
39
          maxlength="6"
40 41 42 43 44
          class="validCodeInput"
          placeholder="请输入"
        />
      </div>
    </base-dialog>
45 46 47 48
  </div>
</template>

<script>
leiqingsong's avatar
leiqingsong committed
49
import { getUserInfo2 } from "@/api/user";
leiqingsong's avatar
leiqingsong committed
50
import { logout } from "@/api/user";
leiqingsong's avatar
leiqingsong committed
51
import { fillInviteCode } from "@/api/user";
52
import BaseDialog from "../components/BaseDialog.vue";
53
export default {
54
  components: { BaseDialog },
55 56 57
  name: "Settings",
  data() {
    return {
leiqingsong's avatar
leiqingsong committed
58
      userName: "",
leiqingsong's avatar
leiqingsong committed
59
      imageBaseUrl: "",
leiqingsong's avatar
leiqingsong committed
60
      headImage: "",
leiqingsong's avatar
leiqingsong committed
61
      avatar: "",
62 63 64 65
      fileList: [],
      fillCode: "",
      inviteeCode: "未填写",
      inviteeCodeDialog: false
66 67
    };
  },
68
  mounted() {
leiqingsong's avatar
leiqingsong committed
69
    this.imageBaseUrl = process.env.VUE_APP_BASE_URL;
leiqingsong's avatar
leiqingsong committed
70
    this.getUser();
leiqingsong's avatar
leiqingsong committed
71
  },
72
  methods: {
leiqingsong's avatar
leiqingsong committed
73
    getUser() {
leiqingsong's avatar
leiqingsong committed
74
      const params = {
leiqingsong's avatar
leiqingsong committed
75
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
76
      };
leiqingsong's avatar
leiqingsong committed
77
      console.log("setting-userId", params);
leiqingsong's avatar
leiqingsong committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
      getUserInfo2(params)
        .then(res => {
          if (res.userId) {
            localStorage.setItem("user", JSON.stringify(res));
            this.$nextTick(() => {
              this.userName = res.userId;
              this.inviteeCode =
                res.beInvitedCode == 1
                  ? "请填写推荐人邀请码"
                  : res.beInvitedCode;
              this.avatar = res.headImage;
              this.headImage = res.headImage;
            });
          }
        })
        .catch(err => {
          if (err.response.status === 502) {
            this.$toast("服务在升级,请稍后重试");
          }
        });
leiqingsong's avatar
leiqingsong committed
98
    },
leiqingsong's avatar
leiqingsong committed
99
    logout() {
100 101
      localStorage.clear();
      logout().then();
leiqingsong's avatar
leiqingsong committed
102
      this.$bridgeToAppFun.logoutToApp();
leiqingsong's avatar
leiqingsong committed
103
    },
leiqingsong's avatar
leiqingsong committed
104 105 106
    jumpToInstructions() {
      this.$router.push("/instructions");
    },
107
    onModefy() {
leiqingsong's avatar
leiqingsong committed
108 109 110
      this.$router.push({
        path: "/modefy-avatar",
        query: {
leiqingsong's avatar
leiqingsong committed
111
          headImage: this.headImage
leiqingsong's avatar
leiqingsong committed
112 113
        }
      });
114
    },
leiqingsong's avatar
leiqingsong committed
115 116 117
    onCloseDialog() {
      this.inviteeCodeDialog = false;
    },
118
    onFillInviteeCode() {
leiqingsong's avatar
leiqingsong committed
119
      if (!this.fillCode) {
leiqingsong's avatar
leiqingsong committed
120
        this.$toast.fail("请填写推荐人邀请码");
leiqingsong's avatar
leiqingsong committed
121 122 123
        return;
      }
      if (!/^[A-z|\d]{6}$/.test(this.fillCode)) {
leiqingsong's avatar
leiqingsong committed
124
        this.$toast.fail("邀请码只支持6位数字+字母的组合");
leiqingsong's avatar
leiqingsong committed
125 126
        return;
      }
127
      this.inviteeCodeDialog = false;
leiqingsong's avatar
leiqingsong committed
128 129
      const params = {
        inviteCode: this.fillCode,
leiqingsong's avatar
leiqingsong committed
130
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
131
      };
leiqingsong's avatar
leiqingsong committed
132 133 134 135 136 137 138 139 140 141 142 143 144
      fillInviteCode(params)
        .then(res => {
          if (res.code == 0) {
            // console.log('成功');
            this.inviteeCode = this.fillCode;
          } else {
            this.$toast.fail(res.message);
          }
        })
        .catch(err => {
          console.log(err);
          this.$toast.fail(err);
        });
145 146
    },
    fillInviterCode() {
leiqingsong's avatar
leiqingsong committed
147 148 149 150
      if (
        this.inviteeCode === "请填写推荐人邀请码" ||
        this.inviteeCode == "1"
      ) {
151 152 153
        this.inviteeCodeDialog = true;
        this.fillCode = "";
      }
154 155 156 157 158 159 160 161 162
    }
  }
};
</script>

<style lang="scss" scoped>
.settings {
  box-sizing: border-box;
  padding: 10px 16px;
leiqingsong's avatar
leiqingsong committed
163 164
  .van-less {
    .van-cell__right-icon {
165 166 167
      display: none;
    }
  }
168 169 170
}
.group-1 {
  margin-bottom: 10px;
171
  .avatar-img {
172 173 174 175 176 177 178 179
    width: 37px;
    height: 37px;
    border-radius: 50%;
  }
}
.logout-btn {
  margin: 10px 0;
}
180 181 182 183 184 185 186 187 188 189 190
.content-tip {
  text-align: center;
  font-size: 14px;
  color: #333333;
}
.validCodeInput {
  width: 245px;
  margin: 35px auto;
  background-color: #f9f9f9;
  border-radius: 20px;
}
191
</style>