<!-- 启动页 -->
<template>
  <view class="page-content">
    <!-- 	<view class="">
			<text>
				查看油站订单 更便捷
			</text>
			<text>
				加油单价 清晰明了
			</text>
    </view>-->
    <view class="text-center logo-part">
      <view class="cu-avatar xl text-sl" :style="'background-image: url('+mainURL+'qr-icon.png)'"></view>
      <view class>
        <text class="text-lg">星油云站</text>
      </view>
    </view>
  </view>
</template>

<script>
import loginApi from '@/api/login.js'
export default {
  data() {
    return {
      mainURL: this.global.mainURL
    }
  },
  onLoad() {
    this.loginWeixin()
  },
  methods: {
    loginWeixin() {
      uni.login({
        provider: 'weixin',
        success: loginRes => {
          const code = loginRes.code
          console.log('启动页code',code)
          loginApi.loginWeixin(code).then(res => {
            if (res.code === 20000) {
              uni.reLaunch({
                url: '/pages/index/index',
                fail: (err) => {
                  console.log(err)
                }
              })
              uni.showToast({
                title: res.msg,
                icon: 'success',
                duration: 3000
              })
              uni.setStorage({
                key: 'Authorization',
                data: res.data.accessToken,
                success: () => {
                  console.log('Authorization成功', res.data.accessToken)
                }
              })
              uni.setStorage({
                key: 'device',
                data: res.data.openid,
                success: () => {
                  console.log('deviceopenid', res.data.openid)
                }
              })
              uni.setStorageSync('userMenu', res.data.loginUser.procedureAuthList)
              uni.setStorageSync('loginUser', {
                id: res.data.loginUser.id,
                name: res.data.loginUser.name
              })
            } else {
              uni.reLaunch({
                url: '/pages/login/boforeLogin/boforeLogin',
                fail: (err) => {
                  console.log(err)
                }
              })
              console.log('res', res.code)
            }


          }).catch(err => {
            uni.reLaunch({
              url: '/pages/login/boforeLogin/boforeLogin',
              fail: (err) => {
                console.log(err)
              }
            })
          })
        },
        fail: err => {
          console.log(err)
        }
      });
    },

  }
}
</script>

<style scoped>
.logo-part {
  position: absolute;
  top: 30%;
  min-width: 100%;
}

.cu-avatar {
  background-color: #fff;
}
</style>
