index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // components/list/index.js
  2. Component({
  3. externalClasses: ['list-class'],
  4. properties: {
  5. template: String,
  6. templateData: Object,
  7. request: Object,
  8. reload: Object,
  9. warp: Boolean,
  10. templateList: Array
  11. },
  12. observers: {
  13. reload(o) {
  14. this._reload && this._reload(o);
  15. }
  16. },
  17. methods: {
  18. getItems({
  19. detail: {
  20. items
  21. }
  22. }) {
  23. let {
  24. data: {
  25. list
  26. }
  27. } = this;
  28. this.setData({
  29. list: [...(list || []), ...items]
  30. })
  31. wx.stopPullDownRefresh();
  32. },
  33. update({
  34. detail: {
  35. type
  36. },
  37. currentTarget: {
  38. dataset: {
  39. index
  40. }
  41. }
  42. }) {
  43. let {
  44. data: {
  45. list = []
  46. }
  47. } = this;
  48. type == "del" && list.splice(index, 1)
  49. this.setData({
  50. list
  51. })
  52. this.triggerEvent("change")
  53. },
  54. reload({
  55. detail: {
  56. reload
  57. }
  58. }) {
  59. this._reload = () => {
  60. this.setData({
  61. list: null
  62. })
  63. reload()
  64. };
  65. },
  66. loadCompletion({ detail: { completion } }) {
  67. this.setData({
  68. completion
  69. })
  70. }
  71. }
  72. })