stock.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/stock/stock.js
  2. const $api = require('../../utils/api.js').API;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. name:'',
  9. id:'',
  10. stock_date:'',
  11. type:'',
  12. page:1,
  13. total:0,
  14. list:[]
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.setData({
  21. stock_date: options.date,
  22. type: options.type
  23. })
  24. if (options.id){
  25. this.setData({id:options.id})
  26. $api.getStock({ id: options.id, stock_date: this.data.stock_date}).then(res=>{
  27. this.setData({
  28. info:res.data.data
  29. })
  30. wx.setNavigationBarTitle({
  31. title: res.data.data.name,
  32. })
  33. })
  34. }else{
  35. this.getData()
  36. }
  37. },
  38. inputChange(e) {
  39. this.setData({
  40. name: e.detail.value
  41. })
  42. this.getData()
  43. },
  44. search() {
  45. this.setData({
  46. total: 0,
  47. list:[],
  48. page:1
  49. })
  50. this.getData()
  51. },
  52. next: function () {
  53. if (this.data.list.length < this.data.total) {
  54. const page = this.data.page + 1
  55. this.setData({
  56. page: page
  57. })
  58. this.getData()
  59. }
  60. },
  61. getData(){
  62. wx.showNavigationBarLoading()
  63. var list = this.data.list;
  64. if(this.data.type == 1){
  65. $api.getHotbuyList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20}).then(res => {
  66. res.data.data.list.forEach(item => {
  67. list.push(item)
  68. })
  69. wx.hideNavigationBarLoading()
  70. this.setData({
  71. list: list,
  72. total: res.data.data.total
  73. })
  74. })
  75. }else{
  76. $api.getHotsellList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20 }).then(res => {
  77. res.data.data.list.forEach(item => {
  78. list.push(item)
  79. })
  80. wx.hideNavigationBarLoading()
  81. this.setData({
  82. list: list,
  83. total: res.data.data.total
  84. })
  85. })
  86. }
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面显示
  95. */
  96. onShow: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面隐藏
  100. */
  101. onHide: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面卸载
  105. */
  106. onUnload: function () {
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function () {
  112. },
  113. /**
  114. * 页面上拉触底事件的处理函数
  115. */
  116. onReachBottom: function () {
  117. },
  118. /**
  119. * 用户点击右上角分享
  120. */
  121. onShareAppMessage: function () {
  122. }
  123. })