stock.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. cur:0,
  15. text:'留下你的观点',
  16. comment:'',
  17. list:[]
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setData({
  24. stock_date: options.date,
  25. type: options.type
  26. })
  27. if (options.id){
  28. this.setData({id:options.id})
  29. this.getComment()
  30. $api.getAuthinfo().then(res=>{
  31. this.setData({
  32. role: res.data.data.role
  33. })
  34. })
  35. if(options.type == 2){
  36. $api.getSellStock({ 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. }else{
  45. $api.getStock({ id: options.id, stock_date: this.data.stock_date }).then(res => {
  46. this.setData({
  47. info: res.data.data
  48. })
  49. wx.setNavigationBarTitle({
  50. title: res.data.data.name,
  51. })
  52. })
  53. }
  54. }else{
  55. this.getData()
  56. }
  57. },
  58. inputchange1(e) {
  59. this.setData({
  60. comment: e.detail.value
  61. })
  62. },
  63. blur(){
  64. this.setData({
  65. comment:'',
  66. pid:null,
  67. text:'留下你的观点'
  68. })
  69. },
  70. sendmsg(){
  71. console.log(233)
  72. var data={
  73. stock_id:this.data.id,
  74. cotent:this.data.comment,
  75. pid:this.data.pid
  76. }
  77. if(!data.cotent){
  78. return
  79. }
  80. $api.postcomment(data).then(res=>{
  81. this.getComment()
  82. this.setData({
  83. comment:'',
  84. pid:null,
  85. text:'留下你的观点'
  86. })
  87. })
  88. },
  89. choice(){
  90. $api.addchoice({stock_id:this.data.id}).then(res=>{
  91. wx.showToast({
  92. title: '加入成功',
  93. })
  94. })
  95. },
  96. tab(e){
  97. this.setData({
  98. cur:e.target.dataset.id
  99. })
  100. },
  101. getComment(){
  102. $api.getComment({stock_id:this.data.id}).then(res=>{
  103. if(res.data.code == 0){
  104. this.setData({
  105. comment_list:res.data.data.list,
  106. comment_count:res.data.data.total
  107. })
  108. }
  109. })
  110. },
  111. answer(e){
  112. this.setData({
  113. focus:true,
  114. text:'回复'+e.target.dataset.name,
  115. pid:e.target.dataset.id
  116. })
  117. },
  118. inputChange(e) {
  119. this.setData({
  120. name: e.detail.value
  121. })
  122. this.getData()
  123. },
  124. search() {
  125. this.setData({
  126. total: 0,
  127. list:[],
  128. page:1
  129. })
  130. this.getData()
  131. },
  132. next: function () {
  133. if (this.data.list.length < this.data.total) {
  134. const page = this.data.page + 1
  135. this.setData({
  136. page: page
  137. })
  138. this.getData()
  139. }
  140. },
  141. getData(){
  142. wx.showNavigationBarLoading()
  143. var list = this.data.list;
  144. if(this.data.type == 1){
  145. $api.getHotbuyList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20}).then(res => {
  146. res.data.data.list.forEach(item => {
  147. list.push(item)
  148. })
  149. wx.hideNavigationBarLoading()
  150. this.setData({
  151. list: list,
  152. total: res.data.data.total
  153. })
  154. })
  155. }else{
  156. $api.getHotsellList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20 }).then(res => {
  157. res.data.data.list.forEach(item => {
  158. list.push(item)
  159. })
  160. wx.hideNavigationBarLoading()
  161. this.setData({
  162. list: list,
  163. total: res.data.data.total
  164. })
  165. })
  166. }
  167. },
  168. /**
  169. * 生命周期函数--监听页面初次渲染完成
  170. */
  171. onReady: function () {
  172. },
  173. /**
  174. * 生命周期函数--监听页面显示
  175. */
  176. onShow: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面卸载
  185. */
  186. onUnload: function () {
  187. },
  188. /**
  189. * 页面相关事件处理函数--监听用户下拉动作
  190. */
  191. onPullDownRefresh: function () {
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function () {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function () {
  202. }
  203. })