stock.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. if(options.type == 2){
  27. $api.getSellStock({ id: options.id, stock_date: this.data.stock_date }).then(res => {
  28. this.setData({
  29. info: res.data.data
  30. })
  31. wx.setNavigationBarTitle({
  32. title: res.data.data.name,
  33. })
  34. })
  35. }else{
  36. $api.getStock({ id: options.id, stock_date: this.data.stock_date }).then(res => {
  37. this.setData({
  38. info: res.data.data
  39. })
  40. wx.setNavigationBarTitle({
  41. title: res.data.data.name,
  42. })
  43. })
  44. }
  45. }else{
  46. this.getData()
  47. }
  48. },
  49. inputChange(e) {
  50. this.setData({
  51. name: e.detail.value
  52. })
  53. this.getData()
  54. },
  55. search() {
  56. this.setData({
  57. total: 0,
  58. list:[],
  59. page:1
  60. })
  61. this.getData()
  62. },
  63. next: function () {
  64. if (this.data.list.length < this.data.total) {
  65. const page = this.data.page + 1
  66. this.setData({
  67. page: page
  68. })
  69. this.getData()
  70. }
  71. },
  72. getData(){
  73. wx.showNavigationBarLoading()
  74. var list = this.data.list;
  75. if(this.data.type == 1){
  76. $api.getHotbuyList({ 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. }else{
  87. $api.getHotsellList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20 }).then(res => {
  88. res.data.data.list.forEach(item => {
  89. list.push(item)
  90. })
  91. wx.hideNavigationBarLoading()
  92. this.setData({
  93. list: list,
  94. total: res.data.data.total
  95. })
  96. })
  97. }
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function () {
  133. }
  134. })