|
|
|
var api = require('../../utils/api.js')
|
|
|
|
var global = require('../../utils/config.js')
|
|
|
|
const app = getApp()
|
|
|
|
import { $wuxActionSheet } from '../../dist/index'
|
|
|
|
Page({
|
|
|
|
data: {
|
|
|
|
gridName: '',
|
|
|
|
gridId: '',
|
|
|
|
idCard: '',
|
|
|
|
userName: '',
|
|
|
|
sex: '',
|
|
|
|
mobile: '',
|
|
|
|
smsCode: '',
|
|
|
|
street: '',
|
|
|
|
community: '',
|
|
|
|
building: '',
|
|
|
|
submitEvent: false,
|
|
|
|
partyMember: false,
|
|
|
|
isPartyMember: '0',
|
|
|
|
wait: 60,
|
|
|
|
btntxt: '获取验证码',
|
|
|
|
tabType: 'tab1',
|
|
|
|
state: '',
|
|
|
|
unionIdStatus: '0',
|
|
|
|
encryptedData: '',
|
|
|
|
iv: '',
|
|
|
|
wxCode: '',
|
|
|
|
gridList: [],
|
|
|
|
changeGridList: []
|
|
|
|
},
|
|
|
|
onLoad() {
|
|
|
|
this.getPrepareComplete().then(res => {
|
|
|
|
this.getGridList()
|
|
|
|
})
|
|
|
|
this.checkWxUnionId()
|
|
|
|
this.getWxCode()
|
|
|
|
},
|
|
|
|
// 拉取 用户信息
|
|
|
|
getPrepareComplete() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
api.prepareComplete().then(res => {
|
|
|
|
console.log('拉取用户信息', res)
|
|
|
|
this.setData({
|
|
|
|
idCard: res.data.identityNo,
|
|
|
|
userName: res.data.realName,
|
|
|
|
sex: res.data.sex,
|
|
|
|
mobile: res.data.mobile,
|
|
|
|
street: res.data.road,
|
|
|
|
community: res.data.villageName,
|
|
|
|
building: res.data.dwellingPlace,
|
|
|
|
state: res.data.state,
|
|
|
|
gridId: res.data.gridId,
|
|
|
|
gridName: res.data.gridName
|
|
|
|
})
|
|
|
|
resolve(true)
|
|
|
|
}).catch(err => {
|
|
|
|
reject(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputIdCard: function (e) {
|
|
|
|
this.setData({
|
|
|
|
idCard: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputUserName: function (e) {
|
|
|
|
this.setData({
|
|
|
|
userName: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adChangeSex: function (e) {
|
|
|
|
this.setData({
|
|
|
|
sex: e.currentTarget.dataset.sex
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputMobile: function (e) {
|
|
|
|
this.setData({
|
|
|
|
mobile: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputSmsCode: function (e) {
|
|
|
|
this.setData({
|
|
|
|
smsCode: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputStreet: function (e) {
|
|
|
|
this.setData({
|
|
|
|
street: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputCommunity: function (e) {
|
|
|
|
this.setData({
|
|
|
|
community: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
adInputBuilding: function (e) {
|
|
|
|
this.setData({
|
|
|
|
building: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 我是居民/我是党员 切换
|
|
|
|
onChange(e) {
|
|
|
|
if (e.detail.key == 'tab2') {
|
|
|
|
this.setData({
|
|
|
|
partyMember: true,
|
|
|
|
isPartyMember: '1',
|
|
|
|
tabType: 'tab2'
|
|
|
|
})
|
|
|
|
console.log('this', this.data.partyMember)
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
partyMember: false,
|
|
|
|
isPartyMember: '0',
|
|
|
|
tabType: 'tab1',
|
|
|
|
idCard: ''
|
|
|
|
})
|
|
|
|
console.log('this', this.data.partyMember)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
outtime() {
|
|
|
|
let that = this
|
|
|
|
if (that.data.wait === 0) {
|
|
|
|
that.setData({
|
|
|
|
wait: 60,
|
|
|
|
btntxt: '获取验证码'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
that.setData({
|
|
|
|
wait: that.data.wait - 1
|
|
|
|
})
|
|
|
|
setTimeout(() => {
|
|
|
|
that.outtime()
|
|
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toRegister() {
|
|
|
|
if (this.data.partyMember) {
|
|
|
|
if (this.data.idCard === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入身份证号',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.data.userName === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入姓名',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.sex === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请选择性别',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.mobile === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入手机号',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.smsCode === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入验证码',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.street === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入所在街道',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.street.length > 30) {
|
|
|
|
wx.showToast({
|
|
|
|
title: '所在街道不超过30字',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.submitEvent === true) {
|
|
|
|
wx.showToast({
|
|
|
|
title: '加载中...',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
wx.showLoading({
|
|
|
|
title: '加载中...'
|
|
|
|
})
|
|
|
|
const para = {
|
|
|
|
partyFlag: this.data.isPartyMember,
|
|
|
|
identityNo: this.data.idCard,
|
|
|
|
mobile: this.data.mobile,
|
|
|
|
smsCode: this.data.smsCode,
|
|
|
|
realName: this.data.userName,
|
|
|
|
sex: this.data.sex,
|
|
|
|
road: this.data.street,
|
|
|
|
villageName: this.data.community,
|
|
|
|
dwellingPlace: this.data.building,
|
|
|
|
gridId: this.data.gridId,
|
|
|
|
wxCode: this.data.unionIdStatus === '1' ? '' : this.data.wxCode,
|
|
|
|
encryptedData: this.data.unionIdStatus === '1' ? '' : this.data.encryptedData,
|
|
|
|
iv: this.data.unionIdStatus === '1' ? '' : this.data.iv
|
|
|
|
}
|
|
|
|
console.log(this.data.tabType)
|
|
|
|
if (this.data.tabType == 'tab1'){
|
|
|
|
api.completeResidentInfo(para).then(function (res) {
|
|
|
|
// console.log(res.data.resultCode)
|
|
|
|
wx.hideLoading()
|
|
|
|
if (res.data.resultCode == 1) {
|
|
|
|
wx.showModal({
|
|
|
|
title: '党员认证失败',
|
|
|
|
showCancel: false,
|
|
|
|
content: res.data.resultMsg,
|
|
|
|
success: function (res) {
|
|
|
|
wx.reLaunch({
|
|
|
|
url: '/pages/indexNew/indexNew'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
wx.showToast({
|
|
|
|
title: '认证成功',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000,
|
|
|
|
complete: function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
wx.reLaunch({
|
|
|
|
url: '/pages/indexNew/indexNew'
|
|
|
|
})
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
api.completePartyInfo(para).then(function (res) {
|
|
|
|
// console.log(res.data.resultCode)
|
|
|
|
wx.hideLoading()
|
|
|
|
if (res.data.resultCode == 1) {
|
|
|
|
wx.showModal({
|
|
|
|
title: '党员认证失败',
|
|
|
|
showCancel: false,
|
|
|
|
content: res.data.resultMsg,
|
|
|
|
success: function (res) {
|
|
|
|
wx.reLaunch({
|
|
|
|
url: '/pages/indexNew/indexNew'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
wx.showToast({
|
|
|
|
title: '认证成功',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000,
|
|
|
|
complete: function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
wx.reLaunch({
|
|
|
|
url: '/pages/indexNew/indexNew'
|
|
|
|
})
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// api.completeInfo(para).then(function (res) {
|
|
|
|
// // console.log(res.data.resultCode)
|
|
|
|
// wx.hideLoading()
|
|
|
|
// if (res.data.resultCode == 1) {
|
|
|
|
// wx.showModal({
|
|
|
|
// title: '党员认证失败',
|
|
|
|
// showCancel: false,
|
|
|
|
// content: res.data.resultMsg,
|
|
|
|
// success: function (res) {
|
|
|
|
// wx.reLaunch({
|
|
|
|
// url: '/pages/index/index'
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// } else {
|
|
|
|
// wx.showToast({
|
|
|
|
// title: '认证成功',
|
|
|
|
// icon: 'none',
|
|
|
|
// duration: 3000,
|
|
|
|
// complete: function () {
|
|
|
|
// setTimeout(function () {
|
|
|
|
// wx.reLaunch({
|
|
|
|
// url: '/pages/index/index'
|
|
|
|
// })
|
|
|
|
// }, 3000);
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
},
|
|
|
|
getSmsCode() {
|
|
|
|
console.log(this.data.mobile)
|
|
|
|
if (this.data.mobile === '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入手机号',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
} else if (this.data.mobile.length !== 11) {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先输入正确手机号',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (this.data.wait < 60) {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请' + this.data.wait + '秒后再试',
|
|
|
|
duration: 2000,
|
|
|
|
icon: 'none'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.outtime()
|
|
|
|
api.sendSms(this.data.mobile).then(function (res) {
|
|
|
|
console.log('已经成功发送验证码')
|
|
|
|
console.log(res)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 性别选择
|
|
|
|
radioChange(e) {
|
|
|
|
this.setData({
|
|
|
|
sex: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 查看用户是否完善个人信息
|
|
|
|
checkWxUnionId() {
|
|
|
|
api.checkWxUnionId().then(res => {
|
|
|
|
console.log('查看用户是否已保存unionId', res)
|
|
|
|
this.setData({
|
|
|
|
unionIdStatus: res.data
|
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
this.setData({
|
|
|
|
unionIdStatus: '0'
|
|
|
|
})
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取用户信息
|
|
|
|
getUserInfo(e) {
|
|
|
|
this.setData({
|
|
|
|
encryptedData: e.detail.encryptedData,
|
|
|
|
iv: e.detail.iv
|
|
|
|
})
|
|
|
|
this.toRegister()
|
|
|
|
},
|
|
|
|
// 获取wxCode
|
|
|
|
getWxCode() {
|
|
|
|
const that = this
|
|
|
|
wx.login({
|
|
|
|
success(res) {
|
|
|
|
that.setData({
|
|
|
|
wxCode: res.code
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取所有网格
|
|
|
|
getGridList() {
|
|
|
|
api.getGridList().then(res => {
|
|
|
|
console.log('获取所有网格', res)
|
|
|
|
const buttonList = []
|
|
|
|
res.data.forEach(item => {
|
|
|
|
if (item.gridId !== this.data.gridId) {
|
|
|
|
buttonList.push({
|
|
|
|
id: item.gridId,
|
|
|
|
text: item.grid
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.setData({
|
|
|
|
gridList: res.data,
|
|
|
|
changeGridList: buttonList
|
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
this.setData({
|
|
|
|
gridList: []
|
|
|
|
})
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 切换网格
|
|
|
|
changeGrid() {
|
|
|
|
const buttonList = []
|
|
|
|
this.data.gridList.forEach(item => {
|
|
|
|
buttonList.push({
|
|
|
|
id: item.gridId,
|
|
|
|
text: item.grid
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const index = buttonList.findIndex(item => item.id === this.data.gridId)
|
|
|
|
if (index > -1) {
|
|
|
|
buttonList.splice(index, 1)
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
changeGridList: buttonList
|
|
|
|
})
|
|
|
|
const that = this
|
|
|
|
$wuxActionSheet().showSheet({
|
|
|
|
buttons: this.data.changeGridList,
|
|
|
|
className: 'dialog-class',
|
|
|
|
buttonClicked(index, item) {
|
|
|
|
that.setData({
|
|
|
|
gridId: item.id,
|
|
|
|
gridName: item.text
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
cancelText: '取消',
|
|
|
|
cancel() { },
|
|
|
|
destructiveButtonClicked() { },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|