stock.js 4.8 KB

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