<template>
  <div class="page">
    <div class="header-bg">
      <div class="header-info">
        <div class="wrap" @click="handleLogin()">
          <div class="user-img-div">
            <img :src="user.avatarUrl" alt="" class="user-img" v-if="user.id && user.avatarUrl"/>
            <open-data type="userAvatarUrl" lang="zh_CN" class="user-img" v-else/>
          </div>
          <div class="user-info">
            <div class="option">
              <template v-if="!user.id">
                <p>登录</p>
                <p>点击进行登录</p>
              </template>
              <template v-else>
                <p v-if="isApprove">{{ user.realName }}</p>
                <p v-else>{{ user.nickName }}</p>
                <p>{{ user.areaName || "" }}</p>
              </template>
            </div>
            <p class="info" v-if="user.id" @click.stop="$linkTo('./userInfo')">个人信息</p>
          </div>
        </div>
      </div>
    </div>
    <div class="approve">
      <img class="icon" src="./authentication-img.png" alt="">
      <div class="flex">
        <span class="cert" v-if="isApprove" v-text="approveLabel" @click="$linkTo('/mods/AppPartyAuth/AppPartyAuth')"/>
        <u-icon v-else name="arrow-right" color="#E7F2FF" size="28"
                :label="approveLabel" label-color="#E7F2FF" label-pos="left" @click="approve"/>
      </div>
    </div>
    <div class="list-wrap">
      <div class="card" v-for="(group,index) in listGroup" :key="index">
        <div class="item" v-for="(item) in group" hover-class="bg-hover" :key="item.label"
             @click="linkTo(item.path, item.type)">
          <div class="block">
            <img class="icon" :src="item.icon" alt="">
          </div>
          <span class="desc" v-if="!item.share">{{ item.label }}</span>
          <button open-type="share" v-else>
            <span>{{ item.label }}</span>
          </button>
        </div>
      </div>
    </div>
    <AiLogin ref="login" @success="getAuth()"/>
  </div>
</template>
<script>
import {mapActions, mapState} from "vuex";

export default {
  name: "AppPcMine",
  appName: "我的",
  customNavigation: true,
  computed: {
    ...mapState(['user', 'token']),
    isApprove() {
      return this.user?.status == 2;
    },
    approveLabel() {
      return this.user?.partyStatusForWX == 2 ? "已认证" :
          this.user?.partyStatusForWX == 1 ? "审核中" :
          this.user?.partyStatusForWX == 3 ? "认证失败" : "前往认证"
    },
    listGroup() {
      return [
        [
          // {
          //   icon: "https://cdn.cunwuyun.cn/wxmp/mine/wodejiating.png",
          //   label: "我的家庭",
          //   path: "./myFamily",
          //   type: 'idNumber'
          // },
          {
            icon: "https://cdn.cunwuyun.cn/wxmp/mine/wodejiaxiang.png",
            label: "我的家乡",
            path: "/mods/AppHometown/AppHometown",
            type: 'token'
          }
        ],
        // [
        //   {
        //     icon: "https://cdn.cunwuyun.cn/wxmp/mine/wodejifen.png",
        //     label: "我的积分",
        //     path: "/mods/AppCreditPoints/AppCreditPoints?type=detail",
        //     type: 'idNumber'
        //   },
        //   {
        //     icon: "https://cdn.cunwuyun.cn/wxmp/mine/chaoshidingdan.png",
        //     label: "超市订单",
        //     path: "/mods/AppOrderList/AppOrderList",
        //     type: 'idNumber'
        //   },
        //   {
        //     icon: "https://cdn.cunwuyun.cn/wxmp/mine/banshijindu.png",
        //     label: "办事进度",
        //     path: "/mods/AppMyPlan/AppMyPlan",
        //     type: 'idNumber'
        //   }
        // ],
      ]
    }
  },
  methods: {
    ...mapActions(['getUserInfo']),
    approve() {
      if (!this.token) {
        this.$refs.login.show();
      } else if (!this.isApprove) {
        if (this.user.status == 0) {
          this.$linkTo('/mods/AppPartyAuth/AppPartyAuth');
        } else {
          this.$linkTo('/mods/AppPartyAuth/partyAuthSuccess')
        }
      }
    },
    linkTo(url, type) {
      if (type) {
        if (this.token) {
          if (type == 'token') {
            this.$linkTo(url)
          }
          if (type == 'idNumber') {
            if (this.user.status == 0) {
              if (!this.user.phone) {
                this.$linkTo('/pages/phone/bingPhoneNumber?from=auth')
              } else {
                this.$linkTo('/mods/AppAuth/AppAuth')
              }
            } else {
              this.$linkTo(url)
            }
          }
        } else {
          this.$refs.login.show()
        }
      } else {
        this.$linkTo(url)
      }
    },
    handleLogin() {
      if (!this.token) {
        this.$refs.login.show();
      }
    },
    getAuth() {
      this.$nextTick(() => {
        this.token && this.getUserInfo()
      })
    }
  },
  onShow() {
    this.getAuth();
  },
  onShareAppMessage() {
    return {
      title: `欢迎使用数字平昌~`,
      path: `/pages/AppHome/AppHome`
    }
  },
}
</script>
<style scoped lang="scss">
@import "~dvcp-wui/common";

.page {
  width: 100%;
  min-height: 100%;
  background-color: #F3F6F9;
  position: relative;

  .header-bg {
    width: 100%;
    height: 512px;
    position: relative;

    .header-info {
      width: 100%;
      height: 100%;
      background: url("https://cdn.cunwuyun.cn/wxmp/sanjianxi/mineBg.png") no-repeat no-repeat;
      background-size: 100% 100%;
      box-sizing: border-box;
      padding: 240px 0 0 48px;

      .wrap {
        width: 100%;
        height: 96px;
        display: flex;
        align-items: center;

        .user-img-div {
          display: inline-block;
          width: 96px;
          height: 96px;
          border-radius: 50%;
          overflow: hidden;
          border: 4px solid #FFFFFF;
          flex-shrink: 0;

          .user-img {
            display: inline-block;
            width: 96px;
            height: 96px;
            border-radius: 58px;
          }
        }

        .user-info {
          flex: 1;
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-left: 26px;
          box-sizing: border-box;
          padding-right: 32px;

          .option {
            & > p:first-child {
              font-size: 34px;
              font-weight: 600;
              color: #333333;
              line-height: 54px;
            }

            & > p:last-child {
              font-size: 26px;
              font-weight: 400;
              color: #7088A0;
              line-height: 36px;
            }
          }

          .info {
            width: 136px;
            height: 48px;
            border-radius: 8px;
            border: 2px solid #7088A0;
            font-size: 26px;
            font-weight: 400;
            color: #7088A0;
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }
      }
    }
  }

  .approve {
    position: absolute;
    left: 50%;
    top: 400px;
    transform: translateX(-50%);
    width: 686px;
    height: 112px;
    background: linear-gradient(90deg, #8FB4FF 0%, #4181FF 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    padding: 0 20px;

    .icon {
      width: 296px;
      height: 52px;
    }

    .cert {
      font-family: PingFangSC-Regular, PingFang SC;
      font-size: 28px;
      color: #E7F2FF;
      margin-right: 4px;
    }
  }

  .list-wrap {
    box-sizing: border-box;
    padding: 32px;

    .card {
      width: 100%;
      min-height: 100px;
      border-radius: 16px;
      background-color: #fff;
      margin-bottom: 32px;

      .item {
        height: 100px;
        display: flex;
        align-items: center;

        &:last-child {
          .desc {
            border-bottom: none !important;
          }
        }

        .block {
          width: 80px;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          flex-shrink: 0;

          .icon {
            width: 44px;
            height: 44px;
          }
        }

        .desc, & > button {
          height: 100%;
          flex: 1;
          font-size: 30px;
          font-weight: 400;
          color: #666666;
          display: flex;
          align-items: center;
          border-bottom: 1px solid #EEEEEE;

          & > span {
            width: 100%;
            height: 100%;
            text-align: left;
            display: flex;
            align-items: center;
          }

          &::after {
            border: none;
          }
        }

        .no-border {
          border-bottom: none;
        }
      }

      &:first-of-type {
        margin-bottom: 32px;
      }
    }
  }

}
</style>
