stock.js 6.5 KB

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