You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
231 lines
7.5 KiB
231 lines
7.5 KiB
// pages/mall/factory/index.js
|
|
import { getFactoryPriceDetail, userPushFollowMill } from "../../../api/ztb"
|
|
import { getPreferList } from "../../../api/moment"
|
|
const event = require('../../../utils/event')
|
|
const tdsdk = require('../../../libs/tdweapp.js')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
safeBottom: app.globalData.safeBottom,
|
|
fragmentHeight: app.globalData.fragmentHeight - 90,
|
|
height: app.globalData.fragmentHeight - 90,
|
|
stickyTop: app.globalData.CustomBar,
|
|
kg: app.globalData.kg,
|
|
scrollTop: 0,
|
|
toView: null,
|
|
id: null,
|
|
tabList: ['报价信息', '讨论', '收货标准', '注意事项'],
|
|
tabIndex: 0,
|
|
factoryDetail: null,
|
|
cateIndex: 0,
|
|
cateId: '',
|
|
daytimes: '',
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize:15
|
|
},
|
|
visible: false,
|
|
hasFollowed: false
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
safeBottom: app.globalData.safeBottom,
|
|
fragmentHeight: app.globalData.fragmentHeight - 90,
|
|
height: app.globalData.fragmentHeight,
|
|
kg: app.globalData.kg,
|
|
stickyTop: app.globalData.CustomBar,
|
|
daytimes: util.formatDate(new Date(), 'Y-M-D')
|
|
// tabIndex: options.tabIndex ? parseInt(options.tabIndex) : 0
|
|
})
|
|
event.on('EventMessage', this, this.onEvent)
|
|
if (options.id) {
|
|
this.data.id = options.id
|
|
this.data.form.millPaperId = options.id
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
getFactoryPriceDetail(options.id).then(result => {
|
|
if (result.data.paperCategoryList && result.data.paperCategoryList.length) {
|
|
this.data.cateId = result.data.paperCategoryList[this.data.cateIndex].categoryId
|
|
}
|
|
if(result.data && result.data.isCooperate === 1){
|
|
if(!app.globalData.userInfo || !app.globalData.userInfo.isVIP){
|
|
this.data.visible = true
|
|
}
|
|
}
|
|
this.setData({ factoryDetail: result.data, hasFollowed:result.data.hasFollowed, visible: this.data.visible })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 570 || message.what == 571 || message.what == 572 || message.what == 573) {
|
|
this.onRefreshList()
|
|
} else if(message.what == 200){
|
|
this.setData({ visible: false })
|
|
}
|
|
},
|
|
onFixedChange: function ({ detail }) {
|
|
this.data.fixed = detail.fixed
|
|
},
|
|
onScroll: function ({ detail }) {
|
|
this.setData({ scrollTop: detail.scrollTop })
|
|
},
|
|
stopTouchMove: function (e) {
|
|
return false
|
|
},
|
|
onClose: function(){
|
|
wx.navigateBack()
|
|
},
|
|
onImageClick: function(){
|
|
wx.navigateTo({ url: '/pages/ztbvip/index' })
|
|
},
|
|
onTabChange: function ({ detail }) {
|
|
if (this.data.tabIndex == Number(detail.index)) {
|
|
return
|
|
}
|
|
if (this.data.fixed) {
|
|
this.setData({ tabIndex: parseInt(detail.index), toView: 'sticky' })
|
|
} else {
|
|
this.setData({ tabIndex: parseInt(detail.index) })
|
|
}
|
|
if (this.data.tabIndex == 1 && !this.data.momentList.length) {
|
|
this.fetchMomentList()
|
|
}
|
|
},
|
|
checkTag: function (e) {
|
|
if (!e.currentTarget.dataset) {
|
|
return
|
|
}
|
|
if (!e.currentTarget.dataset.index && e.currentTarget.dataset.index != 0) {
|
|
return
|
|
}
|
|
if (this.data.cateIndex == e.currentTarget.dataset.index) {
|
|
return
|
|
}
|
|
this.setData({ cateIndex: e.currentTarget.dataset.index })
|
|
},
|
|
saleGood: function (e) {
|
|
if (!app.globalData.userInfo) {
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
if(!this.data.factoryDetail.isOperations){
|
|
util.showToast(this.data.factoryDetail.manageNotifyMessage)
|
|
return
|
|
}
|
|
var item = this.data.factoryDetail.paperCategoryList[this.data.cateIndex]
|
|
if (util.isEmpty(item.unitPrice)) {
|
|
util.showToast('该纸品暂无报价,无法卖货')
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/agent/edit/index?id=' + this.data.factoryDetail.paperMillId + '&categoryId=' + item.categoryId })
|
|
},
|
|
postMoment: function () {
|
|
util.navigateTo('/pages/article/publish/index?factoryId=' + this.data.factoryDetail.paperMillId + '&name=' + this.data.factoryDetail.name)
|
|
},
|
|
//*************************************************momentList************************************************//
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({ momentList: [], ['form.pageNum']: 1, finished: false })
|
|
this.fetchMomentList()
|
|
},
|
|
fetchMomentList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.setData({ requesting: true })
|
|
getPreferList(this.data.form).then(result => {
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `momentList[${this.data.momentList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), requesting: false, finished })
|
|
} else {
|
|
this.setData({ finished: true, requesting: false })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false })
|
|
})
|
|
},
|
|
//分享至朋友
|
|
onShareAppMessage: function () {
|
|
return {
|
|
title: this.data.factoryDetail.name + '废纸报价',
|
|
path: 'pages/index/index?url=/pages/agent/factory/index&key=id&value=' + this.data.factoryDetail.paperMillId
|
|
}
|
|
},
|
|
//分享至朋友圈
|
|
onShareTimeline(res){
|
|
return {
|
|
title: this.data.factoryDetail.name + '废纸报价',
|
|
path: 'pages/index/index?url=/pages/agent/factory/index&key=id&value=' + this.data.factoryDetail.paperMillId
|
|
}
|
|
},
|
|
toService: function () {
|
|
wx.navigateTo({ url: '/submodel/pages/html/service/index' })
|
|
},
|
|
onShow: function () {
|
|
tdsdk.Page.onShow()
|
|
},
|
|
onHide: function(){
|
|
tdsdk.Page.onHide()
|
|
},
|
|
onUnload: function () {
|
|
tdsdk.Page.onUnload()
|
|
event.remove('EventMessage', this)
|
|
},
|
|
onAttentionChange: function (e) {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
var model = { follow: null, paperMillId: this.data.id }
|
|
if (e.currentTarget.dataset.cid == false) {
|
|
//关注
|
|
this.setData({ hasFollowed: true, })
|
|
model.follow = true
|
|
this.userPushFollowMillFct(model)
|
|
setTimeout(() => event.emit('EventMessage', { what: 1101, desc: 'factoryDetails' }), 1000)
|
|
}
|
|
if (e.currentTarget.dataset.cid == true) {
|
|
//取消关注
|
|
this.setData({ hasFollowed: false })
|
|
model.follow = false
|
|
this.userPushFollowMillFct(model)
|
|
setTimeout(() => event.emit('EventMessage', { what: 1101, desc: 'factoryDetails' }), 1000)
|
|
}
|
|
},
|
|
userPushFollowMillFct: function (model) {
|
|
userPushFollowMill(model).then(res => {
|
|
this.getFactoryPriceDetailFct({id:this.data.id})
|
|
})
|
|
},
|
|
getFactoryPriceDetailFct:function(options){
|
|
getFactoryPriceDetail(options.id).then(result => {
|
|
if (result.data.paperCategoryList && result.data.paperCategoryList.length) {
|
|
this.data.cateId = result.data.paperCategoryList[this.data.cateIndex].categoryId
|
|
}
|
|
this.setData({ factoryDetail: result.data, hasFollowed:result.data.hasFollowed })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
})
|