statics.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. titleName:'',
  8. isShow:null,
  9. title:[]
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. var that = this;
  16. var expressData = JSON.parse(decodeURIComponent(options.list)) || [];
  17. var title = JSON.parse(options.title) || [];
  18. var titleName = JSON.parse(options.titleName) || 统计;
  19. this.setData({
  20. expressData,
  21. titleName,
  22. title:title.map(item=>{
  23. return{...item,isShow:null}
  24. }),
  25. },()=>{
  26. that.setData({
  27. expressDataCopy:JSON.stringify(that.data.expressData)
  28. })
  29. })
  30. },
  31. sort(e){
  32. var that = this;
  33. var type = e.currentTarget.dataset.type;
  34. var expressData = this.data.expressData;
  35. var isShow = this.data.isShow;
  36. if(isShow == null){
  37. expressData.sort((a,b)=>b[type] - a[type]) // 升序
  38. isShow = true
  39. }else if(isShow == true){
  40. expressData.sort((a,b)=>a[type] - b[type]) // 降序
  41. isShow = false
  42. }else if(isShow == false){ // 恢复
  43. expressData = JSON.parse(that.data.expressDataCopy);
  44. isShow = null
  45. }
  46. this.setData({
  47. type,
  48. isShow,
  49. expressData,
  50. title:that.data.title.map(item=>{
  51. if(item.type == type){
  52. return{...item,isShow,}
  53. }else{
  54. return {...item,isShow:null,}
  55. }
  56. }),
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload: function () {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh: function () {
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. onReachBottom: function () {
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {
  93. }
  94. })