<template>
  <div class="in-activity-wrap">
    <h5header 
      v-if="isWeb" 
      title="云鹊奖2019" 
      :baseShowHeight="25" 
      :shareObj="shareObj"
      :isCheckAuth="true" 
      @checkAuth="handleLoginCheck"
    />
    <!-- 顶部的四个阶段 进度条 -->
    <ul class="top-process-bar">
      <li v-for="(item, index) in stageDateList" :class="returnStageClass(item, index)">
        <p class="title">{{ item.title }}</p>
        <p class="date">{{ item.date }}</p>
      </li>
    </ul>

    <div class="big-bg-wrap">
      <div class="award-wrap">
        <div class="stage-rule">
          <img class="stage-text" :src="returnStageText()" alt="">
          <img class="rule-btn" src="../assets/img/stage-two/rule-btn.png" alt="" @click="handleRuleBtnClick">
        </div>
        <img class="reward-pic" :src="returnAwardPic()" alt="">
      </div>

      <!-- 未登录 -->
      <div v-if="!isLogin" class="not-login-wrap">
        <img class="gold-coin" src="../assets/img/stage-two/gold-coin.png" alt="">
        <img class="head-icon" src="../assets/img/stage-two/default-login-icon.png" alt="">  
        <div class="content-info">
          <p class="not-login-text">您还未登录</p>
          <p class="tips">登录并加入机构参加活动</p>
        </div>
        <div class="go-login login-but-no-join" @click="goToLogin">去登录<img src="../assets/img/stage-two/right-icon-small.png" alt=""></div>
      </div> 

      <!-- 已登录，但没有加入机构  -->
      <div v-if="isLogin && !isJoin" class="not-login-wrap ">
        <img class="gold-coin" src="../assets/img/stage-two/gold-coin.png" alt="">
        <img class="head-icon" v-if="doctorInfo.avatarImageUrl" :src="doctorInfo.avatarImageUrl" alt="">
        <img class="head-icon" v-else src="../assets/img/stage-two/default-login-icon.png" alt="">  
        <div class="content-info">
          <p class="not-login-text">{{ doctorInfo.name }}</p>
          <p class="tips">尚未加入一个机构</p>
        </div>
        <div class="go-login login-but-nojoin" @click="goToJoin">加入机构<img src="../assets/img/stage-two/right-icon-small.png" alt=""></div>
      </div> 


      <!-- 已登录 且 已加入机构 -->
      <div v-if="isLogin && isJoin" class="user-info-wrap">
        <img class="gold-coin" src="../assets/img/stage-two/gold-coin.png" alt="">
        <div class="basic-info">
          <div class="head-icon">
            <img v-if="doctorInfo.avatarImageUrl" :src="doctorInfo.avatarImageUrl" alt="">
            <img v-else src="../assets/img/stage-two/default-login-icon.png" alt="">
          </div>
          <div class="name-info">
            <p class="name">{{ doctorInfo.name }}</p>
            <p class="company">{{ doctorInfo.hospital }}</p>
          </div>
          <div @click="goToUserDetail" class="detail">个人明细<img src="../assets/img/stage-two/right-icon-small.png" alt=""></div>
        </div>

        <ul class="billboard-wrap">
          <li>
            <p class="title">个人今日勤奋分</p>
            <p class="score">{{doctorInfo.userDayScore}}</p>
            <p class="rank"><img src="../assets/img/stage-two/billboard-flag.png" alt="">今日排名{{doctorInfo.userDayRank}}</p>
            <div @click="goToUserBoard" class="billboard-btn">查看个人榜单<img src="../assets/img/stage-two/right-icon-small.png" alt=""></div>
          </li>
          <li class="organ">
            <p class="title">机构累计勤奋分</p>
            <p class="score">{{doctorInfo.hospitalScore}}</p>
            <p class="rank"><img src="../assets/img/stage-two/billboard-flag.png" alt="">累计排名{{doctorInfo.hospitalRank}}</p>
            <div @click="goToOrganBoard" class="billboard-btn">查看机构榜单<img src="../assets/img/stage-two/right-icon-small.png" alt=""></div>
          </li>
        </ul>
        <p class="score-tips">{{ returnScoreAwardTips }}</p>
        <div class="bean-wrap">
          <p class="personal-total-get">累计个人获得：<span>{{doctorInfo.userTotalBonus}}云鹊豆</span></p>
          <div @click="goToBeanCenter" class="bean-center">云鹊豆中心<img src="../assets/img/stage-two/right-icon-small.png" alt=""></div>
        </div>
        <p class="bean-tips">机构勤奋分达成目标，全员可获云鹊豆</p>
        <div class="bean-stage">
          <img :src="returnBeanImg" alt="">
          <ul class="score-list">
            <li v-for="item in doctorInfo.hospitalLevelScore">达{{item}}分</li>
            <li>12月30日</li>
          </ul>
        </div>
      </div>
    </div>

    <!-- 邀请医生好友学课程 -->
    <div class="invite-doctor-wrap">
      <img class="top-head-icon" src="../assets/img/stage-two/invite-doctor-top.png" alt="">
      <p class="invite-tips">每邀请1位医生好友领取课程，+{{ eachInviteAward.mark }}勤奋分 +{{ eachInviteAward.bean }}云鹊豆</p>
      <div class="invite-list-wrap">
        <ul class="invite-list">
          <template v-if="!isLogin || !isJoin">
            <li>
              <div class="add-btn" @click="eachDoctorClick">
                <img src="../assets/img/stage-two/add-pic-icon.png" alt="">
              </div>
            </li>
            <li>
              <div class="add-btn" @click="eachDoctorClick">
                <img src="../assets/img/stage-two/add-pic-icon.png" alt="">
              </div>
            </li>
            <li>
              <div class="add-btn" @click="eachDoctorClick">
                <img src="../assets/img/stage-two/add-pic-icon.png" alt="">
              </div>
            </li>
            <li>
              <div class="add-btn" @click="eachDoctorClick">
                <img src="../assets/img/stage-two/add-pic-icon.png" alt="">
              </div>
            </li>
          </template>
          <template v-if="isLogin && isJoin">
            <!-- 已邀请的 -->
            <li v-for="item in inviteList">
              <img @click="eachDoctorClick" v-if="item.avatarImageUrl" class="doctor-icon" :src="item.avatarImageUrl" alt="">   
              <img @click="eachDoctorClick" v-else class="doctor-icon" src="../assets/img/stage-two/default-doctor-icon.png" alt="">   
              <p class="text">{{ item.doctorName ? item.doctorName : item.mobile }}</p>
            </li>
            <!-- 未邀请的 -->
            <template v-if="inviteList && inviteList.length < 4">
              <li v-for="item in notInviteShowList">
                <div class="add-btn" @click="eachDoctorClick">
                  <img src="../assets/img/stage-two/add-pic-icon.png" alt="">
                </div>
              </li>
            </template>
          </template>
          <!-- 查看更多 -->
          <li>
            <div @click="seeMore" class="add-btn">
              <img class="right-icon-big" src="../assets/img/stage-two/right-icon-big.png" alt="">
            </div>
            <p class="text see-more">查看更多</p>
          </li>
        </ul>
      </div>
      <div class="invite-btn">
        <img src="../assets/img/stage-two/invite-btn.png" alt="" class="invite-btn">
        <p @click="handleInviteClick" class="text">去邀请</p>
      </div>
      <div class="login-tips">被邀请好友登录APP，收益X4倍</div>
    </div>

    <!-- 每日任务 -->
    <div class="daily-task">
      <div class="top-center-bar">每日任务</div>
      <ul class="task-list">
        <!-- taskList -->
        <li v-for="item in taskList">
          <img class="left-icon" :src="returnEachTaskIcon(item)" alt="">
          <div class="center-wrap">
            <p class="title">{{ item.ruleName }}</p>
            <p class="detail-text">{{returnUnderAwardTips(item)}}</p>
          </div>
          <div @click="goToFinish(item)" :class="returnEachTaskStatus(item)">{{ returnIconText(item) }}</div>
        </li>
      </ul>
    </div>

    <!-- 底部云鹊logo -->
    <div class="bottom-logo">
      <img src="" alt="">
    </div>

    <!-- 打卡成功 弹窗 -->
    <div v-if="clockSuccessVisible" class="toast-wrap" @touchmove.prevent>
      <div class="full-screen-mask"></div>
      <div class="content-wrap">
        <img class="back-image" src="../assets/img/stage-two/clock-success-bg.png" alt="">
        <!-- <img class="back-image" src="../assets/img/stage-two/win-award-bg.png" alt=""> -->
        <!-- <img class="back-image" src="../assets/img/stage-two/award-cup-bg.png" alt=""> -->
        <p class="title">打卡成功</p>
        <p class="message">已获得: {{vm.clockAward.mark}}勤奋分, {{vm.clockAward.bean}}云鹊豆</p>
        <div @click="hideClockModal" class="bottom-btn">我知道了</div>
        <div class="close-btn"></div>
      </div>
    </div>

    <!-- 活动结束 弹窗-->
    <div v-if="activityEndVisible" class="toast-wrap" @touchmove.prevent>
      <div class="full-screen-mask"></div>
      <div class="content-wrap activity-end">
        <p class="content-text">本次活动已结束，感谢您的参与，最终获奖排名将于12月30日10点公布，届时查看</p>
        <ul class="btn-list">
          <li>我知道了</li>
          <li class="high-light">查看昨日获奖</li>
        </ul>
      </div>
    </div>

  </div>
</template>

<script>
  import { getUserScoreInfo, getInviteList, getClockStatus, goToUpdateClock } from '@/service/activityMainpage';
  import { checkHospitalStatus } from '@/service';
  import h5header from '@/components/h5header';
  import { getShareUrl } from '@/utils/index';
  import { Toast } from 'vant';

  const cookies = require('cookie-universal')();
            
  
  let vm = null;
  export default {
    data () {
      return {
        serverTime: '',
        isLogin: false,  // 是否 已登录
        isJoin: false,    // 是否 已加入机构  默认为false
        joinStatus: 3,    // 1-已加入机构 2-机构在审核中状态 3-未加入机构
        currentStage: 0, // 当前处于第几阶段  0表示不在四个阶段里，1-4表示对应阶段，取图片地址用
        stageDateList: [
          { date: '12月16至19日', beginDate: '2019/12/16 00:00:00', endDate: '2019/12/19 23:59:59', title: '高血压学习', award: '小米电视' },
          { date: '12月20至23日', beginDate: '2019/12/20 00:00:00', endDate: '2019/12/23 23:59:59', title: '糖尿病学习', award: '米家洗衣机' },
          { date: '12月24至26日', beginDate: '2019/12/24 00:00:00', endDate: '2019/12/26 23:59:59', title: '中医学习', award: '米家两门冰箱' },
          { date: '12月27至29日', beginDate: '2019/12/27 00:00:00', endDate: '2019/12/29 23:59:59', title: '全科学习', award: '荣耀 Play3' },
        ],
        awardList: {
          No1: '',
          No3: '欧姆龙血压计',
          No10: '欧姆龙体温计',
        },
        appUserInfo: {
          userName: '',
          userMobile: '',
          doctorId: '',
          userToken: '',
          // appVersion: '',
          // systemType: '',
        },
        eachInviteAward: {  // 每邀请1位医生好友领取课程，+??勤奋分 +??云鹊豆 （默认均为20）
          mark: 20,  // 勤奋分 
          bean: 20,  // 云鹊豆
        },
        doctorInfo: {
          name: '',                              // 接口返回用户名字或者手机号带遮掩
          hospital: '',                          // 机构名称
          avatarImageUrl: '',                    // 头像URL
          userDayScore: '1000',                  // 用户当日勤奋分
          userDayRank: '2',                      // 用户当日排名
          hospitalScore: '6000',                 // 机构累计勤奋分
          hospitalRank: '8',                     // 机构累计排名
          userTotalBonus: '7777',                // 个人累计获得云鹊豆
          hospitalLevelScore: [100, 300, 700],   // 三阶段达标分值, 数组返回
          targetRequiredScore: '10',             // 再获得多少分  // 再获得10勤奋分即可上升到前10名获得欧姆龙温度计
          targetRank: '5',                       // 上升到多少名
        },
        
        clockSuccessVisible: false,    // 是否显示 打卡成功 弹窗
        activityEndVisible: false,     // 是否显示 活动结束 弹窗

        inviteList: [],                // 已邀请的用户列表
        notInviteShowList: [],         // 未邀请的默认显示
        
        taskList: [],   // 打卡、课程、SMO
        taskObj: {
          clock: null,   // 打卡
          lesson: null,  // 课程
          smo: null,     // 患者招募
        },
        isClockFinish: false,  // 是否打卡
        clockAward: {          // 打卡的奖励 默认都是5
          mark: 5,
          bean: 5,
        },
        isWeb: false,
        shareObj: {}
      }
    },
    components: {
      h5header,
    },
    computed: {
      returnBeanImg() {
        let hospitalScore = vm.doctorInfo.hospitalScore;
        let arr = vm.doctorInfo.hospitalLevelScore;
        if( hospitalScore < arr[0]){
          return require(`../assets/img/stage-two/bean-stage-0.png`);
        }else if( ((arr[0] == hospitalScore) || (arr[0] < hospitalScore)) && (hospitalScore < arr[1]) ){
          return require(`../assets/img/stage-two/bean-stage-1.png`);
        }else if( ((arr[1] == hospitalScore) || (arr[1] < hospitalScore)) && (hospitalScore < arr[2]) ){
          return require(`../assets/img/stage-two/bean-stage-2.png`);
        }else if( ((arr[2] == hospitalScore) || (arr[2] < hospitalScore)) ){
          return require(`../assets/img/stage-two/bean-stage-3.png`);
        }else{
          return require(`../assets/img/stage-two/bean-stage-0.png`);
        }
      },
      returnScoreAwardTips() {
        let award = '';
        if( vm.doctorInfo && vm.doctorInfo.userDayRank ) {
          let userDayRank = vm.doctorInfo.userDayRank;
          if( userDayRank == 1 ){
            return `今日保持第1名，可获得${vm.awardList.No1}`;
          }else if( userDayRank < 4 ){  // 2-3 提示 再获得X勤奋分即可上升到前Y名获得 第1名奖品
            award = vm.awardList.No1;
          }else if( userDayRank < 11 ){ // 4-10 提示 再获得X勤奋分即可上升到前Y名获得 第3名奖品
            award = vm.awardList.No3;
          }else{  // 10名以后 提示：再获得X勤奋分即可上升到前Y名获得 第10名奖品
            award = vm.awardList.No10;
          }
          return `再获得${vm.doctorInfo.targetRequiredScore}勤奋分即可上升到前${vm.doctorInfo.targetRank}名获得${award}`
        }
      }
    },
    created() {
      vm = this;
      // 取服务器时间，切换不同时间段的显示
      vm.getServerTime();
      
    },
    mounted() {
      vm.shareObj = {
        shareUrl: window.location.href,
        title1: '分享title分享title',
        title2: '分享desc分享desc',
        shareImageUrl: 'https://file.yunqueyi.com/h5/nzhd19/share.png'
      }
      vm.isWeb = vm.$rocNative.isWeb;

      vm.getTasks();  // 放到登录后或其他************************

      vm.$rocNative.appInit();
      vm.getUserInfo();   // 判断是否登录

      if (process.client) {
          window.__refresh = function(params) {
            vm.getUserInfo();   // 判断是否登录
            
          }
      }
    },
    methods: {
      // 获取服务器时间
      getServerTime() {
        // 调取接口获取服务器时间
        let serverTime = 11111;
        
      },
      hideClockModal() {
        vm.clockSuccessVisible = false;
      },
      returnStageText() {
        if(vm.currentStage == 0){
          return '';
        }else{
          return require(`../assets/img/stage-two/stage-0${vm.currentStage}-text.png`);
        }
      },
      returnAwardPic() {
        if(vm.currentStage == 0){
          return '';
        }else{
          return require(`../assets/img/stage-two/award-0${vm.currentStage}-pic.png`)
        }
      },
      returnStageClass(item, index){    // 返回顶部四个时间进度条状态 
        // debugger;
        // 获取当前服务器时间  获取失败则用本地时间 ***************************************************
        let currentTime = 1577376000000 || new Date().getTime();


        let beginTime = new Date(item.beginDate).getTime();
        let endTime = new Date(item.endDate).getTime();
        let status = '';
        if( currentTime < beginTime ){  // 未开始
          status = '';
        }else if( (currentTime == beginTime) || (beginTime < currentTime && currentTime < endTime) || (currentTime == endTime) ){  // 活动中
          status = 'active';
          vm.awardList.No1 = item.award;  // 根据时间段来设置第1名奖品
          vm.currentStage = index + 1; // 决定显示第几张图片
        }else{  // 已结束
          status = 'over';
        };
        return status;
      },
      // 判断用户是否登录？
      getUserInfo() {
        vm.$rocNative 
        .getUserInfo()
        .then(params => {
          // _seft.userToken = params.userToken;  // 存到store里
          if(params && params.userToken){
            cookies.set('token', params.userToken)
          }

          alert(JSON.stringify(params));
          if(params && params.userMobile){   // 已登录 （有手机号表示 已登录，无手机号表示 未登录）
            vm.isLogin = true;
            vm.appUserInfo = params;
            vm.loginCallback();

            
          }else{  // 未登录
            vm.isLogin = false;
          }
        });
      },
      
      // 调用APP登录弹窗
      appLogin() {
        vm.$rocNative.gotoLogin();
      },
      // 登陆ok后 回调： 获取邀请的医生列表等。。
      loginCallback() {
        
        vm.getUserActivityInfo();  
        vm.goToCheckJoin();
      },
      getUserActivityInfo() {  // 获取用户及参加活动的具体信息
        getUserScoreInfo().then(res => {
          alert('获取用户及分数信息。。。');
          alert(JSON.stringify(res))
          
        });
        // 请求接口
        vm.doctorInfo = {
          name: '云鹊医',                              // 接口返回用户名字或者手机号带遮掩
          hospital: '上海协和医院',                          // 机构名称
          avatarImageUrl: 'https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1575272062&di=90feeb5bbc9d7f7122f74be154c6f69c&src=http://b-ssl.duitang.com/uploads/item/201709/06/20170906180625_YNysd.jpeg',                    // 头像URL
          userDayScore: '111',                  // 用户当日勤奋分
          userDayRank: '11',                      // 用户当日排名
          hospitalScore: '600',                 // 机构累计勤奋分
          hospitalRank: '444',                     // 机构累计排名
          userTotalBonus: '555',                // 个人累计获得云鹊豆
          hospitalLevelScore: [111, 222, 333],   // 三阶段达标分值, 数组返回
          targetRequiredScore: '99',             // 再获得多少分  // 再获得10勤奋分即可上升到前10名获得欧姆龙温度计
          targetRank: '3',                       // 上升到多少名
        };
      },
      goToCheckJoin() {   // 检查是否加入结构
        checkHospitalStatus(vm.appUserInfo.userToken).then(res => {
          alert('检查是否加入结构')
          alert(JSON.stringify(res))
          if(res && res.code == '000000' ){
            const status = res.data.status;
            // const status = 15;  // test。。。。。。。。。。。。。。。。。
            if (status && status == 1) { // 机构状态正常
              vm.isJoin = true;
              vm.joinStatus = 1;
              vm.getTaskStatus(vm.clockAward);
              vm.handleGetInviteList();   //登录且已加入机构才获取医生邀请了的列表 
            }else if (status && status == 15) { // 15创建机构审核中
              vm.isJoin = false;
              vm.joinStatus = 2;
            }else {  // 除了1,15 都是未加入机构
              vm.isJoin = false;
              vm.joinStatus = 3;
            }
          }else{
            vm.$toast(res.message);
          }
        });
      },
      handleGetInviteList() {
        // let token = '5463439BE4444FF8BC47CC4575E9D550';   //  开发时用这个调用数据
        // let token = vm.appUserInfo.userToken;          //  正式上线 用这个！！！！
        getInviteList().then(res => {
          alert(JSON.stringify('获取邀请的列表 OK'));
          alert(JSON.stringify(res));

          if(res && res.code == '000000'){
            // alert
            if(res.data && res.data.list){
              vm.inviteList = res.data.list;
              // alert(vm.inviteList.length)
              vm.notInviteShowList = [];
              if( vm.inviteList.length > 4 || vm.inviteList.length == 4 ){
                vm.inviteList.length = 4;
              }else{
                let notInviteLength = 4 - vm.inviteList.length;
                for(let i=0; i<notInviteLength; i++){
                  vm.notInviteShowList.push({
                    notInvite: true
                  })
                }
              }
            }else{
              vm.inviteList = [];
            }

          }else{
            vm.$toast(res.message);
          }
        })
      },
      // 活动规则
      handleRuleBtnClick() {
        alert('跳转至 活动规则页面')
      },
      // 去登录
      goToLogin() {
        alert('去登录...');
        vm.appLogin();
      },
      // 去加入机构
      goToJoin() {
        alert('去加入机构...')
        // 用户点击【加入机构】，继续判断用户是否有创建机构在审核状态，若有，则弹出弹窗提示。若无则跳转加入机构页面
        if( vm.joinStatus == 2 ){        // 机构审核中
          alert('去机构审核中。。。。')
          this.$dialog.confirm({
            title: '提醒',
            message: `抱歉，您创建的机构【${vm.doctorInfo.hospital}】正在审核中，审核通过后可参与活动<br/><br/>如有疑问可联系客：<span>400-920-8877</span><br/>(周一至周五9:00-18:00)`,
            confirmButtonText: '查看进度',
            cancelButtonText: '我知道了',
            className: 'remind-success',
          }).then(() => {
            this.checkVersion(()=>{
              if (this.$rocNative.isAndroid) {
                this.$rocNative.setNeedClearUrl({ url: 'year_end_ssr' });
              }
              this.$rocNative.gotoInstitutionalReview({ url: window.location.href });
            });
          });

        }else if( vm.joinStatus == 3 ){  // 未加入机构
          alert('未加入机构。。。。。')
          this.checkVersion(()=>{
            if (this.$rocNative.isAndroid) {
              this.$rocNative.setNeedClearUrl({ url: 'year_end_ssr' });
            }
            this.$rocNative.gotoActivityHospital({ url: window.location.href });
          })
        }

      },
      checkVersion(callback){
        this.$rocNative.getAppVersionCode().then(res => {
          const appVersion = parseFloat(res.versionCode.replace(/\./g, ''));
          if(appVersion>=317){
            callback();
          }else{
            this.$dialog.alert({
              message: '当前app版本过低，请升级版本后继续操作',
              className: 'version-toast'
            });
          }
        });
      },
      handleLoginCheck(cb) {
        if( !this.isLogin ){                       // 未登录 >>>  去登录
          this.goToLogin();
        }else if( this.isLogin && !this.isJoin ){  // 已登录 && 未加入机构  >>>>  去加入机构
          this.goToJoin();
        }else if( this.isLogin && this.isJoin ){   // 已登录 && 已加入机构  >>>>  去详情页？？
          cb && cb();
        }
      },

      // 跳转至 个人明细 
      goToUserDetail() {
        alert('跳转至 个人明细')
        this.$router.push({
          name: 'person-detail',
        });
      },
      // 查看个人榜单
      goToUserBoard() {
        alert('跳转至 个人榜单')
        this.$router.push({
          name: 'person-ranking',
        });
      },
      // 查看机构榜单
      goToOrganBoard() {
        alert('跳转至 机构榜单')
        this.$router.push({
          name: 'hospital-ranking',
        });
      },
      // 云鹊豆中心
      goToBeanCenter() {
        let url = getShareUrl() + 'integral/#/chirpCenter';
        alert(url)
        let paramList = [
          {
            "key":"pageUrl",
            "value": url,
            "type":4,
            "seqNo":1
          },{
            "key":"showTitle",
            "value": false,
            "type":1,
            "seqNo":2
          },{
            "key":"title",
            "value": '',
            "type":1,
            "seqNo":3
          }
        ]
        vm.$rocNative.dispatchEventByModuleCode && vm.$rocNative.dispatchEventByModuleCode({
            modeCode: 'M300',
            jsonString: paramList
        })

      },

      // “邀请医生好友学课程” 列表中的每一个医生点击事件 跳转至邀请详情页
      eachDoctorClick() {
        let cb = this.goToDoctorPage;
        this.handleLoginCheck(cb);
      },
      // 跳转至邀请详情页
      goToDoctorPage() {  //“被邀请的用户模块“点击逻辑，点击用户头像、“+“或者查看更多，都跳转至邀请详情页
        this.$router.push({
          name: 'invite-details',
        });
      },

      //“邀请医生好友学课程” 查看更多
      seeMore() {
        let cb = this.seeInviteMore;
        this.handleLoginCheck(cb);
      },
      // 跳转至 “查看更多” 页面
      seeInviteMore() {
        this.$router.push({
          name: 'invite-details',
        });
      },

      // 去邀请 按钮
      handleInviteClick() {
        let cb = this.goToShare;
        this.handleLoginCheck(cb);
      },
      goToShare() {
        alert('调app分享');
        // let id = vm.encryptDoctorId();
        let params = {
          id: '',
          taskId: '',
          activityId: '',
        };
        // 调用APP分享

      },
      encryptDoctorId() {
        // 给id加密
        // return 'dddddd'
      },

      // 去打卡 按钮
      goToFinish(item) {
        let cb = () => {
          vm.goToFinishCB(item);
        };
        this.handleLoginCheck(cb);
      },
      goToFinishCB(item) {
        // resourceType 业务类型  1.课程 2.考试 3.调查问卷 4.患者招募 5.宣教漫画 6.打卡 7.邀请
        if( item.resourceType == 6 ){
          // 执行打卡接口
          if( vm.isClockFinish ){  // 已打卡，不执行，未打卡，去调用打卡接口
            // 已打卡，不处理
          }else{ // 未打卡，去打卡
            let params = {
              activityId: item.activityId,
              taskId: item.id,
            };
            goToUpdateClock(params).then(res => {
              alert(JSON.stringify('goTO 更新去打卡状态'));
              alert(JSON.stringify(res));

              if(res && res.code == '000000'){
                if(res.data){  // 打卡成功
                  vm.clockSuccessVisible = true;
                }else{ 
                  vm.$toast(res.message);
                }
              }else{
                vm.$toast(res.message);
              }
            })
          }
        }
      },

      // 每个任务的跳转点击
      handleTaskClick() {
        let cb = this.goToTask;
        this.handleLoginCheck(cb);
      },
      goToTask() {
        console.log('do每个任务的跳转逻辑')
      },
      // 获取每日任务 及 邀请医生好友学课程里的 邀请1位医生的勤奋分及云鹊豆个数
      getTasks() {
        // debugger;
        let res = {
            "data": {
              "loginStatus": 2,
              "taskRuleData": [
                {
                  "id": 14,
                  "activityId": 2, 
                  "resourceType": 7,   // 业务类型  1.课程 2.考试 3.调查问卷 4.患者招募 5.宣教漫画 6.打卡 7.邀请
                  "resourceId": "1",  
                  "resourceChildId": null, 
                  "defaultBackgroundImage": "https://test1-file.yunqueyi.com/image/png/common/2019112809513020.png",
                  "finishBackgroundImage": null,  
                  "taskFrequency": 1,   
                  "finishFrequency": 1,
                  "cumulativeFrequency": null, 
                  "ruleName": "邀请好友测试",  
                  "beginTime": "2019-11-26 00:00:00",  
                  "endTime": "2019-11-27 23:59:59",  
                  "linkId": 1703,  
                  "rewardJsonInfo": [{rewardType:3,rewardQuantity:"100"},{rewardType:1,rewardQuantity:"200"}], 
                  "pushType": 1,
                  "pushLinkUrl": "",
                  "hideEndFlag": 2,   
                  "seqNo": 1,  
                  "deleteFlag": 1,
                  "createdId": 161,
                  "createdTime": "2019-11-28 09:51:58",
                  "modifiedId": 161,
                  "modifiedTime": "2019-11-29 15:30:54",
                  "beginTimeStr": null,
                  "endTimeStr": null,
                  "nowCumulativeFrequency": 0,   
                  "isFinish": 0,   
                  "doctorFinishFrequency": null,  
                  "timeStatus": 1  // 项目时间状态 1.进行中 2.结束 3.未开始
                },
                {
                  "id": 15,
                  "activityId": 2,
                  "resourceType": 6,  // 业务类型  1.课程 2.考试 3.调查问卷 4.患者招募 5.宣教漫画 6.打卡 7.邀请
                  "resourceId": "2",
                  "resourceChildId": null,
                  "defaultBackgroundImage": "https://test1-file.yunqueyi.com/image/png/common/2019112809513020.png",
                  "finishBackgroundImage": null,
                  "taskFrequency": 1,
                  "finishFrequency": 1,
                  "cumulativeFrequency": null,
                  "ruleName": "每日打卡test",
                  "beginTime": "2019-11-26 00:00:00",
                  "endTime": "2019-11-27 23:59:59",
                  "linkId": 1703,
                  "rewardJsonInfo": [{rewardType:3,rewardQuantity: 111},{rewardType:1,rewardQuantity:0}],
                  "pushType": 1,
                  "pushLinkUrl": "",
                  "hideEndFlag": 2,
                  "seqNo": 2,
                  "deleteFlag": 1,
                  "createdId": 161,
                  "createdTime": "2019-11-28 09:51:58",
                  "modifiedId": 161,
                  "modifiedTime": "2019-11-29 15:30:54",
                  "beginTimeStr": null,
                  "endTimeStr": null,
                  "nowCumulativeFrequency": 0,
                  "isFinish": 0,
                  "doctorFinishFrequency": null,
                  "timeStatus": 1
                },
                {
                  "id": 15,
                  "activityId": 2,
                  "resourceType": 1,   // 业务类型  1.课程 2.考试 3.调查问卷 4.患者招募 5.宣教漫画 6.打卡 7.邀请
                  "resourceId": "2",
                  "resourceChildId": null,
                  "defaultBackgroundImage": "https://test1-file.yunqueyi.com/image/png/common/2019112809513020.png",
                  "finishBackgroundImage": null,
                  "taskFrequency": 1,
                  "finishFrequency": 1,
                  "cumulativeFrequency": null,
                  "ruleName": "高血压课程",
                  "beginTime": "2019-11-26 00:00:00",
                  "endTime": "2019-11-27 23:59:59",
                  "linkId": 1703,
                  "rewardJsonInfo": [{rewardType:3,rewardQuantity: 222},{rewardType:1,rewardQuantity:0}],
                  "pushType": 1,
                  "pushLinkUrl": "",
                  "hideEndFlag": 2,
                  "seqNo": 2,
                  "deleteFlag": 1,
                  "createdId": 161,
                  "createdTime": "2019-11-28 09:51:58",
                  "modifiedId": 161,
                  "modifiedTime": "2019-11-29 15:30:54",
                  "beginTimeStr": null,
                  "endTimeStr": null,
                  "nowCumulativeFrequency": 0,
                  "isFinish": 1,
                  "doctorFinishFrequency": null,
                  "timeStatus": 1
                },
                {
                  "id": 15,
                  "activityId": 2,
                  "resourceType": 4,   // 业务类型  1.课程 2.考试 3.调查问卷 4.患者招募 5.宣教漫画 6.打卡 7.邀请
                  "resourceId": "2",
                  "resourceChildId": null,
                  "defaultBackgroundImage": "https://test1-file.yunqueyi.com/image/png/common/2019112809513020.png",
                  "finishBackgroundImage": null,
                  "taskFrequency": 1,
                  "finishFrequency": 1,
                  "cumulativeFrequency": null,
                  "ruleName": "SMO患者招募",
                  "beginTime": "2019-11-26 00:00:00",
                  "endTime": "2019-11-27 23:59:59",
                  "linkId": 1703,
                  "rewardJsonInfo": [{rewardType:3,rewardQuantity: 0},{rewardType:1,rewardQuantity:99}],
                  "pushType": 1,
                  "pushLinkUrl": "",
                  "hideEndFlag": 2,
                  "seqNo": 2,
                  "deleteFlag": 1,
                  "createdId": 161,
                  "createdTime": "2019-11-28 09:51:58",
                  "modifiedId": 161,
                  "modifiedTime": "2019-11-29 15:30:54",
                  "beginTimeStr": null,
                  "endTimeStr": null,
                  "nowCumulativeFrequency": 0,
                  "isFinish": 0,
                  "doctorFinishFrequency": null,
                  "timeStatus": 1
                }
            ],
            "activityData": {
              "id": 2,
              "activityName": "hws-test",
              "isDisabled": 1,
              "unloginBackgroundImage": "https://test1-file.yunqueyi.com/image/png/common/20191129095943428.png",
              "loginBackgroundImage": "https://test1-file.yunqueyi.com/image/png/common/20191129095948283.png",
              "rewardType": "5",
              "beginTime": "2019-11-25 00:00:00",
              "endTime": "2019-11-30 23:59:59",
              "beginTimeStr": null,
              "endTimeStr": null,
              "deleteFlag": 1,
              "createdId": 161,
              "createdTime": "2019-11-26 10:43:40",
              "modifiedId": 161,
              "modifiedTime": "2019-11-29 15:30:54",
              "status": null
            }
          },
          "code": "000000",
          "message": "成功"
        };

        

        let data = res.data;
        let taskRuleData = data.taskRuleData || [];
        
        for(let i=0; i<taskRuleData.length; i++){
          let item = taskRuleData[i];
          let rewardList = [];
          // 获取 邀请节点，进行中 此时获取邀请1个医生对应的 分数 和 豆子 
          if( item.resourceType == 7 && item.resourceId == 1 && item.timeStatus == 1){  
            rewardList = item.rewardJsonInfo || [];
            for( let j=0; j<rewardList.length; j++ ){
              if( rewardList[j].rewardType == 3 ){        // 勤奋分
                vm.eachInviteAward.mark = rewardList[j].rewardQuantity;
              }else if( rewardList[j].rewardType == 1 ){  // 云鹊豆
                vm.eachInviteAward.bean = rewardList[j].rewardQuantity;
              }
            }
          }else if( item.resourceType == 6 && item.timeStatus == 1 ){   // 打卡 默认奖励 5分 5豆
            item.eachInviteAwardMark = 5;  
            item.eachInviteAwardBean = 5;  
            item = vm.formatEachTaskAward(item);
            vm.clockAward = {
              mark: item.eachInviteAwardMark,
              bean: item.eachInviteAwardBean,
              activityId: item.activityId,
              id: item.id,
            };
            vm.taskObj.clock = item;
            
          }else if( item.resourceType == 1 && item.timeStatus == 1 ){  // 课程 默认奖励 20分 20豆
            item.eachInviteAwardMark = 20;  
            item.eachInviteAwardBean = 20;  
            item = vm.formatEachTaskAward(item);

            vm.taskObj.lesson = item;
          }else if( item.resourceType == 4 && item.timeStatus == 1 ){  // smo 没奖励分 默认奖励100豆
            item.eachInviteAwardBean = 100;  
            item = vm.formatEachTaskAward(item);

            vm.taskObj.smo = item;
          }
        };
        vm.taskList = [];
        if( vm.taskObj.clock ){
          vm.taskList.push( vm.taskObj.clock );
        }
        if( vm.taskObj.lesson ){
          vm.taskList.push( vm.taskObj.lesson );
        }
        if( vm.taskObj.smo ){
          vm.taskList.push( vm.taskObj.smo );
        }
        

      },
      getTaskStatus(params) {
        vm.isClockFinish = false;
        getClockStatus(params).then(res => {
          alert(JSON.stringify('GET  GET 打卡状态获取 OK'));
          if(res && res.code == '000000'){
            text = !!res.data ? '已打卡' : '去打卡';
            vm.isClockFinish = !!res.data;  
          }else{
            vm.$toast(res.message);
          }
        })
      },
      returnUnderAwardTips(item) {
        if( typeof item.eachInviteAwardMark != 'undefined' && item.eachInviteAwardMark != '0' ){
          return `+${item.eachInviteAwardMark}勤奋分 +${item.eachInviteAwardBean}云鹊豆`;
        }else{
          return `+${item.eachInviteAwardBean}云鹊豆`;
        }
      },

      // 格式化数据
      formatEachTaskAward(item) {
        let rewardList = item.rewardJsonInfo || [];
        for( let j=0; j<rewardList.length; j++ ){
          if( rewardList[j].rewardType == 3 ){        // 勤奋分
            item.eachInviteAwardMark = rewardList[j].rewardQuantity;
          }else if( rewardList[j].rewardType == 1 ){  // 云鹊豆
            item.eachInviteAwardBean = rewardList[j].rewardQuantity;
          }
        };
        return item;
      },

      // ddd
      // 返回每个任务 icon
      returnEachTaskIcon(item) {    // resourceType 业务类型  1.课程 2.考试 3.调查问卷 4.患者招募 5.宣教漫画 6.打卡 7.邀请
         if( item.resourceType == 6 ){  
           return require('../assets/img/task-icon/daily-clock-icon.png');
         }else if( item.resourceType == 1 ) {
           return require('../assets/img/task-icon/lesson-icon.png');
         }else if( item.resourceType == 4 ){
           return require('../assets/img/task-icon/smo-icon.png');
         }else{
           return require('../assets/img/task-icon/daily-clock-icon.png');
         }
      },
      returnEachTaskStatus(item) {
        if( item.resourceType == 6 ){
          return vm.isClockFinish ? 'right-btn done' : 'right-btn'
        }else{
          return item.isFinish == 0 ? 'right-btn done' : 'right-btn'
        }
      },

      // 返回任务右边的按钮文案
      returnIconText(item) {
        let text = '去完成';
        if( item.resourceType == 6 ){
          return vm.isClockFinish ? '已打卡' : '去打卡';
        }
        if( item.resourceType == 1 ){  // 1-课程
          text = item.isFinish == 0 ? '已完成' : '去学习';
        }else if( item.resourceType == 4 ){  // 4-smo
          text = item.isFinish == 0 ? '已完成' : '去完成';
        }
        return text;
      },

    },  
  }
</script>>

<style lang="less">
  @import '../assets/style/in-activity.less';
</style>
<style lang="less">
  @import '../assets/style/revant.less';
</style>