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.
645 lines
19 KiB
645 lines
19 KiB
var api = require("../../../../utils/api.js")
|
|
Component({
|
|
data: {
|
|
personalInfo: {
|
|
identityNo: "", // 身份证号
|
|
realName: "", // 姓名
|
|
sex: "", // 性别
|
|
mobile: "", // 手机号
|
|
smsCode: "", // 验证码
|
|
road: "", // 什么路
|
|
villageName: "", // 小区
|
|
dwellingPlace: "", // 楼栋号-单元室
|
|
partyFlag: "0",
|
|
lock: false, //锁定提交状态,防止连击
|
|
},
|
|
gridInfo: {
|
|
gridName: "", // 网格名称
|
|
gridId: "" // 网格id
|
|
},
|
|
wxInfo: {
|
|
encryptedData: "", // 完整信息的加密数据
|
|
iv: "", // 初始向量
|
|
wxCode: "", // 微信cod
|
|
},
|
|
smsCodeText: "获取验证码", // 获取验证码button内容
|
|
unionIdStatus: "0", // 是否完善过个人信息,完善过更新,未完善过增加
|
|
getMobileType: "wx" // 获取手机号的方式,默认从微信获取,但是微信新获取部分用户会有各种莫名其妙的bug,所以增加手机号/验证码的方式
|
|
},
|
|
properties: {
|
|
type: {
|
|
type: String,
|
|
value: "resident"
|
|
},
|
|
moreThanOneGrid: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
selectedGrid: {
|
|
type: Object,
|
|
observer: function (value) {
|
|
this.setData({
|
|
gridInfo: value
|
|
})
|
|
}
|
|
}
|
|
},
|
|
lifetimes: {
|
|
attached () {
|
|
this.getPersonalInfo().then(() => {
|
|
this.getGridList()
|
|
})
|
|
this.checkWxUnionId()
|
|
this.getWxCode()
|
|
}
|
|
},
|
|
methods: {
|
|
// 身份证号 双向绑定
|
|
bindIdentityNoInput (e) {
|
|
this.setData({
|
|
"personalInfo.identityNo": e.detail.value.trim('')
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 姓名 双向绑定
|
|
bindRealNameInput (e) {
|
|
this.setData({
|
|
"personalInfo.realName": e.detail.value.trim('')
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 选择性别回调
|
|
bindSexChange (e) {
|
|
this.setData({
|
|
"personalInfo.sex": e.detail.value
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 手机号 双向绑定
|
|
bindMobileInput (e) {
|
|
this.setData({
|
|
"personalInfo.mobile": e.detail.value
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 验证码 双向绑定
|
|
bindSmsCodeInput (e) {
|
|
this.setData({
|
|
"personalInfo.smsCode": e.detail.value
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 路 双向绑定
|
|
bindRoadInput (e) {
|
|
this.setData({
|
|
"personalInfo.road": e.detail.value.trim(' ')
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 小区 双向绑定
|
|
bindVillageNameInput (e) {
|
|
this.setData({
|
|
"personalInfo.villageName": e.detail.value
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 楼栋号-单元室 双向绑定
|
|
bindDwellingPlaceInput (e) {
|
|
this.setData({
|
|
"personalInfo.dwellingPlace": e.detail.value
|
|
})
|
|
console.log(this.data.personalInfo)
|
|
},
|
|
// 获取验证码
|
|
getSmsCode () {
|
|
if (!this.data.personalInfo.mobile.trim('')) {
|
|
this.showToast("请先输入手机号")
|
|
return false
|
|
}
|
|
this.setData({
|
|
smsCodeText: "获取中..."
|
|
})
|
|
const mobile = this.data.personalInfo.mobile.trim('')
|
|
api.sendSms(mobile).then(() => {
|
|
this.showToast("验证码发送成功")
|
|
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: "获取验证码"
|
|
})
|
|
})
|
|
},
|
|
// 获取手机号
|
|
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({
|
|
"personalInfo.mobile": data.data
|
|
})
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
},
|
|
// 获取之前完善的个人信息
|
|
getPersonalInfo () {
|
|
return new Promise((resolve, reject) => {
|
|
api.prepareComplete().then(res => {
|
|
console.log("获取个人信息", res)
|
|
for (const key in this.data.personalInfo) {
|
|
this.data.personalInfo[key] = res.data[key]
|
|
}
|
|
for (const key in this.data.gridInfo) {
|
|
this.data.gridInfo[key] = res.data[key]
|
|
}
|
|
this.setData({
|
|
personalInfo: this.data.personalInfo,
|
|
gridInfo: this.data.gridInfo
|
|
})
|
|
if (this.data.personalInfo.partyFlag === "1") {
|
|
this.triggerEvent("selectTabChange", {
|
|
tab: "partyMember",
|
|
partyFlag: "1"
|
|
})
|
|
}
|
|
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)
|
|
})
|
|
},
|
|
// 获取用户信息
|
|
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(() => {
|
|
this.showToast("获取wxCode失败,请重新提交")
|
|
})
|
|
} else {
|
|
this.showToast("请授权,再完善个人信息")
|
|
return false
|
|
}
|
|
},
|
|
// 获取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 () {
|
|
reject(false)
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 切换网格
|
|
changeGrid () {
|
|
this.triggerEvent("changeGrid", {
|
|
gridId: this.data.gridInfo.gridId
|
|
})
|
|
},
|
|
// 获取当前用户所有网格
|
|
getGridList () {
|
|
this.triggerEvent("getGridList", {
|
|
gridId: this.data.gridInfo.gridId
|
|
})
|
|
},
|
|
// 提交完善信息-从微信获取手机号方式
|
|
submitPersonalInfoByWx () {
|
|
if (!this.data.personalInfo.identityNo) {
|
|
if (this.data.type === "partyMember") {
|
|
this.showToast("请输入身份证号")
|
|
return false
|
|
}
|
|
}
|
|
if (!this.data.personalInfo.realName.trim('')) {
|
|
this.showToast("请填写姓名")
|
|
return false
|
|
}
|
|
if (!this.data.personalInfo.sex) {
|
|
this.showToast("请选择性别")
|
|
return false
|
|
}
|
|
if (!this.data.personalInfo.mobile.trim('')) {
|
|
this.showToast("请填写手机号")
|
|
return false
|
|
}
|
|
// if (!this.data.personalInfo.smsCode) {
|
|
// this.showToast('请填写验证码')
|
|
// return false
|
|
// }
|
|
if (!this.data.personalInfo.road.trim('')) {
|
|
this.showToast("请填写所在小区或所在道路")
|
|
return false
|
|
}
|
|
if (this.data.personalInfo.road.length > 100) {
|
|
this.showToast("小区或所在道路不能超过100个字")
|
|
return false
|
|
}
|
|
this.setData({
|
|
lock: true
|
|
})
|
|
const para = {
|
|
partyFlag: this.data.type === "partyMember" ? "1" : "0",
|
|
identityNo: this.data.personalInfo.identityNo,
|
|
mobile: this.data.personalInfo.mobile.trim(''),
|
|
smsCode: this.data.personalInfo.smsCode,
|
|
realName: this.data.personalInfo.realName.trim(''),
|
|
sex: this.data.personalInfo.sex,
|
|
road: this.data.personalInfo.road.trim(''),
|
|
villageName: this.data.personalInfo.villageName,
|
|
dwellingPlace: this.data.personalInfo.dwellingPlace,
|
|
gridId: this.data.gridInfo.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 : ""
|
|
}
|
|
if (this.data.personalInfo.partyFlag === "1" && this.data.type === "resident") {
|
|
wx.showModal({
|
|
content: "您已是党员,无须进行居民认证,居民认证后会取消党员身份,是否继续?",
|
|
showCancel: true,
|
|
cancelText: "否",
|
|
confirmText: "是",
|
|
confirmColor: "#000000",
|
|
success: (e) => {
|
|
if (e.confirm) {
|
|
wx.showLoading({
|
|
title: "提交中..."
|
|
})
|
|
api.completeResidentInfoV2(para).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
if (res.data.resultCode == 1) {
|
|
wx.showModal({
|
|
title: "认证信息提交成功",
|
|
showCancel: false,
|
|
content: res.data.resultMsg,
|
|
success: () => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: "认证成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
console.log(err)
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
})
|
|
} else if (e.cancel) {
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
return false
|
|
}
|
|
},
|
|
})
|
|
} else {
|
|
wx.showLoading({
|
|
title: "提交中..."
|
|
})
|
|
if (this.data.type === "partyMember") {
|
|
api.completePartyInfoV2(para).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
if (res.data.resultCode == 1) {
|
|
wx.showModal({
|
|
title: "认证信息提交成功",
|
|
showCancel: false,
|
|
content: res.data.resultMsg,
|
|
success: () => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: "认证成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
})
|
|
} else if (this.data.type === "resident") {
|
|
api.completeResidentInfoV2(para).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
if (res.data.resultCode == 1) {
|
|
wx.showModal({
|
|
title: "认证信息提交成功",
|
|
showCancel: false,
|
|
content: res.data.resultMsg,
|
|
success: () => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: "认证成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
console.log(err)
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
})
|
|
}
|
|
}
|
|
},
|
|
// 提交完善信息,手机号输入方式
|
|
submitPersonalInfoBySelf () {
|
|
if (!this.data.personalInfo.identityNo) {
|
|
if (this.data.type === "partyMember") {
|
|
this.showToast("请输入身份证号")
|
|
return false
|
|
}
|
|
}
|
|
if (!this.data.personalInfo.realName.trim('')) {
|
|
this.showToast("请填写姓名")
|
|
return false
|
|
}
|
|
if (!this.data.personalInfo.sex) {
|
|
this.showToast("请选择性别")
|
|
return false
|
|
}
|
|
if (!this.data.personalInfo.mobile.trim('')) {
|
|
this.showToast("请填写手机号")
|
|
return false
|
|
}
|
|
if (!this.data.personalInfo.smsCode) {
|
|
this.showToast("请填写验证码")
|
|
return false
|
|
}
|
|
if (!this.data.personalInfo.road.trim('')) {
|
|
this.showToast("请填写所在街道")
|
|
return false
|
|
}
|
|
this.setData({
|
|
lock: true
|
|
})
|
|
const para = {
|
|
partyFlag: this.data.type === "partyMember" ? "1" : "0",
|
|
identityNo: this.data.personalInfo.identityNo,
|
|
mobile: this.data.personalInfo.mobile.trim(''),
|
|
smsCode: this.data.personalInfo.smsCode,
|
|
realName: this.data.personalInfo.realName.trim(''),
|
|
sex: this.data.personalInfo.sex,
|
|
road: this.data.personalInfo.road.trim(''),
|
|
villageName: this.data.personalInfo.villageName,
|
|
dwellingPlace: this.data.personalInfo.dwellingPlace,
|
|
gridId: this.data.gridInfo.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 : ""
|
|
}
|
|
if (this.data.personalInfo.partyFlag === "1" && this.data.type === "resident") {
|
|
wx.showModal({
|
|
content: "您已是党员,无须进行居民认证,居民认证后会取消党员身份,是否继续?",
|
|
showCancel: true,
|
|
cancelText: "否",
|
|
confirmText: "是",
|
|
confirmColor: "#000000",
|
|
success: (e) => {
|
|
if (e.confirm) {
|
|
wx.showLoading({
|
|
title: "提交中..."
|
|
})
|
|
api.completeResidentInfo(para).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
if (res.data.resultCode == 1) {
|
|
wx.showModal({
|
|
title: "认证信息提交成功",
|
|
showCancel: false,
|
|
content: res.data.resultMsg,
|
|
success: () => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: "认证成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
} else if (e.cancel) {
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
return false
|
|
}
|
|
},
|
|
})
|
|
} else {
|
|
wx.showLoading({
|
|
title: "提交中..."
|
|
})
|
|
if (this.data.type === "partyMember") {
|
|
api.completePartyInfo(para).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
if (res.data.resultCode == 1) {
|
|
wx.showModal({
|
|
title: "认证信息提交成功",
|
|
showCancel: false,
|
|
content: res.data.resultMsg,
|
|
success: () => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: "认证成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
} else if (this.data.type === "resident") {
|
|
api.completeResidentInfo(para).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
lock: false
|
|
})
|
|
if (res.data.resultCode == 1) {
|
|
wx.showModal({
|
|
title: "认证信息提交成功",
|
|
showCancel: false,
|
|
content: res.data.resultMsg,
|
|
success: () => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: "认证成功",
|
|
icon: "none",
|
|
duration: 2000,
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.reLaunch({
|
|
url: "/pages/indexNew/indexNew"
|
|
})
|
|
}, 2000)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
},
|
|
submitPersonalInfo () {
|
|
if (this.data.getMobileType === "wx") {
|
|
this.submitPersonalInfoByWx()
|
|
} else if (this.data.getMobileType === "self") {
|
|
this.submitPersonalInfoBySelf()
|
|
}
|
|
},
|
|
// 代码简化,弹窗统一封装
|
|
showToast (title) {
|
|
wx.showToast({
|
|
title: title,
|
|
icon: "none",
|
|
duration: 2000
|
|
})
|
|
},
|
|
changeGetMobileType () {
|
|
let type = "wx"
|
|
if (this.data.getMobileType === "wx") {
|
|
type = "self"
|
|
} else if (this.data.getMobileType === "self") {
|
|
type = "wx"
|
|
}
|
|
this.setData({
|
|
getMobileType: type
|
|
})
|
|
}
|
|
}
|
|
})
|