stock.js 5.1 KB

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