stock.js 4.5 KB

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