<template>
  <div class="app-container">

    <div class="header">
      <img class="header_img" src="../../../static/images/contracted/contracted_index_head.png" alt="">
      <div class="header_block">
        <p>欢迎，{{ nickName }}</p>
        <p>{{ phone }}</p>
      </div>
      <van-popover
        v-model="showPopover"
        trigger="click"
        :actions="actions"
        @select="onSelect"
        placement="bottom-end"
      >
        <template #reference>
          <img class="header_setting" src="../../../static/images/contracted/contracted_index_icon_1.png" alt="">
        </template>
      </van-popover>
    </div>

    <div class="tab">
      <div :class="{active:taskOption=='FINISHED'}" @click="changeTaskOption('FINISHED')">
        <p><img src="../../../static/images/contracted/contracted_index_icon_4.png" alt="">已完成任务</p>
        <p><span>{{ surveyTask['FINISHED'].length }}</span>个</p>
      </div>
      <div :class="{active:taskOption=='UNFINISHED'}" @click="changeTaskOption('UNFINISHED')">
        <p><img src="../../../static/images/contracted/contracted_index_icon_5.png" alt="">进行中任务</p>
        <p><span>{{ surveyTask['UNFINISHED'].length }}</span>个</p>
      </div>
    </div>

    <div class="list_tt">
      <p>任务清单({{surveyTask[taskOption].length}})</p>
      <p>
        <span><i></i>已完成</span>
        <span><i></i>总数</span>
      </p>
    </div>

    <div class="list_main">
      <van-list>
        <van-swipe-cell v-for="item in surveyTask[taskOption]" :key="item.id" >
          <div class="item" @click="goDetail(item)">
            <img src="../../../static/images/contracted/contracted_index_icon_6.png" alt="">
            <div class="info">
              <div class="title">
                <p class="news_title">{{item.parentName}} {{item.deptName}}</p>
                <p class="tips_mark">{{item.cbfFinishNum}}</p>
              </div>
              <div class="time">
                <p>{{item.surUsernames}}</p>
                <p>{{item.cbfNum}}</p>
              </div>
            </div>
          </div>
          <!-- <template #right>
            <div class="operation">
              delete 删除 edit编辑 view查看 list榜单
              <div class="opera_btn">
                <img src="../../assets/images/sunVillage_info/signature_icon_02.png" alt="" width="35">
                <p>签名</p>
              </div>
              <div class="opera_btn" style="margin: 0 10px;">
                <img src="../../assets/images/sunVillage_info/signature_icon_03.png" alt="" width="35">
                <p>预览</p>
              </div>
              <div class="opera_btn">
                <img src="../../assets/images/sunVillage_info/signature_icon_04.png" alt="" width="35">
                <p>电子合同</p>
              </div>
              <div class="opera_btn">
                <img src="../../assets/images/sunVillage_info/signature_icon_04.png" alt="" width="35">
                <p>线下合同</p>
              </div>
            </div>
          </template> -->
        </van-swipe-cell>
      </van-list>
    </div>

  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import { listSurveyTask } from "@/api/contracted";
  import { getInfo, logout } from "@/api/login";

  export default {
    name: "contractedIndex",
    data() {
      return {
        showPopover: false,
        // 通过 actions 属性来定义菜单选项
        actions: [
          { text: '修改密码',value:1 },
          { text: '退出登录',value:2 }
        ],
        nickName: null,
        phone: null,
        // 调查任务
        surveyTask: {
          'FINISHED': [],         // 已完成任务
          'UNFINISHED': []        // 进行中任务
        },
        // 任务选项
        taskOption: 'FINISHED',
      };
    },
    created() {
      this.getUserInfo();
    },
    methods: {
      getUserInfo() {
        getInfo().then(response => {
          this.nickName = response.user.nickName;
          this.phone = response.user.phonenumber;
          this.getList(response.user.userId);
        });
      },
      getList(userId){
        listSurveyTask({userId: userId}).then(response => {
          this.surveyTask = response.data;
        });
      },
      goDetail(item){
        // 调查任务完成状态：已完成标记为1，未完成标记为2
        let status = '1';
        if (item.surStatus === 'UNFINISHED') {
          status = '2';
        }
        Cookies.set('taskStatus', status, { expires: 30 });
        this.$router.push({path:'/contracted/village/contractor', query: { deptId: item.deptId, deptName: item.deptName }})
      },
      onSelect(action) {
        switch (action.value) {
          case 1:
            this.$router.push({path:'/contracted/user/passWord'})
            break;
          case 2:
            this.loginOut();
            break;
        }
      },
      changeTaskOption(option) {
        this.taskOption = option;
      },
      loginOut() {
        logout().then(res => {
          this.$router.push({ path: '/contracted/login' });
        })
      }
    },
  };
</script>
<style scoped lang="scss">

  .app-container{
    background: #fff url("../../../static/images/contracted/contracted_index_bg.png") no-repeat center;
    background-size: 100% 100%;
    height: 100vh;
    padding: 0 4vw;
  }

  /deep/ .van-popover__wrapper{
    margin-left: auto;
  }

  .header{
    display: flex;
    align-items: center;
    padding: 5vh 0 0;
    .header_img{
      display: block;
      width: 15vw;
      height: 15vw;
      border-radius: 50%;
      border: 3PX solid #ffffff;
    }
    .header_block{
      margin-left: 4vw;
      p{
        font-size: .4rem;
        &:nth-child(1){
          font-size: .5rem;
          font-weight: bold;
          margin-bottom: 1vh;
        }
      }
    }
    .header_setting{
      margin-left: auto;
      width: 6vw;
      margin-bottom: auto;
    }
  }

  .tab{
    display: flex;
    align-items: center;
    justify-content: space-between;
    .active{
      box-shadow: 0 5PX 10PX #c9c9c9;
    }
    div{
      width: 44vw;
      height: 22vw;
      display: flex;
      flex-direction: column;
      justify-content: center;
      padding: 0 5vw;
      border-radius: 4vw;
      margin-top: 3vh;
      position: relative;
      &:nth-child(1){
        background: url("../../../static/images/contracted/contracted_index_icon_2.png") no-repeat center;
        background-size: 100% 100%;
      }
      &:nth-child(2){
        background: url("../../../static/images/contracted/contracted_index_icon_3.png") no-repeat center;
        background-size: 100% 100%;
      }
      p img{
        width: 5vw;
        display: block;
        margin-right: 2vw;
      }
      p{
        display: flex;
        align-items: center;
        &:nth-child(1){
          font-size: .4rem;
        }
        &:nth-child(2){
          font-size: .3rem;
          align-items: end;
          line-height: 1;
          padding-left: 8vw;
          margin-top: 2vw;
          span{
            font-size: .5rem;
            font-weight: bold;
            margin-right: 2vw;
          }
        }
      }
    }
  }

  .list_tt{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3vh;
    p{
      &:first-child{
        font-size: .38rem;
        font-weight: bold;
      }
      &:last-child{
        span{
          color: #999999;
          margin-left: 2vh;
          i{
            display: inline-block;
            width: 1vh;
            height: 1vh;
            border-radius: 100%;
            margin-right: 5PX;
          }
          &:first-child i{
            background: #fc8e13;
          }
          &:last-child i{
            background: #5fe495;
          }
        }
      }
    }
  }

  .list_main{
    margin-top: 15PX;
    height: 65vh;
    overflow-y: scroll;
    .item{
      border-radius: 30px;
      background: #fff;
      box-shadow: 4px 6px 5px rgba(63, 68, 75, 0.1);
      padding:25px 32px;
      margin-bottom: 20px;
      display: flex;
      align-items: center;
      img{
        width: 12%;
        margin-right: 2vh;
      }
      .info{
        flex: 1;
        .title{
          display: flex;
          font-size: 32px;
          align-items: center;
          height: 58px;
          justify-content: space-between;
          .news_title{
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            word-break: break-all;
            overflow: hidden;
            font-weight: bold;
          }
          .tips_mark{
            font-size: 16PX;
            color: #fc8e13;
            text-align: center;
            flex-shrink: 0;
            font-weight: bold;
          }
        }
        .time{
          font-size: 16PX;
          color: #999999;
          display: flex;
          align-items: center;
          margin-top: 5PX;
          justify-content: space-between;
          p:first-child{
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            word-break: break-all;
            overflow: hidden;
          }
          p:last-child{
            font-size: 16PX;
            color: #5fe495;
            text-align: center;
            flex-shrink: 0;
            font-weight: bold;
          }
        }
      }
    }

    .operation{
      display: flex;
      align-items: center;
      justify-content: right;
      text-align: center;
      border-radius: 30px;
      background: #fff;
      box-shadow: 4px 6px 5px rgba(63, 68, 75, 0.1);
      height: 100%;
      padding: 0 15Px;
      margin-left: 10PX;
      .opera_btn{
        border-radius: 50%;
        &.delete{
          background:#df0707;
          margin-left: 10PX;
          .icon{
            width: 22PX;
            height: 29PX;
            background: url('../../assets/images/sunVillage_info/signature_icon_03.png') no-repeat;
            background-size: 100% 100%;
            display: block;
          }
        }
        &.edit{
          background: #79cf13;
          margin-left: 10PX;
          .icon {
            width: 26PX;
            height: 25PX;
            background: url('../../assets/images/sunVillage_info/signature_icon_02.png') no-repeat;
            background-size: 100% 100%;
            display: block;
          }
        }
        &.view{
          background: #3494ff;
          margin-left: 10PX;
          .icon {
            width: 29PX;
            height: 21PX;
            background: url('../../assets/images/sunVillage_info/signature_icon_04.png') no-repeat;
            background-size: 100% 100%;
            display: block;
          }
        }
        &.list{
          background: #79cf13;
          margin-left: 10PX;
          .icon {
            width: 29px;
            height: 21px;
            background: url('../../assets/images/sunVillage_info/list_icon_10.png') no-repeat;
            background-size: 100% 100%;
            display: block;
          }
        }
      }
    }
  }

</style>
