You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
10 KiB
JavaScript

2 years ago
// pages/search/index.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
inputVal: '',
isShowCha: false,
inputPlaceholder: '',
fromProject: false,
from: '',
historyList: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var that = this;
console.log(options.from)
if (options.from == "project") {
wx.setNavigationBarTitle({
title: '职位管理',
})
wx.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#00bebe',
})
that.setData({
fromProject: true,
from: 'project',
inputPlaceholder: '搜索企业名称',
})
}else if(options.from == "townMan"){
wx.setNavigationBarTitle({
title: '我的老乡',
})
that.setData({
// fromProject: false,
from: 'townMan',
inputPlaceholder: '搜索姓名',
})
}else if(options.from == "process"){
wx.setNavigationBarTitle({
title: '我的工单',
})
that.setData({
// fromProject: false,
from: 'process',
inputPlaceholder: '搜索姓名',
})
}else if(options.from == "myProject"){
wx.setNavigationBarTitle({
title: '我的项目',
})
that.setData({
// fromProject: false,
from: 'myProject',
inputPlaceholder: '搜索我的项目',
})
}else if(options.from == "mobile"){
wx.setNavigationBarTitle({
title: '通讯录',
})
that.setData({
// fromProject: false,
from: 'mobile',
inputPlaceholder: '搜索姓名、手机号',
})
}else if(options.from == "announce"){
wx.setNavigationBarTitle({
title: '我的通告',
})
that.setData({
// fromProject: false,
from: 'announce',
inputPlaceholder: '搜索企业名称',
})
}else if(options.from == "announceAuto"){
wx.setNavigationBarTitle({
title: '自动通告',
})
that.setData({
// fromProject: false,
from: 'announceAuto',
inputPlaceholder: '搜索职位名称',
})
}
},
inputTyping: function (e) {
this.setData({
inputVal: e.detail.value,
isShowCha: true
});
console.log(this.data.inputVal == '');
if (this.data.inputVal == '') {
this.setData({
// inputVal: e.detail.value,
isShowCha: false
});
// this.data.billList = [];
// this.data.searchParam.pageNum = 1;
// this.data.searchParam.keys = "";
// this.getList();
// this.getRead();
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
var that = this;
if(app.isNotEmptyCheck(wx.getStorageSync('projectSearch')) && that.data.from == 'project'){
that.setData({
historyList : wx.getStorageSync('projectSearch').reverse()
})
}else if(app.isNotEmptyCheck(wx.getStorageSync('townManSearch')) && that.data.from == 'townMan'){
that.setData({
historyList : wx.getStorageSync('townManSearch').reverse()
})
}else if(app.isNotEmptyCheck(wx.getStorageSync('processSearch')) && that.data.from == 'process'){
that.setData({
historyList : wx.getStorageSync('processSearch').reverse()
})
}else if(app.isNotEmptyCheck(wx.getStorageSync('myProjectSearch')) && that.data.from == 'myProject'){
that.setData({
historyList : wx.getStorageSync('myProjectSearch').reverse()
})
}else if(app.isNotEmptyCheck(wx.getStorageSync('mobileSearch')) && that.data.from == 'mobile'){
that.setData({
historyList : wx.getStorageSync('mobileSearch').reverse()
})
}else if(app.isNotEmptyCheck(wx.getStorageSync('announceSearch')) && that.data.from == 'announce'){
that.setData({
historyList : wx.getStorageSync('announceSearch').reverse()
})
}else if(app.isNotEmptyCheck(wx.getStorageSync('announceAutoSearch')) && that.data.from == 'announceAuto'){
that.setData({
historyList : wx.getStorageSync('announceAutoSearch').reverse()
})
}
that.setData({
historyList:that.data.historyList.slice(0,10)
})
},
searchKey: function (e) {
var that = this;
console.log(that.data.inputVal);
let currText = ''
if (that.data.from == 'project') {
currText = "搜索企业名称"
if(app.isNotEmptyCheck(wx.getStorageSync('projectSearch'))){
that.data.historyList = wx.getStorageSync('projectSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('projectSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('projectSearch')));
}else if(that.data.from == 'townMan') {
currText = "搜索姓名"
if(app.isNotEmptyCheck(wx.getStorageSync('townManSearch'))){
that.data.historyList = wx.getStorageSync('townManSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('townManSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('townManSearch')));
}else if(that.data.from == 'process') {
currText = "搜索姓名"
if(app.isNotEmptyCheck(wx.getStorageSync('processSearch'))){
that.data.historyList = wx.getStorageSync('processSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('processSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('processSearch')));
}else if(that.data.from == 'myProject') {
currText = "搜索我的项目"
if(app.isNotEmptyCheck(wx.getStorageSync('myProjectSearch'))){
that.data.historyList = wx.getStorageSync('myProjectSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('myProjectSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('myProjectSearch')));
}else if(that.data.from == 'mobile') {
currText = "搜索姓名、手机号"
if(app.isNotEmptyCheck(wx.getStorageSync('mobileSearch'))){
that.data.historyList = wx.getStorageSync('mobileSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('mobileSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('mobileSearch')));
}else if(that.data.from == 'announce') {
currText = "搜索企业名称"
if(app.isNotEmptyCheck(wx.getStorageSync('announceSearch'))){
that.data.historyList = wx.getStorageSync('announceSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('announceSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('announceSearch')));
}else if(that.data.from == 'announceAuto') {
currText = "搜索职位名称"
if(app.isNotEmptyCheck(wx.getStorageSync('announceAutoSearch'))){
that.data.historyList = wx.getStorageSync('announceAutoSearch')
}
that.data.historyList.push(that.data.inputVal);
wx.setStorageSync('announceAutoSearch',that.funQC(that.data.historyList));
console.log(that.funQC(wx.getStorageSync('announceAutoSearch')));
}
// wx.redirectTo({
// url: '../myProject/index?searchData='+that.data.inputVal,
// })
var pages = getCurrentPages();
var currPage = pages[pages.length - 1]; // 当前页面
var prevPage = pages[pages.length - 2]; // 上一个页面
if (that.data.inputVal == '') {
prevPage.setData({
inputVal: currText,
chaShowed: false
});
} else {
prevPage.setData({
inputVal: that.data.inputVal,
chaShowed: true
});
}
if(that.data.from == 'announceAuto' || that.data.from == 'announce') {
prevPage.setData({
navlist: 10,
});
}
wx.navigateBack({
delta: -1,
})
// this.data.billList = [];
// this.data.searchParam.pageNum = 1;
// this.data.searchParam.keys = this.data.inputVal;
// this.getList();
// this.getRead();
},
historySearchKey(e){
var that = this;
console.log(e.currentTarget.dataset.text)
var pages = getCurrentPages();
var currPage = pages[pages.length - 1]; // 当前页面
var prevPage = pages[pages.length - 2]; // 上一个页面
prevPage.setData({
inputVal:e.currentTarget.dataset.text,
chaShowed: true
});
if(that.data.from == 'announceAuto' || that.data.from == 'announce') {
prevPage.setData({
navlist: 10,
});
}
wx.navigateBack({
delta: -1,
})
},
// searchinput: function (e) {
// let that = this;
// this.setData({
// inputVal: e.detail.value,
// });
// this.data.searchParam.keys = e.detail.value;
// this.data.searchParam.pageNum = 1;
// that.setData({
// billList: [],
// searchParam: this.data.searchParam,
// });
// if (that.data.timer) {
// clearTimeout(that.data.timer);
// }
// that.data.timer = setTimeout(() => {
// this.getList();
// }, 500);
// },
cle(){
wx.removeStorage({
key: 'myProjectSearch',
})
},
clearInput() {
let that = this;
// this.data.billList = [];
this.setData({
inputVal: "",
isShowCha: false
});
// this.data.searchParam.keys = "";
// this.data.searchParam.pageNum = 1;
// this.setData({
// searchParam: this.data.searchParam,
// });
// this.getList();
// this.getRead();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
funQC(arr){
let newsArr = [];
for (let i = 0; i < arr.length; i++) {
if (app.isEmptyCheck(arr[i])){
continue;
}
if(newsArr.indexOf(arr[i]) === -1){
newsArr.push(arr[i]);
}
}
return newsArr;
},
onReady() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})