// pages/stock/stock.js const $api = require('../../utils/api.js').API; Page({ /** * 页面的初始数据 */ data: { name:'', id:'', stock_date:'', type:'', page:1, total:0, cur:1, text:'留下你的观点', comment:'', list:[], myList:[] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ stock_date: options.date, type: options.type }) $api.getAuthinfo().then(res=>{ this.setData({ user_id:res.data.data.id, role: res.data.data.role }) }) if (options.id){ this.setData({id:options.id}) this.getComment() this.getMylist() $api.getAuthinfo().then(res=>{ this.setData({ role: res.data.data.role }) }) if(options.type == 2){ $api.getSellStock({ id: options.id, stock_date: this.data.stock_date }).then(res => { this.setData({ info: res.data.data }) wx.setNavigationBarTitle({ title: res.data.data.name, }) }) }else{ $api.getStock({ id: options.id, stock_date: this.data.stock_date }).then(res => { this.setData({ info: res.data.data }) wx.setNavigationBarTitle({ title: res.data.data.name, }) }) } }else{ this.getData() } }, getMylist(){ $api.getChoice({ stock_id: this.data.id }).then(res => { this.setData({ myList: res.data.data.list }) }) }, delmsg(e){ var data={ id:e.target.dataset.id } $api.delcomment(data).then(res=>{ this.getComment() }) }, inputchange1(e) { this.setData({ comment: e.detail.value }) }, blur(){ this.setData({ comment:'', pid:null, text:'留下你的观点' }) }, sendmsg(){ var data={ stock_id:this.data.id, cotent:this.data.comment, pid:this.data.pid } if(!data.cotent){ return } $api.postcomment(data).then(res=>{ this.getComment() this.setData({ comment:'', pid:null, text:'留下你的观点' }) }) }, choice(){ $api.addchoice({stock_id:this.data.id}).then(res=>{ wx.showToast({ title: '加入成功', }) var info=this.data.info; info.choiced=1 this.setData({ info: info }) this.getMylist() }) }, delchoice(){ $api.deletechoice({stock_id:this.data.id}).then(res=>{ wx.showToast({ title: '取消成功', }) var info=this.data.info; info.choiced=0 this.setData({ info: info }) this.getMylist() }) }, tab(e){ this.setData({ cur:e.target.dataset.id }) }, getComment(){ $api.getComment({stock_id:this.data.id}).then(res=>{ if(res.data.code == 0){ this.setData({ comment_list:res.data.data.list, comment_count:res.data.data.total }) } }) }, answer(e){ this.setData({ focus:true, text:'回复'+e.target.dataset.name, pid:e.target.dataset.id }) }, inputChange(e) { this.setData({ name: e.detail.value }) this.getData() }, search() { this.setData({ total: 0, list:[], page:1 }) this.getData() }, next: function () { if (this.data.list.length < this.data.total) { const page = this.data.page + 1 this.setData({ page: page }) this.getData() } }, getData(){ wx.showNavigationBarLoading() var list = this.data.list; if(this.data.type == 1){ $api.getHotbuyList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20}).then(res => { res.data.data.list.forEach(item => { list.push(item) }) wx.hideNavigationBarLoading() this.setData({ list: list, total: res.data.data.total }) }) }else{ $api.getHotsellList({ name: this.data.name, stock_date: this.data.stock_date, page: this.data.page, page_size: 20 }).then(res => { res.data.data.list.forEach(item => { list.push(item) }) wx.hideNavigationBarLoading() this.setData({ list: list, total: res.data.data.total }) }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })