stock.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. delchoice(){
  107. $api.deletechoice({stock_id:this.data.id}).then(res=>{
  108. wx.showToast({
  109. title: '取消成功',
  110. })
  111. var info=this.data.info;
  112. info.choiced=0
  113. this.setData({
  114. info: info
  115. })
  116. })
  117. },
  118. tab(e){
  119. this.setData({
  120. cur:e.target.dataset.id
  121. })
  122. },
  123. getComment(){
  124. $api.getComment({stock_id:this.data.id}).then(res=>{
  125. if(res.data.code == 0){
  126. this.setData({
  127. comment_list:res.data.data.list,
  128. comment_count:res.data.data.total
  129. })
  130. }
  131. })
  132. },
  133. answer(e){
  134. this.setData({
  135. focus:true,
  136. text:'回复'+e.target.dataset.name,
  137. pid:e.target.dataset.id
  138. })
  139. },
  140. inputChange(e) {
  141. this.setData({
  142. name: e.detail.value
  143. })
  144. this.getData()
  145. },
  146. search() {
  147. this.setData({
  148. total: 0,
  149. list:[],
  150. page:1
  151. })
  152. this.getData()
  153. },
  154. next: function () {
  155. if (this.data.list.length < this.data.total) {
  156. const page = this.data.page + 1
  157. this.setData({
  158. page: page
  159. })
  160. this.getData()
  161. }
  162. },
  163. getData(){
  164. wx.showNavigationBarLoading()
  165. var list = this.data.list;
  166. if(this.data.type == 1){
  167. $api.getHotbuyList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20}).then(res => {
  168. res.data.data.list.forEach(item => {
  169. list.push(item)
  170. })
  171. wx.hideNavigationBarLoading()
  172. this.setData({
  173. list: list,
  174. total: res.data.data.total
  175. })
  176. })
  177. }else{
  178. $api.getHotsellList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20 }).then(res => {
  179. res.data.data.list.forEach(item => {
  180. list.push(item)
  181. })
  182. wx.hideNavigationBarLoading()
  183. this.setData({
  184. list: list,
  185. total: res.data.data.total
  186. })
  187. })
  188. }
  189. },
  190. /**
  191. * 生命周期函数--监听页面初次渲染完成
  192. */
  193. onReady: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面显示
  197. */
  198. onShow: function () {
  199. },
  200. /**
  201. * 生命周期函数--监听页面隐藏
  202. */
  203. onHide: function () {
  204. },
  205. /**
  206. * 生命周期函数--监听页面卸载
  207. */
  208. onUnload: function () {
  209. },
  210. /**
  211. * 页面相关事件处理函数--监听用户下拉动作
  212. */
  213. onPullDownRefresh: function () {
  214. },
  215. /**
  216. * 页面上拉触底事件的处理函数
  217. */
  218. onReachBottom: function () {
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage: function () {
  224. }
  225. })