市北人才赋能平台 --小程序端
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.

452 lines
10 KiB

6 years ago
// pages/user/index.js
import dayjs from '../../utils/dayjs/index.js'
import relativeTime from '../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
4 years ago
import {
store
} from '../../utils/store.js'
import {
UserModel
} from '../../models/user.js'
let userModel = new UserModel()
4 years ago
import {
AuthModel
} from '../../models/auth.js'
6 years ago
let authModel = new AuthModel()
3 years ago
import {
HomeModel
} from '../../models/home.js'
let homeModel = new HomeModel()
4 years ago
import {
ServiceModel
} from '../../models/service.js'
4 years ago
let serviceModel = new ServiceModel()
const app = getApp()
6 years ago
Page({
/**
* 页面的初始数据
*/
data: {
6 years ago
messageTotal: Number,
4 years ago
isAuth: false,
whistle: false,
service: [
[{
id: 1,
name: '公益活动'
4 years ago
},
{
id: 2,
name: '户籍档案'
4 years ago
},
{
id: 3,
name: '子女入学'
},
{
id: 4,
name: '医疗保证'
4 years ago
},
{
id: 5,
name: '老有所依'
4 years ago
},
{
id: 6,
name: '便捷政务'
4 years ago
},
{
id: 7,
name: '人才贷'
4 years ago
},
{
id: 8,
name: '便利出行'
4 years ago
},
{
id: 9,
name: '乐游琴岛'
4 years ago
},
{
id: 10,
name: '阳光健身'
4 years ago
},
4 years ago
],
4 years ago
[{
id: 11,
name: '家政服务'
},
{
id: 12,
name: '法律服务'
},
{
id: 13,
name: '企业游学'
4 years ago
},
{
id: 14,
name: 'Talent下午茶'
4 years ago
},
{
id: 15,
name: '配偶安置'
},
{
id: 16,
name: '节日温暖'
4 years ago
},
{
id: 17,
name: '学历教育'
},
{
id: 18,
name: '特色文娱'
4 years ago
},
{
id: 19,
name: '兴趣培训'
4 years ago
},
{
id: 20,
name: '停车服务'
4 years ago
},
4 years ago
]
4 years ago
],
servicePublic: [
{
4 years ago
id: 1,
name: '公益活动'
4 years ago
},
{
id: 2,
name: '户籍档案'
4 years ago
},
{
id: 3,
name: '便捷政务'
4 years ago
},
{
id: 4,
3 years ago
name: '学历教育'
},
{
id: 5,
name: '场景开放'
},
{
id: 6,
name: '企业招聘'
},
{
id: 7,
name: '名人堂'
},
{
id: 8,
4 years ago
name: '法律服务'
},
{
id: 5,
name: '企业游学'
},
{
id: 6,
name: '兴趣培训'
},
4 years ago
],
talentsType: -1,
3 years ago
shield: '../../images/shield.png',
banners: [],
6 years ago
},
4 years ago
6 years ago
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
4 years ago
serviceModel.getService(res => {
var serviceList = res.result
var service = []
var list = []
let j = 1;
4 years ago
var pList = []
var serviceData=[]
for (var i = 0; i < serviceList.length; i++) {
4 years ago
list.push(serviceList[i])
4 years ago
if (j == 10) {
4 years ago
j = 1;
service.push(list)
list = []
4 years ago
} else {
4 years ago
j++;
}
4 years ago
this.data.servicePublic.forEach(item => {
if (serviceList[i].server_name == item.name) {
pList.push(serviceList[i])
}
})
4 years ago
}
3 years ago
for (let i = 0; i <pList.length; i += 6) {
serviceData.push(pList.slice(i, i + 6))
4 years ago
};
// console.log(serviceData)
console.log('service-->',service)
3 years ago
// console.log('servicePublic-->',serviceData)
4 years ago
this.setData({
4 years ago
service: service,
servicePublic: serviceData
4 years ago
})
4 years ago
// console.log(this.data.servicePublic)
4 years ago
})
3 years ago
// this.fetchHomeBanner()
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage']
});
},
fetchHomeBanner() {
this.setData({
banners: []
})
homeModel.getHomeBanner(res => {
//console.log('Banner')
console.log(res)
const datas = res.list
let tempBanners = []
datas.forEach(item => {
tempBanners.push({
id: item.id,
image: item.titlePic,
title: item.title,
type: item.type
})
})
this.setData({
banners: tempBanners
})
})
6 years ago
},
onShow: function () {
if (store.hasBindUserInfo()) {
5 years ago
console.log("onshow");
this.getUserInfo()
this.setData({
isAuth: true
})
} else {
4 years ago
if (app.globalData.navigate.mobile) {
var params = {
4 years ago
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
3 years ago
avatarUrl: app.globalData.navigate.faceImg,
id:app.globalData.navigate.id,
}
4 years ago
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
3 years ago
phone: params.phone,
id:params.id
})
wx.reLaunch({
url: '/pages/user/index',
})
})
4 years ago
} else {
this.setData({
isAuth: false
})
}
4 years ago
console.log("isAuth--",this.data.isAuth);
// wx.redirectTo({
// url: '/pages/weChatAuth/index',
// })
}
4 years ago
6 years ago
},
// 获取用户信息
4 years ago
getUserInfo() {
userModel.getUserInfo(res => {
3 years ago
console.log("--getUserInfo--");
console.log(res)
6 years ago
let nickName = res.result.nickName
let avatarUrl = res.result.avatarUrl
4 years ago
if (nickName && avatarUrl) {
//console.log('已授权')
6 years ago
this.setData({
6 years ago
userInfo: res.result,
6 years ago
avatarUrl: res.result.avatarUrl,
nickName: res.result.nickName,
4 years ago
isAuth: true,
talentsType: res.result.talentsType
}, () => {
if (store.hasPhone()) {
//console.log('已经绑定手机号码')
this.getMsgStatus()
} else {
//console.log('未绑定手机号码')
4 years ago
if (app.globalData.navigate.mobile) {
var params = {
4 years ago
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
3 years ago
avatarUrl: app.globalData.navigate.faceImg,
id:app.globalData.navigate.id
}
4 years ago
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
3 years ago
phone: params.phone,
id:params.id
})
wx.reLaunch({
url: '/pages/user/index',
})
})
4 years ago
} else {
wx.showModal({
title: '温馨提示',
content: '是否前往验证手机号码?',
success(res) {
if (res.confirm) {
// wx.redirectTo({
// url: '/pages/register/index',
// })
wx.redirectTo({
url: '/pages/weChatAuth/index?type=2',
})
} else if (res.cancel) {
wx.switchTab({
url: '/pages/home/index',
})
}
}
})
}
}
6 years ago
})
store.saveUserInfo({
nickName: res.result.nickName,
avatarUrl: res.result.avatarUrl,
3 years ago
phone: res.result.phone || '',
id: res.result.id
6 years ago
})
4 years ago
} else {
if (app.globalData.navigate.mobile) {
var params = {
4 years ago
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
3 years ago
avatarUrl: app.globalData.navigate.faceImg,
id: app.globalData.navigate.id
}
4 years ago
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
3 years ago
phone: params.phone,
id: params.id
})
wx.reLaunch({
url: '/pages/user/index',
})
})
}
6 years ago
}
6 years ago
})
},
// 获取未读消息
4 years ago
getMsgStatus() {
userModel.getMyMessageTotal(res => {
//console.log(res.result.total)
this.setData({
messageTotal: Number(res.result.total)
})
})
4 years ago
userModel.getMyWhistleMessage(res => {
if (res.result.reminders == 1) {
this.setData({
whistle: true
})
4 years ago
} else {
this.setData({
whistle: false
})
}
})
6 years ago
},
// cell点击
4 years ago
onTapItem(e) {
const {
type
} = e.currentTarget.dataset
4 years ago
console.log('type-->',type)
4 years ago
if (this.data.isAuth) {
if (type === 'myInfo') {
console.log('进入个人信息页面');
console.log(this.data.userInfo);
wx.navigateTo({
5 years ago
url: `/pages/user/${type}/index?userIcon=${this.data.userInfo.avatarUrl}&userName=${this.data.userInfo.nickName}&userPhone=${this.data.userInfo.phone || ''}&company=${this.data.userInfo.company || ''}&position=${this.data.userInfo.position || ''}&street=${this.data.userInfo.departId || ''}&age=${this.data.userInfo.age || ''}&genderIndex=${this.data.userInfo.gender || ''}&education=${this.data.userInfo.education || ''}&professionalTitle=${this.data.userInfo.title || ''}&talentTitle=${this.data.userInfo.designation || ''}&prize=${this.data.userInfo.honor || ''}`,
})
} else {
wx.navigateTo({
url: `/pages/user/${type}/index`,
})
}
} else {
wx.redirectTo({
3 years ago
url: '/pages/weChatAuth/index?tabType=login',
})
6 years ago
}
4 years ago
},
4 years ago
service: function () {
4 years ago
wx.navigateTo({
url: '/pages/service/service',
})
4 years ago
4 years ago
},
4 years ago
vip: function () {
4 years ago
wx.navigateTo({
url: '/pages/service/vipCard/vipCard',
})
},
4 years ago
jump: function (e) {
4 years ago
wx.navigateToMiniProgram({
appId: e.currentTarget.dataset.appid,
// path: 'page/index/index?id=123',
extraData: {
// foo: 'bar'
},
envVersion: 'release',
success(res) {
// 打开成功
}
})
return;
},
goTraffic(){
wx.navigateToMiniProgram({
appId: 'wx0773fc2238f4ca70',
path: '',
envVersion: 'release', // 打开正式版
success(res) {
// 打开成功
console.log('打开成功')
},
fail: function (err) {
console.log(err);
}
})
6 years ago
}
})