<template>
	<view class="certinfo">
		<!-- 认证第一步 -->
		<view class="ce-frist">
			<view class="cert-title">我的认证</view>
			<!-- 机构认证 -->
      <view v-if="is_show_institutions">
        <view class="ce-tit">机构认证</view>
        <view class="ce-fbox">
          <view class="fbicon fbjg"></view>
          <view class="fbtit">机构认证</view>
          <view class="fbdesc">
            含企业、政府、事业单位、团体、组织
          </view>
          <view class="fbbtn" @click="orgverify()">{{institutionsStr}}</view>
        </view>
      </view>
			<!-- 个人认证 -->
      <view v-if="is_show_people">
        <view class="ce-tit">个人认证</view>
        <view class="ce-fbox">
          <view class="fbicon fbgr"></view>
          <view class="fbtit">个人认证</view>
          <view class="fbdesc">
            适用于个人用户
          </view>
          <view class="fbbtn" @click="personverify()">{{peopleStr}}</view>
        </view>
      </view>
		</view>
	
	</view>
</template>

<script>
	import { checkLogin } from '@/core/app'
  import {listLibrary} from "../../../api/verify";
  import { returnAccountId } from '@/core/app'

	export default {
		data() {
			return {
				// 是否已登录
				isLogin: false,
        peopleStr: '立即认证',
        institutionsStr: '立即认证',
        is_show_people: true,
        is_show_institutions: true,
			}
		},
    mounted() {
      this.listLibrary()
    },
		onShow() {
			// 判断是否已登录
			this.isLogin = checkLogin()
			if(!this.isLogin){
				uni.navigateTo({
					url:"/pages/login/index"
				})
			}
		},
		methods: {
			//机构认证
			orgverify(){
        if (this.institutionsStr === '待缴费') {
          uni.navigateTo({url: "/pages/goods/payment/verifyPayment"})
        } else if (this.institutionsStr === '认证通过') {

        } else {
          this.$navTo("pages/user/mycertinfo/orgverify")
        }
			},
			//个人认证
			personverify(){
        if (this.peopleStr === '待缴费') {
          uni.navigateTo({url: "/pages/goods/payment/verifyPayment"})
        } else if (this.institutionsStr === '认证通过') {

        } else {
          this.$navTo("pages/user/mycertinfo/personverify")
        }
			},
      // 获取认证信息
      listLibrary() {
        const app = this
        let accountId = returnAccountId()
        return new Promise((resolve, reject) => {
          listLibrary(accountId)
              .then(result => {
                if (result.resultCode === "00000000") {
                  let state = result.data.state;
                  let paystatu = result.data.paystatu;
                  let isposttion = result.data.isposttion;
                  let userTypes = result.data.usertype;

                  let str1 = app.institutionsStr// 显示按钮
                  let str2 = app.peopleStr// 显示按钮

                  if (isposttion == 1) {
                    //判断是在白名单里
                    if (userTypes !== undefined) {
                      if (userTypes == "企业") {
                        app.is_show_people = false // 隐藏个人
                        if (state == "1" || state == "3" || state == "7" || state == "0") {
                          str1 = "认证中"
                        } else if (state == "2" || state == "4" || state == "5") {
                          str1 = "认证失败"
                        } else if (state == "6") {
                          str1 = "认证通过"
                        }
                      } else if (userTypes == "服务商") {
                        app.is_show_people = false // 隐藏个人
                        if (state == "1" || state == "3" || state == "7" || state == "0") {
                          str1 = '认证中'
                        } else if (state == "2" || state == "4" || state == "5") {
                          str1 = '认证失败'
                        } else if (state == "6") {
                          str1 = '认证通过'
                        }
                      }
                    }
                  } else {
                    //判断不是在白名单里
                    if (userTypes !== undefined) {
                      if (userTypes === "个人") {
                        app.is_show_institutions = false
                        if (paystatu == "1") {
                          if (state == "1" || state == "3" || state == "7" || state == "0") {
                            str2 = '认证中'
                          } else if (state == "2" || state == "4" || state == "5") {
                            str2 = '认证失败'
                          } else if (state == "6") {
                            str2 = '认证通过'
                          }
                        } else if (paystatu == "2") {
                          str2 = '待缴费'
                        }
                      } else if (userTypes == "企业") {
                        app.is_show_people = false
                        if (paystatu == "1") {
                          if (state == "1" || state == "3" || state == "7" || state == "0") {
                            str1 = '认证中'
                          } else if (state == "2" || state == "4" || state == "5") {
                            str1 = '认证失败'
                          } else if (state == "6") {
                            str1 = '认证通过'
                          }
                        } else if (paystatu == "2") {
                          str1 = '待缴费'
                        }
                      } else if (userTypes == "服务商") {
                        app.is_show_people = false
                        if (paystatu == "1") {
                          if (state == "1" || state == "3" || state == "7" || state == "0") {
                            str1 = '认证中'
                          } else if (state == "2" || state == "4" || state == "5") {
                            str1 = '认证失败'
                          } else if (state == "6") {
                            str1 = '认证通过'
                          }
                        } else if (paystatu == "2") {
                          str1 = '待缴费'
                        }
                      }
                    }
                  }

                  app.institutionsStr = str1
                  app.peopleStr = str2
                }
                resolve()
              })
              .catch(reject)
        })
      },
		}
	}
</script>

<style lang="scss" scoped>
.certinfo{
	min-height: 100%;
	background: #fff;
	height: 100vh;
	// 认证的类型
	.ce-frist{
		background: #fff;
		padding-left: 22rpx;
		
		.cert-title{
			font-size: 26rpx;
			padding: 32rpx;
		}
		.ce-tit{
			text-align: left;
			margin: 0 26rpx 16rpx;
		}
		.ce-fbox{
			text-align: center;
			border: 2rpx solid #AAAAAA;
			border-radius: 3%;
			width: 80%;
			padding: 12rpx;
			min-height: 60rpx;
			margin: 24rpx auto ;
			
			.fbicon{
				background-image: url("../../../static/icons.png");
				background-size: cover;
				height: 80rpx;
				width: 80rpx;
				margin: 30px auto;
			}
			// 机构图标
			.fbjg{
				background-position: 0 -490rpx;
			}
			// 个人图标
			.fbgr{
				background-position: 0 -590rpx;
			}
			
			.fbdesc{
				margin:0 22rpx;
			}
			
			.fbbtn{
				color: #4A90E2;
			}
		}
	}
}
</style>
