transporDetails.js 2.5 KB

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