<template>
  <div class="app-container">
    <van-nav-bar title="农用品库" fixed placeholder />
      <div style="display: flex;padding: 0 3% 0.2rem;">
        <form action="#" style="flex: 0.75;">
          <van-search
            v-model="queryParams.productName"
            placeholder="请输入农用品名称"
            @input="handleQuery"
          >
          </van-search>
        </form>
        <van-button type="info" @click="sheetShow = true"  style="flex: 0.25;border-radius: 30PX;height: 0.95rem;">
          <van-icon name="../../../static/images/lawEnforcement/icon/icon_ssbt.png" size="17" style="vertical-align: middle;margin-right: 5px;" />筛选
        </van-button>
      </div>
      <van-row style="padding: 0.2rem 3%;" v-show="showSxtj">
        <van-col :span="20"><p style="line-height: 20px;font-size: 14px;color: #878787;">筛选条件：{{showProductType}} {{showCategory}}</p></van-col>
        <van-col :span="4" align="right"><van-icon name="close" size="20" @click="resetQuery"/></van-col>
      </van-row>
      <van-action-sheet v-model="sheetShow" title="筛选" duration="0.2" close-icon="arrow-down">
        <div class="sheetContent">
          <van-field
            readonly
            clickable
            name="picker"
            v-model="showProductType"
            label="农用品类型"
            placeholder="点击选择当事人类型"
            @click="showNyplx = true"
          />
          <van-popup v-model="showNyplx" position="bottom">
            <van-picker
              show-toolbar
              :columns="productTypeColumns"
              @confirm="onConfirmNyplx"
              @cancel="showNyplx = false"
            />
          </van-popup>
          <van-field
            readonly
            clickable
            name="picker"
            v-model="showCategory"
            label="农用品种类"
            placeholder="点击选择案件状态"
            @click="showNypzl = true"
          />
          <van-popup v-model="showNypzl" position="bottom">
            <van-picker
              show-toolbar
              :columns="categoryColumns"
              @confirm="onConfirmNypzl"
              @cancel="showNypzl = false"
            />
          </van-popup>
        </div>
        <van-row>
          <van-col :span="12" align="center"><van-button type="default" style="width: 90%;height: 1.2rem;border-radius: 4PX;" @click="resetQuery">重置</van-button></van-col>
          <van-col :span="12" align="center"><van-button type="info" style="width: 90%;height: 1.2rem;border-radius: 4PX;" @click="handleQuery">确定</van-button></van-col>
        </van-row>
      </van-action-sheet>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList"
    >
      <van-swipe-cell v-for="(item,index) in newList" :key="index">
        <div class="tabsBox">
          <van-cell :title="item.productName" center>
            <template #icon>
              <van-icon name=".../../../static/images/lawEnforcement/icon/icon_nypk.png" size="36" color="#539FFD" style="margin-right: 10px;" />
            </template>
            <template #default>
              <p style="color: #1D6FE9;">{{item.content}}克/升</p>
            </template>
          </van-cell>
          <van-cell title="登记证号" :value="item.recordCode" center/>
          <van-cell title="农药类别" :value="item.category" center/>
          <van-cell title="剂型" :value="item.agent" center/>
          <van-cell title="有效期至" :value="item.effectiveDate" center/>
          <van-cell title="登记证持有人" :value="item.recordHolder" center/>
        </div>
      </van-swipe-cell>
    </van-list>
    <law></law>
  </div>
</template>
<script>
import { productList , getTopDeptId } from "@/api/lawEnforcement/index";
import law from "@/components/common/law_footer";
export default {
  name: "index",
  components: {
    law
  },
  data() {
    return {
      value:'',
      radio:'',
      //是否显示加载
      loading: false,
      //是否滚动到底部
      finished: false,
      sheetShow: false,
      showNyplx: false,
      showNypzl: false,
      showSxtj: false,
      //查询参数
      queryParams: {
        // 分页
        pageNum: 1,
        pageSize: 10,
        deptId:100,
        // 查询排序
        orderByColumn: "id",
        isAsc: "desc",
        productType: null,
        recordCode: null,
        productName: null,
        category: null,
        agent: null,
        checkStatus:"1",
      },
      //新闻集合
      newList:[],
      //轮播图集合
      bannerList:'',
      productTypeOptions:[],
      categoryOptions:[],
      typeColumns:[],
      productTypeColumns:[],
      categoryColumns:[],
      showProductType : '',
      showCategory : '',
    };
  },
  created() {
    this.getDicts("product_type").then(response => {
      this.productTypeOptions = response.data;
      for (var i = 0 ; i < response.data.length ; i++){
        this.productTypeColumns.push({text: response.data[i].dictLabel, value: response.data[i].dictValue})

      }
    });
    this.getDicts("category_type").then(response => {
      this.categoryOptions = response.data;
      for (var i = 0 ; i < response.data.length ; i++){
        this.categoryColumns.push({text: response.data[i].dictLabel, value: response.data[i].dictValue})
      }
    });
    this.getDeptId();
  },
  methods: {
    getDeptId(){
      getTopDeptId().then(response => {
        this.queryParams.deptId = response.data;
        this.getList();
      })
    },
    getList(){
      this.loading = true;
      productList(this.queryParams).then(response => {
        this.newList = response.rows;
        if(this.newList.length >= response.total){
          this.finished = true;
          return;
        }
        this.queryParams.pageNum += 1 ;
        this.loading = false;
      });
    },
    onConfirmNypzl(data){
      this.queryParams.category = data.value;
      this.showCategory = data.text;
      this.showNypzl = false;
    },
    onConfirmNyplx(data){
      this.queryParams.productType = data.value;
      this.showProductType = data.text
      this.showNyplx = false;
    },
    resetQuery(){
      this.queryParams = {
        // 分页
        pageNum: 1,
          pageSize: 10,
          deptId:100,
          // 查询排序
          orderByColumn: "id",
          isAsc: "desc",
          productType: null,
          recordCode: null,
          productName: null,
          category: null,
          agent: null,
          checkStatus:"1",
      },
      this.showProductType = '';
      this.showCategory = '';
      this.showSxtj = false;
      this.getDeptId()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if( this.showProductType != '' || this.showCategory != '' ){
        this.showSxtj = true;
      }
      this.caseList = [];
      this.queryParams.pageNum = 1;
      this.getList();
    },
  },
};
</script>

<style scoped lang="scss">
@font-face {
  font-family: SourceHanSansCNBold;
  src: url("../../../assets/fonts/SourceHanSansCN-Bold.otf");
}
.app-container {
  padding: 0.2rem 3%;
}
/deep/ .van-action-sheet__content{
  padding-bottom: 0.5rem;
}
.sheetContent{
  padding: 10PX 1% 1rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid #eeeeee;
  .sheetTitle{
    font-size: 0.42rem;
    background-color: transparent;
    width:auto;
    color: #333333;
    border:none;
    margin-bottom: 10PX;
    padding: 0 15px;
  }
  /deep/ .van-row{
    margin-bottom: 10PX;
  }
  /deep/ .van-col{
    text-align: center;
    padding: 0 15px;
  }
  .active{
    background-color: #1D6FE9;
    color: #FFFFFF;
    border: none;
  }
  p{
    font-size: 0.42rem;
    padding: 0.2rem 0;
    color: #666666;
    border-radius: 4PX;
    border: 1px solid #B4B0B0;
  }
}
/deep/ .van-action-sheet__header{
  border-bottom: 8PX solid #eeeeee;
}
/deep/.van-swipe-cell{
  margin-bottom: 0.2rem;
  border-radius: 0.2rem;
  overflow: hidden;
  box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
}
/deep/ .van-search__content{
  background-color: #ffffff;
  border-radius: 20PX;
  border: 1px solid #cccccc;
  margin-right: 2%;
}
/deep/ .van-search__action{
  background-color: #1D6FE9;
  border-radius: 20PX;
  text-align: center;
  color: #ffffff;
}
/deep/ .van-search{
  background-color: transparent;
  padding: 0;
}
.van-cell__title{
  color: #666666;
}
/deep/ .van-nav-bar--fixed{
  background: url("../../../../static/images/lawEnforcement/head_bg.png") 100%;
}
/deep/.van-cell__title{
  flex: 1;
}
/deep/.van-cell__title span{
  font-family: Arial;
  font-size: 0.4rem;
  font-weight: normal;
}
/deep/.van-cell__value{
  color: #333333;
  flex: 1.2;
}
/deep/ .van-nav-bar__title{
  display: flex;
  max-width: initial;
  color: #ffffff;
  p{
    line-height: 30Px;
    margin-left: 6Px;
    font-size: 21Px;
    color: #D60303;
    font-family: SourceHanSansCNBold;
  }
}
/deep/ .van-tabs__content{
  width: 96%;
  margin: 0 auto;
}
/deep/ van-tab__pane-wrapper{
  padding: 0 2%;
}
/deep/ .van-tab{
  border: none;
  color: #1D6FE9;
}
/deep/ .van-tab--active{
  border-radius: 30Px;
  box-shadow: 0px 5px 5px #ccc;
  background-color: #FE1313!important;
}
/deep/ .van-tabs--card>.van-tabs__wrap{
  height: 0.9rem;
  margin: 10Px 0;
}
/deep/ .van-tab__pane{
  background: #FFF;
  border-radius: 8Px;
  overflow: hidden;
}
/deep/ .van-tabs__nav--card{
  padding: 3Px 2%;
  border: none;
  border-radius: 1rem;
  height: 0.9rem;
}
.bannerTit{
  position: absolute;
  bottom: 10px;
  background: rgba(255,255,255,0.3);
  width: 100%;
  height: 0.8rem;
  line-height: 0.8rem;
  color: #fff;
  overflow: hidden;
  padding: 0 3%;
  font-size: 16Px;
}
.link{
  color: #000;
}
.my-swipe {
  border-radius: 8Px;
}
.my-swipe .van-swipe-item .van-image{
  width: 100%;
}
.van-grid-item p{
  margin-top: 10px;
}
.newTit{
  font-size: 0.45rem;
  margin: 0.4rem 0;
  font-family: Source Han Sans SC, Source Han Sans SC-Medium;
  font-weight: 500;
  text-align: left;
  color: #333333;
}
.newContent{
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  word-break: break-all;
  overflow: hidden;
}
.search-icon {
  line-height: inherit;
  margin-left: 10px;
}
.tabsBox{
  /deep/.van-row{
    margin-top: 15PX;
    .van-col{
      font-size: 0.4rem;
    }
  }
}
</style>
