stock.js 6.5 KB

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