<!-- 登录 -->
<template>
  <view class="login">
        <view class="middle">
			<view class="logo">
				<u-input style="width: 100%;height: 100%;background-color: #0D1A3C;" type="text"></u-input>
			</view>
			<button class="button" @click="login">
				微信用户一键登录/注册
			</button>
		</view>
  </view>
</template>

<script>
import { getOpenid } from '@/apis/main.js'
export default {
  components: {},
    data() {
      return {

      };
    },
  computed: {},
  watch: {},
  methods: {
    login(){
        uni.login({
            provider: 'weixin',
            success: (res) => {
                console.log(res)
                // uni.getUserInfo({
                //     provider: 'weixin',
                //     success: (res) => {
                //         console.log(res)
                //     }
                // })
                getOpenid({ code: res.code }).then(result => {
                    const { wxBindType, wxOpenId, accessToken, openId,userName } = result.data
                    if (wxBindType === 1) { // 已经绑定
                        this.$setSS('accessToken', accessToken)
                        this.$setSS('phone', userName)
                    } else { // 未绑定
                        this.$setSS('wxOpenId', wxOpenId)
                    }
                })
            }
        })
    }
  },
  created() {

  },
  mounted() {

  },
}
</script>
<style lang='scss' scoped>

</style>