fraWeekReport.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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) {
  55. this.setData({
  56. noData: true
  57. })
  58. }else{
  59. // console.log("我的打印", res.data.records[0]);
  60. this.setData({
  61. reportList: res.data.records[0]
  62. })
  63. }
  64. } else {
  65. wx.showToast({
  66. title: res.errmsg,
  67. icon: 'none'
  68. })
  69. }
  70. });
  71. },
  72. getReportDate() {
  73. util.request(api.getReportDate, {}, 'get').then(res => {
  74. if (res.errno === 0) {
  75. console.log("我的打印", res.data);
  76. this.setData({
  77. reportDateList: res.data.reverse()
  78. })
  79. // 使用map方法转换每个日期对象
  80. const formattedDates = res.data.map(date => {
  81. // 格式化月份和日期,确保它们总是两位数
  82. const beginDate = date.beginDate.split('-').map(part => part.padStart(2, '0')).join('-');
  83. const endDate = date.endDate.split('-').map(part => part.padStart(2, '0')).join('-');
  84. // 返回格式化后的日期字符串
  85. return `${beginDate}-${endDate}`;
  86. });
  87. this.setData({
  88. columns: formattedDates
  89. })
  90. } else {
  91. wx.showToast({
  92. title: res.errmsg,
  93. icon: 'none'
  94. })
  95. }
  96. });
  97. },
  98. showWeekDate() {
  99. this.setData({
  100. showPopup: true
  101. })
  102. },
  103. onClose() {
  104. this.setData({
  105. showPopup: false
  106. });
  107. },
  108. onConfirm(event) {
  109. const {
  110. picker,
  111. value,
  112. index
  113. } = event.detail;
  114. this.setData({
  115. showPopup: false,
  116. selectedWeek: value,
  117. index: index,
  118. beginDate: this.data.reportDateList[index].beginDate,
  119. endDate: this.data.reportDateList[index].endDate
  120. });
  121. console.log("选中",value,index,this.data.reportDateList[index].beginDate);
  122. this.getReportList()
  123. },
  124. onCancel() {
  125. this.setData({
  126. showPopup: false
  127. });
  128. },
  129. })