<template>
  <div class="home_wrapper">
    <!--  头部开始  -->
    <div class="header">
      <div class="header_left" @click="onClickLeft">
        <img src="../../../../static/images/agriculturalTrusteeship/return.png">
        <p>退出登录</p>
      </div>
<!--      <p class="header_right" @click="showDeptId = true">{{deptName}}</p>-->
<!--      <van-popup v-model="showDeptId" position="bottom" get-container="body">-->
<!--        <van-cascader-->
<!--          v-model="villageValue"-->
<!--          title="请选择"-->
<!--          :options="deptOptions"-->
<!--          @close="showDeptId = false"-->
<!--          @finish="onConfirmDept"-->
<!--          active-color="#1989fa"-->
<!--          :field-names="hcAreaInfoFieldName"-->
<!--        />-->
<!--      </van-popup>-->
    </div>
    <!--  头部结束  -->

    <div class="nav">
      <div class="content">
        <van-cell :border="false" center>
          <template #title>
            <p class="tt">机构信息</p>
          </template>
          <template #right-icon>
<!--            v-if="serviceForm.auditStatus != '3'"-->
            <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_edit.png" @click="$router.push({name:'agriculturalTrusteeshipServiceEdit'})">
          </template>
        </van-cell>

        <van-field
          readonly
          label="机构名称"
          left-icon="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_com.png"
          input-align="right"
          :border="false"
        />

        <van-cell :border="false">
          <template #title>
            <div class="serviceName">
              <span :class="{'active':serviceForm.auditStatus == '3'}">{{serviceForm.auditStatus == '1'?'待审核':serviceForm.auditStatus == '3'?'已通过':serviceForm.auditStatus == '2'?'驳回':''}}</span>
              <p>{{serviceForm.financialName}}</p>
            </div>
          </template>
        </van-cell>

        <van-field
          readonly
          :value="serviceForm.linker"
          label="姓名"
          left-icon="../../../../static/images/agriculturalTrusteeship/login/login_icon_name.png"
          input-align="right"
          :border="false"
          placeholder="姓名"
        />

        <van-field
          readonly
          :value="serviceForm.phone"
          label="联系方式"
          left-icon="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_phone.png"
          input-align="right"
          :border="false"
          placeholder="联系方式"
        />

      </div>
    </div>

    <!--  内容开始  -->
    <div class="main">

      <div class="main_btn" v-if="serviceForm.financialType == '1'">
        <div class="btn_box_01" @click="$router.push({name:'agriculturalTrusteeshipShopAdd'})">
          <p>+</p>
          <p>发布新产品</p>
        </div>
        <div class="btn_box_02" @click="$router.push({name:'agriculturalTrusteeshipShopNeedsList'})">
          <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_see2.png" alt="">
          <p>查看贷款需求</p>
        </div>
<!--        <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_add2.png" style="margin: 0 auto;display: block;" @click="$router.push({name:'agriculturalTrusteeshipShopAdd'})">-->
<!--        <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_see.png" style="margin: 0 auto;display: block;" @click="$router.push({name:'agriculturalTrusteeshipShopAdd'})">-->
      </div>

      <div class="main_btn" v-else>
        <div class="btn_box_01" style="width: 100%;" @click="$router.push({name:'agriculturalTrusteeshipShopAdd'})">
          <p>+</p>
          <p>发布新产品</p>
        </div>
      </div>



      <van-tabs v-model="active" sticky animated>
        <van-tab title="服务中">
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="getList"
          >
            <!--            @load="onLoad"-->
            <div class="main_content_right_list" v-for="(item,index) in productListYes" :key="index">
              <img v-if="item.mainImg" :src="item.mainImg" style="width: 25vw;height: 25vw;" @click="$router.push({name:'agriculturalTrusteeshipShopDetail',query:{id:item.id}})">
              <img v-else src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 25vw;height: 25vw;">
              <div class="main_content_right_list_content">
                <p class="tt" @click="$router.push({name:'agriculturalTrusteeshipShopDetail',query:{id:item.id}})">{{item.productName}}</p>
                <div class="tab">
                  <p>{{item.productType}}</p>
                  <div>
                    <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_01.png" @click="$router.push({name:'agriculturalTrusteeshipShopEdit',query:{id:item.id}})" />
                    <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_02.png" @click="productOut(item.id)"/>
                  </div>
                </div>
              </div>
            </div>
          </van-list>

        </van-tab>
        <van-tab title="已下架">

          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="getList"
          >
            <!--            @load="onLoad"-->
            <div class="main_content_right_list" v-for="(item,index) in productListNo" :key="index">
              <img v-if="item.mainImg" :src="item.mainImg" style="width: 25vw;height: 25vw;" @click="$router.push({name:'agriculturalTrusteeshipShopDetail',query:{id:item.id}})">
              <img v-else src="../../../../static/images/agriculturalTrusteeship/zwtp.png" style="width: 25vw;height: 25vw;">
              <div class="main_content_right_list_content">
                <p class="tt" @click="$router.push({name:'agriculturalTrusteeshipShopDetail',query:{id:item.id}})">{{item.productName}}</p>
                <div class="tab">
                  <p>{{item.productType}}</p>
                  <div>
                    <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_01.png" @click="$router.push({name:'agriculturalTrusteeshipShopEdit',query:{id:item.id}})" />
                    <img src="../../../../static/images/agriculturalTrusteeship/insurance/shop_icon_03.png" @click="productIn(item.id)"/>
                  </div>
                </div>
              </div>
            </div>
          </van-list>

        </van-tab>
      </van-tabs>
    </div>
    <!--  内容结束  -->

  </div>
</template>
<script>
  import Cookies from "js-cookie";
  import {productList, productOut, productIn, serviceGet, treeselect} from "@/api/agriculturalTrusteeship";
  import {Dialog} from "vant";
  export default {
    name: "agriculturalTrusteeshipShopList",
    data() {
      return {
        activeKey: 0,
        active: 0,
        loading: false,
        finished: false,
        productList:[],
        productListYes:[],
        productListNo:[],
        query:{
          financialServiceId:Cookies.get('ACCESS-SESSION-ID'),
          pageNum:1,
          pageSize:'10',
        },
        serviceForm:{},
        deptOptions:[],
        deptName:'张村',
        showDeptId:false,
        villageValue : '',
        hcAreaInfoFieldName: {
          text: "label",
          value: "value",
          children: "children",
        },
      };
    },
    created() {
      this.getDetail();
      treeselect().then(res=>{
        if (res.code == 200) {
          this.deptOptions = res.data;
        }
      })
    },
    methods: {
      getDetail(){
        serviceGet(Cookies.get('ACCESS-SESSION-ID')).then(response => {
          if (response.code == 200){
            this.serviceForm = response.data;
          }else{
            Dialog.confirm({
              title: '系统提示',
              message: '登录状态已过期，请重新登录',
              confirmButtonText: '重新登录',
              cancelButtonText: '取消'
            }).then(() => {
              window.location.href = '/agriculturalTrusteeship/login';
            });
          }

        });
      },
      getList(){
        productList(this.query).then(response => {
          response.rows.map(res=>{
            if (res.mainImg){
              let supplyMasterMap = res.mainImg.split( "," )
              res.mainImg = '/api'+supplyMasterMap[0]
            }
            if(res.sysYesNo == 'Y'){
              this.productListYes.push(res);
            }
            if(res.sysYesNo == 'N'){
              this.productListNo.push(res);
            }
            this.productList.push(res);
          })
          if(this.productList.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.query.pageNum += 1 ;
          }
        });
      },
      productIn(id){
        productIn(id).then(response => {
          this.$notify({ type: 'success', message: '上架成功' });
          location.reload()
        });
      },
      productOut(id){
        productOut(id).then(response => {
          this.$notify({ type: 'success', message: '下架成功' });
          location.reload()
        });
      },
      //选择案件属地
      onConfirmDept({ selectedOptions }){
        this.query.deptId = selectedOptions[selectedOptions.length-1].value;
        this.deptName = selectedOptions[selectedOptions.length-1].label;
        this.showDeptId = false
        this.productListYes = [];
        this.productListNo = [];
        this.getList();
      },
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
  background: #ffffff;
  height: 100vh;
  overflow: hidden;
}
  /*头部*/
  .header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    padding: 2vh 4% 2vh;
    .header_left{
      display: flex;
      align-items: center;
      p{
        font-size: .4rem;
        color: #ffffff;
        line-height: 1;
        margin-left: 10PX;
      }
    }
    .header_right{
      font-size: .35rem;
      background: #ffffff url("../../../../static/images/agriculturalTrusteeship/address.png") no-repeat 10PX center;
      padding: 2PX 15PX 2PX 25PX;
      border-radius: 50PX;
    }
  }

  .main_btn{
    display: flex;
    background: #ffffff;
    border-top-left-radius: 25PX;
    border-top-right-radius: 25PX;
    overflow: hidden;
    padding: 4vw 4% 0;
    justify-content: space-between;
    .btn_box_01{
      width: 48%;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 1Px dashed #4E7FFF;
      color: #4E7FFF;
      font-size: .35rem;
      line-height: 15vw;
      border-radius: 10Px;
      p:first-child{
        font-weight: bold;
        margin-right: 5PX;
      }
    }
    .btn_box_02{
      width: 48%;
      display: flex;
      justify-content: center;
      align-items: center;
      background: rgba(78,127,255,0.17);
      color: #1E49BB;
      font-size: .35rem;
      line-height: 15vw;
      border-radius: 10Px;
      p{
        margin-left: 5PX;
      }
    }
  }

  .serviceName{
    display: flex;
    align-items: center;
    justify-content: space-between;
    span{
      background: #E8E8E8;
      padding: 0 8PX;
      border-radius: 5PX;
      color: #7A7A7A;
      margin-right: 5PX;
    }
    .active{
      background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
      color: #ffffff;
    }
  }

  .nav{
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    padding-bottom: 15PX;
    .tt{
      font-size: .45rem;
      color: #334281;
    }
    .content{
      background: #ffffff;
      width: 92%;
      margin: 0 auto;
      box-shadow: 0px 0px 10PX rgba(0,0,0,0.1);
      border-radius: 25PX;
      padding: 1.5vh 4%;
    }
    /deep/ .van-cell{
      padding: 0;
      margin-bottom: 10PX;
      &:last-child{
        margin: 0;
      }
    }
  }

  /* 内容 */
  .main{
    background-image: linear-gradient(to right , #6E93F3 , #7E89E9 , #54C6E4);
    /deep/ .van-tabs__nav{
      /*border-top-left-radius: 25PX;*/
      /*border-top-right-radius: 25PX;*/
      /*overflow: hidden;*/
    }
    /deep/ .van-tabs__line{
      background: #334281!important;
    }
    /deep/ .van-tab--active{
      color: #334281;
    }
    /deep/ .van-tabs__content{
      background: #ffffff;
      padding-top: 2vh;
    }
    .search{
       display: flex;
       justify-content: space-between;
       align-items: center;
       width: 92%;
       margin: 0PX auto;
       border: 1px solid #6E93F3;
       padding: 1PX 1PX 1PX 12PX ;
       border-radius: 50PX;
       input{
         flex: 1;
         background: transparent;
         margin-left: 10PX;
       }
    }
    .content{
      width: 92%;
      margin: 0 auto;
      margin-top: 2vh;
      .content_tt{
        font-size: .35rem;
      }
      .content_con{
        display: flex;
        justify-content: space-between;
        margin-top: 1.5vh;
        .content_con_left{
          display: flex;
          flex-direction:column;
          justify-content: space-between;
          p{
            font-size: .35rem;
            padding-left: 18PX;
            &:nth-child(1){
              background: url("../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_project.png") no-repeat left center;
            }
            &:nth-child(2){
              background: url("../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_name.png") no-repeat left center;
            }
            &:nth-child(3){
              background: url("../../../../static/images/agriculturalTrusteeship/insurance/insurance_list_iphone.png") no-repeat left center;
            }
          }
        }
        .content_con_right{
          display: flex;
          justify-content: end;
          align-items: center;
          img{
            border-radius: 10PX;
            width: 40%;
            margin-left: 5%;
            box-shadow: 0px 5PX 10PX rgba(0,0,0,0.2);
            &:last-child{
              width: auto;
              box-shadow: none;
            }
          }
        }
      }
    }
    .main_content_right_list{
      display: flex;
      margin: 0 auto;
      margin-top: 2vh;
      width: 92%;
      img{
        border-radius: 15PX;
        margin-right: 4%;
        width: 30%;
      }
      .main_content_right_list_content{
        display: flex;
        flex-direction:column;
        justify-content: space-between;
        flex: 1;
        .tt{
          color: #333333;
          font-size: .35rem;
        }
        .tab{
          display: flex;
          justify-content: space-between;
          align-items: center;
          p{
            flex-shrink: 0;
            &:nth-child(1){
              color: #497CE8;
              background: #E2E9FD;
              padding: 4PX 10PX;
              border-radius: 5PX;
            }
          }
          div{
            display: flex;
            justify-content: space-between;
            align-items: center;
            img{
              display: block;
              border-radius: none;
              margin-right: 0;
              width: 50%;
            }
          }
        }
        .name{
          color: #8F8F8F;
          background: url("../../../../static/images/agriculturalTrusteeship/index/name_icon.png") no-repeat left center;
          padding-left: 18PX;
        }
      }
    }
  }
</style>
