锦水居民端小程序
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.

497 lines
13 KiB

const api = require("../../../../utils/api")
5 years ago
const app = getApp()
import { $wuxActionSheet } from "../../../../dist/index"
const config = require("../../../../utils/config")
5 years ago
Page({
/**
* 页面的初始数据 全部为必填项
*/
data: {
realName: "", //真实姓名
mobile: "", //手机号
identityNo: "", //身份证号码
road: "", //所在道路
villageName: "", //小区名
dwellingPlace: "", //住处(楼栋-单元-房间)
5 years ago
gridId: Number, //居住网格id
gridName: "",
wxCode: "", //用户unionId为空时 传入
encryptedData: "", //用户unionId为空时 传入
iv: "", //用户unionId为空时 传入
// introduce: "", //自我介绍
volunteerNickname:"",//昵称
volunteerSignature:"",//签名
volunteerFaceImg:"",//头像
unionIdStatus: "0",
5 years ago
wait: 60,
smsCode: "",
btntxt: "获取验证码",
dialogTitle: "",
dialogContent: "",
dialogConfirmText: "",
dialogCancelText: "",
getMobileType: "wx",
smsCodeText: "获取验证码",
5 years ago
uploadImageList: [],
5 years ago
disabled:false
5 years ago
},
onLoad: function () {
this.getPrepareComplete().then(() => {
5 years ago
this.getGridList()
})
this.checkWxUnionId()
this.getWxCode()
},
bindRealNameInput (e) {
5 years ago
this.setData({
realName: e.detail.value
})
},
bindMobileInput (e) {
5 years ago
this.setData({
mobile: e.detail.value
})
},
nickname (e){
5 years ago
this.setData({
volunteerNickname: e.detail.value
})
},
bindSmsCodeInput (e) {
5 years ago
this.setData({
smsCode: e.detail.value
})
},
bindIdentityNoInput (e) {
5 years ago
this.setData({
identityNo: e.detail.value
})
},
adInputStreet (e) {
5 years ago
this.setData({
road: e.detail.value
})
},
adInputCommunity (e) {
5 years ago
this.setData({
villageName: e.detail.value
})
},
adInputBuilding (e) {
5 years ago
this.setData({
dwellingPlace: e.detail.value
})
},
// adInputIntroduce (e) {
// this.setData({
// introduce: e.detail.value
// })
// },
volunteerSignature (e) {
5 years ago
this.setData({
volunteerSignature: e.detail.value
})
},
5 years ago
// 查看用户是否完善个人信息
checkWxUnionId () {
5 years ago
api.checkWxUnionId().then(res => {
console.log("查看用户是否已保存unionId", res)
5 years ago
this.setData({
unionIdStatus: res.data
})
}).catch(err => {
this.setData({
unionIdStatus: "0"
5 years ago
})
console.log(err)
})
},
// 获取wxCode
getWxCode () {
5 years ago
const that = this
wx.login({
success (res) {
5 years ago
that.setData({
wxCode: res.code
})
}
})
},
// 获取用户信息
getUserInfo (e) {
5 years ago
this.setData({
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
})
5 years ago
if (e.detail.iv) {
5 years ago
this.submission()
5 years ago
} else {
5 years ago
wx.showToast({
title: "您拒绝了获取信息,无法完成认证",
icon: "none",
5 years ago
duration: 3000
})
}
5 years ago
},
// 拉取 用户信息
getPrepareComplete () {
5 years ago
return new Promise((resolve, reject) => {
api.prepareComplete().then(res => {
console.log("拉取用户信息", res)
5 years ago
this.setData({
identityNo: res.data.identityNo,
realName: res.data.realName,
mobile: res.data.mobile,
road: res.data.road,
villageName: res.data.villageName,
dwellingPlace: res.data.dwellingPlace,
state: res.data.state,
gridId: res.data.gridId,
5 years ago
gridName: res.data.gridName,
volunteerNickname:res.data.volunteerNickname,
volunteerSignature:res.data.volunteerSignature,
volunteerFaceImg:res.data.volunteerFaceImg,
// introduce:res.data.introduce
5 years ago
})
resolve(true)
}).catch(() => {
5 years ago
reject(false)
})
})
},
// 获取所有网格
getGridList () {
5 years ago
api.getGridList().then(res => {
console.log("获取所有网格", res)
5 years ago
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)
})
},
// 志愿者认证提交
submission () {
5 years ago
if (!this.data.realName) {
this.showToast("请输入姓名")
5 years ago
return false
}
5 years ago
if (this.data.realName.length > 20) {
this.showToast("姓名不能超过20个字")
5 years ago
return false
}
5 years ago
5 years ago
if (!this.data.identityNo) {
this.showToast("请输入身份证号")
5 years ago
return false
}
5 years ago
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (reg.test(this.data.identityNo) === false) {
this.showToast("请输入正确的身份证号")
5 years ago
return false
}
if (this.data.getMobileType === "wx") {
5 years ago
if (!this.data.mobile) {
this.showToast("请获取手机号")
5 years ago
return false
}
} else if (this.data.getMobileType === "self") {
5 years ago
if (!this.data.mobile) {
this.showToast("请输入手机号")
5 years ago
return false
}
if (!this.data.smsCode) {
this.showToast("请输入验证码")
5 years ago
return false
}
}
5 years ago
if(!this.data.volunteerFaceImg){
this.showToast("请上传头像")
5 years ago
return false
}
if(!this.data.volunteerNickname){
this.showToast("请输入昵称")
5 years ago
return false
}
if(!this.data.volunteerSignature){
this.showToast("请输入签名")
5 years ago
return false
}
5 years ago
if (!this.data.road) {
this.showToast("请填写所在小区或所在道路")
5 years ago
return false
5 years ago
}
5 years ago
if (this.data.road.length > 100) {
this.showToast("小区或所在道路不能超过100个字")
5 years ago
return false
}
// if (!this.data.introduce) {
// this.showToast("请输入自我介绍")
// return false
// }
5 years ago
// if (!this.data.introduce.length > 200) {
// this.showToast("自我介绍输入内容不超过200字")
// return false
// }
5 years ago
const params = {
smsCode: this.data.smsCode,
realName: this.data.realName,
mobile: this.data.mobile,
identityNo: this.data.identityNo,
road: this.data.road,
villageName: this.data.villageName,
dwellingPlace: this.data.dwellingPlace,
gridId: this.data.gridId,
// introduce: this.data.introduce,
5 years ago
volunteerFaceImg:this.data.volunteerFaceImg,
volunteerNickname:this.data.volunteerNickname,
volunteerSignature:this.data.volunteerSignature,
wxCode: this.data.unionIdStatus === "1" ? "" : this.data.wxCode,
encryptedData: this.data.unionIdStatus === "1" ? "" : this.data.encryptedData,
iv: this.data.unionIdStatus === "1" ? "" : this.data.iv
5 years ago
}
wx.showLoading({
title: "正在提交",
5 years ago
})
5 years ago
api.authenticate(params).then(res => {
5 years ago
wx.hideLoading()
let state = res.data.userState
app.globalData.infoCompleted = state
wx.removeStorageSync("token")
wx.setStorageSync("token", res.data.token)
5 years ago
this.setData({
dialogVisible: !this.data.dialogVisible,
dialogTitle: "志愿者认证",
dialogContent: ["您已认证成功,快去报名吧"],
dialogConfirmText: "确定",
5 years ago
// dialogCancelText: '否'
5 years ago
})
})
},
confirmDialog () {
5 years ago
wx.navigateBack({
delta: 1
})
},
changeGetMobileType () {
let type = "wx"
if (this.data.getMobileType === "wx") {
type = "self"
} else if (this.data.getMobileType === "self") {
type = "wx"
5 years ago
}
this.setData({
getMobileType: type
})
},
// 获取验证码
getSmsCode () {
5 years ago
if (!this.data.mobile) {
this.showToast("请先输入手机号")
5 years ago
return false
}
this.setData({
smsCodeText: "获取中..."
5 years ago
})
const mobile = this.data.mobile
api.sendSms(mobile).then(() => {
this.showToast("验证码发送成功")
5 years ago
let num = 60
this.setData({
smsCodeText: "60s后重新获取"
})
const timer = setInterval(() => {
if (num >= 1) {
this.setData({
smsCodeText: `${num}s后重新获取`
})
--num
5 years ago
} else {
clearInterval(timer)
this.setData({
smsCodeText: "获取验证码"
5 years ago
})
}
}, 1000)
5 years ago
}).catch(err => {
5 years ago
console.log(err)
this.setData({
smsCodeText: "获取验证码"
5 years ago
})
})
},
// 获取手机号
getPhoneNumber (e) {
if (e.detail.errMsg === "getPhoneNumber:ok") {
5 years ago
const para = {
wxCode: "",
5 years ago
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
}
const that = this
wx.login({
success (res) {
5 years ago
para.wxCode = res.code
api.getWxPhone(para).then(data => {
console.log("获取微信手机号", data)
5 years ago
that.setData({
mobile: data.data
})
}).catch(err => {
console.log(err)
})
}
})
}
},
// 代码简化,弹窗统一封装
showToast (title) {
5 years ago
wx.showToast({
title: title,
icon: "none",
5 years ago
duration: 2000
})
},
5 years ago
// 上传头像
// 选择图片 上传弹窗 - 上传图片方式 - 选择图片 - 上传图片 - 回调赋值
chooseImage () {
const _this = this
_this.setData({
uploadImageList: [],
5 years ago
disabled:true
5 years ago
})
$wuxActionSheet().showSheet({
buttons: [
{ text: "拍照" },
{ text: "从相册中获取" },
5 years ago
],
className: "dialog-class",
buttonClicked (index) {
console.log(":::::::::::::"+index)
5 years ago
if (index === 0) {
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["camera"],
5 years ago
success (res) {
const uploadImageList = [..._this.data.uploadImageList]
uploadImageList.push({
uploaded: false,
ossUrl: "",
5 years ago
imgUrl: res.tempFilePaths[0],
imageId: ++_this.data.imageId
})
_this.setData({
uploadImageList
})
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: res.tempFilePaths[0],
name: "file",
5 years ago
header: {
"Content-type": "multipart/form-data"
5 years ago
},
success (fileRes){
uploadImageList[uploadImageList.length - 1].uploaded = true
uploadImageList[uploadImageList.length - 1].ossUrl = JSON.parse(fileRes.data).data
_this.setData({
uploadImageList
})
_this.setData({
5 years ago
volunteerFaceImg:uploadImageList[0].ossUrl,
disabled:false
5 years ago
})
console.log(">>>>>>>>>>>"+_this.data.volunteerFaceImg)
5 years ago
}
})
}
})
} else if (index === 1) {
wx.chooseImage({
count: 3 - _this.data.uploadImageList.length,
sizeType: ["original", "compressed"],
sourceType: ["album"],
5 years ago
success (res) {
const uploadImageList = []
const endIndex = _this.data.uploadImageList.length
res.tempFilePaths.forEach(item => {
uploadImageList.push({
uploaded: false,
ossUrl: "",
5 years ago
imgUrl: item,
imageId: ++_this.data.imageId
})
})
_this.setData({
uploadImageList: [..._this.data.uploadImageList,...uploadImageList]
})
uploadImageList.forEach((item, index) => {
return (function (index) {
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: res.tempFilePaths[index],
name: "file",
5 years ago
header: {
"Content-type": "multipart/form-data"
5 years ago
},
success (fileRes){
uploadImageList[index].uploaded = true
uploadImageList[index].ossUrl = JSON.parse(fileRes.data).data
_this.data.uploadImageList = _this.data.uploadImageList.slice(0, endIndex)
_this.setData({
uploadImageList: [..._this.data.uploadImageList, ...uploadImageList]
})
// _this.data.setData({
// volunteerFaceImg:uploadImageList[0].ossUrl
// })
_this.setData({
5 years ago
volunteerFaceImg:uploadImageList[0].ossUrl,
disabled:false
5 years ago
})
}
})
})(index)
})
}
})
}
return true
},
cancelText: "取消",
cancel () {
5 years ago
_this.setData({
disabled:false
})
console.log(":::::::::::::::")
5 years ago
},
destructiveButtonClicked () {},
5 years ago
})
},
5 years ago
})