// pages/emergency/resourse/index/index.js
const app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    condition: '',

    canChange: false,
    freshIng: false,
    latlng: {},
    page: 1,
    pageSize: 10,
    list: []
  },

  pageLifetimes: {
    show: function () {
      this.getList();
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {

    /**
     * 搜索
     */
    inputSearch: function (e) {
      this.data.condition = e.detail.value;
      this.refresh();
    },

    /**
     * 刷新
     * @param {*} params 
     */
    refresh: function (params) {
      this.data.page = 1;
      this.data.list = [];
      this.setData(this.data)
      this.getList();
    },

    /**
     * 获取应急通讯录体系
     */
    getList: function () {
      const params = {
        page: this.data.page,
        limit: this.data.pageSize,
        userId: app.globalData.userInfo.userId,
        condition: this.data.condition
      }
      app.axios("GET", "app", "/Othexpert/performUserPage", params, false).then(res => {
        console.log(res,'res===>');
        this.data.freshIng = false;
        if (res.code == 1) {
          let page = Number.parseInt(res.data.pageNum);
          if (this.data.page == 1) {
            this.data.list = res.data.list;
          } else {
            var list = this.data.list;
            if (this.data.page == page) this.data.list = [...list, ...res.data.list]
          }
          if (res.data.list?.length > 0) this.data.page = page + 1
        }
        this.setData(this.data);
      })
    },
  }
})