You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
621 lines
17 KiB
621 lines
17 KiB
// subpages/family/pages/bindFamily/bindFamily.js
|
|
const api = require('../../../../utils/api')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
isApplied: true,
|
|
fmData: {
|
|
identityNo: '', // 身份证号
|
|
realName: '', // 姓名
|
|
sex: '', // 性别
|
|
mobile: '', // 手机号
|
|
smsCode: '', // 验证码
|
|
road: '', // 什么路
|
|
villageName: '', // 小区
|
|
dwellingPlace: '', // 楼栋号-单元室
|
|
partyFlag: '0'
|
|
},
|
|
submitBtnIsAllowed: false,
|
|
villageRelationList:[],
|
|
villageDisable:true,
|
|
buildRelationList:[],
|
|
buildDisable:true,
|
|
unitRelationList:[],
|
|
unitDisable:true,
|
|
houseRelationList:[],
|
|
houseDisable:true,
|
|
roomCode: '', // 通过扫房屋二维码进入到该页面,会有个房屋编码
|
|
smsCodeText: '获取验证码', // 获取验证码button内容
|
|
getMobileType: 'wx', // 获取手机号的方式,默认从微信获取,但是微信新获取部分用户会有各种莫名其妙的bug,所以增加手机号/验证码的方式
|
|
unionIdStatus: '0', // 是否完善过个人信息,完善过更新,未完善过增加
|
|
wxInfo: {
|
|
encryptedData:'',// 完整信息的加密数据
|
|
iv: '', // 初始向量
|
|
wxCode: '', // 微信cod
|
|
},
|
|
gridInfo: {
|
|
gridName: '', // 网格名称
|
|
gridId: '' // 网格id
|
|
},
|
|
houseInfo: {}, // 通过roomCode获取的房屋信息
|
|
inputDisabled: false, // 输入身份证号,查询到信息的话,禁止修改
|
|
selectBuildingId: '', // 选择的楼栋id
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
wx.showToast({title: '加载中', icon: 'loading', duration: 10000});
|
|
if (options.q) {
|
|
let arr = decodeURIComponent(options.q).split('/')
|
|
this.setData({
|
|
roomCode: arr[arr.length - 1]
|
|
})
|
|
}
|
|
this.getUserState()
|
|
this.checkWxUnionId()
|
|
this.getWxCode()
|
|
wx.hideToast()
|
|
if (!this.data.roomCode) {
|
|
this.getPersonalInfo().then(res => {
|
|
this.getVillageList()
|
|
})
|
|
}
|
|
},
|
|
getVillageList () {
|
|
const params = {
|
|
streetId: '',
|
|
communityId: '',
|
|
gridId: this.data.gridInfo.gridId
|
|
}
|
|
api.getPlotOptionApp(params).then(res => {
|
|
if (res.data.length > 0) {
|
|
res.data.forEach(item => {
|
|
let ob = {
|
|
label: item.dictName,
|
|
value: item.dictValue
|
|
}
|
|
this.data.villageRelationList.push(ob)
|
|
})
|
|
this.setData({
|
|
villageRelationList: this.data.villageRelationList
|
|
})
|
|
}
|
|
})
|
|
},
|
|
getBuildingList (plotId) {
|
|
const params = {
|
|
plotId: plotId
|
|
}
|
|
api.getBuildingOptionApp(params).then(res => {
|
|
if (res.data && res.data.length > 0) {
|
|
res.data.forEach(item => {
|
|
let ob = {
|
|
label: item.dictName,
|
|
value: item.dictValue
|
|
}
|
|
this.data.buildRelationList.push(ob)
|
|
})
|
|
this.setData({
|
|
buildRelationList: this.data.buildRelationList
|
|
})
|
|
}
|
|
})
|
|
},
|
|
getUnitOption (buildingId) {
|
|
const params = {
|
|
buildingId: buildingId
|
|
}
|
|
api.getUnitOption(params).then(res => {
|
|
if (res.data.length > 0) {
|
|
res.data.forEach(item => {
|
|
let ob = {
|
|
label: item.dictName,
|
|
value: item.dictValue
|
|
}
|
|
this.data.unitRelationList.push(ob)
|
|
})
|
|
this.setData({
|
|
unitRelationList: this.data.unitRelationList
|
|
})
|
|
}
|
|
})
|
|
},
|
|
getHouseOption (buildingId, unit) {
|
|
const params = {
|
|
buildingId: buildingId,
|
|
unit: unit
|
|
}
|
|
api.getHouseOption(params).then(res => {
|
|
if (res.data.length > 0) {
|
|
res.data.forEach(item => {
|
|
let ob = {
|
|
label: item.dictName,
|
|
value: item.dictValue
|
|
}
|
|
this.data.houseRelationList.push(ob)
|
|
})
|
|
this.setData({
|
|
houseRelationList: this.data.houseRelationList
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 获取之前完善的个人信息
|
|
getPersonalInfo () {
|
|
return new Promise((resolve, reject) => {
|
|
api.prepareComplete().then(res => {
|
|
console.log('获取个人信息', res)
|
|
for(const key in this.data.gridInfo) {
|
|
this.data.gridInfo[key] = res.data[key]
|
|
}
|
|
this.setData({
|
|
gridInfo: this.data.gridInfo
|
|
})
|
|
resolve(true)
|
|
}).catch(err => {
|
|
console.log(err)
|
|
reject(false)
|
|
})
|
|
})
|
|
},
|
|
// 查看用户是否完善个人信息
|
|
checkWxUnionId() {
|
|
api.checkWxUnionId().then(res => {
|
|
console.log('查看用户是否已保存unionId', res)
|
|
this.setData({
|
|
unionIdStatus: res.data
|
|
// unionIdStatus: '0'
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
unionIdStatus: '0'
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 根据微信code查询用户当前状态
|
|
getUserState() {
|
|
let _this = this
|
|
wx.login({
|
|
success(res) {
|
|
if (res.code) {
|
|
let code = res.code
|
|
api.getToken(code).then(res => {
|
|
const state = res.data.userState
|
|
app.globalData.infoCompleted = state
|
|
wx.setStorageSync('topGridName', res.data.grid)
|
|
wx.setStorageSync('token', res.data.token)
|
|
_this.getUserInfoById()
|
|
})
|
|
} else {
|
|
console.log('登录失败' + res.errMsg)
|
|
}
|
|
}
|
|
})
|
|
},
|
|
// 获取用户信息
|
|
getUserInfoById () {
|
|
api.getUserInfo().then(res => {
|
|
console.log("用户信息", res)
|
|
if (res.data.identityNo) {
|
|
wx.reLaunch({
|
|
url: `../index/index?roomCode=${this.data.roomCode}`
|
|
})
|
|
}
|
|
this.getHouseInfo()
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 获取房屋信息
|
|
getHouseInfo () {
|
|
if (!this.data.roomCode) {
|
|
return
|
|
}
|
|
const params = {
|
|
roomCode: this.data.roomCode
|
|
}
|
|
api.getHouseInfo(params).then(res => {
|
|
console.log(res.data)
|
|
if (res.code == 0) {
|
|
this.setData({
|
|
houseInfo: res.data
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 获取成员信息
|
|
getFamilyMember () {
|
|
if (!this.data.fmData.identityNo) {
|
|
return
|
|
}
|
|
if (this.data.fmData.identityNo.length < 16) {
|
|
return
|
|
}
|
|
const params = {
|
|
idCard: this.data.fmData.identityNo
|
|
}
|
|
api.getFamilyMember(params).then(res => {
|
|
console.log(res.data)
|
|
if (res.data) {
|
|
this.setData({
|
|
'fmData.realName': res.data.userName ? res.data.userName : '',
|
|
'fmData.sex': res.data.gender ? res.data.gender : '',
|
|
'fmData.mobile': res.data.mobile ? res.data.mobile : '',
|
|
inputDisabled: true
|
|
})
|
|
} else {
|
|
this.setData({
|
|
inputDisabled: false
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 身份证号
|
|
bindIdCardInput (e) {
|
|
this.setData({
|
|
'fmData.identityNo': e.detail.value
|
|
})
|
|
console.log(this.data.fmData)
|
|
},
|
|
bindIdCardBlur (e) {
|
|
this.setData({
|
|
'fmData.identityNo': e.detail.value
|
|
})
|
|
this.getFamilyMember()
|
|
},
|
|
// 姓名 双向绑定
|
|
bindRealNameInput (e) {
|
|
this.setData({
|
|
'fmData.realName': e.detail.value
|
|
})
|
|
console.log(this.data.fmData)
|
|
},
|
|
// 选择性别
|
|
bindSexChange (e) {
|
|
this.setData({
|
|
'fmData.sex': e.detail.value
|
|
})
|
|
console.log(this.data.fmData)
|
|
},
|
|
// 更换手机验证方式
|
|
changeGetMobileType () {
|
|
let type = 'wx'
|
|
if (this.data.getMobileType === 'wx') {
|
|
type = 'self'
|
|
} else if (this.data.getMobileType === 'self') {
|
|
type = 'wx'
|
|
}
|
|
this.setData({
|
|
getMobileType: type
|
|
})
|
|
},
|
|
// 手机号 双向绑定
|
|
bindMobileInput (e) {
|
|
this.setData({
|
|
'fmData.mobile': e.detail.value
|
|
})
|
|
console.log(this.data.fmData)
|
|
},
|
|
// 验证码 双向绑定
|
|
bindSmsCodeInput (e) {
|
|
this.setData({
|
|
'fmData.smsCode': e.detail.value
|
|
})
|
|
console.log(this.data.fmData)
|
|
},
|
|
// 获取手机号
|
|
getPhoneNumber (e) {
|
|
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
|
const para = {
|
|
wxCode: '',
|
|
encryptedData: e.detail.encryptedData,
|
|
iv: e.detail.iv
|
|
}
|
|
const that = this
|
|
wx.login({
|
|
success (res) {
|
|
para.wxCode = res.code
|
|
api.getWxPhone(para).then(data => {
|
|
console.log('获取微信手机号', data)
|
|
that.setData({
|
|
'fmData.mobile': data.data
|
|
})
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
},
|
|
// 获取验证码
|
|
getSmsCode () {
|
|
if (!this.data.fmData.mobile) {
|
|
wx.showToast({
|
|
title: '请先输入手机号',
|
|
icon: 'none',
|
|
duration: 2500
|
|
})
|
|
return false
|
|
}
|
|
this.setData({
|
|
smsCodeText: '获取中...'
|
|
})
|
|
const mobile = this.data.fmData.mobile
|
|
api.sendSms(mobile).then(res => {
|
|
wx.showToast({
|
|
title: '验证码发送成功',
|
|
icon: 'none',
|
|
duration: 2500
|
|
})
|
|
let num = 60
|
|
this.setData({
|
|
smsCodeText: "60s后重新获取"
|
|
})
|
|
const timer = setInterval(() => {
|
|
if (num >= 1) {
|
|
this.setData({
|
|
smsCodeText: `${num}s后重新获取`
|
|
})
|
|
--num
|
|
} else {
|
|
clearInterval(timer)
|
|
this.setData({
|
|
smsCodeText: '获取验证码'
|
|
})
|
|
}
|
|
}, 1000)
|
|
}).catch(err =>{
|
|
console.log(err)
|
|
this.setData({
|
|
smsCodeText: '获取验证码'
|
|
})
|
|
})
|
|
},
|
|
syncPicker(e){
|
|
// if(e.currentTarget.dataset.type ==='road' && !this.data.fmData.road){
|
|
// wx.showToast({
|
|
// title: '请先选择路牌号',
|
|
// icon: 'none',
|
|
// duration: 1000 // 持续的时间
|
|
// })
|
|
// }
|
|
},
|
|
// 路牌号 双向绑定
|
|
bindRoadInput (e) {
|
|
this.setData({
|
|
// 'houseInfo.houseAddress': e.detail.value,
|
|
'fmData.road': e.detail.value
|
|
})
|
|
console.log(this.data.houseInfo)
|
|
},
|
|
villageSyncPicker(e){
|
|
this.setData({
|
|
'houseInfo.plotName' : this.data.villageRelationList[e.detail.value].label,
|
|
'fmData.villageName' : this.data.villageRelationList[e.detail.value].label
|
|
})
|
|
this.getBuildingList(this.data.villageRelationList[e.detail.value].value)
|
|
},
|
|
buildSyncPicker(e){
|
|
this.setData({
|
|
'houseInfo.buildingNo' : this.data.buildRelationList[e.detail.value].label,
|
|
selectBuildingId: this.data.buildRelationList[e.detail.value].value,
|
|
'fmData.dwellingPlace': this.data.buildRelationList[e.detail.value].label
|
|
})
|
|
this.getUnitOption(this.data.buildRelationList[e.detail.value].value)
|
|
},
|
|
unitSyncPicker(e){
|
|
this.setData({
|
|
'houseInfo.unit' : this.data.unitRelationList[e.detail.value].label
|
|
})
|
|
this.getHouseOption(this.data.selectBuildingId, this.data.unitRelationList[e.detail.value].value)
|
|
},
|
|
houseSyncPicker(e){
|
|
this.setData({
|
|
'houseInfo.roomNo' : this.data.houseRelationList[e.detail.value].label,
|
|
'houseInfo.id': this.data.houseRelationList[e.detail.value].value
|
|
})
|
|
},
|
|
// 获取wxCode
|
|
getWxCode() {
|
|
const that = this
|
|
return new Promise((resolve, reject) => {
|
|
wx.login({
|
|
success(res) {
|
|
that.setData({
|
|
'wxInfo.wxCode': res.code
|
|
})
|
|
console.log('wxInfo', that.data.wxInfo)
|
|
resolve(true)
|
|
},
|
|
fail (err) {
|
|
reject(false)
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 获取用户信息
|
|
getUserInfo(e) {
|
|
if (e.detail.errMsg === 'getUserInfo:ok') {
|
|
this.setData({
|
|
'wxInfo.encryptedData': e.detail.encryptedData,
|
|
'wxInfo.iv': e.detail.iv
|
|
})
|
|
this.getWxCode().then(() => {
|
|
this.submitPersonalInfo()
|
|
}).catch(() => {
|
|
wx.showToast({
|
|
title: '获取wxCode失败,请重新提交',
|
|
icon: 'none',
|
|
duration: 2500
|
|
})
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: '请授权,再完善个人信息',
|
|
icon: 'none',
|
|
duration: 2500
|
|
})
|
|
return false
|
|
}
|
|
},
|
|
submitPersonalInfo () {
|
|
if (this.data.getMobileType === 'wx') {
|
|
this.submitPersonalInfoByWx()
|
|
} else if (this.data.getMobileType === 'self') {
|
|
this.submitPersonalInfoBySelf()
|
|
}
|
|
this.submitHouseInfo()
|
|
},
|
|
// 提交完善信息-从微信获取手机号方式
|
|
submitPersonalInfoByWx () {
|
|
if (!this.data.fmData.identityNo) {
|
|
this.showToast('请输入身份证号')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.realName) {
|
|
this.showToast('请填写姓名')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.sex) {
|
|
this.showToast('请选择性别')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.mobile) {
|
|
this.showToast('请填写手机号')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.road) {
|
|
this.showToast('请填写所在街道')
|
|
return false
|
|
}
|
|
// if (!this.data.fmData.smsCode) {
|
|
// this.showToast('请填写验证码')
|
|
// return false
|
|
// }
|
|
const para = {
|
|
partyFlag: '0',
|
|
identityNo: this.data.fmData.identityNo,
|
|
mobile: this.data.fmData.mobile,
|
|
smsCode: this.data.fmData.smsCode,
|
|
realName: this.data.fmData.realName,
|
|
sex: this.data.fmData.sex,
|
|
road: this.data.fmData.road,
|
|
villageName: this.data.fmData.villageName,
|
|
dwellingPlace: this.data.fmData.dwellingPlace,
|
|
gridId: this.data.gridInfo.gridId ? this.data.gridInfo.gridId : this.data.houseInfo.gridId,
|
|
wxCode: this.data.unionIdStatus === '0' ? this.data.wxInfo.wxCode : '',
|
|
encryptedData: this.data.unionIdStatus === '0' ? this.data.wxInfo.encryptedData : '',
|
|
iv: this.data.unionIdStatus === '0' ? this.data.wxInfo.iv : ''
|
|
}
|
|
console.log(para)
|
|
api.completeResidentInfoV2(para).then(res => {
|
|
wx.reLaunch({
|
|
url: `../index/index?roomCode=${!this.data.roomCode ? this.data.houseInfo.roomNo : this.data.roomCode}`
|
|
})
|
|
})
|
|
},
|
|
// 提交完善信息,手机号输入方式
|
|
submitPersonalInfoBySelf () {
|
|
if (!this.data.fmData.identityNo) {
|
|
this.showToast('请输入身份证号')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.realName) {
|
|
this.showToast('请填写姓名')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.sex) {
|
|
this.showToast('请选择性别')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.mobile) {
|
|
this.showToast('请填写手机号')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.smsCode) {
|
|
this.showToast('请填写验证码')
|
|
return false
|
|
}
|
|
if (!this.data.fmData.road) {
|
|
this.showToast('请填写所在街道')
|
|
return false
|
|
}
|
|
const para = {
|
|
partyFlag: '0',
|
|
identityNo: this.data.fmData.identityNo,
|
|
mobile: this.data.fmData.mobile,
|
|
smsCode: this.data.fmData.smsCode,
|
|
realName: this.data.fmData.realName,
|
|
sex: this.data.fmData.sex,
|
|
road: this.data.fmData.road,
|
|
villageName: this.data.fmData.villageName,
|
|
dwellingPlace: this.data.fmData.dwellingPlace,
|
|
gridId: this.data.gridInfo.gridId ? this.data.gridInfo.gridId : this.data.houseInfo.gridId,
|
|
wxCode: this.data.unionIdStatus === '0' ? this.data.wxInfo.wxCode : '',
|
|
encryptedData: this.data.unionIdStatus === '0' ? this.data.wxInfo.encryptedData : '',
|
|
iv: this.data.unionIdStatus === '0' ? this.data.wxInfo.iv : ''
|
|
}
|
|
console.log(para)
|
|
api.completeResidentInfo(para).then(res => {
|
|
wx.reLaunch({
|
|
url: `../index/index?roomCode=${!this.data.roomCode ? this.data.houseInfo.roomNo : this.data.roomCode}`
|
|
})
|
|
})
|
|
},
|
|
submitHouseInfo () {
|
|
if (!this.data.fmData.identityNo) {
|
|
this.showToast('请输入您的身份证号')
|
|
return
|
|
}
|
|
if (!this.data.fmData.realName) {
|
|
this.showToast('请输入您的姓名')
|
|
return
|
|
}
|
|
if (!this.data.fmData.mobile) {
|
|
this.showToast('请输入您的手机号')
|
|
return
|
|
}
|
|
if (!this.data.fmData.road) {
|
|
this.showToast('请填写路牌号')
|
|
return false
|
|
}
|
|
const houseAddress = this.data.houseInfo.gridName + '-'
|
|
+ this.data.houseInfo.plotName + '-'
|
|
+ this.data.houseInfo.buildingName + '-'
|
|
+ this.data.houseInfo.unit + '-'
|
|
+ this.data.houseInfo.roomNo
|
|
const params = {
|
|
flag: this.data.inputDisabled ? '0' : '1', // 是否新增人员表示(0:否;1:是)
|
|
unitId: this.data.houseInfo.id,
|
|
userName: this.data.fmData.realName,
|
|
idCard: this.data.fmData.identityNo,
|
|
mobile: this.data.fmData.mobile,
|
|
houseAddress: houseAddress,
|
|
community: this.data.houseInfo.communityName,
|
|
deptId: this.data.gridInfo.gridId ? this.data.gridInfo.gridId : this.data.houseInfo.gridId,
|
|
plot: this.data.houseInfo.plotName,
|
|
buildingNo: this.data.houseInfo.buildingNo ? this.data.houseInfo.buildingNo : this.data.houseInfo.buildingName,
|
|
unit: this.data.houseInfo.unit,
|
|
roomNo: this.data.houseInfo.roomNo
|
|
}
|
|
api.bindingFamily(params).then(res => {
|
|
console.log(res.data)
|
|
})
|
|
},
|
|
// 代码简化,弹窗统一封装
|
|
showToast (title) {
|
|
wx.showToast({
|
|
title: title,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
})
|