<template>
  <view class="page flex-col">
    <view class="box_1 flex-col justify-end">


      <view class="box_7 flex-row justify-between">
        <view class="image-text_1 flex-row justify-between">
          <view class="group_1 flex-col">
            <view class="image-wrapper_2 flex-col">
              <image
                class="image_2"
                referrerpolicy="no-referrer"
                :src="selfInfo && selfInfo.avatar ? imageUrl + '/' + selfInfo.avatar : '/static/lanhu_gerenzhongxin/FigmaDDSSlicePNG185e54e3ffd47170ac4e6e5108c9a54f.png'"
              />
            </view>
          </view>
          <view class="text-group_1 flex-col justify-between">
			  <view v-if="selfInfo.nickname" class="text_3">{{ selfInfo.nickname}}</view>
			  <view v-if="selfInfo.username" class="text_3">{{selfInfo.username}}</view>
			<view v-else @click="toLogin()" class="text_2">登录/注册</view>
            <text v-if="!selfInfo.username"class="text_3">登录将开启全部服务</text>
          </view>
        </view>
        <view class="image-text_2 flex-col justify-between">
          <image
            class="label_1"
            referrerpolicy="no-referrer"
            src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNG7e67772393591f7c5436c0b59f7b3b17.png"
          />
          <text class="text-group_2">学车码</text>
        </view>
      </view>
      <view class="box_8 flex-row">
        <view class="image-wrapper_3 flex-col justify-center">
          <image
            class="label_2"
            referrerpolicy="no-referrer"
            :src="coachDetails && coachDetails.image ? imageUrl + '/' + coachDetails.image : '/static/lanhu_gerenzhongxin/FigmaDDSSlicePNGa95a4d1d98d08b238a3082514eefafd0.png'"
          />
        </view>
        <view class="text-group_3 flex-col justify-between">
          <text class="text_4" v-if="coachDetails.name != null">{{ coachDetails.name }}</text>
		  <text class="text_111" v-else> 暂无教练信息 </text>
          <view class="text-wrapper_1" v-if="coachDetails.seniority != null">
            <text class="text_5">教龄：</text>
            <text class="text_6">{{ coachDetails.seniority }}</text>
            <text class="text_7">年</text>
          </view>
		  
        </view>
        <!-- <view class="text-wrapper_2" v-if="coachDetails">
          <text class="text_8">学员数：</text>
          <text class="text_9">{{}}</text>
        </view>
		<view class="text-wrapper_2" v-else>
		  <text class="text_8">暂无数据</text>
		</view> -->
      </view>
    </view>
    <view class="box_9 flex-col">
      <view class="block_1 flex-col">
        <text class="text_10">我的订单</text>
        <view class="list_1 flex-row">
          <view
            class="image-text_3 flex-col justify-between"
            v-for="(item, index) in loopData"
            :key="index"
			@click="toOrderPage(item.orderType,item.type)"
          >
            <image
              class="label_3"
              referrerpolicy="no-referrer"
              :src="item.url"
            />
            <text class="text-group_4" v-text="item.text"></text>
          </view>
        </view>
      </view>
      <view class="block_2 flex-row" @click="goMyInDetails()">
        <view class="image-wrapper_4 flex-col">
          <image
            class="thumbnail_2"
            referrerpolicy="no-referrer"
            src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNG1bb0cdc369203c305a42d848736e8f01.png"
          />
        </view>
        <text class="text_11">个人信息</text>
        <image
          class="thumbnail_3"
          referrerpolicy="no-referrer"
          src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNG4f20daae79bb7c60189f8702897465d1.png"
        />
      </view>
      <view class="block_3 flex-row">
        <view class="image-wrapper_5 flex-col">
          <image
            class="thumbnail_4"
            referrerpolicy="no-referrer"
            src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNGb5e90b5b4c1f154eb4e27313164118a4.png"
          />
        </view>
        <text class="text_12">在线客服</text>
        <image
          class="thumbnail_5"
          referrerpolicy="no-referrer"
          src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNG4f20daae79bb7c60189f8702897465d1.png"
        />
      </view>
      <view class="block_4 flex-row">
        <view class="image-wrapper_6 flex-col">
          <image
            class="thumbnail_6"
            referrerpolicy="no-referrer"
            src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNGa728895586dafec1bde5f90c89d05c48.png"
          />
        </view>
        <text class="text_13">建议反馈</text>
        <image
          class="thumbnail_7"
          referrerpolicy="no-referrer"
          src="/static/lanhu_gerenzhongxin/FigmaDDSSlicePNG4f20daae79bb7c60189f8702897465d1.png"
        />
      </view>
    </view>
    <tabbar :msg='msg'></tabbar>
  </view>
</template>
<script>
	import headers from '../../components/header/headers.vue'
	import tabbar from '../../components/tabbar/tabbar.vue'
	import request from '@/utils/request.js'
  import {
    getLocalUserInfo,
    getToken
  } from '@/utils/auth'
export default {

  data() {
    return {
		msg: "3",
		selfInfo: {},
		coachDetails:{},
		userDetails: {},
      loopData: [
        {
          url: '/static/myImgs/alreadyPaid.png',
          text: '已付款',
		  orderType: '2',
		  type: '2',
        },
        {
          url: '/static/myImgs/alreadyInterviewed.png',
          text: '已面签',
		  orderType: '4',
		  type: '3',
        },
        {
          url: '/static/myImgs/registered.png',
          text: '已报名',
		  orderType: '2',
		  type: '4',
        },
        {
          url: '/static/myImgs/allOrder.png',
          text: '全部订单',
		  orderType: '',
		  type: '1',
        }
      ],
      constants: {},
      imageUrl: this.$imagesUrl,
    };
  },
  onLoad() {
  	this.selfInfo = getLocalUserInfo()
    console.log("用户信息", this.selfInfo)
	this.getUserInfo()
  },
  onShow() {
  	if (getToken()) {
  		// this.findSelfInfo()
  	}

  },
  onPullDownRefresh() {
  	console.log("刷新");
  	uni.stopPullDownRefresh()
  },
  onReachBottom() {
  	// this.show = true
  	setTimeout(() => {
  		console.log("加载执行");
  	}, 2000)
  },
  components: {
  	headers,
  	tabbar
  },
  methods: {
	  goback() {
	  	uni.navigateBack()
	  },
	  toLogin() {
	  	uni.navigateTo({
	  		url: "/pages/login/login"
	  	})
	  },
	  /*async findSelfInfo() {
	  	let res = await request({
	  		url: `/app-api/small/driving/findSelfInfo`,
	  		method: 'get',
	  	})
	  	console.log(res, 138);
	  	this.selfInfo = res
	  },*/

	  toOrderPage(orderType,type) {
	        uni.navigateTo({
	          url: `/newPages/orderList/index?orderType=${orderType}&type=${type}&userId=${this.selfInfo.id}`
	        })
	      },
	  goMyInDetails(){
		  uni.navigateTo({
		    url: `/newPages/informationAdd/index?userId=${this.selfInfo.id}`
		  })
	  },
	  
	  getUserInfo(){
	    request({
	      url: '/app-api/small/dl-drive-school-student/getByUserId',
	      method: 'GET',
	      params: {
	        userId: this.selfInfo.id,
	      },
	    }).then(res => {
	      this.userDetails = res.data
		  console.log('userDetails', this.userDetails)
		  if(this.userDetails.sourceUserId !== null){
			  this.getCoachDetails(this.userDetails.sourceUserId)
		  }
	    })
	  },
	  
	  getCoachDetails(userId){
		  request({
			  url: '/app-api/dl-drive-school-coach-small/getCoachByUserId',
			  method: 'GET',
			  params: {
				  userId: userId
			  }
		  }).then(res => {
			  this.coachDetails = res.data
			  console.log('coachDetails', this.coachDetails);
		  })
	  }

  }
};
</script>
<style lang='scss'>
@import '../common/common.scss';
@import './assets/style/index.rpx.scss';
</style>
