home.js 5.39 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
// pages/home/home.js
import { loginPage } from "../login/login.js"
const app = getApp()
const networkUtil = require('../../utils/network_util.js')
const api = require('../../utils/apiFile.js')
var QR_Scare = 2

Page(Object.assign({}, loginPage, {

/**
* 页面的初始数据
*/
data: {
// 1首页 2登录
pageType:0,
areaName: app.globalData.openInfo.hospitalName || '',
imageUrl:'',
info:{}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (option) {
console.log('home_options:', option)
if (app.globalData.token) {
this.homePage()
this.requestHomeInfo()
} else {
this.loginPage()
}
},
onPullDownRefresh(){
console.log('onPullDownRefresh')
if (app.globalData.token) {
this.requestHomeInfo()
}
},
homePage(){
this.setData({
pageType: 1
})
wx.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#477DEB'
})
wx.setNavigationBarTitle({
title: '基层辅助孕妇建档平台',
})
},
loginPage(){
this.setData({
pageType: 2
})
wx.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#ffffff'
})
wx.setNavigationBarTitle({
title: '',
})
},
// --------------------------首页--------------------------
requestHomeInfo(){
var self = this
networkUtil.showLoading()
networkUtil._get(api.BuildCountInfo, { hospitalId: app.globalData.openInfo.hospitalId}, function (res) {
console.log(res)
self.setData({
info:res.data.data,
imageUrl: 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' + res.data.data.ticket
})
self.setQRImage()
}, function (res) {
networkUtil.showErrorToast(res.errormsg)
self.setQRImage()
})
},
logout() {
var self = this
wx.showModal({
title: '提示',
content: '是否退出登录?',
success: function (res) {
if (res.confirm) {
wx.setStorageSync('userToken', '')
wx.setStorageSync('QR_FilePath', '')
app.globalData.token = ''
self.loginPage()
} else if (res.cancel) {

}
}
})
},
longTapImage() {
var self = this
wx.showActionSheet({
itemList: ['查看大图'],
success: function (res) {
console.log('111', res)
if (res.tapIndex == 0) {
console.log('111', res.tapIndex)
wx.previewImage({
urls: [self.data.imageUrl],
})
}
},
fail: function (res) {
console.log(res.errMsg)
}
})
},
// 二维码相关
setQRImage() {
var fileP = wx.getStorageSync('QR_FilePath')
if (fileP) {
this.drawQR(fileP)
this.data.imageUrl = fileP
console.log('已经有了', fileP)
} else {
this.downLoadQR()
}
},
downLoadQR() {
networkUtil.showLoading('获取二维码中')
var self = this
wx.downloadFile({
url: self.data.imageUrl,
success: function (res) {
if (res.statusCode === 200) {
wx.setStorageSync('QR_FilePath', res.tempFilePath)
self.drawQR(res.tempFilePath)
// setTimeout(function () {
// 延迟等绘制完保存成图片
// wx.canvasToTempFilePath({
// x: 0,
// y: 0,
// width: 174,
// height: 174,
// destWidth: 696,
// destHeight: 696,
// canvasId: 'QR_canvas',
// quality: 1,
// success: function (res) {
// console.log('成功:', res.tempFilePath)
// wx.setStorageSync('QR_FilePath', res.tempFilePath)
// self.data.imageUrl = res.tempFilePath
// }
// })
// }, 3500)
}
},
fail: function () {
networkUtil.showErrorToast('未加载出二维码,请下拉刷新页面')
},
complete: function () {
wx.hideToast()
}
})
},
drawQR(QRImage) {
var ctx = wx.createCanvasContext('QR_canvas', this)
ctx.drawImage(QRImage, 0, 0, 174, 174)
// ctx.drawImage('../../utils/image/icon.png', 57, 57, 60, 60)
ctx.draw()
},
// --------------------------登录--------------------------
submitLoginData(e){
console.log(e)
var str = ''
if (!e.detail.value.phone) {
str = '请填写您的手机号'
} else if (e.detail.value.phone.length < 11) {
str = '请填写正确的手机号'
} else if (!e.detail.value.loginPwd) {
str = '请输入密码'
} else if (e.detail.value.loginPwd.length < 6) {
str = '密码必须为6位以上'
}
if (str) {
networkUtil.showErrorToast(str)
return
}
var self = this
var param = e.detail.value
if (!app.globalData.openInfo.hospitalId){
networkUtil.showErrorToast('未从二维码中获取到医院信息')
return
}
param.hospitalId = app.globalData.openInfo.hospitalId
networkUtil.showLoading()
networkUtil._get(api.login, param, function (res) {
console.log(res)
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000
})
app.globalData.token = res.data.token
wx.setStorageSync('userToken', res.data.token)
self.homePage()
self.requestHomeInfo()
}, function (res) {
networkUtil.showErrorToast(res.errormsg)
})
}
}))