<template>
  <view>
    <view class="user_box">
      <view class="box_left">
        <navigator url="/pages/user/settings">
          <image class="user_image" :src="userInfo.userpic"></image>
        </navigator>
      </view>
      <view class="box_center">
        <view class="user_name">{{ userInfo.username }}</view>
        <view class="user_info">{{ userInfo.phone }}</view>
      </view>
      <view class="box_right">
        <navigator url="/pages/user/info" class="company_text" v-if="!userInfo.city_id">请选择城市</navigator>
        <navigator url="/pages/user/settings" class="setting_page" v-if="userInfo.city_id">
          <image class="setting_icon" src="../../static/icon/setting.png"></image>
        </navigator>
      </view>
    </view>
    <view class="balance_content">
      <view class="balance_content_main">
        <view style="display: flex">
          <view class="price_content" style="margin-right: 45rpx"> <text class="title">当前余额（元）</text> <text>0.00</text></view>
          <view class="price_content"> <text class="title">已成功提现（元）</text> <text>0.00</text></view>
        </view>
        <view class="withdraw_btn" @click="_goWithdraw">提现</view>
      </view>
      <view class="balance_content_detail" @click="_goBalance">
        <view>查看余额明细</view>
        <view>></view>
      </view>
    </view>
    <view class="navigator_list">
      <navigator class="navigator_item" url="/pages/orders/index">
        <image class="navigator_image" src="../../static/icon/orders.png" mode=""></image>
        <view class="navigator_title">预约</view>
      </navigator>
      <navigator class="navigator_item" url="/pages/coupon/index">
        <image class="navigator_image" src="../../static/icon/coupon.png" mode=""></image>
        <view class="navigator_title">优惠券</view>
      </navigator>
      <navigator class="navigator_item" url="/pages/score/orders">
        <image class="navigator_image" src="../../static/icon/score_gift.png" mode=""></image>
        <view class="navigator_title">积分订单</view>
      </navigator>
      <navigator class="navigator_item" url="/pages/recruitment/index">
        <image class="navigator_image" src="../../static/icon/score_gift.png" mode=""></image>
        <view class="navigator_title">拉新活动</view>
      </navigator>
    </view>
    <view class="alter_info">本程序暂不提供在线交易以及支付功能，您所提交的预约，我们将验证您的购药资质并交由有售卖药品资质的商业公司与您联系确认并提供线下后续服务。</view>
    <view class="packet_content">
      <view class="close_btn" @click="closeRule"> X </view>
      <image src="../../static/icon/red_packet.gif" class="red_packet" @click="_getredpacket" />
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {
        username: "请登录",
        userpic: "../../static/icon/doctor.png",
        phone: "kailin",
        status: 0,
        city_id: 0,
      },
    };
  },
  onLoad(param) {
    // 存储分享标识
    if (param.share_uid) {
      uni.setStorageSync("share_uid", param.share_uid);
      console.log("share_uid", param.share_uid);
    }
    // #ifdef MP-WEIXIN
    //分享按钮
    uni.showShareMenu({
      withShareTicket: true,
      menus: ["shareAppMessage", "shareTimeline"],
    });
    // #endif
  },
  onShareAppMessage(obj) {
    //获取当前用户信息
    let userInfo = uni.getStorageSync("userInfo");
    let param = "";
    if (userInfo.uid) {
      param = "?share_uid=" + userInfo.uid;
    }
    // 获取分享信息
    let shareList = getApp().globalData.shareList;
    // 获取分享信息
    let shareObj = {
      title: "药优惠 得积分 兑豪礼",
      //path: '/pages/score/lottery',
      path: "/pages/user/index",
      imageUrl: "",
    };
    // 循环列表
    for (let i in shareList) {
      if (shareList[i].pages == "pages/user/index") {
        shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
        shareObj.title = shareList[i].title ? shareList[i].title : shareObj.title;
        shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
      }
    }
    if (param) {
      shareObj.path += param;
    }
    // 返回分享信息
    return shareObj;
  },
  onShow() {
    // 登录提示
    if (!this.$checkAccess.alterLogin()) return;
    // 判断数据
    this.$http.request("api/custom/get_info").then((callback) => {
      if (callback.code == "success") {
        if (!callback.data.userpic) callback.data.userpic = "../../static/icon/doctor.png";
        // 赋值
        this.userInfo = callback.data;
        // 存储登录标识
        uni.setStorageSync("userInfo", callback.data);
      }
    });
  },
  methods: {
    _getredpacket() {
      uni.navigateTo({
        url: "/pages/redpacket/list",
      });
    },
    _goWithdraw() {
      uni.navigateTo({
        url: "/pages/user/withdraw",
      });
    },
    _goBalance() {
      uni.navigateTo({
        url: "/pages/balance/index",
      });
    },
  },
};
</script>

<style lang="less">
.user_box {
  width: 680rpx;
  height: 180rpx;
  overflow: hidden;
  background: #ffffff;
  padding: 10rpx 35rpx;
  .box_left {
    float: left;
    display: block;
    width: 140rpx;
    height: 140rpx;
    .user_image {
      display: block;
      width: 120rpx;
      height: 120rpx;
      border-radius: 50%;
      margin: 10rpx auto;
    }
  }
  .box_center {
    float: left;
    width: 300rpx;
    height: 140rpx;
    margin-left: 35rpx;
    .user_name {
      font-size: 30rpx;
      line-height: 80rpx;
    }
    .user_info {
      color: #999999;
      font-size: 24rpx;
      line-height: 60rpx;
    }
  }
  .box_right {
    float: right;
    width: 140rpx;
    height: 140rpx;
    font-size: 20rpx;
    line-height: 140rpx;
    .setting_page {
      width: 140rpx;
      height: 140rpx;
      display: block;
      overflow: hidden;
      .setting_icon {
        width: 60rpx;
        height: 60rpx;
        display: block;
        margin: 40rpx auto;
      }
    }
    .company_text {
      color: #e03519;
      width: 140rpx;
      height: 140rpx;
      font-size: 20rpx;
      text-align: center;
      line-height: 140rpx;
    }
  }
}
.navigator_list {
  display: flex; // 弹性盒模型
  overflow: hidden;
  margin: 20rpx auto;
  background: #ffffff;
  padding: 35rpx 0rpx;
  .navigator_item {
    float: left;
    height: 160rpx;
    display: block;
    margin: 0rpx auto;
    text-align: center;
    .navigator_image {
      width: 80rpx;
      height: 80rpx;
      margin: 20rpx auto;
      border-radius: 5rpx;
    }
    .navigator_title {
      width: 120rpx;
      display: block;
      font-size: 30rpx;
      line-height: 40rpx;
      text-align: center;
    }
  }
}
.alter_info {
  display: block;
  color: #e03519;
  font-size: 20rpx;
  overflow: hidden;
  margin: 20rpx auto;
  background: #ffffff;
  line-height: 40rpx;
  padding: 35rpx 35rpx;
}
.balance_content {
  margin: 20rpx;
  padding: 35rpx;
  background-color: #fff;
  box-sizing: border-box;
  .balance_content_main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 36rpx;
    .price_content {
      display: flex;
      flex-direction: column;
      > .title {
        font-size: 24rpx;
        margin-bottom: 15rpx;
      }
    }
    .withdraw_btn {
      color: #ffffff;
      background-color: #169bd5;
      border-radius: 60rpx;
      padding: 10rpx 20rpx;
      width: 90rpx;
      text-align: center;
      line-height: 40rpx;
    }
  }
  .balance_content_detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 2rpx solid #f3f3f3;
    font-size: 24rpx;
    padding-top: 18rpx;
  }
}
.packet_content {
  position: absolute;
  right: 0;
  bottom: 15%;
  width: 160rpx;
  height: 160rpx;
  .red_packet {
    width: 100%;
    height: 100%;
  }
  .close_btn {
    width: 40rpx;
    height: 40rpx;
    font-size: 24rpx;
    line-height: 40rpx;
    border-radius: 50%;
    border: 1rpx solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 5rpx;
    left: 0;
  }
}
</style>
