123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- // parents/pages/search/search.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { LibSearch, LibManagerSearch} from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, hasLibraryService, hasVipService } = getApp()
- const { baseImgUrl, thumbnail, qrcodeInvalidToastText, borrowToastText, reservationsToastText, wishToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- thumbnail,
- baseImgUrl,
- borrowToastText,
- reservationsToastText,
- wishToastText,
- isLoaded: 1,
- isStaffData: 0,
- pageSize: 10,
- pageNo: 1,
- isAll: 0,
- addNum:0,
- isShow: 0,
- list:[],
- itemIndex: 0,
- items: ['按周阅读量排序', '按借阅热度排序', '按借阅量TOP10排序'],
- content: '',
- isReturn: 0,
- isStaffReturn:0,
- isType:false,
- managerList:[],
- addmanagerList:[],
- vipList:[],
- nodataArray: {
- text: "搜索无结果"
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.type == 0 || options.type == 1){
- this.setData({
- isStaffData: 1
- });
- wx.setNavigationBarTitle({
- title: `搜索`,
- })
- }
- if (options.addNum == 1) {
- console.log('99')
- this.setData({
- addNum: 1
- });
- wx.setNavigationBarTitle({
- title: `添加人员`,
- })
- }
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
- options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
- this.setData({ options })
- console.log(options)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // this.getData(res => {
- // this.setData({ isLoaded: 1 })
- // })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- returnBack:function(){
- wx.navigateBack({
-
- })
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- const { isAll, options } = this.data
- const { type = 1 } = options
- if (type == 1) return
- this.setData({ pageNo: 1 })
- this.getData(res => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll, options } = this.data
- const { type = 1 } = options
- if (type == 1 || isAll) return
- this.getData()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 选择跳转进入页
- */
- NavigateToInfo: function (e) {
- const { index } = e.currentTarget.dataset
- navigateTo({
- url: 'president/pages/Personnel_edit/Personnel_edit',
- })
- },
- /**
- * 获取搜索数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { options, content, managerList=[], vipList=[] } = this.data
- const { libId } = options
- LibSearch({ data: { name:content, libId, }, continuousFn }).then(res => {
- const { managerList, vipList } = res.data
- this.setData({ managerList: managerList, vipList: vipList })
- console.log(managerList)
- console.log(vipList)
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- * 获取添加人员搜索数据
- */
- getaddNumData: function (cb) {
- const continuousFn = { fn: this.getaddNumData, param: { ...arguments } }
- const { options, content, addmanagerList = [], } = this.data
- const { libId } = options
- LibManagerSearch({ data: { name: content, libId, }, continuousFn }).then(res => {
- const { list} = res.data
- this.setData({ addmanagerList: list })
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- /**
- * 输入搜索值获取添加人员搜索数据
- */
- inputaddNumSearchCtl: function (e) {
- const { value } = e.detail
- const { content } = this.data
- if (content == value) {
- return
- }
- this.setData({ content: value, isReturn: 1, pageNo: 1 })
- this.getaddNumData()
- },
- /**
- * 输入搜索值
- */
- inputSearchCtl: function (e) {
- const { value } = e.detail
- const { content, managerList = [], vipList = [] } = this.data
- if (content == value) {
- return
- }
- this.setData({ content: value, pageNo: 1, isStaffReturn: 1, managerList:[], vipList:[]})
- this.getData()
- },
- /**
- * 清除搜索值
- */
- clearSearchCtl: function () {
- this.setData({ content: '' })
- },
- /**
- * 提交搜索值
- */
- submitSearchCtl: function () {
- this.setData({ isReturn: 1, pageNo: 1 })
- this.getData()
- },
- })
|