stock.js 6.1 KB

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