stock.js 6.7 KB

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