// components/list/index.js
Component({
  externalClasses: ['list-class'],
  properties: {
    template: String,
    templateData: Object,
    request: Object,
    reload: Object,
    warp: Boolean,
    templateList: Array
  },
  observers: {
    reload(o) {
      this._reload && this._reload(o);
    }
  },
  methods: {
    getItems({
      detail: {
        items
      }
    }) {
      let {
        data: {
          list
        }
      } = this;
      this.setData({
        list: [...(list || []), ...items]
      })
      wx.stopPullDownRefresh();
    },
    update({
      detail: {
        type
      },
      currentTarget: {
        dataset: {
          index
        }
      }
    }) {
      let {
        data: {
          list = []
        }
      } = this;
      type == "del" && list.splice(index, 1)
      this.setData({
        list
      })
      this.triggerEvent("change")
    },
    reload({
      detail: {
        reload
      }
    }) {
      this._reload = () => {
        this.setData({
          list: null
        })
        reload()
      };
    },
    loadCompletion({ detail: { completion } }) {
      this.setData({
        completion
      })
    }
  }
})