<template>
  <div>
    <van-nav-bar title="历史随访" @click-left="$router.back()" left-arrow fixed placeholder safe-area-inset-top />
    <div class="box">
      <van-search v-model="historyform.name" shape="round" show-action placeholder="请输入姓名" @search="onSearch">
        <template #action>
          <div style="display:flex;align-items:center;">
            <div @click="onSearch">搜索</div>
            <van-button v-if="roleIdStr==15" size="mini" @click="$router.push({path:'/followUp/addfollow'})">新建随访</van-button>
          </div>
        </template>
      </van-search>
    </div>
    <van-list v-model="loading" :immediate-check="false" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <history :historyList="historyList"></history>
    </van-list>
  </div>
</template>
<script>
import { historyFollowUp } from '../../api/index.js'
import history from './history.vue'
export default {
  components: { history },
  data() {
    return {
      roleIdStr: JSON.parse(sessionStorage.getItem('userInfo')).roleIdStr,
      active: 0,
      loading: false,
      finished: false,
      historyList: '',
      historyform: {
        pageNum: 1,
        pageSize: 20,
        isSupervise:
          JSON.parse(sessionStorage.getItem('userInfo')).roleIdStr == 14
            ? 2
            : 1,
        name: '',
      },
    }
  },
  created() {
    this.loading = true
    this.historyFollowUp()
  },
  methods: {
    async historyFollowUp() {
      const res = await historyFollowUp(this.historyform)
      this.loading = false
      if (this.historyform.pageNum == 1) {
        this.historyList = res.data.records
      } else {
        this.historyList = this.historyList.concat(res.data.records)
      }

      if (this.historyList.length >= res.data.total) {
        this.finished = true
      } else {
        this.finished = false
      }
    },
    onLoad() {
      this.loading = true
      this.historyform.pageNum = this.historyform.pageNum + 1
      this.historyFollowUp()
    },
    onSearch() {
      this.historyform.pageNum = 1
      this.historyFollowUp()
    },
  },
}
</script>
<style lang="scss" scoped>
.box {
  width: 100%;
  position: fixed;
  background-color: #fff;
  z-index: 9999;
}
.van-list {
  padding: 0 30px;
  padding-top: 26px;
  margin-top: 92px;
}
.van-button {
  width: 160px;
  background-color: #1677ff;
  color: #fff;
  font-size: 24px;
  border-radius: 8px;
  margin-left: 10px;
}
.van-search__action:active {
  background-color: transparent;
}
</style>