// pages/homePage/index.js
|
const $$ = require('../../utils/util');
|
const app = getApp();
|
|
// 咨询动态
|
function getVideoAndMessageApi(param) {
|
return $$.request({
|
url: 'paHotNews/listShow',
|
type: 'get',
|
submitData: param || {},
|
service: 'sys',
|
noToken: true
|
});
|
}
|
|
// 调解资源
|
function getResourseApi(param) {
|
return $$.request({
|
url: 'ctUnit/countUnit',
|
type: 'get',
|
submitData: param || {},
|
service: 'cust'
|
});
|
}
|
|
function loginApi(submitData) {
|
return $$.request({
|
url: 'paAccount/tryRegister',
|
type: 'post',
|
submitData,
|
service: 'cust',
|
noToken: true
|
});
|
}
|
|
function registerApi(submitData) {
|
return $$.request({
|
url: 'paAccount/empower',
|
type: 'post',
|
submitData,
|
service: 'cust',
|
noToken: true
|
});
|
}
|
|
Page({
|
/**
|
* 页面的初始数据
|
*/
|
msgCheckId: null, // 已经阅读过的提示不在弹出
|
data: {
|
visible: true,
|
imgUrl: $$.url.img,
|
demoImgUrl: $$.url.img + 'Aimge.png',
|
agreementMsg: '', // 服务协议
|
popupVisible: false,
|
banner: [{
|
image: `${$$.url.img}Banner1.png`,
|
image1: `${$$.url.img}banner4.png`
|
}, {
|
image: `${$$.url.img}Banner2.png`,
|
image1: `${$$.url.img}banner3.png`
|
}], // 轮播图
|
// banner: [`${$$.url.img}Banner1.png`, `${$$.url.img}Banner2.png`, `${$$.url.img}banner3.png`, `${$$.url.img}banner4.png`], // 轮播图
|
countUnitData: {}, //化解资源
|
userInfo: {}, //用户信息
|
video: [], // 热门视频
|
videoMore: false,
|
newMessage: [], // 最新资讯
|
newMessageMore: false,
|
message: [{}], // 消息通知
|
// 底部弹窗消息
|
popupMsg: [{
|
show: false,
|
type: 1,
|
title: '实名认证提醒',
|
subTitle: '您尚未通过实名认证,请尽快前往认证',
|
buttonText: '前往认证',
|
}],
|
},
|
|
// 跳转资讯链接
|
goSeeMessage(e) {
|
let url = e.currentTarget.dataset.url;
|
console.log('url', url);
|
wx.navigateTo({
|
url: '../webview/index?showUrl=' + url
|
});
|
},
|
|
// 调解资源去看看
|
handleNavigateTo(e) {
|
let type = e.currentTarget.dataset.type;
|
let url = e.currentTarget.dataset.url;
|
if (type === 'register') {
|
if (!$$.userTest('all', 'bottom')) {
|
this.setData({
|
popupMsg: [{
|
show: true,
|
type: 1,
|
title: '实名认证提醒',
|
subTitle: '您尚未通过实名认证,请尽快前往认证',
|
buttonText: '前往认证',
|
}, ],
|
});
|
return;
|
}
|
wx.navigateTo({
|
url: url,
|
});
|
} else {
|
if ($$.userTest('login')) {
|
wx.navigateTo({
|
url: '../../pages/findAdjust/index?type=' + (type === 'mediater' ? '1' : '2'),
|
});
|
}
|
}
|
},
|
|
// 查看更多
|
handleGetMore(e) {
|
let type = e.currentTarget.dataset.type;
|
wx.navigateTo({
|
url: `../../pages/homePageInfo/index?type=${type}`,
|
});
|
},
|
|
// 跳转
|
_handleGoPage(e) {
|
let url = e.currentTarget.dataset.url;
|
wx.navigateTo({
|
url: url,
|
});
|
},
|
|
// 平台协议操作
|
handleAgree(e) {
|
let type = e.currentTarget.dataset.type;
|
if (type === 'noAgree') {
|
this.selectComponent('#tabbar-page').loginOut();
|
$$.loginOutClearData();
|
} else {
|
// 同意协议之后退出登录后不重复弹出
|
wx.setStorage({
|
key: 'agreement',
|
data: 1
|
});
|
}
|
this.setData({
|
popupVisible: false
|
});
|
},
|
|
// 跳转至我的消息
|
handleGoToMessageCenter() {
|
wx.navigateTo({
|
url: '../../pages/messageCenter/index',
|
});
|
},
|
|
// 关闭消息弹窗
|
handleClosePopupMsg(e) {
|
let index = e.currentTarget.dataset.index;
|
this.data.popupMsg[index].show = false;
|
this.data.popupMsg[index].content?.forEach((x) => {
|
this.msgCheckId = [...(this.msgCheckId || []), x.caseId];
|
});
|
this.setData({
|
popupMsg: this.data.popupMsg
|
});
|
},
|
|
// 消息弹窗操作, TODO:跳转至详情页面的代码屏蔽,暂无用到,后续不用可删除
|
handleClickPopupMsg(e) {
|
let value = e.currentTarget.dataset.item;
|
// let t = e.currentTarget.dataset.t;
|
if (e.currentTarget.dataset.type === 'more' && value.content.length === 1) {
|
return;
|
}
|
this.handleClosePopupMsg(e);
|
if (value.type === 1) {
|
wx.navigateTo({
|
url: '../../pages/realNameAuthentication/index'
|
});
|
return;
|
}
|
if (value.type === 2 || (value.type === 3 && value.content[t].meetType === '22_00020-1')) {
|
wx.navigateTo({
|
url: '../../pages/myMediate/index'
|
});
|
return;
|
}
|
if (value.type === 4 || (value.type === 3 && value.content[t].meetType === '22_00020-2')) {
|
wx.navigateTo({
|
url: '../../pages/myJudicialConfirmation/index'
|
});
|
return;
|
}
|
},
|
|
|
// 获取首页视频资讯数据
|
async getVideoAndMessage(param) {
|
const res = await getVideoAndMessageApi(param);
|
if (res.type) {
|
let hotVideoList = res.data.hotVideoList || [];
|
let hotNewsList = res.data.hotNewsList || [];
|
wx.setStorage({
|
key: 'homePageNewMsgTime',
|
data: $$.timeFormat(new Date(), 'YYYY-MM-DD HH:mm:ss'),
|
});
|
this.setData({
|
video: hotVideoList.filter((item, index) => index < 2),
|
videoMore: hotVideoList.length > 2 ? true : false,
|
newMessage: hotNewsList.filter((item, index) => index < 2),
|
newMessageMore: hotNewsList.length > 2 ? true : false,
|
});
|
}
|
},
|
|
// 获取首页调解资源数量
|
async getResourse(param) {
|
const res = await getResourseApi(param);
|
this.setData({
|
countUnitData: res.data
|
});
|
},
|
|
// 获取服务协议
|
async getAgreement() {
|
const res = await $$.commonRequest({
|
url: `${$$.url.txt}agree.txt`,
|
type: 'get'
|
});
|
if (res) {
|
this.data.popupVisible = true;
|
this.setData({
|
popupVisible: true,
|
agreementMsg: `<pre class="pre">${res || '-'}</pre>`
|
});
|
}
|
},
|
|
// 前往查看
|
AiModalClick(e) {
|
let item = e.currentTarget.dataset.item;
|
wx.navigateTo({
|
url: '../../pages/AIAide/index?caseDes=' + item.caseDes + '&caseClaim=' + item.caseClaim + '&caseId=' + item.caseId
|
});
|
this.setData({
|
AiModal: false
|
})
|
},
|
|
// 关闭AI弹窗
|
addClosePopup() {
|
this.setData({
|
AiModal: false
|
})
|
},
|
|
// 登录,获取用户信息
|
async handleGetUserInfo() {
|
|
wx.getUserProfile({
|
desc: '完善用户信息',
|
complete(res) {
|
if (res.errMsg === 'getUserProfile:ok') {
|
wx.login({
|
async success(res2) {
|
if (res2.code) {
|
const accountInfo = wx.getAccountInfoSync();
|
const submitData = {
|
appid: accountInfo.miniProgram.appId,
|
code: res2.code,
|
avatar: res?.userInfo.avatarUrl,
|
encryptedData: res.encryptedData,
|
ivStr: res.iv,
|
};
|
$$.showLoading();
|
const res3 = await registerApi(submitData);
|
$$.hideLoading();
|
if (res3.type) {
|
wx.setStorage({
|
key: 'userInfo',
|
data: res3.data
|
});
|
app.globalData.token = res3.data.token;
|
$$.showToast({
|
title: '登录成功',
|
icon: 'success'
|
});
|
await $$.sleep();
|
wx.reLaunch({
|
url: '../../pages/homePage/index',
|
});
|
}
|
} else {
|
$$.hideLoading();
|
$$.showToast('登录失败,请稍后重试');
|
}
|
},
|
});
|
} else {
|
$$.hideLoading();
|
$$.showToast({
|
title: '抱歉!授权失败'
|
});
|
}
|
},
|
});
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {},
|
|
onShow(options) {
|
if (!app.globalData.token) {
|
$$.showModal({
|
content: '抱歉您未登录,是否前往登录?',
|
success: (res) => {
|
if (res.confirm) {
|
this.handleGetUserInfo();
|
}
|
},
|
});
|
return;
|
}
|
// this.getUserInfo()
|
let userInfo = wx.getStorageSync('userInfo') || {};
|
let AICase = wx.getStorageSync('AICase') || '';
|
if (AICase) {
|
this.setData({
|
AiModal: AICase
|
})
|
wx.removeStorage({
|
key: 'AICase'
|
})
|
}
|
let appid = wx.getAccountInfoSync().miniProgram.appId;
|
this.setData({
|
userInfo
|
});
|
|
|
let that = this;
|
wx.getStorage({
|
key: 'homePageNewMsgTime',
|
complete: (res) => {
|
if (that.data.video.length === 0 || !that.data.countUnitData) {
|
this.getVideoAndMessage({
|
appid
|
});
|
this.getResourse({
|
appid
|
});
|
return;
|
}
|
if (res.data && $$.moment().diff($$.moment(res.data), 'minute') > 60) {
|
this.getVideoAndMessage({
|
appid
|
});
|
this.getResourse({
|
appid
|
});
|
}
|
},
|
});
|
|
// 获取弹窗信息提醒
|
if (app.globalData.token) {
|
|
if (!$$.userTest('realName', 'bottom')) {
|
this.setData({
|
popupMsg: [{
|
show: true,
|
type: 1,
|
title: '实名认证提醒',
|
subTitle: '您尚未通过实名认证,请尽快前往认证',
|
buttonText: '前往认证',
|
}, ],
|
});
|
return;
|
}
|
}
|
},
|
|
onHide() {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {},
|
|
|
});
|