    <template>
  <view class="login">
    <view class="welcome">欢迎加入正恒车业！</view>
    <view class="makesure">请确认授权以下信息</view>
    <view class="get">获取你的公开信息（ 昵称、头像等 ）</view>
    <button
      class="btn"
      type="primary"
      open-type="getUserInfo"
      lang="zh_CN"
      @getuserinfo="onGotUserInfo"
    >微信授权</button>
  </view>
</template>

    <script>
import requestP from "../../static/js/request.js";
export default {
  data() {
    return {
      code: ""
    };
  },
  onLoad() {},

  methods: {
    onGotUserInfo() {
      var t = this
      wx.getSetting({
        success: res => {
          wx.login({
            success: res => {
              console.log(res);
              t.code = res.code;
              console.log(t.code);
              wx.getUserInfo({
                success: res => {
                  console.log(res, 11);
                  t.tx = res.userInfo.avatarUrl;
                  t.nickname = res.userInfo.nickName;
                  requestP
                    .requestP({
                      url: "user/login",
                      data: {
                        code: t.code,
                        nickname: t.nickname,
                        avatar_url: t.tx
                      }
                    })
                    .then(res => {
                      console.log(res);
                      uni.setStorageSync("openid", res.data.openid);
                      console.log(res.data.openid, 12222222);
                      uni.redirectTo({
                        url: "/pages/index/index"
                      });
                    });
                }
              });
            }
          });

          console.log(res, 14);
        }
      });
      console.log(101);
      console.log(this.code, 7946);
    }
  }
};
</script>

    <style lang="scss">
.login {
  width: 100vw;
  .welcome {
    color: #333333;
    font-size: 28upx;
    font-weight: bold;
    margin-left: 100upx;
    margin-top: 227upx;
  }
  .makesure {
    color: #333333;
    font-size: 20upx;
    margin-top: 99upx;
    margin-left: 99upx;
  }
  .get {
    color: #999999;
    font-size: 20upx;
    margin-left: 99upx;
    margin-top: 15upx;
    margin-bottom: 58upx;
  }
  .btn {
    width: 550upx;
    height: 72upx;
    background-color: #04cb00;
    line-height: 72upx;
    text-align: center;
    color: white;
    font-size: 28upx;
    margin: 0 auto;
  }
}
</style>