锦水居民端小程序
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.
 

122 lines
3.1 KiB

// subpages/understandJs/pages/archivesDept/archivesDept.js
const api = require('../../../../utils/understandJs')
Page({
/**
* 页面的初始数据
*/
data: {
pageIndex: 1,
pageSize: 10,
searchContent: '',
deptId:'',
archivesList: [],
nodata: false,
loadMoreType: 'none',
loadMoreVisible: false,
deptName: '',
listType: 0 //档案列表样式 1-搜索样式 0-无搜索样式
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options)
this.setData({
searchContent: options.searchContent,
deptId: options.deptId,
deptName: options.dept,
listType: options.searchContent.length
})
wx.setNavigationBarTitle({
title: options.dept
})
this.search(this.data.deptId, this.data.searchContent)
},
bindInputValue (e) {
this.setData({
searchContent: e.detail.value
})
},
searchFile () {
if(!this.data.searchContent.trim('')) {
wx.showToast({
title: '不能为空',
icon: 'none',
duration: 2000
})
return;
}
this.data.archivesList = []
this.search(this.data.deptId, this.data.searchContent.trim(''))
},
search(deptId, keywords) {
let params = {
pageIndex: this.data.pageIndex,
pageSize: this.data.pageSize,
deptId,
searchContent: keywords
}
api.archivelist(params).then(res => {
console.log('搜索接口', res);
this.setData({
archivesList: [...this.data.archivesList,...res.data],
nodata: false,
loadMoreType: res.data.length === this.data.pageSize ? 'loading' : 'none',
loadMoreVisible: res.data.length === this.data.pageSize ? false : true
})
if (this.data.archivesList.length == 0) {//没有值
this.setData({
nodata: true,
loadMoreType: 'none',
loadMoreVisible: false,
})
} else if (keywords != '') {
let reg = new RegExp(keywords,'g')
this.data.archivesList.forEach(item => {
item.title = item.title.replace(reg,'<span style="color:red">'+keywords+'</span>')
// item.archivesNum = item.archivesNum.replace(reg,'<span style="color:red">'+keywords+'</span>')
})
this.setData({
archivesList: this.data.archivesList
})
console.log(this.data.archivesList)
}
}).catch(err => {
this.setData({
archivesList: [],
nodata: true,
loadMoreType: 'none',
loadMoreVisible: false,
})
console.log(err)
})
},
/**
* 跳转到档案详情
*/
goToArchivesDetail (e) {
console.log(e.currentTarget.dataset)
wx.navigateTo({
url: `../archivesDetail/archivesDetail?archiveId=${e.currentTarget.dataset.archiveId}`
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.setData({
loadMoreVisible: true
})
if (this.data.loadMoreType === 'loading') {
this.setData({
pageIndex: this.data.pageIndex + 1,
pageSize: this.data.pageSize,
})
this.search(this.data.deptId, this.data.searchContent)
}
}
})