index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. data: {
  5. type: 0,
  6. showTipDialog: false,
  7. showTimeModal: false,
  8. isPickerRender: false,
  9. isPickerShow: false,
  10. startTime: new Date().toLocaleDateString(),
  11. endTime: new Date().toLocaleDateString(),
  12. pickerConfig: {
  13. endDate: true,
  14. column: "day",
  15. dateLimit: true,
  16. initStartTime: new Date().toLocaleDateString(),
  17. initEndTime: new Date().toLocaleDateString(),
  18. limitStartTime: "2015-05-06",
  19. limitEndTime: "2065-05-06"
  20. }
  21. },
  22. onLoad: function (options) {
  23. },
  24. onShow: function () {
  25. this.getData();
  26. },
  27. getData: function () {
  28. wx.showLoading();
  29. let token = wx.getStorageSync('token');
  30. app.util.ProReq('platformmobile.getIndexData', {
  31. token
  32. }).then(res => {
  33. wx.hideLoading();
  34. wx.stopPullDownRefresh();
  35. let {
  36. business_data,
  37. goods_data,
  38. sales_data,
  39. todayOrderData,
  40. user_data
  41. } = res;
  42. this.setData({
  43. business_data,
  44. goods_data,
  45. sales_data,
  46. todayOrderData,
  47. user_data,
  48. type: 0
  49. })
  50. }).catch(err => {
  51. wx.hideLoading();
  52. wx.stopPullDownRefresh();
  53. app.util.message(err.message || '请求出错', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  54. })
  55. },
  56. sortData: function () {
  57. // type 0 全部,1 今日 ,2 昨日 ,3 7日, 4 时间段
  58. // begin_time
  59. // end_time
  60. let { type, startTime, endTime } = this.data;
  61. wx.showLoading();
  62. let token = wx.getStorageSync('token');
  63. app.util.ProReq('platformmobile.searchAnalySalesByTime', {
  64. token,
  65. type,
  66. begin_time: startTime,
  67. end_time: endTime
  68. }).then(res => {
  69. wx.hideLoading();
  70. }).catch(err => {
  71. wx.hideLoading();
  72. this.setData({
  73. sales_data: err.sales_data
  74. })
  75. })
  76. },
  77. changeNav: function (e) {
  78. let type = e.currentTarget.dataset.type || 0;
  79. this.setData({
  80. type,
  81. startTime: "",
  82. endTime: ""
  83. }, ()=>{
  84. this.sortData();
  85. })
  86. },
  87. /**
  88. * 页面相关事件处理函数--监听用户下拉动作
  89. */
  90. onPullDownRefresh: function () {
  91. this.getData();
  92. },
  93. confirmMessage: function () {
  94. this.setData({
  95. showTipDialog: !this.data.showTipDialog
  96. })
  97. },
  98. handleModal: function () {
  99. this.setData({
  100. showTimeModal: !this.data.showTimeModal
  101. })
  102. },
  103. pickerShow: function () {
  104. this.setData({
  105. isPickerShow: true,
  106. isPickerRender: true,
  107. chartHide: true
  108. });
  109. },
  110. pickerHide: function () {
  111. this.setData({
  112. isPickerShow: false,
  113. chartHide: false
  114. });
  115. },
  116. bindPickerChange: function (e) {
  117. this.getData(this.data.sensorList[e.detail.value].id);
  118. this.setData({
  119. index: e.detail.value,
  120. sensorId: this.data.sensorList[e.detail.value].id
  121. });
  122. },
  123. setPickerTime: function (val) {
  124. let data = val.detail;
  125. this.setData({
  126. type: 4,
  127. startTime: data.startTime,
  128. endTime: data.endTime
  129. }, ()=>{
  130. this.sortData();
  131. });
  132. }
  133. })