抖音b端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
4.5 KiB

  1. // pages/creditOperate/index.js
  2. const config = require('../../config/config.js')
  3. const Http = require('../../utils/HttpBasics.js')
  4. const util = require('../../utils/util.js')
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. date: util.formatTime(new Date(), 'yyyy-MM-dddd'), //默认起始时间
  12. date2: util.formatTime(new Date(), 'yyyy-MM-dddd'), //默认结束时间
  13. endDate: util.formatTime(new Date(), 'yyyy-MM-dddd'),
  14. list: [],
  15. showNocontent: false,
  16. todayDate: null,
  17. pageNum: 1,
  18. length: 0,
  19. userInfo:null,
  20. listData:[],
  21. loading:false,
  22. content:'正在加载中',
  23. pages:null
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. this.getUser()
  30. },
  31. bindDateChange(e) {
  32. let that = this;
  33. that.setData({
  34. date: e.detail.value,
  35. })
  36. console.log(that.data.date)
  37. },
  38. bindDateChange2(e) {
  39. let that = this;
  40. that.setData({
  41. date2: e.detail.value,
  42. })
  43. console.log(that.data.date2)
  44. },
  45. search(){
  46. this.getList(this.data.pageNum)
  47. },
  48. getUser(){
  49. let _this=this;
  50. app.globalData.userInfo().then(res => {
  51. this.setData({
  52. userInfo: res
  53. })
  54. _this.getList(1);
  55. console.log(res);
  56. })
  57. },
  58. formatData(data){
  59. let arr=[];
  60. data.map((item,index)=>{
  61. let a = {};
  62. a.value = [item];
  63. a.dateR = item.createDate01;
  64. let indexSt=0;
  65. let haveIf=false;
  66. arr.map((item01,index01)=>{
  67. if (item.createDate01 == item01.dateR){
  68. indexSt = index01;
  69. haveIf=true;
  70. }
  71. })
  72. if (haveIf && (new Date(item.createDate)).valueOf() >= (new Date((this.data.date + ' 00:00:00').replace(/-/g, "/"))).getTime() && (new Date(item.createDate)).valueOf() <= (new Date((this.data.date2 + ' 23:59:59').replace(/-/g, "/"))).getTime()){
  73. arr[indexSt].value.push(item)
  74. } else if ((new Date(item.createDate)).valueOf() >= (new Date((this.data.date + ' 00:00:00').replace(/-/g, "/"))).getTime() && (new Date(item.createDate)).valueOf() <= (new Date((this.data.date2 + ' 23:59:59').replace(/-/g, "/"))).getTime()){
  75. arr.push(a)
  76. }
  77. })
  78. this.setData({
  79. list:arr
  80. })
  81. },
  82. getList(page){
  83. let _this=this;
  84. Http.get({
  85. url: config.api.getCreditList,
  86. data: {
  87. pageNum: page,
  88. pageSize: 10,
  89. startTime: this.data.date + " 00:00:00",
  90. endTime: this.data.date2 + " 23:59:59",
  91. merchantId: _this.data.userInfo.merchant_id
  92. }
  93. })
  94. .then(res => {
  95. tt.stopPullDownRefresh();
  96. let data=res.data.list;
  97. let listData = [];
  98. if(page==1){
  99. listData = res.data.list;
  100. }else{
  101. listData = _this.data.listData;
  102. }
  103. console.log(data)
  104. data.map((item, index) => {
  105. let haveIf = false;
  106. item.createDate01 = util.formatTime(item.createDate, 'yyyy-MM-dddd')
  107. listData.map((item02, index02) => {
  108. if (item02.creditId == item.creditId) {
  109. haveIf = true;
  110. }
  111. })
  112. if (!haveIf) {
  113. listData.push(item)
  114. }
  115. })
  116. _this.formatData(listData)
  117. if (res.data.pages <= page) {
  118. _this.setData({
  119. listData,
  120. pageNum: res.data.pages-1,
  121. content: '已经加载全部数据!'
  122. })
  123. } else {
  124. _this.setData({
  125. listData,
  126. loading: false,
  127. content:'小主,我在玩命加载中...'
  128. })
  129. }
  130. })
  131. .catch(err => {
  132. tt.stopPullDownRefresh();
  133. tt.showToast({
  134. title: err.message,
  135. icon: 'none',
  136. duration: 2000,
  137. mask: false
  138. });
  139. });
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 刷新
  163. */
  164. onPullDownRefresh: function (e) {
  165. let that = this;
  166. that.setData({
  167. pageNum: 1,
  168. list: []
  169. });
  170. that.getList(1);
  171. },
  172. onReachBottom: function () {
  173. var that = this;
  174. that.data.pageNum++;
  175. that.setData({
  176. pageNum: that.data.pageNum,
  177. loading: true
  178. });
  179. that.getList(that.data.pageNum);
  180. },
  181. /**
  182. * 用户点击右上角分享
  183. */
  184. onShareAppMessage: function () {
  185. }
  186. })