408 lines
11 KiB
JavaScript
408 lines
11 KiB
JavaScript
const app = getApp()
|
|
const util = require('../../utils/util')
|
|
var miucms = require('../../utils/miucms.js');
|
|
const common = require("../../utils/commonMethod")
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
kw: '',
|
|
isdefault: true, // 是否显示默认页面
|
|
historyList: [],
|
|
info: {},
|
|
loading: false,
|
|
page: 1,
|
|
list: [],
|
|
showTOTOP: false,
|
|
title: "",
|
|
placeholder: "",
|
|
sex: {
|
|
1: '限男生',
|
|
2: '限女生',
|
|
3: '男女皆可'
|
|
},
|
|
hotwordlist: [], // 热门数据
|
|
total: 0,
|
|
bottomLift: 32,
|
|
type: "", // 搜索类型 flyingFriend interviewExperience offercollege offersummary question school tenement thread vote xg
|
|
typeObj: {
|
|
flyingFriend: "找飞友",
|
|
interviewExperience: "面经",
|
|
offercollege: "Offer",
|
|
offersummary: "总结",
|
|
question: "问答",
|
|
school: "院校",
|
|
tenement: "租房",
|
|
thread: "文章",
|
|
vote: "投票",
|
|
},
|
|
|
|
autoFocus: false,
|
|
pl: "",
|
|
|
|
contrastcount: 0, // 项目对比 数量
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
rpx15: 15,
|
|
onLoad: function (options) {
|
|
// options['kw'] = "技术"
|
|
miucms.pageStart(app).then(() => {
|
|
this.rpx15 = util.rpxTopx(15)
|
|
|
|
const screen_data = app.screen_data || {}
|
|
this.setData({
|
|
type: options.type || '',
|
|
kw: options.kw || '',
|
|
pl: options.pl || '',
|
|
sid: options.sid || '',
|
|
bottomLift: screen_data.bottomLift,
|
|
})
|
|
|
|
// 香港项目库的 需要 获取对比库值
|
|
if (options.type == 'xg') {
|
|
common.xgBasicData(this, app).then(data => {
|
|
this.setData({
|
|
contrastcount: data.contrastcount,
|
|
})
|
|
})
|
|
}
|
|
|
|
this.getInit()
|
|
if (this.data.kw) this.getList()
|
|
if (this.data.pl) {
|
|
this.setData({
|
|
autoFocus: false
|
|
})
|
|
setTimeout(() => {
|
|
this.setData({
|
|
autoFocus: true
|
|
})
|
|
}, 300)
|
|
}
|
|
})
|
|
},
|
|
|
|
onPageScroll(e) {
|
|
if (e.scrollTop > 1000 && !this.data.showTOTOP) {
|
|
this.setData({
|
|
showTOTOP: true
|
|
})
|
|
} else if (e.scrollTop < 1000 && this.data.showTOTOP) {
|
|
this.setData({
|
|
showTOTOP: false
|
|
})
|
|
}
|
|
},
|
|
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
this.getList()
|
|
},
|
|
|
|
getInit() {
|
|
wx.showLoading()
|
|
util.wxpost('/miniprogramApi/offer/search', {
|
|
type: this.data.type
|
|
}).then(res => {
|
|
wx.hideLoading()
|
|
var data = res.data;
|
|
let historyList = wx.getStorageSync('historyList') || [];
|
|
|
|
let placeholder = data.placeholder
|
|
let title = data.title
|
|
const type = this.data.type
|
|
if (type == 'flyingFriend') {
|
|
// title = '搜索找飞友'
|
|
placeholder = '输入搜索关键词,例如航班号'
|
|
}
|
|
|
|
this.setData({
|
|
placeholder,
|
|
hotwordlist: data.hotwordlist,
|
|
title,
|
|
historyList,
|
|
})
|
|
})
|
|
},
|
|
// 点击选择关键词
|
|
selectKW(e) {
|
|
const kw = e.currentTarget.dataset.name
|
|
this.setData({
|
|
kw,
|
|
})
|
|
|
|
if (!this.data.historyList.includes(kw)) this.data.historyList.unshift(kw)
|
|
|
|
this.setData({
|
|
historyList: this.data.historyList
|
|
})
|
|
|
|
wx.setStorage({
|
|
data: this.data.historyList,
|
|
key: 'historyList',
|
|
})
|
|
|
|
this.clearData()
|
|
this.getList()
|
|
},
|
|
|
|
// 点取消
|
|
canclefocus() {
|
|
wx.navigateBack()
|
|
},
|
|
|
|
search(e) {
|
|
if (this.data.kw == '') this.data.kw = this.data.pl
|
|
if (this.data.kw == '') return false
|
|
|
|
if (!this.data.historyList.includes(this.data.kw)) this.data.historyList.unshift(this.data.kw)
|
|
|
|
this.setData({
|
|
historyList: this.data.historyList
|
|
})
|
|
|
|
wx.setStorage({
|
|
data: this.data.historyList,
|
|
key: 'historyList',
|
|
})
|
|
|
|
this.clearData()
|
|
this.getList()
|
|
},
|
|
|
|
clearData() {
|
|
this.setData({
|
|
list: [],
|
|
page: 1,
|
|
loading: false,
|
|
})
|
|
},
|
|
|
|
clearKW() {
|
|
this.setData({
|
|
kw: '',
|
|
list: [],
|
|
page: 1,
|
|
isdefault: true,
|
|
})
|
|
},
|
|
|
|
delKW() {
|
|
let that = this;
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '确定删除历史搜索吗?',
|
|
success(e) {
|
|
if (e.confirm) {
|
|
that.setData({
|
|
historyList: []
|
|
})
|
|
wx.removeStorage({
|
|
key: 'historyList',
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
getList() {
|
|
const page = this.data.page
|
|
const kw = this.data.kw
|
|
if (this.data.loading || page == 0 || !kw) return
|
|
this.data.loading = true
|
|
// 代表是第一次搜索需要统计
|
|
if (page == 1) {
|
|
util.statistics({
|
|
name: "search",
|
|
data: {
|
|
kw
|
|
}
|
|
})
|
|
}
|
|
|
|
wx.showLoading()
|
|
let url = "/miniprogramApi/offer/search/lists"
|
|
|
|
if (this.data.type == 'xg') url = 'https://api.gter.net/v1/program/getList'
|
|
|
|
util.wxpost(url, {
|
|
page,
|
|
keyword: kw,
|
|
type: this.data.type,
|
|
limit: 20,
|
|
sid: this.data.sid,
|
|
}).then(res => {
|
|
var data = res.data;
|
|
if (res.code != 200) return
|
|
|
|
let list = data.data || []
|
|
const date = new Date()
|
|
const month = date.getMonth() + 1
|
|
const year = date.getFullYear()
|
|
|
|
list.forEach(element => {
|
|
if (this.data.type == 'xg') {
|
|
element['tuition_fee_text'] = common.formatNumberWithSpaces(element.tuition_fee || '')
|
|
element['random'] = app.randomString(6)
|
|
// element['semesterState'] = month > element.semester.month && year + 1 <= element.semester.year
|
|
element['semesterState'] = (year < element.semester.year) || (year === element.semester.year && month < element.semester.month)
|
|
}
|
|
|
|
if (element.type == 'appmsgalbum') {
|
|
element.data['timeFormat'] = util.timeago(element.data.create_time, 2)
|
|
element.data['url'] = encodeURIComponent(element.data.url)
|
|
}
|
|
|
|
if (element.type == 'offersummary') {
|
|
element.data['timestampText'] = util.strtimeago(element.data.timestamp, 2)
|
|
}
|
|
|
|
if (element.type == 'offercollege') {
|
|
element.data['timestamp'] = util.strtimeago(element.data.timestamp, 2)
|
|
}
|
|
|
|
if (element.type == 'interviewExperience') {
|
|
element.data['timeFormat'] = util.strtimeago(element.data.releasetime, 2)
|
|
}
|
|
|
|
if (element.type == 'vote') {
|
|
element.data['timeFormat'] = util.strtimeago(element.data.releasetime, 2)
|
|
if (element.status == 0) {
|
|
element.data['time'] = util.changeTime(new Date(element.data.deadline * 1000))
|
|
} else {
|
|
element.data['time'] = util.changeTimeago(new Date(element.data.deadline * 1000))
|
|
}
|
|
}
|
|
|
|
// 去除掉问答的 标签
|
|
if (element.type == 'thread') {
|
|
element.data['timeFormat'] = util.timeago(element.data.dateline, 2)
|
|
}
|
|
|
|
if (element.type == 'question') {
|
|
element.data.content = element.data.content.replace(/<[^>]*>/g, '');
|
|
}
|
|
|
|
if (element.type == 'tenement') {
|
|
// element.data = util.handleHousing(element.data)
|
|
element.data['timeFormat'] = util.timeago(element.data.updatetime, 2)
|
|
}
|
|
})
|
|
const target = this.data.list.concat(list) || []
|
|
this.setData({
|
|
loading: false,
|
|
list: target,
|
|
page: data.count > data.page * 20 ? page + 1 : 0,
|
|
total: data.count,
|
|
isdefault: false,
|
|
})
|
|
|
|
wx.nextTick(() => {
|
|
wx.hideLoading()
|
|
})
|
|
})
|
|
},
|
|
|
|
// 物品的点击事件
|
|
handleClick(e) {
|
|
const index = e.currentTarget.dataset.index
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
util.wxpost("https://api.gter.net/v1/program/addContrast", {
|
|
projectid: id
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
const list = this.data.list
|
|
|
|
list[index]['contraststatus'] = {
|
|
ismanage: 1,
|
|
status: 1,
|
|
}
|
|
|
|
this.setData({
|
|
list,
|
|
contrastcount: data.count,
|
|
})
|
|
|
|
app.globalData.basicData['contrastcount'] = data.count
|
|
|
|
common.toast(res.message)
|
|
})
|
|
},
|
|
|
|
// 点击跳转
|
|
goPage(e) {
|
|
const url = e.currentTarget.dataset.url
|
|
common.goPage(url)
|
|
},
|
|
|
|
openMoreSelect(e) {
|
|
const index = e.currentTarget.dataset.index || 0
|
|
|
|
let list = this.data.list
|
|
list.forEach(element => {
|
|
element['moreState'] = false
|
|
})
|
|
|
|
list[index]['moreState'] = true
|
|
|
|
this.setData({
|
|
list,
|
|
})
|
|
},
|
|
|
|
closeMoreSelect(e) {
|
|
const list = this.data.list
|
|
list.forEach(element => {
|
|
element['moreState'] = false
|
|
})
|
|
|
|
this.setData({
|
|
list,
|
|
})
|
|
},
|
|
|
|
addProject(e) {
|
|
const index = e.currentTarget.dataset.index
|
|
const id = e.currentTarget.dataset.id
|
|
|
|
util.wxpost("https://api.gter.net/v1/program/addContrast", {
|
|
projectid: id
|
|
}).then(res => {
|
|
if (res.code != 200) return
|
|
const data = res.data
|
|
|
|
let list = this.data.list
|
|
// if (list[index]['contraststatus'] == null) list[index]['contraststatus'] = {}
|
|
|
|
list[index]['contraststatus'] = {
|
|
status: 1,
|
|
ismanage: 1,
|
|
}
|
|
|
|
this.setData({
|
|
list,
|
|
contrastcount: data.count,
|
|
})
|
|
|
|
app.globalData.basicData['contrastcount'] = data.count
|
|
|
|
common.toast(res.message)
|
|
})
|
|
},
|
|
|
|
|
|
}) |