stock.js 5.3 KB

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