customermanage.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. call(e){
  111. let mobile= e.currentTarget.dataset['index'];
  112. if(mobile!==""){
  113. wx.makePhoneCall({
  114. phoneNumber: mobile
  115. })
  116. }
  117. },
  118. cancelEvent: function () {
  119. this.popup.close();
  120. },
  121. confirmEvent: function () {
  122. const self = this;
  123. if (this.popup.data.type == 'success' && this.popup.data.params) {
  124. const { id } = this.popup.data.params;
  125. app.$http.deleteForm('/user/cancelBind', {
  126. id
  127. }).then(({ status, msg }) => {
  128. if (status === 0) {
  129. wx.showToast({
  130. title: '解绑成功',
  131. })
  132. setTimeout(() => {
  133. self.getList();
  134. app.globalData = {};
  135. app.getUserInfo(app.token);
  136. self.popup.close();
  137. }, 1500)
  138. } else {
  139. wx.showToast({
  140. title: msg,
  141. icon: 'none'
  142. })
  143. }
  144. })
  145. }
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady: function () {
  151. //获得popup组件
  152. this.popup = this.selectComponent("#popup");
  153. },
  154. /**
  155. * 生命周期函数--监听页面显示
  156. */
  157. onShow: function () {
  158. this.getList();
  159. },
  160. })