stock.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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:1,
  12. page:1,
  13. total:0,
  14. cur:1,
  15. text:'我要解读',
  16. comment:'',
  17. list:[],
  18. page1:1,
  19. total1:0,
  20. myList:[],
  21. searchList:[],
  22. nbComments:[],
  23. todaynb:0
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. this.setData({
  30. type:options.type,
  31. stock_date:options.stock_date
  32. })
  33. $api.getAuthinfo().then(res=>{
  34. this.setData({
  35. user_id:res.data.data.id,
  36. role: res.data.data.role
  37. })
  38. })
  39. if (options.id){
  40. //详情
  41. this.setData({
  42. id:options.id,
  43. list:[],
  44. page1:1,
  45. total1:0
  46. })
  47. this.getComment()
  48. this.getMylist()
  49. $api.getAuthinfo().then(res=>{
  50. this.setData({
  51. role: res.data.data.role
  52. })
  53. })
  54. $api.getStock({ id: options.id, stock_date: this.data.stock_date }).then(res => {
  55. this.setData({
  56. info: res.data.data
  57. })
  58. wx.setNavigationBarTitle({
  59. title: res.data.data.name,
  60. })
  61. })
  62. $api.getStockNbcomments({stock_id:options.id,date:this.data.stock_date}).then(res=>{
  63. this.setData({
  64. nbComments:res.data.data.list
  65. })
  66. })
  67. this.getPlarer()
  68. }else{
  69. this.getData()
  70. $api.getNbcomments({date:this.data.stock_date}).then(res=>{
  71. this.setData({
  72. todaynb:res.data.data.total
  73. })
  74. })
  75. }
  76. },
  77. //获取今日持仓
  78. getPlarer(){
  79. var list = this.data.list
  80. $api.getStockPlayer({ id: this.data.id, stock_date: this.data.stock_date,page:this.data.page1 }).then(res=>{
  81. wx.hideNavigationBarLoading()
  82. res.data.data.list.forEach(item => {
  83. list.push(item)
  84. })
  85. this.setData({
  86. list: list,
  87. total1: res.data.data.total
  88. })
  89. })
  90. },
  91. next1: function () {
  92. if (this.data.cur==1 && this.data.list.length < this.data.total1) {
  93. const page = this.data.page1 + 1
  94. this.setData({
  95. page1: page
  96. })
  97. this.getPlarer()
  98. }
  99. },
  100. bindDateChange(e){
  101. this.setData({
  102. stock_date:e.detail.value,
  103. list:[]
  104. })
  105. wx.showNavigationBarLoading()
  106. this.getData()
  107. },
  108. toSearch(){
  109. wx.navigateTo({
  110. url: '../stock/stock?type=2',
  111. })
  112. },
  113. getMylist(){
  114. $api.getChoice({ stock_id: this.data.id }).then(res => {
  115. this.setData({
  116. myList: res.data.data.list
  117. })
  118. })
  119. },
  120. delmsg(e){
  121. var data={
  122. id:e.target.dataset.id
  123. }
  124. $api.delcomment(data).then(res=>{
  125. this.getComment()
  126. })
  127. },
  128. inputchange1(e) {
  129. this.setData({
  130. comment: e.detail.value
  131. })
  132. },
  133. blur(){
  134. this.setData({
  135. comment:'',
  136. pid:null,
  137. text:'我要解读'
  138. })
  139. },
  140. sendmsg(){
  141. var data={
  142. stock_id:this.data.id,
  143. cotent:this.data.comment,
  144. pid:this.data.pid
  145. }
  146. if(!data.cotent){
  147. return
  148. }
  149. $api.postcomment(data).then(res=>{
  150. this.getComment()
  151. this.setData({
  152. comment:'',
  153. pid:null,
  154. text:'我要解读'
  155. })
  156. })
  157. },
  158. choice(){
  159. $api.addchoice({stock_id:this.data.id}).then(res=>{
  160. wx.showToast({
  161. title: '加入成功',
  162. })
  163. var info=this.data.info;
  164. info.choiced=1
  165. this.setData({
  166. info: info
  167. })
  168. this.getMylist()
  169. })
  170. },
  171. delchoice(){
  172. $api.deletechoice({stock_id:this.data.id}).then(res=>{
  173. wx.showToast({
  174. title: '取消成功',
  175. })
  176. var info=this.data.info;
  177. info.choiced=0
  178. this.setData({
  179. info: info
  180. })
  181. this.getMylist()
  182. })
  183. },
  184. tab(e){
  185. this.setData({
  186. cur:e.target.dataset.id
  187. })
  188. },
  189. getComment(){
  190. $api.getComment({stock_id:this.data.id}).then(res=>{
  191. if(res.data.code == 0){
  192. this.setData({
  193. comment_list:res.data.data.list,
  194. comment_count:res.data.data.total
  195. })
  196. }
  197. })
  198. },
  199. answer(e){
  200. this.setData({
  201. focus:true,
  202. text:'回复'+e.target.dataset.name,
  203. pid:e.target.dataset.id
  204. })
  205. },
  206. inputChange(e) {
  207. this.setData({
  208. name: e.detail.value
  209. })
  210. this.getData('search')
  211. },
  212. search() {
  213. this.setData({
  214. total: 0,
  215. list:[],
  216. page:1
  217. })
  218. this.getData()
  219. },
  220. next: function () {
  221. if (this.data.list.length < this.data.total) {
  222. const page = this.data.page + 1
  223. this.setData({
  224. page: page
  225. })
  226. this.getData()
  227. }
  228. },
  229. getData(type){
  230. wx.showNavigationBarLoading()
  231. var list = this.data.list;
  232. var data={}
  233. if(type == 'search'){
  234. data={ name: this.data.name, stock_date: this.data.stock_date}
  235. this.setData({
  236. searchList:[]
  237. })
  238. }else{
  239. data={ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20}
  240. }
  241. $api.getHotbuyList(data).then(res => {
  242. res.data.data.list.forEach(item => {
  243. list.push(item)
  244. })
  245. wx.hideNavigationBarLoading()
  246. if(type == 'search'){
  247. this.setData({
  248. searchList: res.data.data.list
  249. })
  250. }else{
  251. this.setData({
  252. list: list,
  253. total: res.data.data.total
  254. })
  255. }
  256. })
  257. },
  258. /**
  259. * 生命周期函数--监听页面初次渲染完成
  260. */
  261. onReady: function () {
  262. },
  263. /**
  264. * 生命周期函数--监听页面显示
  265. */
  266. onShow: function () {
  267. },
  268. /**
  269. * 生命周期函数--监听页面隐藏
  270. */
  271. onHide: function () {
  272. },
  273. /**
  274. * 生命周期函数--监听页面卸载
  275. */
  276. onUnload: function () {
  277. },
  278. /**
  279. * 页面相关事件处理函数--监听用户下拉动作
  280. */
  281. onPullDownRefresh: function () {
  282. },
  283. /**
  284. * 页面上拉触底事件的处理函数
  285. */
  286. onReachBottom: function () {
  287. },
  288. /**
  289. * 用户点击右上角分享
  290. */
  291. onShareAppMessage: function () {
  292. }
  293. })