fraWeekReport.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const util = require("../../../utils/jmsUtil");
  2. const api = require("../../../api/jms");
  3. Page({
  4. data: {
  5. noData: false,
  6. dataId: '',
  7. reportList: {},
  8. reportDateList: [],
  9. showPopup: false,
  10. beginDate: '',
  11. endDate: '',
  12. columns: [],
  13. selectedWeek: '',
  14. index: 0
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. console.log("optons", options);
  21. this.setData({
  22. dataId: options.id
  23. })
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow() {
  29. this.getReportList()
  30. this.getReportDate()
  31. },
  32. onHide: function () {
  33. console.log('onHide');
  34. },
  35. onUnload: function () {
  36. console.log('onunload');
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. getReportList() {
  44. let params = {
  45. isFra: 1,
  46. pushFraFlag: 1,
  47. beginDate: this.data.beginDate.replace(/\//g, '-'),
  48. endDate: this.data.endDate.replace(/\//g, '-') ,
  49. dataId: this.data.dataId
  50. }
  51. console.log("params",params);
  52. util.request(api.GetReportList, params, 'post').then(res => {
  53. if (res.errno === 0) {
  54. if (res.data == null || res.data == undefined ) {
  55. this.setData({
  56. noData: true
  57. })
  58. }else{
  59. console.log("我的打印", res.data.records[0]);
  60. let reportList=res.data.records[0];
  61. this.setData({
  62. noData:false,
  63. })
  64. // 遍历 record 对象,并过滤 null 值
  65. for (const key in reportList) {
  66. if (reportList[key] != null) {
  67. reportList[key] = reportList[key];
  68. }else{
  69. reportList[key]="暂无"
  70. }
  71. }
  72. this.setData({
  73. reportList: reportList
  74. })
  75. }
  76. } else {
  77. wx.showToast({
  78. title: res.errmsg,
  79. icon: 'none'
  80. })
  81. }
  82. });
  83. },
  84. getReportDate() {
  85. util.request(api.getReportDate, {}, 'get').then(res => {
  86. if (res.errno === 0) {
  87. console.log("我的打印", res.data);
  88. this.setData({
  89. reportDateList: res.data.reverse()
  90. })
  91. // 使用map方法转换每个日期对象
  92. const formattedDates = res.data.map(date => {
  93. // 格式化月份和日期,确保它们总是两位数
  94. const beginDate = date.beginDate.split('-').map(part => part.padStart(2, '0')).join('-');
  95. const endDate = date.endDate.split('-').map(part => part.padStart(2, '0')).join('-');
  96. // 返回格式化后的日期字符串
  97. return `${beginDate}-${endDate}`;
  98. });
  99. this.setData({
  100. columns: formattedDates
  101. })
  102. } else {
  103. wx.showToast({
  104. title: res.errmsg,
  105. icon: 'none'
  106. })
  107. }
  108. });
  109. },
  110. showWeekDate() {
  111. console.log(111);
  112. this.setData({
  113. showPopup: true
  114. })
  115. },
  116. onClose() {
  117. this.setData({
  118. showPopup: false
  119. });
  120. },
  121. onConfirm(event) {
  122. const {
  123. picker,
  124. value,
  125. index
  126. } = event.detail;
  127. this.setData({
  128. showPopup: false,
  129. selectedWeek: value,
  130. index: index,
  131. beginDate: this.data.reportDateList[index].beginDate,
  132. endDate: this.data.reportDateList[index].endDate
  133. });
  134. console.log("选中",value,index,this.data.reportDateList[index].beginDate);
  135. this.getReportList()
  136. },
  137. onCancel() {
  138. this.setData({
  139. showPopup: false
  140. });
  141. },
  142. })