<template>
  <div class="app-container">
    <div class="header_main">
      查农药
      <div class="return_btn" @click="onClickLeft"></div>
      <div class="jg"></div>
    </div>

    <div class="main">

      <div class="main_box">
        <van-field v-model="queryParams.recordCode" :border="false" label="登记证号" placeholder="请输入登记证号" input-align="right" />
        <van-field v-model="queryParams.productName" :border="false" label="农药名称" placeholder="请输入农药名称" input-align="right" />
        <van-field v-model="queryParams.recordHolder" :border="false" label="登记证持有人" placeholder="请输入登记证持有人" input-align="right" />
        <van-field
          readonly
          clickable
          :border="false"
          label="农药种类"
          placeholder="请选择"
          v-model="category"
          @click="showCategory = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
        />
        <van-popup v-model="showCategory" position="bottom">
          <van-picker
            show-toolbar
            :columns="categoryOptions"
            @confirm="onConfirmCategory"
            @cancel="showCategory = false"
          />
        </van-popup>
        <van-popup v-model="showAgent" position="bottom">
          <van-picker
            show-toolbar
            :columns="agentOptions"
            @confirm="onConfirmAgent"
            @cancel="showAgent = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          :border="false"
          label="全部剂型"
          placeholder="请选择"
          v-model="agent"
          @click="showAgent = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
        />
      </div>

      <p class="submitButton" @click="getList('search')">立即查询</p>
      <div class="scroll_box">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="getList"
        >
          <div class="list_box" v-for="(item,index) in list" :key="index">
            <van-cell center :to="{name:'lawEnforcementPesticidesDetail', query: {content:item}}">
              <template #title>
                <div class="tt">
                  <span>{{item.productName}}</span>
                  <span>{{item.content}}%</span>
                </div>
                <div class="first">
                  <span>{{item.recordCode}}</span>
                  <span>{{item.category}}</span>
                  <span>{{item.agent}}</span>
                </div>
                <p class="dress">{{item.recordHolder}}</p>
              </template>
              <template #label>
                <div class="label">
                  <p>有效期始 {{item.firstApprovalDate}}</p>
                  <p>有效期至 {{item.effectiveDate}}</p>
                </div>
              </template>
            </van-cell>
          </div>
        </van-list>
      </div>
    </div>

  </div>
</template>

<script>
  import { listProduct } from "@/api/lawEnforcement/index";
  export default {
    name: "programmeDetail",
    data() {
      return {
        loading: false,
        finished: false,
        form:{},
        value:'',
        showCategory:false,
        showAgent:false,
        queryParams: {
          // 分页
          pageNum: 1,
          pageSize: 10,
          // 查询排序
          orderByColumn: "id",
          isAsc: "desc",
          recordCode: null,  // 查询参数-登记证号
          productName: null,  // 查询参数-农药名称
          category: null,  // 查询参数-农药种类
          agent: null, // 查询参数-剂型
          recordHolder:null,   // 查询参数-登记证持有人
        },
        list:[],
        categoryOptions:[],
        agentOptions:[],
        category: null,  // 查询参数-农药种类
        agent: null, // 查询参数-剂型
      };
    },
    created() {
      // this.getDictionaries()
      // 农药种类
      this.getDicts("category_type").then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.categoryOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
      });
      // 剂型
      this.getDicts("agent_type").then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.agentOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
      });

    },
    methods: {
      getList(type){
        var _this = this;
        if (type == 'search'){
          this.list = [];
          this.queryParams.pageNum = 1 ;
        }
        listProduct(_this.queryParams).then(response => {
          response.rows.map(res=>{
            // res.businessType = res.businessType == '' ? '' : this.selectDictLabel(this.businessTypeOptions, res.businessType);
            this.list.push(res);
          })
          console.log(this.list.length)
          if(this.list.length >= response.total){
            this.finished = true;
            return;
          }else{
            this.loading = false;
            this.queryParams.pageNum += 1 ;
          }
        });
      },
      onConfirmCategory(data){
        this.category = data.text;
        this.queryParams.category = data.value;
        this.showCategory = false;
      },
      onConfirmAgent(data){
        this.agent = data.text;
        this.queryParams.agent = data.value;
        this.showAgent = false;
      },
    },
  }
</script>

<style scoped lang="scss">
  .jg{
    height: 180PX;
  }
  .app-container {

  }
  .top_box{
    line-height: 1;
    text-align: left;
    width: 85%;
    margin: 0 auto;
    padding-bottom: 10PX;
    background: url('../../../../static/images/lawEnforcement/new/retrospect_icon_14.png') no-repeat right bottom;
    .top_01{
      display: flex;
      align-items: center;
      font-size: 0.4rem;
      margin-top: 15PX;
      img{
        margin-right: 10PX;
      }
    }
    .tt{
      font-size: 0.7rem;
      margin-top: 15PX;
    }
    .top_02{
      display: flex;
      align-items: center;
      font-size: 0.3rem;
      margin-top: 15PX;
      i{
        display: inline-block;
        width: 15PX;
        height: 15PX;
        margin-right: 3PX;
      }
      p{
        display: flex;
        align-items: center;
        margin-right: 10PX;
        &:nth-child(1){
          i{
            background: url('../../../../static/images/lawEnforcement/new/retrospect_icon_11.png') no-repeat center;
            background-size: auto 15PX;
          }
        }
        &:nth-child(2){
          i{
            background: url('../../../../static/images/lawEnforcement/new/retrospect_icon_12.png') no-repeat center;
            background-size: auto 15PX;
          }
        }
        &:nth-child(3){
          i{
            background: url('../../../../static/images/lawEnforcement/new/retrospect_icon_13.png') no-repeat center;
            background-size: auto 15PX;
          }
        }
      }
    }
  }
  .main{
    position: absolute;
    width: 100%;
    top: 58PX;
  }
  .center_box{
    text-align: center;
    padding: 30PX 0!important;
    p{
      margin-top: 15PX;
      &:nth-child(2){
        font-size: 0.4rem;
        color: #59C145;
      }
      &:nth-child(3){
        font-size: 0.4rem;
        color: #B4B0B0;
        display: inline-block;
        background: url('../../../../static/images/lawEnforcement/new/retrospect_icon_16.png') no-repeat left center;
        padding-left: 20PX;
      }
    }
  }
  /deep/ .van-cell{
    padding-bottom: 0;
    padding-top: 0;
    margin-bottom: 10PX;
    &:last-child{
      margin-bottom: 0;
    }
  }
  .header_main{
    /*height: 116px;*/
    background: url('../../../../static/images/lawEnforcement/new/header_bg.png') no-repeat;
    background-size: 100% 100%;
    /*position: fixed;*/
    top: 0;
    left: 0;
    width: 100%;
    font-size: 36px;
    line-height: 116px;
    text-align: center;
    color: #fff;
    z-index: 999;
    .return_btn{
      width: 24px;
      height: 43.2px;
      background: url('../../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
      background-size: 20px 36px;
      position: absolute;
      left: 38px;
      top: 36px;
    }
    .add_btn{
      width: 56.4px;
      height: 40.8px;
      background: url('../../../assets/images/sunVillage_info/list_icon_9.png') center center no-repeat;
      background-size: 47px 34px;
      position: absolute;
      right: 38px;
      top: 36px;
    }
  }
  /deep/ .van-radio--horizontal{
    margin-left: 0.32rem;
    margin-right: 0;
  }
  .peopleList{
    padding-right: 3%;
    .van-row{
      margin-bottom: 10PX;
      .van-col{
        text-align: center;
        font-size: 14PX;
      }
      &:first-child{
        .van-col{
          color: #1D6FE9;
        }
      }
    }
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    margin-top: 0;
    position: relative;
  }
  .main_box{
    width: 90%;
    margin: 0 auto;
    border-radius: 10PX;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
    padding: 20PX 5PX;
    .van-icon{
      vertical-align: middle;
    }
    .custom-title{
      font-size: 17PX;
      color: #333333;
      vertical-align: middle;
      line-height: 1;
      position: relative;
    }
    .tap{
      color: #1D6FE9;
    }
    .bgBlue{
      display: block;
      position: absolute;
      width: 17PX;
      height: 17PX;
      border-radius: 50%;
      background-color: rgba(29,111,233,0.26);
      top: -2PX;
      right: -8PX;
    }
  }
  .submitButton{
    width: 70%;
    margin: 50px auto;
    background-image: linear-gradient(to right, #2E79E9 , #77A6EF);
    text-align: center;
    color: #ffffff;
    height: 70px;
    line-height: 70px;
    border-radius: 8PX;
  }
  .scroll_box{
    height: calc(100vh - 100px - 200PX - 100PX);
    overflow: hidden;
    overflow-y: scroll;
  }
  .addFamily{
    position: absolute;
    top: -2px;
    right: 0;
    border-radius: 50%;
  }
  /deep/.van-cell__title{
    .tt{
      display: flex;
      justify-content: space-between;
      span:first-child{
        background: url('../../../../static/images/lawEnforcement/icon/pesticides_icon_01.png') no-repeat left center;
        padding-left: 15PX;
      }
    }
    .first{
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 5PX;
      span{
        color: #1D6FE9;
        font-size: 0.35rem;
        &:first-child{
          background: rgba(29,111,233,0.2);
          padding: 3PX 5PX;
          line-height: 1;
          border-radius: 3PX;
        }
      }
    }
    .dress{
      font-size: .35rem;
      color: #1CB8B1;
      margin-top: 5PX;
    }
    span{
      font-family: Arial;
      font-size: 0.4rem;
      font-weight: normal;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      word-break: break-all;
      overflow: hidden;
    }
  }
  .list_box{
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    width: 94%;
    margin: 0 auto 10PX;
    padding: 12PX 0;
    background: #ffffff;
    border-radius: 8PX;
  }
  .label {
    display: flex;
    justify-content: space-between;
    p{
      display: inline-block;
      font-size: 0.35rem;
    }
  }
</style>
