<!-- 我的 -->
<template>
  <div class="page_my">
    <div class="myTop">
      <img src="../../assets/images/myBanner.png" alt />
      <div class="avatar">
        <div v-if="adminid != 0" style="width:100%;height:100%">
          <img v-if="roleInfo.avatar != ''" :src="roleInfo.avatar" alt />
          <img
            v-if="roleInfo.avatar == ''"
            src="../../assets/images/mydefault.png"
            alt
          />
        </div>
        <img
          v-else
          src="../../assets/images/mydefault.png"
          alt
        />
      </div>
      <div class="userMain" @click="toMyIndex">
        <div class="userBox">
          <div class="userTxt">
            <span v-if="roleInfo.user_name != ''"
              ><p class="userName">{{ roleInfo.user_name }}</p></span
            >
            <span v-if="roleInfo.user_name == ''"
              ><p class="userName">{{ userName.name }}</p></span
            >
            <p class="signature">{{ roleInfo.message }}</p>
          </div>
          <van-icon name="arrow" class="arrow" />
        </div>
      </div>
      <router-link to="/invite">
        <div class="invitebox">
          <img src="../../assets/images/invite.png" alt />
        </div>
      </router-link>

      <div class="myInfo" @click="toMyInfo">
        <div class="myInfoLeft">
          <img src="../../assets/images/myIcon1.png" alt />
          <p>我的信息</p>
        </div>
        <van-icon class="arrow" name="arrow" />
      </div>

       <router-link to="/ElectronicSignature">
        <div class="myInfo1">
          <div class="myInfoLeft">
            <img src="../../assets/images/myIcon9.png" alt />
            <p>电子签名</p>
          </div>
          <van-icon class="arrow" name="arrow" />
        </div>
       </router-link>
    </div>

    <div class="myBox">
      <div class="myBoxOne">
        <div class="myInfoLeft">
          <img src="../../assets/images/myIcon2.png" alt />
          <p>我的医院/组织/团队</p>
        </div>
      </div>
      <div
        class="myBoxTwo noBorder"
        v-for="(item, index) in organaziton"
        :key="index"
      >
        <div class="myInfoLeft">
          <span v-if="item.org_logo == ''"
           ><img src="../../assets/images/m01.png" alt
          /></span>
          <span v-if="item.org_logo !== ''"><img :src="item.org_logo"/></span>
          <p  @click="toManage(item.admin_user_id,item.id)">{{ item.org_name }}</p>
        </div>

        <div class="myInfoRight">
          <div
            v-if="item.creator == $store.getters.user.org.creator && position == 1"
            class="myInfoRightBtn"
            @click="toEditOrg()"
          >
            管理
          </div>
          <van-icon
            class="arrow"
            name="arrow"
            @click="toManage(item.admin_user_id,item.id)"
          />
        </div>
      </div>
    </div>
    <div class="myBox">
      <router-link to="/perfectOrg">
        <div class="myBoxOne">
          <div class="myInfoLeft">
            <img src="../../assets/images/myIcon3.png" alt />
            <p>创建医院/组织/团队</p>
          </div>
          <van-icon class="arrow" name="arrow" />
        </div>
      </router-link>
      <router-link to="/modifypsw" v-if="this.organaziton[0].org_id!=10683">
        <div class="myBoxOne">
          <div class="myInfoLeft">
            <img src="../../assets/images/myIcon4.png" alt />
            <p>修改密码</p>
          </div>
          <van-icon class="arrow" name="arrow" />
        </div>
      </router-link>
    </div>
    <div class="myBox">
      <router-link to="/about">
        <div class="myBoxOne">
          <div class="myInfoLeft">
            <img src="../../assets/images/myIcon7.png" alt />
            <p>关于我们</p>
          </div>
          <van-icon class="arrow" name="arrow" />
        </div>
      </router-link>
    </div>
    <div class="myBox" @click="LoginOut">
      <div class="myBoxOne" @click="LoginOut">
        <div class="myInfoLeft">
          <img src="../../assets/images/myIcon8.png" alt />
          <div>
            <p>退出登录</p>
          </div>
        </div>
        <van-icon class="arrow" name="arrow" />
      </div>
    </div>
  </div>
</template>
<script>
import {
  getMyInformation,
  LoginOut,
  getMyOrganazition,
  getMyInforName,
  getMyInformationThree,
  getMyOrgInformation,
  getMyInformationFour,
  getRolePosition,
  getOrgs
} from '@/api/patient/patient'
import { uParseTime } from '@/utils/tools'
import { GetHomeData } from '@/api/home'
import { setRem } from '@/libs/functionRem'
export default {
  data () {
    return {
      roleInfo: {},
      admin_user_id: 0,
      adminid: 0,
      organaziton: [],
      userName: {},
      creator: 0,
      ids: 0,
      isCreateOrg: false,
      org_id: 0,
      cretor: 0,
      position: 0
    }
  },
  methods: {
    LoginOut () {
      LoginOut(this.adminid).then(response => {
        if (response.data.state === 1) {
          var msg = response.data.data.msg
          // console.log("msg是", msg);
          this.$store.dispatch('SetScheduals', {})
          this.$store.dispatch('SetWaitScheduals', {})

          this.isRouterAlive = false
          this.$nextTick(function () {
            this.isRouterAlive = true
          })
          localStorage.removeItem('searchWord')
          this.$router.push('/')
        }
      })
    },
    GetHomeData () {
      GetHomeData().then(response => {
        if (response.data.state === 1) {
          var orgs = response.data.data.orgs
          // console.log("orgs", orgs);
          // this.organaziton = orgs;
          this.isCreateOrg = response.data.data.isCreateOrg
          var cretor = response.data.data.cretor
          //  console.log("cretor", cretor);
          this.cretor = cretor
        }
      })
    },
    getOrgs () {
      getOrgs().then(response => {
        if (response.data.state === 1) {
          var orgs = response.data.data.orgs
          // console.log('orgs', orgs)
          
          this.organaziton = orgs
        }
      })
    },
    getRoleids (ids) {
      var arr = []
      arr = ids.split(',')
      var arr2 = [...new Set(arr)]
      // console.log(arr2)
      getRoleids(arr2).then(response => {})
    },
    getMyInformation (id) {
      getMyInformation(id).then(response => {
        if (response.data.state === 1) {
          var roleInfo = response.data.data.roleInfo

          this.admin_user_id = roleInfo.id
          this.adminid = roleInfo.admin_user_id
          this.roleInfo = roleInfo
        }
      })
    },
    getMyInforName (id) {
      getMyInforName(id).then(response => {
        if (response.data.state === 1) {
          var Rolename = response.data.data.Rolename
          var username = response.data.data.Username
          this.userName = username
        }
      })
    },
    getTime (time) {
      // return uParseTime(time, "{y}-{m}-{d} {h}:{i}:{s}");
      return uParseTime(time, '{y}-{m}-{d}')
    },
    toFeed () {
      this.$router.push('/feedBack?id=' + this.admin_user_id)
    },
    toMyInfo () {
      if (this.adminid == 0) {
        this.$router.push('/myInfo?id=' + this.admin_user_id)
      }
      if (this.adminid !== 0) {
        this.$router.push(
          '/myInfo?id=' + this.adminid + '&orgid=' + this.org_id
        )
      }
    },
    toManage (id, orgid) {
      this.$router.push('/organizationinfo?id=' + id + '&orgid=' + orgid)
    },
    toEditOrg () {
      // this.$router.push('/editorg?id=' + id)
      this.$router.push('/manageconsole')
    },
    toMyIndex () {
      this.$router.push('/myInfo?id=' + this.ids + '&orgid=' + this.org_id)
    },
    getMyInformationThree (id) {
      getMyInformationThree(id).then(response => {
        if (response.data.state === 1) {
          var roleInfo = response.data.data.roleInfo
          // console.log("无机构", roleInfo);
          this.roleInfo = roleInfo
          this.roleInfo.user_name = roleInfo.name
          this.admin_user_id = roleInfo.id
        }
      })
    },
    // 获取机构信息
    getMyOrgInformation (creator) {
      getMyOrgInformation(creator).then(response => {
        if (response.data.state === 1) {
          var information = response.data.data.information
          this.roleInfo = information
        }
      })
    },
    getMyInformationFour () {
      getMyInformationFour().then(response => {
        var Username = response.data.data.Username
        // console.log("userName", Username);
        this.roleInfo = Username
        this.adminid = Username.admin_user_id
        this.org_id = Username.org_id
        this.ids = Username.admin_user_id
      })
    },
    getRolePosition () {
      getRolePosition().then(response => {
        if (response.data.state === 1) {
          var names = response.data.data.names
          // console.log('names', names)
          var arr = []
          arr = names.split(',')
          var arr2 = [...new Set(arr)]
          // console.log('arr2', arr2)
          for (let i = 0; i < arr2.length; i++) {
            if (arr2[i] == '超级管理员' || arr2[i] == '子管理员') {
              this.position = 1
            }
          }
        }
      })
    }
  },
  created () {
    setRem()
    this.GetHomeData()
    var creator = this.$store.getters.user.org.creator
    // console.log('creator', creator)
    if (creator === 0) {
      var adminid = this.$store.getters.user.admin.id
      this.getMyInformationThree(adminid)
      this.adminid = 0
      var adminid = this.$store.getters.user.admin.id
      this.ids = adminid
      return false
    }
    if (creator !== 0) {
      this.getMyInformationFour()
    }
    this.getRolePosition()
    this.getOrgs()
  }
}
</script>
<style lang="scss" scoped>
.page_my {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: #fafafa;
  .myTop {
    position: relative;
    height: 20rem;
    img {
      width: 100%;
      height: 11.25rem;
    }
    .avatar {
      position: absolute;
      left: 1rem;
      top: 2.5rem;
      width: 4.375rem;
      height: 4.375rem;
      background: rgba(50, 50, 50, 1);
      // border: 2px solid rgba(255, 255, 255, 1);
      border-radius: 50%;
      img {
        border-radius: 50%;
        width: 100%;
        height: 100%;
      }
    }
    .userMain {
      position: absolute;
      left: 6.25rem;
      top: 3.375rem;
      width: 70%;
      color: #fff;
      .arrow {
        font-size: 1rem;
      }
    }
    .userBox {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .userName {
      font-size: 1.25rem;
      margin-bottom: 0.625rem;
    }
    .signature {
      font-size: 0.75rem;
    }
    .invitebox {
      // width: 21.5625rem;
      height: 4.75rem;
      position: absolute;
      top: 8.75rem;
      left: 0.9375rem;
      right: 0.9375rem;
      box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.16);
      img {
        height: 100%;
        width: 100%;
      }
    }
    .myInfo {
      width: 100%;
      height: 3.125rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 2.25rem;
      padding: 0 0.875rem;
      background: #fff;
      border-bottom: 1px solid #e5e5e5;
      .myInfoLeft {
        display: flex;
        align-items: center;
        height: 100%;
        img {
          width: 1.125rem;
          height: 1.125rem;
          margin-right: 0.5rem;
          border-radius: 50%;
        }
        p {
          margin-top: 0.125rem;
          font-size: 1rem;
        }
      }
      .arrow {
        font-size: 1rem;
        color: #9f9f9f;
      }
    }
    .myInfo1 {
      width: 100%;
      height: 3.125rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 0.875rem;
      background: #fff;
      .myInfoLeft {
        display: flex;
        align-items: center;
        height: 100%;
        img {
          width: 1.125rem;
          height: 1.125rem;
          margin-right: 0.5rem;
          border-radius: 50%;
        }
        p {
          margin-top: 0.125rem;
          font-size: 1rem;
        }
      }
      .arrow {
        font-size: 1rem;
        color: #9f9f9f;
      }
    }
  }
  .myBox {
    margin: 0.8125rem 0;
    background: #fff;
    > a:last-child > div {
      border: none;
    }
    > div:last-child {
      border: none;
    }
    .myBoxOne {
      width: 100%;
      height: 3.125rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 0.875rem;
      border-bottom: 1px solid #e5e5e5;
      font-size: 1rem;
      .myInfoLeft {
        display: flex;
        align-items: center;
        height: 100%;
        img {
          width: 1.125rem;
          height: 1.125rem;
          margin-right: 0.5rem;
        }
        // p {
        //   margin-top: 0.125rem;
        // }
      }
      .arrow {
        color: #9f9f9f;
      }
    }
    .myBoxTwo {
      height: 3.125rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-right: 0.875rem;
      background: #fff;
      margin-left: 2.5rem;
      border-bottom: 1px solid #e5e5e5;
      font-size: 1rem;
      .myInfoLeft {
        display: flex;
        align-items: center;
        height: 100%;
        img {
          width: 1.875rem;
          height: 1.875rem;
          margin-right: 0.5rem;
          border-radius: 50%;
        }
        // p {
        //   margin-top: 0.125rem;
        // }
      }
      .myInfoRight {
        display: flex;
        align-items: center;
        .myInfoRightBtn {
          width: 3.625rem;
          height: 1.875rem;
          background: rgba(255, 255, 255, 1);
          border: 1px solid rgba(51, 138, 251, 1);
          border-radius: 0.3125rem;
          text-align: center;
          line-height: 1.875rem;
          color: #338afb;
          font-size: 0.9375rem;
          margin-right: 0.625rem;
        }
      }
      .arrow {
        color: #9f9f9f;
      }
    }
  }
  a {
    color: #000;
  }
}
</style>
