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

464 lines
11 KiB

// pages/user/index.js
import dayjs from '../../utils/dayjs/index.js'
import relativeTime from '../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
import {
store
} from '../../utils/store.js'
import {
UserModel
} from '../../models/user.js'
let userModel = new UserModel()
import {
AuthModel
} from '../../models/auth.js'
let authModel = new AuthModel()
import {
HomeModel
} from '../../models/home.js'
let homeModel = new HomeModel()
import {
ServiceModel
} from '../../models/service.js'
let serviceModel = new ServiceModel()
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
messageTotal: Number,
isAuth: false,
whistle: false,
service: [
[{
id: 1,
name: '公益活动'
},
{
id: 2,
name: '户籍档案'
},
{
id: 3,
name: '子女入学'
},
{
id: 4,
name: '医疗保证'
},
{
id: 5,
name: '老有所依'
},
{
id: 6,
name: '便捷政务'
},
{
id: 7,
name: '人才贷'
},
{
id: 8,
name: '便利出行'
},
{
id: 9,
name: '乐游琴岛'
},
{
id: 10,
name: '阳光健身'
},
],
[{
id: 11,
name: '家政服务'
},
{
id: 12,
name: '法律服务'
},
{
id: 13,
name: '企业游学'
},
{
id: 14,
name: 'Talent下午茶'
},
{
id: 15,
name: '配偶安置'
},
{
id: 16,
name: '节日温暖'
},
{
id: 17,
name: '学历教育'
},
{
id: 18,
name: '特色文娱'
},
{
id: 19,
name: '兴趣培训'
},
{
id: 20,
name: '停车服务'
},
]
],
servicePublic: [
{
id: 1,
name: '公益活动'
},
{
id: 2,
name: '户籍档案'
},
{
id: 3,
name: '便捷政务'
},
{
id: 4,
name: '学历教育'
},
{
id: 5,
name: '场景开放'
},
{
id: 6,
name: '企业招聘'
},
{
id: 7,
name: '名人堂'
},
{
id: 8,
name: '法律服务'
},
{
id: 5,
name: '企业游学'
},
{
id: 6,
name: '兴趣培训'
},
{
id: 7,
name: '邮轮体验'
},
],
talentsType: -1,
shield: '../../images/shield.png',
banners: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
serviceModel.getService(res => {
var serviceList = res.result;
var service = [];
var list = [];
var pList = [];
var serviceData = [];
var j = 0;
for (var i = 0; i < serviceList.length; i++) {
list.push(serviceList[i]);
j++;
if (j == 10) {
service.push(list);
list = [];
j = 0;
}
this.data.servicePublic.forEach(item => {
if (serviceList[i].server_name == item.name) {
pList.push(serviceList[i]);
}
});
}
if (list.length > 0) {
service.push(list);
}
for (let i = 0; i < pList.length; i += 6) {
serviceData.push(pList.slice(i, i + 6));
}
console.log('service-->', service);
console.log('servicePublic-->', serviceData);
// 更新页面数据
this.setData({
service: service,
servicePublic: serviceData
});
});
// 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
})
})
},
onShow: function () {
if (store.hasBindUserInfo()) {
console.log("onshow");
this.getUserInfo()
this.setData({
isAuth: true
})
} else {
if (app.globalData.navigate.mobile) {
var params = {
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
avatarUrl: app.globalData.navigate.faceImg,
id:app.globalData.navigate.id,
}
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone,
id:params.id
})
wx.reLaunch({
url: '/pages/user/index',
})
})
} else {
this.setData({
isAuth: false
})
}
console.log("isAuth--",this.data.isAuth);
// wx.redirectTo({
// url: '/pages/weChatAuth/index',
// })
}
},
// 获取用户信息
getUserInfo() {
userModel.getUserInfo(res => {
console.log("--getUserInfo--");
console.log(res)
let nickName = res.result.nickName
let avatarUrl = res.result.avatarUrl
if (nickName && avatarUrl) {
//console.log('已授权')
this.setData({
userInfo: res.result,
avatarUrl: res.result.avatarUrl,
nickName: res.result.nickName,
isAuth: true,
talentsType: res.result.talentsType
}, () => {
if (store.hasPhone()) {
//console.log('已经绑定手机号码')
this.getMsgStatus()
} else {
//console.log('未绑定手机号码')
if (app.globalData.navigate.mobile) {
var params = {
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
avatarUrl: app.globalData.navigate.faceImg,
id:app.globalData.navigate.id
}
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone,
id:params.id
})
wx.reLaunch({
url: '/pages/user/index',
})
})
} 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',
})
}
}
})
}
}
})
store.saveUserInfo({
nickName: res.result.nickName,
avatarUrl: res.result.avatarUrl,
phone: res.result.phone || '',
id: res.result.id
})
} else {
if (app.globalData.navigate.mobile) {
var params = {
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
avatarUrl: app.globalData.navigate.faceImg,
id: app.globalData.navigate.id
}
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone,
id: params.id
})
wx.reLaunch({
url: '/pages/user/index',
})
})
}
}
})
},
// 获取未读消息
getMsgStatus() {
userModel.getMyMessageTotal(res => {
//console.log(res.result.total)
this.setData({
messageTotal: Number(res.result.total)
})
})
userModel.getMyWhistleMessage(res => {
if (res.result.reminders == 1) {
this.setData({
whistle: true
})
} else {
this.setData({
whistle: false
})
}
})
},
// cell点击
onTapItem(e) {
const {
type
} = e.currentTarget.dataset
console.log('type-->',type)
if (this.data.isAuth) {
if (type === 'myInfo') {
console.log('进入个人信息页面');
console.log(this.data.userInfo);
wx.navigateTo({
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({
url: '/pages/weChatAuth/index?tabType=login',
})
}
},
service: function () {
wx.navigateTo({
url: '/pages/service/service',
})
},
vip: function () {
wx.navigateTo({
url: '/pages/service/vipCard/vipCard',
})
},
jump: function (e) {
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);
// }
// })
// }
})