partnerCommonRecord.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. // pages/partnerCommonRecord/partnerCommonRecord.js
  2. var that;
  3. var Util = require('../../utils/util.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. urlHttp: '',
  8. id : 0,
  9. tabId : 0,//默认tab id
  10. recordList: {},//关系列表
  11. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  12. callbackcount: 10, //返回数据的个数
  13. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  14. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  15. scrollTrue : false,//页面滚动
  16. },
  17. onLoad: function (options) {
  18. var that = this;
  19. var host = getApp().globalData.servsers;
  20. console.log(options.id)
  21. that.setData({
  22. urlHttp: host ,
  23. tabId: options.id
  24. })
  25. },
  26. onShow: function () {
  27. var that = this;
  28. var host = getApp().globalData.servsers;
  29. var un_id = getApp().globalData.un_id;
  30. var openid = getApp().globalData.openid;
  31. var userRole = getApp().globalData.userRole;
  32. var tabId = that.data.tabId;
  33. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)){
  34. wx.navigateTo({
  35. url: '/pages/authorize/authorize?link=partnerCommonRecord',
  36. })
  37. }else{
  38. if (tabId == 0) {
  39. //邀请客户
  40. that.recordPerson();
  41. wx.setNavigationBarTitle({
  42. title: '邀请客户'
  43. })
  44. } else {
  45. //收益记录
  46. that.recordEarnings();
  47. wx.setNavigationBarTitle({
  48. title: '收益记录'
  49. })
  50. }
  51. }
  52. },
  53. //tab切换
  54. tabChange:function(e){
  55. var that = this;
  56. var tabId = e.currentTarget.dataset.id;
  57. var tabIdOld = that.data.tabId;
  58. if (tabId == tabIdOld){
  59. return false;
  60. }else{
  61. that.setData({
  62. tabId: tabId,
  63. recordList: {},
  64. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  65. callbackcount: 10, //返回数据的个数
  66. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  67. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  68. scrollTrue : false
  69. })
  70. if (tabId == 0) {
  71. //邀请客户
  72. that.recordPerson();
  73. wx.setNavigationBarTitle({
  74. title: '邀请客户'
  75. })
  76. } else {
  77. //收益记录
  78. that.recordEarnings();
  79. wx.setNavigationBarTitle({
  80. title: '收益记录'
  81. })
  82. }
  83. }
  84. },
  85. //分页获取用户分销关系列表
  86. recordPerson:function(e){
  87. var that = this;
  88. var host = getApp().globalData.servsers;
  89. var un_id = getApp().globalData.un_id;
  90. var openid = getApp().globalData.openid;
  91. var userRole = getApp().globalData.userRole;
  92. wx.request({
  93. url: host + "api/distributeSell/getRelationList",
  94. data: {
  95. userId: un_id,//当前用户userId
  96. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  97. offset: 0,
  98. limit: 10
  99. },
  100. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  101. header: {
  102. 'Accept': 'application/json'
  103. },
  104. success: function (res) {
  105. if (res.data.data.total == 10 ) {
  106. that.setData({
  107. recordList: res.data.data.rows,
  108. searchPageNum: 0, //第一次加载,设置1
  109. searchSongList: [], //放置返回数据的数组,设为空
  110. isFromSearch: true, //第一次加载,设置true
  111. searchLoading: true, //把"上拉加载"的变量设为true,显示
  112. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  113. scrollTrue : true
  114. })
  115. } else if (res.data.data.total > 0 && res.data.data.total < 10){
  116. that.setData({
  117. recordList: res.data.data.rows,
  118. searchPageNum: 0, //第一次加载,设置1
  119. searchSongList: [], //放置返回数据的数组,设为空
  120. isFromSearch: true, //第一次加载,设置true
  121. searchLoading: false, //把"上拉加载"的变量设为true,显示
  122. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  123. scrollTrue : true
  124. });
  125. }
  126. if (res == null || res.data == null) {
  127. console.error('网络请求失败');
  128. return;
  129. }
  130. }
  131. })
  132. },
  133. //收益记录
  134. recordEarnings:function(e){
  135. var that = this;
  136. var host = getApp().globalData.servsers;
  137. var un_id = getApp().globalData.un_id;
  138. var openid = getApp().globalData.openid;
  139. var userRole = getApp().globalData.userRole;
  140. wx.request({
  141. url: host + "api/distributeSell/getEarnList",
  142. data: {
  143. userId: un_id,//当前用户userId
  144. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  145. offset: 0,
  146. limit: 10
  147. },
  148. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  149. header: {
  150. 'Accept': 'application/json'
  151. },
  152. success: function (res) {
  153. console.log(res);
  154. if (res.data.data.total == 10) {
  155. that.setData({
  156. recordList: res.data.data.rows,
  157. searchPageNum: 0, //第一次加载,设置1
  158. searchSongList: [], //放置返回数据的数组,设为空
  159. isFromSearch: true, //第一次加载,设置true
  160. searchLoading: true, //把"上拉加载"的变量设为true,显示
  161. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  162. scrollTrue : true
  163. })
  164. } else if (res.data.data.total > 0 && res.data.data.total < 10) {
  165. that.setData({
  166. recordList: res.data.data.rows,
  167. searchPageNum: 0, //第一次加载,设置1
  168. searchSongList: [], //放置返回数据的数组,设为空
  169. isFromSearch: true, //第一次加载,设置true
  170. searchLoading: false, //把"上拉加载"的变量设为true,显示
  171. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  172. scrollTrue : true
  173. });
  174. }
  175. if (res == null || res.data == null) {
  176. console.error('网络请求失败');
  177. return;
  178. }
  179. }
  180. })
  181. },
  182. fetchSearchList: function () {//加载更多
  183. var that = this;
  184. var host = getApp().globalData.servsers;
  185. var un_id = getApp().globalData.un_id;
  186. var openid = getApp().globalData.openid;
  187. var userRole = getApp().globalData.userRole;
  188. var tabId = that.data.tabId;
  189. if (tabId == 0){
  190. //关系列表
  191. wx.request({
  192. url: host + "api/distributeSell/getRelationList",
  193. data: {
  194. userId: un_id,//当前用户userId
  195. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  196. offset: parseInt(that.data.searchPageNum),
  197. limit: 10
  198. },
  199. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  200. header: {
  201. 'Accept': 'application/json'
  202. },
  203. success: function (res) {
  204. if (res.data.data.total > 0) {
  205. let recordList = [];
  206. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  207. that.data.isFromSearch ? recordList = res.data.data.rows : recordList = that.data.recordList.concat(res.data.data.rows)
  208. that.setData({
  209. recordList: recordList, //获取数据数组
  210. searchLoading: true , //把"上拉加载"的变量设为false,显示
  211. scrollTrue : true
  212. });
  213. } else {
  214. that.setData({
  215. searchLoadingComplete: true, //把“没有数据”设为true,显示
  216. searchLoading: false , //把"上拉加载"的变量设为false,隐藏
  217. scrollTrue: true
  218. });
  219. }
  220. if (res == null || res.data == null) {
  221. console.error('网络请求失败');
  222. return;
  223. }
  224. }
  225. })
  226. }else{
  227. //收益记录
  228. wx.request({
  229. url: host + "api/distributeSell/getEarnList",
  230. data: {
  231. userId: un_id,//当前用户userId
  232. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  233. offset: parseInt(that.data.searchPageNum),
  234. limit: 10
  235. },
  236. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  237. header: {
  238. 'Accept': 'application/json'
  239. },
  240. success: function (res) {
  241. if (res.data.data.total > 0) {
  242. let recordList = [];
  243. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  244. that.data.isFromSearch ? recordList = res.data.data.rows : recordList = that.data.recordList.concat(res.data.data.rows)
  245. that.setData({
  246. recordList: recordList, //获取数据数组
  247. searchLoading: true, //把"上拉加载"的变量设为false,显示
  248. scrollTrue: true
  249. });
  250. } else{
  251. that.setData({
  252. searchLoadingComplete: true, //把“没有数据”设为true,显示
  253. searchLoading: false, //把"上拉加载"的变量设为false,隐藏
  254. scrollTrue: true
  255. });
  256. }
  257. if (res == null || res.data == null) {
  258. console.error('网络请求失败');
  259. return;
  260. }
  261. }
  262. })
  263. }
  264. },
  265. //滚动到底部触发事件
  266. searchScrollLower: function () {
  267. var that = this;
  268. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  269. that.setData({
  270. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  271. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  272. });
  273. that.fetchSearchList();
  274. }
  275. },
  276. //下拉刷新
  277. onPullDownRefresh: function () {
  278. var that = this;
  279. var tabId = that.data.tabId;
  280. // if (tabId == 0){
  281. // that.recordPerson();
  282. // }else{
  283. // that.recordEarnings();
  284. // }
  285. },
  286. })