aqyj/pages/bind/binduser.js

303 lines
7.2 KiB
JavaScript

// pages/bind/binduser.js
var util = require('../../utils/util.js')
Page({
/**
* 页面的初始数据
*/
data: {
username:'',
password:'',
mpopenid:'',
isExists:false,
msg:''
},
usernameChange: function (e) {
this.data.username = e.detail.value
},
passwordChange: function (e) {
this.data.password = e.detail.value
},
denglu: function(){
var that=this
var postdata = {
username: that.data.username,
password: that.data.password,
mpopenid: getApp().globalData.userInfo.mpopenid
}
wx.request({
url: getApp().globalData.serverUrl + 'bindmp',
header: {
'content-type': 'application/json', //
},
method: 'POST',
data: postdata,
success: res => {
if (res.statusCode === 200) {
if (res.data.code == 1) {
wx.showToast({})
getApp().globalData.userInfo = {
userid: 0,
username: '',
name: '',
isaqy: 0,
mpopenid: '',
companyid: '',
perms: [],
openid:null
}
//重置globaldata和session
getApp().mplogin()
// wx.switchTab({
// url: '/pages/main/main',
// })
}else{
wx.showModal({
content: '账户或密码不正确!',
showCancel: false,
confirmText: "确定"
})
}
}
}
});
},
denglu2: function(){
var data = this.data
data.username = 'test4'
data.password = 'q4'
wx.request({
url: getApp().globalData.serverUrl + 'bindmp',
header: {
'content-type': 'application/json', //
},
method: 'POST',
data:data,
success: res => {
if (res.statusCode === 200) {
if (res.data.code == 1) {
wx.showToast({})
getApp().globalData.userInfo = {
userid: 0,
username: '',
name: '',
isaqy: 0,
mpopenid: '',
companyid: '',
perms: [],
openid:null
} //重置globaldata和session
getApp().mplogin()
wx.switchTab({
url: '/pages/main/main',
})
}else{
wx.showModal({
content: '账户或密码不正确!',
showCancel: false,
confirmText: "确定"
})
}
}
}
});
},
getUserbasic:function(){
var that = this
wx.request({
url: getApp().globalData.serverUrl + 'api/get_user_from_username?username='+that.data.username,
header: {
'content-type': 'application/json', //
},
method: 'GET',
success: res => {
if (res.data.code == 1) {
that.setData({
isExists:true
})
that.setData(res.data.data)
} else {
that.setData({
isExists: false,
msg:'未查到该账户信息,是否账户有误'
})
}
}
});
},
onGetInfo:function(e){
this.setData({
userInfo:e.detail.userInfo
})
this.denglu()
},
onGetInfo2:function(e){
this.setData({
userInfo:e.detail.userInfo
})
this.denglu2()
},
getUserProfile: function(e){
wx.getUserProfile({
desc: '获取头像和昵称', //
success: (res) => {
this.setData({
userInfo: res.userInfo
})
this.denglu()
},
fail:(res)=>{
this.denglu()
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let url=null
if(options.q){
let q = decodeURIComponent(options.q)
if (q) {
if(q.indexOf("checktrain")!=-1){
let pxid = util.getQueryString(q, 'trainid')
url = '/pages/train/check?fromwx=1&pxid='+pxid
getApp().globalData.hopeUrl = url
}
else if(q.indexOf("equipment")!=-1){
let id = util.getQueryString(q, 'id')
url = '/pages/equipment/detail?fromwx=1&id='+id
getApp().globalData.hopeUrl = url
}
else if(q.indexOf("riskact")!=-1){
let id = util.getQueryString(q, 'id')
url = '/pages/riskact/detail?fromwx=1&id='+id
getApp().globalData.hopeUrl = url
}
else if(q.indexOf("area")!=-1){
let id = util.getQueryString(q, 'id')
url = '/pages/area/detail?fromwx=1&id='+id
getApp().globalData.hopeUrl = url
}
else if(q.indexOf("examtest")!=-1){
let id = util.getQueryString(q, 'id')
url = '/pages/examtest/note?fromwx=1&id='+id
getApp().globalData.hopeUrl = url
}
else if(q.indexOf("safelist")!=-1){
let id = util.getQueryString(q, 'id')
url = '/pages/safelist/index?fromwx=1&id='+id
getApp().globalData.hopeUrl = url
}
else if(q.indexOf("mgt")!=-1){
let id = util.getQueryString(q, 'id')
url = '/pages/mgt/index?fromwx=1&id='+id
getApp().globalData.hopeUrl = url
}
}
}
if(getApp().globalData.sessionId){
if(getApp().globalData.hopeUrl){
wx.redirectTo({
url: getApp().globalData.hopeUrl,
})
getApp().globalData.hopeUrl = null
}
else{
wx.switchTab({
url: '/pages/main/main',
})
}
return
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
wx.hideHomeButton()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
showPw(){
wx.showModal({
title: '',
content: '默认密码是0000,如果您修改过或者账号错误,请联系贵公司管理员(一般是安全管理部门),请及时登陆pc端修改密码!',
showCancel:false,
confirmText:'知道了',
success (res) {
}
})
},
intro:function(){
let fileurl = getApp().globalData.serverUrl + 'media/安全生产管理系统-国检集团.docx'
wx.showLoading({
title: '下载中...',
})
console.log(fileurl)
wx.downloadFile({
url: fileurl,
success(res) {
const filePath = res.tempFilePath
console.log(filePath)
var filetype
if (fileurl.indexOf(".docx") != -1) {
filetype = 'docx'
}
wx.openDocument({
filePath,
fileType: filetype,
success(res) {
wx.hideLoading()
console.log('打开文档成功')
}, fail: function (e) {
console.log(e)
}
})
}
})
}
})