jhwxapp/miniprogram/pages/saft-qr-view/index.js

178 lines
5.5 KiB
JavaScript
Raw Normal View History

2023-08-10 01:21:29 +08:00
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
app.getOPenId()
const {q} = options;
wx.setStorageSync('options', options)
       if (q) {
         let urlStr = decodeURIComponent(q);
let subStrUrl = urlStr.substr(urlStr.indexOf("?"),urlStr.length-1)
let params = this.getRequest(subStrUrl)
this.checkUserApprovalSkipView(params)
       }else{
this.checkUserApprovalSkipView(options)
}
},
/**
* 获取请求地址信息
*/
getRequest(url) {
var theRequest = new Object();
var strs;
if (url.indexOf("?") != -1) {
let str = url.substr(1);
strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
},
/**
* 判断扫码用户是否有权限
*/
checkUserApprovalSkipView(params){
//获取当前扫码用户的openId
let openId = wx.getStorageSync('openId') != null || wx.getStorageSync('openId') ?wx.getStorageSync('openId'):"123"
wx.request({
url: app.globalData.szhUrl + "/business/saftEducationOpenIdMap/list",
method:"post",
data:{
openId
},
header: {
'content-type': 'application/x-www-form-urlencoded' //修改此处即可
},
success(res){
let data = res.data
if(data.code == '0' && data.rows.length > 0){
let result = data.rows
//获取用户在实名制用户信息
wx.request({
url: app.globalData.smzUrl+"/mkl/api/searchUserInfoList",
method:"POST",
data:{
projectId: params.smzProjectId,
isWork:1,
idcardnum:(!result[0].cardId || result[0].cardId == 'null')?'':result[0].cardId,
userphone:(!result[0].phoneNumber || result[0].phoneNumber == 'null')? '':result[0].phoneNumber
},
header: {
'content-type': 'application/x-www-form-urlencoded' //修改此处即可
},
success(res){
//获取二维码内容
let companyId = params.companyId.split(",")
let userInfo = res.data.data
if(!userInfo){
app.toast("实名制系统查无此人,请确认系统录入或人员进场")
setTimeout(()=>{
wx.redirectTo({
url: '../gengduogongneng/gengduogongneng'
})
},2000)
return;
}
if(userInfo.length > 0){
let companyIds = userInfo[0].uninName
if(companyId.indexOf(companyIds) >= 0){
//当前扫码用户绑定openId和对应劳务公司跳转学习页面
wx.navigateTo({
url: `../winter-training/index?szhprojectId=${params.projectId}&smzprojectId=${params.smzProjectId}&cultivateType=${params.cultivateTypeId}&mainId=${params.id}&userName=${result[0].userName}&typeWordName=${result[0].typeWordName}&companyName=${result[0].companyName}&signUrl=${result[0].signUrl}&cardId=${result[0].cardId}`,
})
}else{
//当前扫码用户绑定公司和对应参与公司不符
app.toast("无权限学习,用户在实名制绑定协作队伍不符")
setTimeout(()=>{
// wx.exitMiniProgram({success: (res) => {}})
wx.redirectTo({
url: '../gengduogongneng/gengduogongneng'
})
},2000)
}
}
}
})
}else{
//当前扫码用户没有绑定openId,跳转二维码绑定页面
wx.navigateTo({
url: `../learn-page/index?szhprojectId=${params.projectId}&smzProjectId=${params.smzProjectId}`,
})
}
},
fail(res) {
console.log(res)
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})