brokerindex.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // customer/pages/brokerindex/brokerindex.js
  2. var App = getApp();
  3. var utils = require("../../../utils/http");
  4. var page = 1;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. loading: false,
  11. name: '',
  12. phone: '',
  13. community_name: '',
  14. type: '',
  15. brokerRanklist: [],
  16. swiperData: []
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. page = 1;
  23. if (!!options.type) {
  24. this.setData({
  25. type: options.type
  26. })
  27. }
  28. this.getBrokerRank();
  29. wx.hideHomeButton();
  30. },
  31. jumpMinePage:function(e) {
  32. wx.reLaunch({
  33. url: '/customer/pages/broker/broker',
  34. })
  35. },
  36. nameInput(e) {
  37. console.log(e)
  38. this.setData({
  39. name: e.detail.value
  40. })
  41. },
  42. phoneInput(e) {
  43. this.setData({
  44. phone: e.detail.value
  45. })
  46. },
  47. communityNameInput(e) {
  48. this.setData({
  49. community_name: e.detail.value
  50. })
  51. },
  52. //手机号正则验证
  53. isPhoneNum: function (phone) {
  54. var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
  55. if (!myreg.test(phone)) {
  56. return false;
  57. }
  58. return true;
  59. },
  60. /**
  61. * 添加客户
  62. */
  63. addCustomer: function () {
  64. var that = this;
  65. if (!that.data.phone) {
  66. wx.showToast({
  67. title: '请填写手机号',
  68. icon: 'none',
  69. });
  70. return false;
  71. }
  72. if (!this.isPhoneNum(that.data.phone)) {
  73. wx.showToast({
  74. title: '手机号格式错误',
  75. icon: 'none',
  76. });
  77. return false;
  78. }
  79. wx.showLoading({
  80. title: '提交中...'
  81. });
  82. that.setData({
  83. loading: true,
  84. })
  85. utils.$post({
  86. url: App.globalData.webUrl + 'api/agents_work/add_customer',
  87. header: {
  88. 'Authorization': 'bearer ' + App.globalData.token
  89. },
  90. data: {
  91. name: that.data.name,
  92. phone: that.data.phone,
  93. community_name: that.data.community_name
  94. },
  95. success: function (res) {
  96. wx.hideLoading();
  97. if (res.data.code == '0') {
  98. wx.showToast({
  99. title: '添加成功',
  100. icon: 'none',
  101. duration: 1500
  102. })
  103. that.setData({
  104. loading: false,
  105. name: '',
  106. phone: '',
  107. community_name: ''
  108. })
  109. } else {
  110. wx.showToast({
  111. title: res.data.msg,
  112. icon: 'none',
  113. duration: 1500
  114. })
  115. }
  116. }
  117. })
  118. },
  119. /**
  120. * 经纪人排名列表
  121. */
  122. getBrokerRank() {
  123. let that = this;
  124. utils.$post({
  125. url: App.globalData.webUrl + 'api/agents_work/agent_rank_list',
  126. header: {
  127. 'Authorization': 'bearer ' + App.globalData.token
  128. },
  129. data: {
  130. page: page,
  131. limit: 10,
  132. },
  133. success: function (res) {
  134. if (res.data.code == '0') {
  135. that.setData({
  136. datashow: true,
  137. brokerRanklist: res.data.data
  138. })
  139. if (that.data.brokerRanklist.length) {
  140. if (that.data.brokerRanklist.length > 6) {
  141. that.setData({
  142. swiperData: that.data.brokerRanklist.slice(0,6)
  143. })
  144. } else {
  145. that.setData({
  146. swiperData: that.data.brokerRanklist
  147. })
  148. }
  149. }
  150. if (that.data.type == 'rank') {
  151. wx.pageScrollTo({scrollTop: 750})
  152. }
  153. }
  154. }
  155. })
  156. },
  157. /**
  158. * 生命周期函数--监听页面初次渲染完成
  159. */
  160. onReady() {
  161. },
  162. /**
  163. * 生命周期函数--监听页面显示
  164. */
  165. onShow() {
  166. },
  167. /**
  168. * 生命周期函数--监听页面隐藏
  169. */
  170. onHide() {
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload() {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh() {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom() {
  186. if (this.data.type == 'rank') {
  187. page++;
  188. let that = this;
  189. utils.$post({
  190. url: App.globalData.webUrl + 'api/agents_work/agent_rank_list',
  191. header: {
  192. 'Authorization': 'bearer ' + App.globalData.token
  193. },
  194. data: {
  195. page: page,
  196. limit: 10,
  197. },
  198. success: function (res) {
  199. if (res.data.code == '0') {
  200. let arr = that.data.brokerRanklist.concat(res.data.data);
  201. that.setData({
  202. datashow: true,
  203. brokerRanklist: arr
  204. })
  205. }
  206. }
  207. })
  208. }
  209. },
  210. /**
  211. * 用户点击右上角分享
  212. */
  213. onShareAppMessage() {
  214. }
  215. })