phone.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import HTTP from "../../../../requestFn/Api"
  2. const app = getApp();
  3. Page({
  4. data: {
  5. garden_id: null,
  6. class_list: [],
  7. class_id: 0,
  8. class_name: "全部",
  9. phone_list: [],
  10. page: 1,
  11. page_size: 10,
  12. has_more: true,
  13. },
  14. onLoad(options) {
  15. const that = this;
  16. const {
  17. garden_id
  18. } = app.globalData;
  19. if (garden_id) {
  20. that.setData({
  21. garden_id
  22. })
  23. }
  24. that.getPhone_class(garden_id);
  25. },
  26. onShow() {
  27. this.init();
  28. },
  29. init() {
  30. this.setData({
  31. page: 1,
  32. has_more: true
  33. })
  34. this.getPhone(true)
  35. },
  36. getPhone_class(garden_id) {
  37. const that = this;
  38. HTTP.GetPhone_class({
  39. garden_id,
  40. page: 1,
  41. page_size: 9999,
  42. }).then(res => {
  43. const class_list = res.list.filter(item => item.enable);
  44. that.setData({
  45. class_list: [{
  46. id: 0,
  47. class_name: "全部"
  48. }, ...class_list]
  49. })
  50. })
  51. },
  52. getPhone(flag = false) {
  53. const that = this;
  54. let {
  55. class_id,
  56. garden_id,
  57. page,
  58. page_size,
  59. phone_list
  60. } = that.data;
  61. HTTP.GetPhone({
  62. garden_id,
  63. page,
  64. page_size,
  65. class_id
  66. }).then(res => {
  67. const newArray = res.list.filter(item => item.enable)
  68. that.setData({
  69. phone_list: flag ? newArray : [...newArray, ...phone_list],
  70. page: ++page,
  71. has_more: page_size === newArray.length
  72. })
  73. })
  74. },
  75. bindPickerChange(e) {
  76. const that = this;
  77. const {
  78. class_list,
  79. } = that.data
  80. const {
  81. value
  82. } = e.detail;
  83. const class_id = class_list[value].id
  84. that.setData({
  85. class_name: class_list[value].class_name,
  86. class_id
  87. });
  88. that.init()
  89. },
  90. callphone(e) {
  91. const {
  92. phone
  93. } = e.currentTarget.dataset;
  94. wx.makePhoneCall({
  95. phoneNumber: phone,
  96. })
  97. },
  98. onReachBottom() {
  99. if (!this.data.has_more) {
  100. wx.showToast({
  101. title: '没有更多数据了',
  102. icon: 'none'
  103. })
  104. return console.log('没有更多数据了');
  105. }
  106. this.getPhone()
  107. },
  108. onPullDownRefresh: function () {
  109. app.onRefresh();
  110. this.init();
  111. },
  112. })