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

    <div class="header">
      <div class="header_block">
        <img class="header_img" src="../../../static/images/contracted/contracted_index_head.png" alt="">
        <p>{{ nickName }}</p>
      </div>
      <div class="icon_block">
        <img class="header_setting" src="../../../static/images/pest/index/index_icon_01.png" alt="">
        <img class="header_setting" src="../../../static/images/pest/index/login_out.png" alt="">
      </div>
    </div>

    <div class="tab">
      <div class="tab_block">
        <div style="flex: 1;">
          <p>新住作物有限公司</p>
          <p>部门名称名称</p>
        </div>
        <img src="../../../static/images/pest/index/pest_index_icon_4.png" alt="">
      </div>
      <div class="tab_block" @click="changeTaskOption('UNFINISHED')">
        <div style="flex: 1;">
          <div class="tab_tit">
            <p>小麦</p>
            <span>切换作物 ></span>
          </div>
          <p>返青期</p>
        </div>
        <img src="../../../static/images/pest/index/pest_index_icon_5.png" alt="">
      </div>
    </div>

    <img src="../../../static/images/pest/index/pest_index_icon_6.png" width="100%" style="border-radius: 4vw;margin-top: 15px;box-shadow: 0 5PX 10PX #DDDDDD;" alt="">

    <van-grid :column-num="4" :border="false" style="background-color: #ffffff;border-radius: 4vw;overflow: hidden;margin-top: 15px;box-shadow: 0 5PX 10PX #DDDDDD;">
      <van-grid-item :to="{name:'pestAgriculturalRecords'}">
        <img src="../../../static/images/pest/index/pest_index_icon_7.png" alt="">
        <p>农事记录</p>
      </van-grid-item>
      <van-grid-item :to="{name:'insectMonitoring'}">
        <img src="../../../static/images/pest/index/pest_index_icon_8.png" alt="">
        <p>虫情监测</p>
      </van-grid-item>
      <van-grid-item :to="{name:'soilTesting'}">
        <img src="../../../static/images/pest/index/pest_index_icon_9.png" alt="">
        <p>土壤检测</p>
      </van-grid-item>
      <van-grid-item :to="{name:'weather'}">
        <img src="../../../static/images/pest/index/pest_index_icon_10.png" alt="">
        <p>气象服务</p>
      </van-grid-item>
      <van-grid-item :to="{name:'temperatureAndHumidity'}">
        <img src="../../../static/images/pest/index/pest_index_icon_11.png" alt="">
        <p>温湿度</p>
      </van-grid-item>
      <van-grid-item :to="{name:'growthMonitoring'}">
        <img src="../../../static/images/pest/index/pest_index_icon_12.png" alt="">
        <p>长势监测</p>
      </van-grid-item>
      <van-grid-item>
        <img src="../../../static/images/pest/index/pest_index_icon_13.png" alt="">
        <p>物联网设备</p>
      </van-grid-item>
    </van-grid>

    <div class="list_tt">
      <p>预警 <img src="../../../static/images/pest/index/pest_index_icon_14.png" style="vertical-align: middle;" alt=""></p>
      <p>
        <span>查看全部 ></span>
      </p>
    </div>

    <div class="list_main">
      <van-list>
        <van-swipe-cell v-for="(item,index) in 10" :key="index" >
          <div class="item" @click="goDetail(item)">
            <img src="../../../static/images/pest/index/pest_index_icon_15.png" alt="">
            <div class="info">
              <div class="title">
                <p class="news_title">物品名称名称名称名称</p>
                <p class="tips_mark">仓库</p>
              </div>
              <div class="time">
                <p>库存量 <span>+100</span></p>
                <p>预警值 <span>50</span></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: #F2F6F2 url("../../../static/images/pest/index/pest_index_bg.png") no-repeat top;
    background-size: 100% auto;
    height: 100vh;
    padding: 0 4vw;
  }

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

  /deep/ .van-grid-item{
    &:nth-child(-n+4){
      .van-grid-item__content {
        padding-bottom: 0;
      }
    }
  }

  /deep/ .van-grid-item__content{
    p{
      margin-top: 15px;
      color: #1C234C;
    }
  }

  .header{
    display: flex;
    align-items: center;
    padding: 5vh 0 0;
    .header_img{
      display: block;
      width: 10vw;
      height: 10vw;
      border-radius: 50%;
      border: 3PX solid #ffffff;
    }
    .header_block{
      display: flex;
      align-items: center;
      background-color: rgba(255,255,255,.8);
      padding-right: 5vw;
      border-radius: 100vh;
      p{
        font-size: .4rem;
        margin-left: 10px;
      }
    }
    .icon_block{
      display: flex;
      margin-left: auto;
    }
    .header_setting{
      width: 4.5vw;
      margin-bottom: auto;
      margin-left: 40px;
    }
  }

  .tab{
    display: flex;
    align-items: center;
    justify-content: space-between;
    .tab_block{
      width: 45vw;
      height: 18vw;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 2vw;
      border-radius: 4vw;
      margin-top: 3vh;
      position: relative;
      box-shadow: 0 5PX 10PX #DDDDDD;
      &:nth-child(1){
        background: #ffffff url("../../../static/images/pest/index/pest_index_icon_2.png") no-repeat center;
        background-size: 100% 100%;
      }
      &:nth-child(2){
        background: #ffffff url("../../../static/images/pest/index/pest_index_icon_3.png") no-repeat center;
        background-size: 100% 100%;
      }
      img{
        width: 10vw;
        display: block;
        margin-left: 2vw;
      }
      .tab_tit{
        display: flex;
        align-items: center;
        span{
          font-size: .25rem;
          border: 1px solid #FCC762;
          background-color: #FED565;
          color: #F58D1F;
          padding: 2px 10px;
          border-radius: 100vh;
          margin-left: auto;
        }
      }
      p{
        display: flex;
        align-items: center;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        word-break: break-all;
        overflow: hidden;
        &:nth-child(1){
          font-size: .35rem;
        }
        &:nth-child(2){
          font-size: .3rem;
          align-items: end;
          line-height: 1;
          margin-top: 2vw;
          color: rgba(28,35,76,.5);
        }
      }
    }
  }

  .list_tt{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3vh;
    p{
      &:first-child{
        font-size: .38rem;
      }
      &: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: 35vh;
    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: 14PX;
            color: #1C234C;
            text-align: center;
            flex-shrink: 0;
            background: linear-gradient(to right,#8AE15B,#BBFE9C);
            padding: 5px 25px;
            border-radius: 100vh;
          }
        }
        .time{
          font-size: 16PX;
          color: #c1c1c1;
          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;
            span{
              color: #5fe495;
              font-weight: bold;
            }
          }
          p:last-child{
            font-size: 16PX;
            text-align: center;
            flex-shrink: 0;
            span{
              color: #5fe495;
              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>
