partnerBusinessRecord.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // pages/partnerBusinessRecord/partnerBusinessRecord.js
  2. var that;
  3. var Util = require('../../utils/util.js');
  4. Page({
  5. data: {
  6. urlHttp : '',
  7. tabId: 0, //默认tab id
  8. year : '', //年
  9. month : '', //月,
  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. that.setData({
  21. urlHttp: host,
  22. year: options.year,
  23. month: options.month,
  24. tabId: options.tabId
  25. })
  26. },
  27. onShow: function () {
  28. var that = this;
  29. var host = getApp().globalData.servsers;
  30. var un_id = getApp().globalData.un_id;
  31. var openid = getApp().globalData.openid;
  32. var userRole = getApp().globalData.userRole;
  33. var tabId = that.data.tabId;
  34. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  35. wx.navigateTo({
  36. url: '/pages/authorize/authorize?link=partnerBusinessRecord',
  37. })
  38. } else {
  39. if (tabId == 0) {
  40. //邀请客户
  41. that.recordPerson();
  42. wx.setNavigationBarTitle({
  43. title: '邀请客户'
  44. })
  45. } else {
  46. //收益记录
  47. that.recordEarnings();
  48. wx.setNavigationBarTitle({
  49. title: '收益记录'
  50. })
  51. }
  52. }
  53. },
  54. //tab切换
  55. tabChange: function (e) {
  56. var that = this;
  57. var tabId = e.currentTarget.dataset.id;
  58. var tabIdOld = that.data.tabId;
  59. if (tabId == tabIdOld) {
  60. return false;
  61. } else {
  62. that.setData({
  63. tabId: tabId,
  64. recordList: {},
  65. searchPageNum: 0, // 设置加载的第几次,默认是第一次
  66. callbackcount: 10, //返回数据的个数
  67. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  68. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  69. scrollTrue: false
  70. })
  71. if (tabId == 0) {
  72. //邀请客户
  73. that.recordPerson();
  74. wx.setNavigationBarTitle({
  75. title: '邀请客户'
  76. })
  77. } else {
  78. //收益记录
  79. that.recordEarnings();
  80. wx.setNavigationBarTitle({
  81. title: '收益记录'
  82. })
  83. }
  84. }
  85. },
  86. //上一个月的记录
  87. monthPre:function(e){
  88. var that = this;
  89. var month = that.data.month;
  90. var year = that.data.year;
  91. var tabId = that.data.tabId;
  92. if (month >1){
  93. month --;
  94. }else{
  95. month = 12;
  96. year --;
  97. }
  98. that.setData({
  99. month: month,
  100. year: year
  101. })
  102. if (tabId == 0) {
  103. //邀请客户
  104. that.recordPerson();
  105. wx.setNavigationBarTitle({
  106. title: '邀请客户'
  107. })
  108. }else{
  109. //收益记录
  110. that.recordEarnings();
  111. wx.setNavigationBarTitle({
  112. title: '收益记录'
  113. })
  114. }
  115. },
  116. //下一个月的记录
  117. monthN: function (e) {
  118. var that = this;
  119. var nowMonth = (new Date()).getMonth() + 1;//系统时间月份
  120. var month = that.data.month;
  121. var year = that.data.year;
  122. var tabId = that.data.tabId;
  123. if (month < 12 && month < nowMonth){
  124. month++;
  125. } else if (month == 12){
  126. month = 1;
  127. year ++;
  128. }
  129. that.setData({
  130. month: month,
  131. year: year
  132. })
  133. if (tabId == 0) {
  134. //邀请客户
  135. that.recordPerson();
  136. wx.setNavigationBarTitle({
  137. title: '邀请客户'
  138. })
  139. } else {
  140. //收益记录
  141. that.recordEarnings();
  142. wx.setNavigationBarTitle({
  143. title: '收益记录'
  144. })
  145. }
  146. },
  147. //商务 - 邀请客户
  148. recordPerson: function (e) {
  149. var that = this;
  150. var host = getApp().globalData.servsers;
  151. var un_id = getApp().globalData.un_id;
  152. var openid = getApp().globalData.openid;
  153. var userRole = getApp().globalData.userRole;
  154. var year = that.data.year;
  155. var month = that.data.month < 10 ? '0' + that.data.month : that.data.month;
  156. wx.request({
  157. url: host + "api/distributeSell/getRelationList",
  158. data: {
  159. userId: un_id,//当前用户userId
  160. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  161. date: year + '-' + month,
  162. offset: 0,
  163. limit: 10
  164. },
  165. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  166. header: {
  167. 'Accept': 'application/json'
  168. },
  169. success: function (res) {
  170. if (res.data.data.total == 10) {
  171. that.setData({
  172. recordList: res.data.data.rows,
  173. searchPageNum: 0, //第一次加载,设置1
  174. searchSongList: [], //放置返回数据的数组,设为空
  175. isFromSearch: true, //第一次加载,设置true
  176. searchLoading: true, //把"上拉加载"的变量设为true,显示
  177. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  178. scrollTrue: true
  179. })
  180. } else if (res.data.data.total > 0 && res.data.data.total < 10) {
  181. that.setData({
  182. recordList: res.data.data.rows,
  183. searchPageNum: 0, //第一次加载,设置1
  184. searchSongList: [], //放置返回数据的数组,设为空
  185. isFromSearch: true, //第一次加载,设置true
  186. searchLoading: false, //把"上拉加载"的变量设为true,显示
  187. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  188. scrollTrue: true
  189. });
  190. }else{
  191. that.setData({
  192. recordList: '',
  193. searchPageNum: 0, //第一次加载,设置1
  194. searchSongList: [], //放置返回数据的数组,设为空
  195. isFromSearch: true, //第一次加载,设置true
  196. searchLoading: false, //把"上拉加载"的变量设为true,显示
  197. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  198. scrollTrue: true
  199. });
  200. }
  201. if (res == null || res.data == null) {
  202. console.error('网络请求失败');
  203. return;
  204. }
  205. }
  206. })
  207. },
  208. //商务 - 累计成交
  209. recordEarnings: function (e) {
  210. var that = this;
  211. var host = getApp().globalData.servsers;
  212. var un_id = getApp().globalData.un_id;
  213. var openid = getApp().globalData.openid;
  214. var userRole = getApp().globalData.userRole;
  215. var year = that.data.year;
  216. var month = that.data.month < 10 ? '0' + that.data.month : that.data.month;
  217. wx.request({
  218. url: host + "api/distributeSell/getEarnList",
  219. data: {
  220. userId: un_id,//当前用户userId
  221. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  222. date: year + '-' + month,
  223. offset: 0,
  224. limit: 10
  225. },
  226. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  227. header: {
  228. 'Accept': 'application/json'
  229. },
  230. success: function (res) {
  231. if (res.data.data.total == 10) {
  232. that.setData({
  233. recordList: res.data.data.rows,
  234. searchPageNum: 0, //第一次加载,设置1
  235. searchSongList: [], //放置返回数据的数组,设为空
  236. isFromSearch: true, //第一次加载,设置true
  237. searchLoading: true, //把"上拉加载"的变量设为true,显示
  238. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  239. scrollTrue: true
  240. })
  241. } else if (res.data.data.total > 0 && res.data.data.total < 10) {
  242. that.setData({
  243. recordList: res.data.data.rows,
  244. searchPageNum: 0, //第一次加载,设置1
  245. searchSongList: [], //放置返回数据的数组,设为空
  246. isFromSearch: true, //第一次加载,设置true
  247. searchLoading: false, //把"上拉加载"的变量设为true,显示
  248. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  249. scrollTrue: true
  250. });
  251. }else{
  252. that.setData({
  253. recordList: '',
  254. searchPageNum: 0, //第一次加载,设置1
  255. searchSongList: [], //放置返回数据的数组,设为空
  256. isFromSearch: true, //第一次加载,设置true
  257. searchLoading: false, //把"上拉加载"的变量设为true,显示
  258. searchLoadingComplete: false, //把“没有数据”设为false,隐藏
  259. scrollTrue: true
  260. });
  261. }
  262. console.log(res.data.data.rows);
  263. if (res == null || res.data == null) {
  264. console.error('网络请求失败');
  265. return;
  266. }
  267. }
  268. })
  269. },
  270. fetchSearchList: function () {//加载更多
  271. var that = this;
  272. var host = getApp().globalData.servsers;
  273. var un_id = getApp().globalData.un_id;
  274. var openid = getApp().globalData.openid;
  275. var userRole = getApp().globalData.userRole;
  276. var tabId = that.data.tabId;
  277. if (tabId == 0) {
  278. //关系列表
  279. wx.request({
  280. url: host + "api/distributeSell/getRelationList",
  281. data: {
  282. userId: un_id,//当前用户userId
  283. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  284. offset: parseInt(that.data.searchPageNum),
  285. limit: 10
  286. },
  287. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  288. header: {
  289. 'Accept': 'application/json'
  290. },
  291. success: function (res) {
  292. if (res.data.data.total > 0) {
  293. let recordList = [];
  294. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  295. that.data.isFromSearch ? recordList = res.data.data.rows : recordList = that.data.recordList.concat(res.data.data.rows)
  296. that.setData({
  297. recordList: recordList, //获取数据数组
  298. searchLoading: true, //把"上拉加载"的变量设为false,显示
  299. scrollTrue: true
  300. });
  301. } else {
  302. that.setData({
  303. searchLoadingComplete: true, //把“没有数据”设为true,显示
  304. searchLoading: false, //把"上拉加载"的变量设为false,隐藏
  305. scrollTrue: true
  306. });
  307. }
  308. if (res == null || res.data == null) {
  309. console.error('网络请求失败');
  310. return;
  311. }
  312. }
  313. })
  314. } else {
  315. //收益记录
  316. wx.request({
  317. url: host + "api/distributeSell/getEarnList",
  318. data: {
  319. userId: un_id,//当前用户userId
  320. userRole: userRole,//用户角色 0 普通用户 1 商务用户
  321. offset: parseInt(that.data.searchPageNum),
  322. limit: 10
  323. },
  324. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  325. header: {
  326. 'Accept': 'application/json'
  327. },
  328. success: function (res) {
  329. if (res.data.data.total > 0) {
  330. let recordList = [];
  331. //如果isFromSearch是true从data中取出数据,否则先从原来的数据继续添加
  332. that.data.isFromSearch ? recordList = res.data.data.rows : recordList = that.data.recordList.concat(res.data.data.rows)
  333. that.setData({
  334. recordList: recordList, //获取数据数组
  335. searchLoading: true, //把"上拉加载"的变量设为false,显示
  336. scrollTrue: true
  337. });
  338. } else {
  339. that.setData({
  340. searchLoadingComplete: true, //把“没有数据”设为true,显示
  341. searchLoading: false, //把"上拉加载"的变量设为false,隐藏
  342. scrollTrue: true
  343. });
  344. }
  345. if (res == null || res.data == null) {
  346. console.error('网络请求失败');
  347. return;
  348. }
  349. }
  350. })
  351. }
  352. },
  353. //滚动到底部触发事件
  354. searchScrollLower: function () {
  355. var that = this;
  356. if (that.data.searchLoading && !that.data.searchLoadingComplete) {
  357. that.setData({
  358. searchPageNum: that.data.searchPageNum + 1, //每次触发上拉事件,把searchPageNum+1
  359. isFromSearch: false //触发到上拉事件,把isFromSearch设为为false
  360. });
  361. that.fetchSearchList();
  362. }
  363. },
  364. })