// 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 { 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: '企业家沙龙' }, { 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: '法律服务' }, ], talentsType: -1, shield: '../../images/shield.png' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { serviceModel.getService(res => { var serviceList = res.result var service = [] var list = [] let j = 1; var pList = [] var serviceData=[] for (var i = 0; i < serviceList.length; i++) { list.push(serviceList[i]) if (j == 10) { j = 1; service.push(list) list = [] } else { j++; } this.data.servicePublic.forEach(item => { if (serviceList[i].server_name == item.name) { pList.push(serviceList[i]) } }) } for (let i = 0; i ',service) this.setData({ service: service, servicePublic: serviceData }) // console.log(this.data.servicePublic) }) }, 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 } userModel.navigateUser(params, res => { store.saveUserInfo({ nickName: params.nickName, avatarUrl: params.avatarUrl, phone: params.phone }) wx.reLaunch({ url: '/pages/user/index', }) }) } else { this.setData({ isAuth: false }) } // 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 } userModel.navigateUser(params, res => { store.saveUserInfo({ nickName: params.nickName, avatarUrl: params.avatarUrl, phone: params.phone }) 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 || '' }) } else { if (app.globalData.navigate.mobile) { var params = { phone: app.globalData.navigate.mobile, nickName: app.globalData.navigate.nickname, avatarUrl: app.globalData.navigate.faceImg } userModel.navigateUser(params, res => { store.saveUserInfo({ nickName: params.nickName, avatarUrl: params.avatarUrl, phone: params.phone }) 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) 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', }) } }, 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); } }) } })