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.
221 lines
5.6 KiB
221 lines
5.6 KiB
import { getIssueList, getProjectList} from "../../utils/api"
|
|
import { formatTimestamp } from "../../utils/common"
|
|
|
|
Page({
|
|
data: {
|
|
issueList: [],
|
|
loadMoreVisible: false,
|
|
loadMoreType: "none",
|
|
preloadVisible: false,
|
|
timestamp: "",
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
projectList: [],
|
|
type: "project",
|
|
searchInputValue: "",
|
|
searchTimer: ""
|
|
},
|
|
onLoad (options) {
|
|
if (options.type) {
|
|
this.setData({
|
|
type: options.type
|
|
})
|
|
}
|
|
},
|
|
onReady () {
|
|
this.pullDownRefresh = this.selectComponent("#pulldown-refresh")
|
|
},
|
|
onPageScroll (e) {
|
|
this.pullDownRefresh.onPageScroll(e)
|
|
},
|
|
onReachBottom () {
|
|
this.setData({
|
|
loadMoreVisible: true
|
|
})
|
|
if (this.data.loadMoreType === "loading") {
|
|
this.setData({
|
|
pageNo: this.data.pageNo + 1
|
|
})
|
|
if (this.data.type === "issue") {
|
|
this.pullDownGetIssueList()
|
|
} else if (this.data.type === "project") {
|
|
this.pulldownGetProjectList()
|
|
}
|
|
}
|
|
},
|
|
// 下拉刷新 获取议题列表
|
|
getIssueList () {
|
|
this.setData({
|
|
timestamp: formatTimestamp(),
|
|
preloadVisible: true,
|
|
issueList: [],
|
|
pageNo: 1
|
|
})
|
|
const para = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: this.data.searchInputValue,
|
|
orderType: "0",
|
|
firstCategoryCode: ""
|
|
}
|
|
getIssueList(para).then(res => {
|
|
console.log("获取议题列表", res)
|
|
this.setData({
|
|
issueList: [...res.data],
|
|
preloadVisible: false,
|
|
loadMoreType: res.data.length === 10 ? "loading" : "none"
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
issueList: [],
|
|
preloadVisible: false,
|
|
loadMoreType: "none",
|
|
loadMoreVisible: false
|
|
})
|
|
console.log(err)
|
|
}).finally(() => {
|
|
this.pullDownRefresh.stopRefresh()
|
|
})
|
|
},
|
|
// 上拉加载更多
|
|
pullDownGetIssueList () {
|
|
const para = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: this.data.searchInputValue,
|
|
orderType: "0",
|
|
firstCategoryCode: ""
|
|
}
|
|
getIssueList(para).then(res => {
|
|
console.log("获取议题列表", res)
|
|
this.setData({
|
|
issueList: [...this.data.issueList,...res.data],
|
|
preloadVisible: false,
|
|
loadMoreType: res.data.length === 10 ? "loading" : "none"
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
issueList: [],
|
|
preloadVisible: false,
|
|
loadMoreType: "none",
|
|
loadMoreVisible: false
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 跳转详情
|
|
navigateToIssueDetail (e) {
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=issue&detailId=${e.detail.issueId}`
|
|
})
|
|
},
|
|
// 下拉刷新 获取 项目列表接口
|
|
getProjectList () {
|
|
this.setData({
|
|
timestamp: formatTimestamp(),
|
|
pageNo: 1,
|
|
preloadVisible: true,
|
|
loadMoreVisible: false,
|
|
projectList: [],
|
|
})
|
|
const para = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: this.data.searchInputValue,
|
|
categoryCode: ""
|
|
}
|
|
getProjectList(para).then(res => {
|
|
console.log("获取项目列表", res)
|
|
this.setData({
|
|
projectList: [...res.data],
|
|
preloadVisible: false,
|
|
loadMoreType: res.data.length === 10 ? "loading" : "none"
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
projectList: [],
|
|
preloadVisible: false,
|
|
loadMoreType: "none"
|
|
})
|
|
console.log(err)
|
|
}).finally(() => {
|
|
this.pullDownRefresh.stopRefresh()
|
|
})
|
|
},
|
|
// 上拉加载 项目列表
|
|
pulldownGetProjectList () {
|
|
const para = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: this.data.searchInputValue,
|
|
categoryCode: ""
|
|
}
|
|
getProjectList(para).then(res => {
|
|
console.log("获取项目列表", res)
|
|
this.setData({
|
|
projectList: [...this.data.projectList,...res.data],
|
|
preloadVisible: false,
|
|
loadMoreType: res.data.length === 10 ? "loading" : "none"
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
projectList: [],
|
|
preloadVisible: false,
|
|
loadMoreType: "none"
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 跳转到项目详情
|
|
navigateToProjectDetail (e) {
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=project&detailId=${e.detail.projectId}`
|
|
})
|
|
},
|
|
// 下拉刷新
|
|
searchPullDownRefresh () {
|
|
if (this.data.searchInputValue) {
|
|
if (this.data.type === "issue") {
|
|
this.getIssueList()
|
|
} else if (this.data.type === "project") {
|
|
this.getProjectList()
|
|
}
|
|
} else {
|
|
this.pullDownRefresh.stopRefresh()
|
|
this.setData({
|
|
issueList: [],
|
|
projectList: []
|
|
})
|
|
}
|
|
},
|
|
// input 框 双向绑定
|
|
bindSearchInput (e) {
|
|
this.setData({
|
|
searchInputValue: e.detail.value
|
|
})
|
|
},
|
|
debounceSearch () {
|
|
clearTimeout(this.data.searchTimer)
|
|
this.data.searchTimer = setTimeout(() => {
|
|
this.search()
|
|
}, 500)
|
|
},
|
|
search () {
|
|
if (this.data.searchInputValue) {
|
|
if (this.data.type === "issue") {
|
|
this.getIssueList()
|
|
} else if (this.data.type === "project") {
|
|
this.getProjectList()
|
|
}
|
|
} else {
|
|
this.setData({
|
|
issueList: [],
|
|
projectList: []
|
|
})
|
|
}
|
|
}
|
|
})
|