<template>
  <div class="examine-box" :style="'height:' + fullHeight + 'px'">
    <!-- nav -->
    <div class="dbd">
      <!-- 返回 -->
      <el-page-header title @back="goBack" content="查看已录信息"></el-page-header>

      <!-- 添加框 -->
      <el-button v-show="addShow" type="text" @click="dialogFormVisible = true, addition()">
        <img src="../../assets/imageOne/statistics.png" alt class="examine-img" />
      </el-button>

      <!-- 背景渐变 -->
      <div class="bgc"></div>
    </div>

    <!-- <div class="main-content" :style="'height:' + fullHeight + 'px'"> -->
    <div class="main-content">
      <!-- tab切换 -->
      <ul class="examine-box-main-tab">
        <li
          class="main-tab-plant"
          v-for="(item,index) in items"
          :key="index"
          :class="{active:istrue==index}"
          @click="istrue=index, qingqiu(index)"
        >{{ item.name }}</li>
      </ul>

      <!-- <div class="main-contentA" :style="'height:' + fullHeight + 'px'"> -->
      <div class="main-contentA">
        <!-- 筛选框 -->
        <div class="examine-box-sizer">
          <!-- 月份筛选器 -->
          <el-cascader
            :options="options"
            v-model="selectedOptionsA"
            placeholder="月份筛选"
            @change="resultA($event)"
            class="content"
            :props="propsA"
          ></el-cascader>
          <!-- 月份筛选器 -->

          <!-- 地址筛选器 -->
          <el-cascader
            :options="optionsA"
            v-model="selectedOptions"
            placeholder="地址筛选"
            @change="result($event)"
            class="content"
            :props="props"
          ></el-cascader>
          <!-- 地址筛选器 -->
        </div>

        <mescroll-vue ref="mescroll" :down="mescrollDown" :up="mescrollUp" @init="mescrollInit">
          <!-- 暂无数据 -->
          <div class="content-block" v-if="isShow">
            <img src="../../assets/imageOne/423.png" alt class="content-block-img" />
            <div class="content-block-text">暂无数据</div>
          </div>
          <!-- 暂无数据 -->

          <div class="content-blocks" @click="chakan($event, item.id)" v-else v-for="(item, index) in this.redata" :key="index">
            <div class v-if="item.defa == '1'">
              <img src="../../../static/moren.png" alt class="moren" />
            </div>
            <div class="yuan1"></div>
            <div class="yuan2"></div>
            <!-- 多选框和调查时间 -->
            <div class="content-blocks-div">
              <div :class="item.defa == 1 ? 'checkboxkua' : 'checkboxkuaA'">
                <el-checkbox
                  v-if="item.defa != 1"
                  v-model="checked"
                  :label="item.id"
                  @change="chang($event, item.id, index)"
                ></el-checkbox>
              </div>

              <div class="content-blocks-div-diaocha">
                <span class="diaocha">调查时间：</span>
                <span class="time">{{item.upl_time}}</span>
              </div>

              <!-- 详情按钮 -->
              <div class="content-blocks-btn">
                <!-- <span class="content-blocks-btn-xiangqi" @click="chakan($event, item.id)">详情</span> -->
                <span class="content-blocks-btn-xiangqi">详情</span>
                <img
                  src="../../assets/imageOne/right.png"
                  alt
                  class="content-blocks-div-diaocha-img"
                />
              </div>
            </div>
            <div class="content-blocks-frame"></div>

            <div class="content-blocks-div1">
              <!-- 采集地址 -->
              <div class="content-blocks-div2">
                <span class="content-blocks-div2-location">采集地区：</span>
                <span class="content-blocks-div2-site">{{ item.city | ellipsis }}</span>
              </div>

              <!-- 采集人 -->
              <div class="content-blocks-div2">
                <span class="content-blocks-div2-gatherer">采集人：</span>
                <span class="content-blocks-div2-name">{{item.user_name}}</span>
              </div>
            </div>
          </div>
        </mescroll-vue>

        <!-- 删除框 -->
        <el-dialog
          title="提示"
          :visible.sync="dialogVisibleshan"
          width="7rem"
          :before-close="handleCloseshanchu"
        >
          <span>确定删除此条信息吗？</span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisibleshan = false, delqueding()">取 消</el-button>
            <el-button type="primary" @click="dialogVisibleshan = false,shanchuque()">确 定</el-button>
          </span>
        </el-dialog>
        <!-- 删除框 -->

        <!-- 删除、导出 -->
      </div>

      <el-collapse-transition>
        <div class="examine-box-nav transition-box" v-show="shanShow">
          <div class="examine-box-nav-div" @click="del()">
            <img src="../../assets/imageOne/41.png" alt class="examine-box-nav-img1" />
            <span class="examine-box-nav-div-del">删除</span>
          </div>

          <div class="examine-box-nav-div">
            <img src="../../assets/imageOne/40.png" alt class="examine-box-nav-img2" />
            <span @click="AAAAA()" class="examinebtn">导出</span>
          </div>
        </div>
      </el-collapse-transition>
    </div>
  </div>
</template>

<script>
// 引入mescroll的vue组件
import MescrollVue from "mescroll.js/mescroll.vue";
export default {
  name: "examine",
  //限时数据文本的字数限时
  filters: {
    ellipsis(value) {
      if (!value) return "";
      if (value.length > 12) {
        return value.slice(0, 12) + "...";
      }
      return value;
    }
  },
  inject: ["reload"], //注入reload方法
  data() {
    return {
      dataIndex: "", //是否选中默认数据
      addShow: false, //在列表为空时，进行隐藏
      checked: [], //多选框的
      shanShow: false, //删除、导出界面显示或隐藏
      form: {
        newName: "" //添加中input的双向绑定
      },
      // dialogTableVisible: false,
      dialogVisibleshan: false, //删除
      formLabelWidth: "120px",
      // dialogTableVisible: false,
      inputText: "",
      current: "", //点击list的下标
      redata: [], //后端数据
      conheight: {
        height: ""
      },
      fullHeight: document.documentElement.clientHeight, //
      loading: true, //loading
      isShow: false, //判断是否有数据
      reBlob: [], //导出数据
      ID: localStorage.getItem("examineID"),
      longClick: 0, // 长按标志
      timeOutEvent: 0, // 计时器
      istrue: localStorage.getItem("examineIndex"),
      items: [{ name: "虫害" }, { name: "病害" }],
      //时间筛选框
      value1: "",
      //地区下拉框
      optionsA: [],
      props: {
        value: "value",
        label: "value"
      },
      selectedOptions: [],
      //月份下拉框
      options: [],
      propsA: {
        value: "value",
        label: "value"
      },
      selectedOptionsA: [],
      //上拉加载下拉刷新
      //测试
      mescroll: null, // mescroll实例对象
      mescrollDown: {}, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
      mescrollUp: {
        // 上拉加载的配置.
        callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
        //以下是一些常用的配置,当然不写也可以的.
        page: {
          num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
          size: 6 //每页数据条数,默认10
        },
        isBounce: true, //根据记录的滚动条高度回弹
        htmlNodata: '<p class="upwarp-nodata">-- 已经到底了! --</p>',
        noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;
        // 避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
        // 这就是为什么无更多数据有时候不显示的原因
        toTop: {
          //回到顶部按钮
          // src: "../../../static/gotop.png", //图片路径,默认null,支持网络图
          src:
            "http://pic.51yuansu.com/pic3/cover/00/65/23/5896fa4bc81fc_610.jpg", //图片路径,默认null,支持网络图
          offset: 800 //列表滚动1000px才显示回到顶部按钮
        },
        empty: {
          //列表第一页无任何数据时,显示的空提示布局; 需配置warpId才显示
          warpId: "", //父布局的id (1.3.5版本支持传入dom元素)
          icon: "./static/mescroll/mescroll-empty.png", //图标,默认null,支持网络图
          tip: "暂无相关数据~" //提示
        },
        onScroll: function(mescroll, y, isUp) {
          //监听滚动条
          // console.log(y);
        },
        lazyLoad: {
          use: true // 是否开启懒加载,默认false
        }
      },
      aggregate: "" //后端传来数据的总条数
    };
  },
  beforeRouteEnter(to, from, next) {
    // 如果没有配置顶部按钮或isBounce,则beforeRouteEnter不用写
    next(vm => {
      // 滚动到原来的列表位置,恢复顶部按钮和isBounce的配置
      vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter();
    });
  },
  beforeRouteLeave(to, from, next) {
    // 如果没有配置顶部按钮或isBounce,则beforeRouteLeave不用写
    // 记录列表滚动的位置,隐藏顶部按钮和isBounce的配置
    this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave();
    next();
  },
  components: {
    MescrollVue // 注册mescroll组件
  },
  watch: {
    fullHeight(val) {
      //监控浏览器高度变化
      if (!this.timer) {
        this.fullHeight = val;
        this.timer = true;
        let that = this;
        setTimeout(function() {
          //防止过度调用监测事件，导致卡顿
          that.timer = false;
        }, 400);
      }
    },
    checked(val) {
      // console.log(val);
    }
  },
  mounted() {
    let _this = this;
    this.get_boderHeight();
    //判断如果biaoshi为空的话就存否则不存
    if (localStorage.getItem("examineIndex") === null) {
      localStorage.setItem("examineIndex", "0");
    }
  },

  // 请求后端数据
  created() {
    let _this = this;
    window.addEventListener("resize", _this.getHeight);
    _this.getHeight();

    //请求筛选地址中的数据
  },
  methods: {
    mescrollInit(mescroll) {
      this.mescroll = mescroll; // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
    },

    // 上拉回调 page = {num:1, size:10}; num:当前页 ,默认从1开始; size:每页数据条数,默认10
    upCallback(page, mescroll) {
      let _this = this;
      if (localStorage.getItem("examineIndex") === "0") {
        _this.selectedOptionsA = []; //月份筛选制空
        _this.selectedOptions = []; //地址筛选制空
        _this.resultData() //请求地址和月份数据
        _this
          .$axios({
            method: "get",
            url: "bigservers/seeuser",
            params: {
              page: this.mescrollUp.page.num,
              pest_sort: "2"
            }
          })
          .then(res => {
            //判断当前是否有数据
            if (res.data.dat.length === 0) {
              this.isShow = true;
              this.addShow = false;
              mescroll.endErr();
            } else if (res.data.dat.length !== 0) {
              this.addShow = true;
              //判断当前是否有设置为默认的数据
              var array = res.data.dat;
              for (var i = 0; i < array.length; i++) {
                if (array[i].defa == "1") {
                  localStorage.setItem("defaultType", "2");
                  localStorage.setItem("defaultID", array[i].id);
                  localStorage.setItem("defaultHarmID", array[i].harm_id);
                }
              }

              //判断data中的变量是否为空 ，为空的话存后端发来的总条数
              if (this.aggregate === "") {
                //存变量
                this.aggregate = res.data.num;
                var b = 6;
                this.aggregate = this.aggregate / b;
                this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
              }
              //删除了默认的每页条数后判断数是否大于页码
              if (this.mescrollUp.page.num <= this.aggregate) {
                if (this.aggregate <= "1") {
                  var hasNext = false;
                } else if (this.aggregate > "1") {
                  var hasNext = true;
                }
                this.$axios({
                  method: "get",
                  url: "bigservers/seeuser",
                  params: {
                    page: this.mescrollUp.page.num,
                    pest_sort: "2"
                  }
                })
                  .then(res => {
                    let arr = res.data.dat;
                    // 如果是第一页需手动置空列表
                    if (page.num === 1) this.redata = [];
                    // 把请求到的数据添加到列表
                    this.redata = this.redata.concat(arr);
                    for (var i = 0; i < this.redata.length; i++) {
                      if (this.redata[i].defa == "1") {
                        localStorage.setItem("defaultID", this.redata[i].id);
                      }
                    }
                    console.log(this.redata)
                    // 数据渲染成功后,隐藏下拉刷新的状态
                    this.$nextTick(() => {
                      mescroll.endSuccess(arr.length, hasNext);
                    });

                    if (arr.length === 0) {
                      this.isShow = true;
                      this.addShow = false;
                    } else if (arr.length !== 0) {
                      this.isShow = false;
                      this.addShow = true;
                    }
                  })
                  .catch(error => {
                    mescroll.endErr();
                  });
              } else if (this.mescrollUp.page.num > this.aggregate) {
                // // 数据渲染成功后,隐藏下拉刷新的状态
                // this.$nextTick(() => {
                //   mescroll.endSuccess(this.aggregate);
                // });
              }
            }

            // 数据渲染成功后,隐藏下拉刷新的状态
            this.$nextTick(() => {
              mescroll.endSuccess(this.aggregate, hasNext);
            });
          })
          .catch(error => {
            mescroll.endErr();
            console.log(error);
          });
      } else if (localStorage.getItem("examineIndex") === "1") {
        _this.resultData() //请求地址和月份数据
        _this.selectedOptionsA = []; //月份筛选制空
        _this.selectedOptions = []; //地址筛选制空
        _this
          .$axios({
            method: "get",
            url: "bigservers/seeuser",
            params: {
              page: this.mescrollUp.page.num,
              pest_sort: "1"
            }
          })
          .then(res => {
            //判断当前是否有设置为默认的数据
            var array = res.data.dat;
            for (var i = 0; i < array.length; i++) {
              if (array[i].defa == "1") {
                localStorage.setItem("defaultType", "1");
                localStorage.setItem("defaultID", array[i].id);
                localStorage.setItem("defaultHarmID", array[i].harm_id);
              }
            }
            //判断当前是否有数据
            if (res.data.dat.length === 0) {
              this.isShow = true;
              this.addShow = false;
              mescroll.endErr();
            } else if (res.data.dat.length !== 0) {
              this.addShow = true;
              //判断data中的变量是否为空 ，为空的话存后端发来的总条数
              if (this.aggregate === "") {
                //存变量
                this.aggregate = res.data.num;
                var b = 6;
                this.aggregate = this.aggregate / b;
                this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
              }
              //删除了默认的每页条数后判断数是否大于页码
              // console.log(this.mescrollUp.page.num)
              if (this.mescrollUp.page.num <= this.aggregate) {
                if (this.aggregate <= "1") {
                  var hasNext = false;
                } else if (this.aggregate > "1") {
                  var hasNext = true;
                }
                this.$axios({
                  method: "get",
                  url: "bigservers/seeuser",
                  params: {
                    page: this.mescrollUp.page.num,
                    pest_sort: "1"
                  }
                })
                  .then(res => {
                    let arr = res.data.dat;
                    // 如果是第一页需手动置空列表
                    if (page.num === 1) this.redata = [];
                    // 把请求到的数据添加到列表
                    this.redata = this.redata.concat(arr);
                    for (var i = 0; i < this.redata.length; i++) {
                      if (this.redata[i].defa == "1") {
                        localStorage.setItem("defaultID", this.redata[i].id);
                      }
                    }
                    // 数据渲染成功后,隐藏下拉刷新的状态
                    this.$nextTick(() => {
                      mescroll.endSuccess(arr.length, hasNext);
                    });
                    if (arr.length === 0) {
                      this.isShow = true;
                      this.addShow = false;
                    } else if (arr.length !== 0) {
                      this.isShow = false;
                      this.addShow = true;
                    }
                  })
                  .catch(error => {
                    mescroll.endErr();
                  });
              } else if (this.mescrollUp.page.num > this.aggregate) {
                // 数据渲染成功后,隐藏下拉刷新的状态
                this.$nextTick(() => {
                  mescroll.endSuccess(this.aggregate, hasNext);
                });
              }
            }
            // 数据渲染成功后,隐藏下拉刷新的状态
            this.$nextTick(() => {
              mescroll.endSuccess(this.aggregate, hasNext);
            });
          })
          .catch(error => {
            mescroll.endErr();
            console.log(error);
          });
      }
    },

    //地区月份数据
    resultData() {
      let _this = this;
      var index = localStorage.getItem("examineIndex");
      if (index == "0") {
        //虫害
        var pest_sort = "2";
      } else if (index == "1") {
        //病害
        var pest_sort = "1";
      }
      _this
        .$axios({
          method: "get",
          url: "bigservers/cate",
          params: {
            pest_sort: pest_sort
          }
        })
        .then(res => {
          _this.optionsA = res.data.city; //地区筛选
          _this.options = res.data.month; //月份筛选
          // localStorage.setItem("examineRetDizhi", res.data[0].ret); //存地址ret数据
        })
        .catch(err => {
          console.log(err);
        });
    },

    //地区筛选
    result(e) {
      let _this = this;
      //判断当前是病害还是虫害
      _this.selectedOptionsA = [];
      if (localStorage.getItem("examineIndex") === "0") {
        //虫害
        var postData = _this.$qs.stringify({
          city: e[0],
          ret: "screen",
          pest_sort: "2"
        });
      } else if (localStorage.getItem("examineIndex") === "1") {
        //病害
        var postData = _this.$qs.stringify({
          city: e[0],
          ret: "screen",
          pest_sort: "1"
        });
      }
      _this
        .$axios({
          method: "post",
          url: "bigservers/seeuser",
          data: postData,
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(res => {
          if (res.data.nums == 0) {
            _this.isShow = true;
          } else if (res.data.nums != 0) {
            _this.redata = res.data.date;
            _this.isShow = false;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //月份筛选
    resultA(e) {
      let _this = this;
      var string = e[0];
      _this.selectedOptions = [];
      var a = string.replace(/[\u4e00-\u9fa5]/gi, "");
      //判断当前是病害还是虫害
      if (localStorage.getItem("examineIndex") === "0") {
        //虫害
        var postData = _this.$qs.stringify({
          month: a,
          ret: "screen",
          pest_sort: "2"
        });
      } else if (localStorage.getItem("examineIndex") === "1") {
        //病害
        var postData = _this.$qs.stringify({
          month: a,
          ret: "screen",
          pest_sort: "1"
        });
      }
      // let postData = _this.$qs.stringify({
      //   month: a,
      //   ret: "screen"
      // });
      _this
        .$axios({
          method: "post",
          url: "bigservers/seeuser",
          data: postData,
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(res => {
          if (res.data.nums == 0) {
            _this.isShow = true;
          } else if (res.data.nums != 0) {
            _this.isShow = false;
            _this.redata = res.data.date;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    //点击多选框执行的事件
    chang(e, id, index) {
      let _this = this;
      if (_this.checked.length === 0) {
        _this.shanShow = false;
      } else if (_this.checked.length !== 0) {
        _this.shanShow = true;
      }
      console.log(index);
      //判断当前选中的数据是否为默认数据
      var arr = _this.checked;
      var data = _this.redata;
      var find = false;

      if (data[index].defa == "1" && find == false) {
        var find = true;
        this.$confirm("该数据为设置的默认数据, 是否选中?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            _this.dataIndex = "1";
            this.$message({
              type: "success",
              message: "选中成功!",
              duration: 500
            });
          })
          .catch(() => {
            _this.dataIndex = "";
            _this.shanShow = false;
            arr.splice(index, "1");
            this.$message({
              type: "info",
              message: "选中取消",
              duration: 1500
            });
          });
      }
    },

    //动态获取浏览器高度
    get_boderHeight() {
      const that = this;
      window.onresize = () => {
        return (() => {
          window.fullHeight = document.documentElement.clientHeight;
          that.fullHeight = window.fullHeight;
        })();
      };
    },

    getHeight() {
      this.conheight.height = window.innerHeight - 170 + "px";
    },

    goBack() {
      let _this = this;
      localStorage.removeItem("examineID");
      // localStorage.removeItem("examineIndex");
      localStorage.removeItem("examinePage");
      localStorage.removeItem("examineRetDizhi");
      _this.selectedOptionsA = []; //月份筛选制空
      _this.selectedOptions = []; //地址筛选制空
      _this.$router.push("/home");
    },

    //点击右上角图标，跳转到统计数据页面
    addition() {
      let _this = this;
      //判断当前是在虫害还是病害
      if (localStorage.getItem("examineIndex") === "0") {
        console.log(this.redata);
        if (this.redata.length === "0") {
          this.$notify({
            title: "警告",
            message: "虫害暂无数据不能进行统计，请先添加数据",
            type: "warning"
          });
        } else if (this.redata.length !== "0") {
          _this.$router.push("/statistics");
          // location.reload();
        }
      } else if (localStorage.getItem("examineIndex") === "1") {
        if (this.redata.length === "0") {
          this.$notify({
            title: "警告",
            message: "病害暂无数据不能进行统计，请先添加数据",
            type: "warning"
          });
        } else if (this.redata.length !== "0") {
          _this.$router.push("/statistics");
          // location.reload();
        }
      }
    },

    handleClose(done) {
      let _this = this;
      _this.dialogVisible = false;
    },

    //点击查看触发事件
    chakan(e, id) {
      let _this = this;
      _this.longClick = 0; // 初始化
      if (
        e.target.className == "content-blocks-div2" ||
        e.target.className == "content-blocks-btn" ||
        e.target.className == "content-blocks-btn-xiangqi" ||
        e.target.className == "content-blocks-div-diaocha-img" ||
        e.target.className == 'content-blocks-div1' ||
        e.target.className == "moren"
      ) {
        let el = e.currentTarget;
        let dataID = id;
        localStorage.setItem("examineID", dataID);
        _this.$router.push("/particulars");
      }
    },

    //删除框
    handleCloseshanchu(done) {
      let _this = this;
      _this.dialogVisibleshan = false;
    },

    //点击小弹框中的删除
    shanchu(e, id) {
      let _this = this;
      _this.dialogVisible = false;
      if (e.target.className === "content-blocks-div-diaocha-img") {
        let el = e.currentTarget;
        let dataID = id;
        localStorage.setItem("examineID", dataID);
      }
    },

    //删除确定事件
    shanchuque() {
      let _this = this;
      var data = JSON.stringify(_this.checked);
      var postData = _this.$qs.stringify({
        ret: "all_del",
        user_id: data
      });
      //判断当前选中的数据是否为默认数据
      var arr = _this.checked;

      if (_this.dataIndex == "1") {
        //有默认数据
        this.$confirm("删除的数据中有设置的默认数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            _this
              .$axios({
                url: "bigservers/seeuser",
                method: "post",
                data: postData,
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded"
                }
              })
              .then(res => {
                if (res.status == 200) {
                  if (res.data.code == 200) {
                    _this.shanShow = false; //将删除按钮隐藏
                    _this.checked = []; //将删除多选框内的ID删除
                    this.$message({
                      message: "删除成功",
                      type: "success",
                      showClose: true,
                      duration: 1500
                    });
                    localStorage.removeItem("defaultID"); //删除默认ID
                    localStorage.removeItem("defaultType"); //删除默认类型
                    _this.refreshData(); //请求数据
                    _this.resultData(); //请求月份地区数据
                  } else if (res.data.code == null) {
                    this.$message({
                      showClose: true,
                      duration: 1500,
                      message: "删除错误，请重试",
                      type: "error"
                    });
                  }
                } else {
                  this.$message({
                    showClose: true,
                    duration: 1500,
                    message: "请求失败，请查看网络",
                    type: "error"
                  });
                }
              })
              .catch(err => {
                console.log(err);
              });
          })
          .catch(() => {
            _this.checked = [];
            _this.shanShow = false;
            arr.splice(i, "1");
            this.$message({
              type: "info",
              message: "删除取消"
            });
          });
      } else if (_this.dataIndex == "") {
        //没有默认数据
        _this
          .$axios({
            url: "bigservers/seeuser",
            method: "post",
            data: postData,
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          })
          .then(res => {
            if (res.status == 200) {
              if (res.data.code == 200) {
                _this.shanShow = false; //将删除按钮隐藏
                _this.checked = []; //将删除多选框内的ID删除
                this.$message({
                  message: "删除成功",
                  type: "success",
                  duration: 1500,
                  showClose: true
                });
                _this.refreshData(); //请求数据
                _this.resultData(); //请求月份地区数据
              } else if (res.data.code == null) {
                this.$message({
                  showClose: true,
                  message: "删除错误，请重试",
                  type: "error",
                  duration: 1500
                });
              }
            } else {
              this.$message({
                showClose: true,
                message: "请求失败，请查看网络",
                type: "error",
                duration: 1500
              });
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    },

    //删除取消
    delqueding() {
      var _this = this;
      _this.checked = []; //制空
      _this.shanShow = false;
    },

    //多选删除按钮事件
    del() {
      let _this = this;
      _this.dialogVisibleshan = true;
    },

    //导出功能
    dropDown() {},

    btn() {
      let _this = this;
      // location.reload();
      const timer = setInterval(() => {
        localStorage.removeItem("examineID");
      }, 1000);
    },

    //切换是虫害还是病害
    qingqiu(index) {
      let _this = this;
      localStorage.setItem("examineIndex", index); //保存已录区别下标
      //请求筛选地址中的数据
      _this.resultData();

      // 清空当前筛选值
      _this.selectedOptions = ""; //
      _this.selectedOptionsA = "";
      //判断当前点击的是虫害还是病害
      if (index === 0) {
        _this
          .$axios({
            method: "get",
            url: "bigservers/seeuser?page=1&pest_sort=2"
          })
          .then(res => {
            if (res.data.dat.length === 0) {
              _this.isShow = true;
            } else if (res.data.dat.length !== 0) {
              _this.isShow = false;
              _this.redata = res.data.dat;
              let a = res.data.page;
              let b = "4";
              let d = a / b;
              if (d % 1 === 0) {
                _this.page = d * 10;
              } else {
                let g = Math.ceil(d) * 10;
                _this.page = g;
              }
            }
            _this.axiosShow = true;
          })
          .catch(error => {
            console.log(error);
          });
      } else if (index === 1) {
        _this
          .$axios({
            method: "get",
            url: "bigservers/seeuser?page=1&pest_sort=1"
          })
          .then(res => {
            if (res.data.dat.length === 0) {
              _this.isShow = true;
            } else if (res.data.dat.length !== 0) {
              _this.isShow = false;
              _this.redata = res.data.dat;
              let a = res.data.page;
              let b = "4";
              let d = a / b;
              if (d % 1 === 0) {
                _this.page = d * 10;
              } else {
                let g = Math.ceil(d) * 10;
                _this.page = g;
              }
            }
            _this.axiosShow = true;
          })
          .catch(error => {
            console.log(error);
          });
      }
    },

    //转换时间格式
    p(s) {
      return s < 10 ? "0" + s : s;
    },

    //时间筛选选择确定
    timeAscertain(e) {
      //开始时间
      const a = new Date(e[0]);
      const resDate =
        a.getFullYear() +
        "-" +
        this.p(a.getMonth() + 1) +
        "-" +
        this.p(a.getDate());
      const resTime =
        this.p(a.getHours()) +
        ":" +
        this.p(a.getMinutes()) +
        ":" +
        this.p(a.getSeconds());

      //结束时间
      const b = new Date(e[1]);
      const resDateA =
        b.getFullYear() +
        "-" +
        this.p(b.getMonth() + 1) +
        "-" +
        this.p(b.getDate());
      const resTimeA =
        this.p(b.getHours()) +
        ":" +
        this.p(b.getMinutes()) +
        ":" +
        this.p(b.getSeconds());

      let postData = this.$qs.parse({
        ret: localStorage.getItem("examineIndex"),
        start_time: resDate,
        end_time: resDateA,
        page: this.mescrollUp.page.num
      });
      this.$axios({
        method: "post",
        url: "bigservers/screen_time",
        data: postData
      })
        .then(res => {
          if (res.data.dat.length === 0) {
            this.isShow = true;
            const timer = setInterval(() => {
              // location.reload();
            }, 2000);
          } else if (res.data.dat.length !== 0) {
            this.redata = res.data.dat;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    //导出excel表格
    AAAAA() {
      let _this = this;
      let data = JSON.stringify(_this.checked);
      var name = sessionStorage.getItem("login");
      let postData = this.$qs.stringify({
        user_id: data,
        username: name
      });
      this.$axios({
        method: "post",
        url: "bigservers/expores",
        data: postData
      })
        .then(res => {
          if (res.status == 200) {
            console.log(res.data[0]);
            // window.location.href =
            //   "http://47.104.218:8000/" + res.data[0].file;

            window.location.href = "bigservers/" + res.data[0].file;

            _this.shanShow = false;
            _this.checked = [];
          } else {
            this.$notify({
              title: "失败",
              message: "请求失败，请查看网络再进行操作",
              type: "error",
              duration: 1000
            });
          }
        })
        .catch(err => {
          this.$notify({
            title: "失败",
            message: "请求失败",
            type: "error",
            duration: 1000
          });
        });
    },

    //删除等事件触发后进行调用的数据接口
    refreshData() {
      var _this = this;
      //判断当前是虫害还是病害
      if (localStorage.getItem("examineIndex") == "0") {
        _this
          .$axios({
            method: "get",
            url: "bigservers/seeuser?page=1&pest_sort=2"
          })
          .then(res => {
            if (res.data.dat.length === 0) {
              _this.isShow = true;
            } else if (res.data.dat.length !== 0) {
              _this.isShow = false;
              _this.redata = res.data.dat;
              let a = res.data.page;
              let b = "4";
              let d = a / b;
              if (d % 1 === 0) {
                _this.page = d * 10;
              } else {
                let g = Math.ceil(d) * 10;
                _this.page = g;
              }
            }
            _this.axiosShow = true;
          })
          .catch(error => {
            console.log(error);
          });
      } else if (localStorage.getItem("examineIndex") == "1") {
        _this
          .$axios({
            method: "get",
            url: "bigservers/seeuser?page=1&pest_sort=1"
          })
          .then(res => {
            if (res.data.dat.length === 0) {
              _this.isShow = true;
            } else if (res.data.dat.length !== 0) {
              _this.isShow = false;
              _this.redata = res.data.dat;
              let a = res.data.page;
              let b = "4";
              let d = a / b;
              if (d % 1 === 0) {
                _this.page = d * 10;
              } else {
                let g = Math.ceil(d) * 10;
                _this.page = g;
              }
            }
            _this.axiosShow = true;
          })
          .catch(error => {
            console.log(error);
          });
      }
    }
  }
};
</script>

<style lang="scss">
@import "../../assets/style/bus.scss";
@import "../../assets/style/scss/examine.scss";
</style>

<style lang="scss">
.checkboxkua {
  width: 0.35rem;
  display: inline-block;
  margin: -0.35rem 0.55rem 0 0;
}
.checkboxkuaA {
  display: inline-block;
  margin: -0.3rem 0 0 0;
}
</style>