customermanage.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/customermanage/customermanage.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. pagesList: [],
  9. loading: true,
  10. dataLoadComplete: false,
  11. params: {
  12. pageNum: 1,
  13. pageSize: 15,
  14. },
  15. },
  16. addCustomer() {
  17. wx.navigateTo({
  18. url: '/pages/customermanage/addcustomer'
  19. })
  20. },
  21. getList(showSetTip) {
  22. const that = this;
  23. wx.showLoading({ mask: true });
  24. this.setData({
  25. title: '加载中',
  26. loading: true
  27. })
  28. const params = JSON.parse(JSON.stringify(that.data.params));
  29. app.$http.get('/user/getAccountInfoPage', params).then(({ status, data: { list = [], total = 0 }, msg }) => {
  30. if (0 === status) {
  31. let result = list,
  32. dataLoadComplete = false;
  33. // 判断数据是否全部加载完成
  34. if (15 != list.length) {
  35. dataLoadComplete = true;
  36. }
  37. // 不是第一页时,合并原有数据
  38. if (1 != params.pageNum) {
  39. result = this.data.pagesList.concat(result)
  40. }
  41. this.setData({
  42. pagesList: result,
  43. dataLoadComplete
  44. })
  45. }
  46. wx.hideLoading();
  47. this.setData({
  48. loading: false
  49. })
  50. if(showSetTip) {
  51. wx.showToast({
  52. title: '设置成功',
  53. icon: 'success'
  54. })
  55. }
  56. }).catch(() => {
  57. wx.hideLoading();
  58. this.setData({
  59. loading: false
  60. })
  61. })
  62. },
  63. // 滚动到处理
  64. scrollBottom() {
  65. if (this.data.dataLoadComplete) {
  66. return
  67. }
  68. this.setData({
  69. 'params.pageNum': this.data.params.pageNum + 1
  70. })
  71. this.getList();
  72. },
  73. setDefault(e) {
  74. const { id, isDefault } = e.currentTarget.dataset.item;
  75. if (!isDefault) {
  76. wx.showLoading();
  77. app.$http.postForm('/user/setDefault', {
  78. id
  79. }).then(({ status, msg }) => {
  80. if (status === 0) {
  81. app.globalData = {};
  82. app.getUserInfo(app.token);
  83. this.getList(true);
  84. } else {
  85. wx.showToast({
  86. title: msg,
  87. icon: 'none'
  88. })
  89. }
  90. wx.hideLoading();
  91. }).catch(() => {
  92. wx.hideLoading();
  93. })
  94. }
  95. },
  96. unbindDevice(e) {
  97. const {id, username, userNumber} = e.currentTarget.dataset.item;
  98. this.popup.setData({
  99. extClass: 'customer-popup',
  100. showIcon: false,
  101. title: '您确认解绑当前户号?',
  102. content: `户名:${username || '-'}`,
  103. content1: `户号:${userNumber || '-'}`,
  104. params: {
  105. id
  106. }
  107. });
  108. this.popup.show();
  109. },
  110. cancelEvent: function () {
  111. this.popup.close();
  112. },
  113. confirmEvent: function () {
  114. const self = this;
  115. if (this.popup.data.type == 'success' && this.popup.data.params) {
  116. const { id } = this.popup.data.params;
  117. app.$http.deleteForm('/user/cancelBind', {
  118. id
  119. }).then(({ status, msg }) => {
  120. if (status === 0) {
  121. wx.showToast({
  122. title: '解绑成功',
  123. })
  124. setTimeout(() => {
  125. self.getList();
  126. app.globalData = {};
  127. app.getUserInfo(app.token);
  128. self.popup.close();
  129. }, 1500)
  130. } else {
  131. wx.showToast({
  132. title: msg,
  133. icon: 'none'
  134. })
  135. }
  136. })
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. //获得popup组件
  144. this.popup = this.selectComponent("#popup");
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. this.getList();
  151. },
  152. })