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

744 lines
21 KiB

const api = require("../../../../utils/api")
const new_api = require('../../utils/api')
const app = getApp()
import { $wuxActionSheet } from "../../../../dist/index"
const config = require("../../../../utils/config")
Page({
/**
* 页面的初始数据 全部为必填项
*/
data: {
statusHeight: 0, // 自定义头部状态栏高度
navigationHeight: 0, // 自定义头部导航栏高度
getImgUrl: '', //后台配置背景
realName: "", //真实姓名
mobile: "", //手机号
identityNo: "", //身份证号码
road: "", //所在道路
villageName: "", //小区名
dwellingPlace: "", //住处(楼栋-单元-房间)
gridId: Number, //居住网格id
gridName: "",
wxCode: "", //用户unionId为空时 传入
encryptedData: "", //用户unionId为空时 传入
iv: "", //用户unionId为空时 传入
// introduce: "", //自我介绍
volunteerNickname:"",//昵称
volunteerSignature:"",//签名
volunteerFaceImg:"",//头像
unionIdStatus: "0",
wait: 60,
smsCode: "",
btntxt: "获取验证码",
dialogTitle: "",
dialogContent: "",
dialogConfirmText: "",
dialogCancelText: "",
getMobileType: "wx",
smsCodeText: "获取验证码",
uploadImageList: [],
disabled:false,
lock: false, //锁定提交状态,防止连击
volunteerTag: {}, //志愿者标签id
tagList: [{
tagName: '请选择',
id: ''
}],
tagIndex: 0,
volunteerDept: {}, //志愿者部门id
deptList: [{
deptName: '请选择',
id: ''
}],
deptIndex: 0,
teamNames: [], //
teamType: {}, //志愿者团队分类
teamTypeList: [{
typeName: '请选择',
typeCode: '',
id: ''
}],
teamTypeIndex: 0,
team: {}, //志愿者团队名称
teamList: [{
teamName: '请选择',
teamType: '',
id: ''
}],
teamIndex: 0,
},
onLoad: function () {
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight
})
this.getImgUrl()
this.getPrepareComplete().then(() => {
this.getGridList()
// this.getVolunteerTags()
// this.getVolunteerDepts()
// this.getTeamTypeList().then(res => {
// if (this.data.team.id) {
// this.getTeamTypeName()
// }
// })
})
this.checkWxUnionId()
this.getWxCode()
},
//返回上一级
goback () {
wx.navigateBack({
delta: 1
})
},
bindRealNameInput (e) {
this.setData({
realName: e.detail.value
})
},
bindMobileInput (e) {
this.setData({
mobile: e.detail.value
})
},
nickname (e){
this.setData({
volunteerNickname: e.detail.value
})
},
bindSmsCodeInput (e) {
this.setData({
smsCode: e.detail.value
})
},
bindIdentityNoInput (e) {
this.setData({
identityNo: e.detail.value
})
},
adInputStreet (e) {
this.setData({
road: e.detail.value
})
},
adInputCommunity (e) {
this.setData({
villageName: e.detail.value
})
},
adInputBuilding (e) {
this.setData({
dwellingPlace: e.detail.value
})
},
// adInputIntroduce (e) {
// this.setData({
// introduce: e.detail.value
// })
// },
volunteerSignature (e) {
this.setData({
volunteerSignature: e.detail.value
})
},
// 获取志愿者标签列表
getVolunteerTags () {
api.getVolunteerTags().then(res => {
if (res.code == 0 && res.msg == 'success') {
this.setData({
tagList: this.data.tagList.concat(res.data)
})
res.data.forEach((item, key) => {
if (item.id == this.data.volunteerTag.id) {
this.setData({
'volunteerTag.tag': item.tagName,
tagIndex: parseInt(key)+1
})
}
})
}
}).catch(err => {
console.log(err)
})
},
// 获取志愿者部门列表
getVolunteerDepts () {
api.getVolunteerDepts().then(res => {
if (res.code == 0 && res.msg == 'success') {
this.setData({
deptList: this.data.deptList.concat(res.data)
})
res.data.forEach((item, key) => {
if (item.id == this.data.volunteerDept.id) {
this.setData({
'volunteerDept.dept': item.deptName,
deptIndex: parseInt(key)+1
})
}
})
}
}).catch(err => {
console.log(err)
})
},
// 获取配置图片
getImgUrl:function (){//0:咨询热线
let that = this
api.getImgUrl("4").then(function (res) {
that.setData({
getImgUrl: res.data[0]
})
})
},
// 查看用户是否完善个人信息
checkWxUnionId () {
api.checkWxUnionId().then(res => {
console.log("查看用户是否已保存unionId", res)
this.setData({
unionIdStatus: res.data
})
}).catch(err => {
this.setData({
unionIdStatus: "0"
})
console.log(err)
})
},
// 获取wxCode
getWxCode () {
const that = this
wx.login({
success (res) {
that.setData({
wxCode: res.code
})
}
})
},
// 获取用户信息
getUserInfo (e) {
this.setData({
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
})
if (e.detail.iv) {
this.submission()
} else {
wx.showToast({
title: "您拒绝了获取信息,无法完成认证",
icon: "none",
duration: 3000
})
}
},
// 拉取 用户信息
getPrepareComplete () {
return new Promise((resolve, reject) => {
api.prepareComplete().then(res => {
console.log("拉取用户信息", res)
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,
gridName: res.data.gridName,
volunteerNickname:res.data.volunteerNickname,
volunteerSignature:res.data.volunteerSignature,
volunteerFaceImg:res.data.volunteerFaceImg,
'volunteerTag.id': res.data.volunteerTagId || '0',
'volunteerDept.id': res.data.volunteerDeptId || '0',
'team.id': res.data.teamId || '',
teamNames: res.data.teamNames
// introduce:res.data.introduce
})
resolve(true)
}).catch(() => {
reject(false)
})
})
},
// 获取所有网格
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)
})
},
// 志愿者认证提交
submission () {
if (!this.data.realName.trim('')) {
this.showToast("请输入姓名")
return false
}
if (this.data.realName.length > 20) {
this.showToast("姓名不能超过20个字")
return false
}
if (!this.data.identityNo.trim('')) {
this.showToast("请输入身份证号")
return false
}
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (reg.test(this.data.identityNo) === false) {
this.showToast("请输入正确的身份证号")
return false
}
if (this.data.getMobileType === "wx") {
if (!this.data.mobile.trim('')) {
this.showToast("请获取手机号")
return false
}
} else if (this.data.getMobileType === "self") {
if (!this.data.mobile.trim('')) {
this.showToast("请输入手机号")
return false
}
if (!this.data.smsCode) {
this.showToast("请输入验证码")
return false
}
}
if(!this.data.volunteerFaceImg){
this.showToast("请上传头像")
return false
}
if(!this.data.volunteerNickname.trim('')){
this.showToast("请输入昵称")
return false
}
// if (this.data.volunteerTag.id == '') {
// this.showToast("请选择小组")
// return false
// }
// if(!this.data.volunteerSignature){
// this.showToast("请输入格言")
// return false
// }
if (!this.data.road.trim('')) {
this.showToast("请填写所在小区或所在道路")
return false
}
if (this.data.road.length > 100) {
this.showToast("小区或所在道路不能超过100个字")
return false
}
// if (!this.data.introduce) {
// this.showToast("请输入自我介绍")
// return false
// }
// if (!this.data.introduce.length > 200) {
// this.showToast("自我介绍输入内容不超过200字")
// return false
// }
const params = {
smsCode: this.data.smsCode,
realName: this.data.realName.trim(''),
mobile: this.data.mobile.trim(''),
identityNo: this.data.identityNo,
road: this.data.road.trim(''),
villageName: this.data.villageName,
dwellingPlace: this.data.dwellingPlace,
gridId: this.data.gridId,
// introduce: this.data.introduce,
volunteerFaceImg:this.data.volunteerFaceImg,
volunteerNickname:this.data.volunteerNickname.trim(''),
volunteerSignature:this.data.volunteerSignature,
// volunteerTagId: this.data.volunteerTag.id,
// volunteerDeptId: this.data.volunteerDept.id,
// teamId: this.data.team.id || '',
wxCode: this.data.unionIdStatus === "1" ? "" : this.data.wxCode,
encryptedData: this.data.unionIdStatus === "1" ? "" : this.data.encryptedData,
iv: this.data.unionIdStatus === "1" ? "" : this.data.iv
}
this.setData({
lock: true
})
wx.showLoading({
title: "正在提交",
})
api.authenticate(params).then(res => {
wx.hideLoading()
let state = res.data.userState
app.globalData.infoCompleted = state
wx.removeStorageSync("token")
wx.setStorageSync("token", res.data.token)
this.setData({
lock: false,
dialogVisible: !this.data.dialogVisible,
dialogTitle: "志愿者认证",
dialogContent: ["您已认证成功,快去报名吧"],
dialogConfirmText: "确定",
// dialogCancelText: '否'
})
}).catch(err => {
console.log(err)
this.setData({
lock: false
})
})
},
confirmDialog () {
app.globalData.volunteerChange = true
wx.navigateBack({
delta: 1
})
},
changeGetMobileType () {
let type = "wx"
if (this.data.getMobileType === "wx") {
type = "self"
} else if (this.data.getMobileType === "self") {
type = "wx"
}
this.setData({
getMobileType: type
})
},
// 获取验证码
getSmsCode () {
if (!this.data.mobile.trim('')) {
this.showToast("请先输入手机号")
return false
}
this.setData({
smsCodeText: "获取中..."
})
const mobile = this.data.mobile
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({
mobile: data.data
})
}).catch(err => {
console.log(err)
})
}
})
}
},
// 代码简化,弹窗统一封装
showToast (title) {
wx.showToast({
title: title,
icon: "none",
duration: 2000
})
},
// 上传头像
// 选择图片 上传弹窗 - 上传图片方式 - 选择图片 - 上传图片 - 回调赋值
chooseImage () {
const _this = this
_this.setData({
uploadImageList: [],
disabled:true
})
$wuxActionSheet().showSheet({
buttons: [
{ text: "拍照" },
{ text: "从相册中获取" },
],
className: "dialog-class",
buttonClicked (index) {
console.log(":::::::::::::"+index)
if (index === 0) {
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["camera"],
success (res) {
const uploadImageList = [..._this.data.uploadImageList]
uploadImageList.push({
uploaded: false,
ossUrl: "",
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",
header: {
"Content-type": "multipart/form-data"
},
success (fileRes){
uploadImageList[uploadImageList.length - 1].uploaded = true
uploadImageList[uploadImageList.length - 1].ossUrl = JSON.parse(fileRes.data).data
_this.setData({
uploadImageList
})
_this.setData({
volunteerFaceImg:uploadImageList[0].ossUrl,
disabled:false
})
console.log(">>>>>>>>>>>"+_this.data.volunteerFaceImg)
}
})
}
})
} else if (index === 1) {
wx.chooseImage({
count: 3 - _this.data.uploadImageList.length,
sizeType: ["original", "compressed"],
sourceType: ["album"],
success (res) {
const uploadImageList = []
const endIndex = _this.data.uploadImageList.length
res.tempFilePaths.forEach(item => {
uploadImageList.push({
uploaded: false,
ossUrl: "",
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",
header: {
"Content-type": "multipart/form-data"
},
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({
volunteerFaceImg:uploadImageList[0].ossUrl,
disabled:false
})
}
})
})(index)
})
}
})
}
return true
},
cancelText: "取消",
cancel () {
_this.setData({
disabled:false
})
console.log(":::::::::::::::")
},
destructiveButtonClicked () {},
})
},
//
choosePicker (e) {
let index = e.detail.value
this.setData({
tagIndex: index,
'volunteerTag.id': this.data.tagList[index].id,
'volunteerTag.tag': this.data.tagList[index].tagName
})
},
//
choosePicker2 (e) {
let index = e.detail.value
this.setData({
deptIndex: index,
'volunteerDept.id': this.data.deptList[index].id,
'volunteerDept.dept': this.data.deptList[index].deptName
})
},
//
chooseTeamType (e) {
let index = e.detail.value
this.setData({
teamTypeIndex: index,
'teamType.typeName': this.data.teamTypeList[index].typeName,
'teamType.typeCode': this.data.teamTypeList[index].typeCode,
'teamType.id': this.data.teamTypeList[index].id,
teamList: [],
teamIndex: 0,
team: {}
})
this.getAppTeamListByType()
},
//
chooseTeamName (e) {
let index = e.detail.value
this.setData({
teamIndex: index,
'team.teamName': this.data.teamList[index].teamName,
'team.teamType': this.data.teamList[index].teamType,
'team.id': this.data.teamList[index].id
})
},
// 获取团队类别列表
getTeamTypeList () {
let param = {
pageSize : 99,
pageIndex : 1,
teamId: ''
}
return new Promise((resolve, reject) => {
new_api.getTeamTypeList(param).then(res => {
if (res.code == 0 && res.msg == 'success') {
this.setData({
teamTypeList: this.data.teamTypeList.concat(res.data)
})
}
resolve()
}).catch(err => { reject() })
})
},
getTeamTypeName () {
let param = {
pageSize : 99,
pageIndex : 1,
teamId: this.data.team.id
}
new_api.getTeamTypeList(param).then(res => {
if (res.code == 0 && res.msg == 'success') {
console.log(this.data.teamTypeList)
this.data.teamTypeList.forEach((item, key) => {
if (item.id == res.data[0].id) {
this.setData({
'teamType.typeName': item.typeName,
'teamType.typeCode': item.typeCode,
teamTypeIndex: parseInt(key),
'teamType.id': item.id
})
this.getAppTeamListByType()
}
})
}
}).catch(err => {})
},
// 获取团队列表
getAppTeamListByType () {
if (!this.data.teamType.typeCode) {
this.setData({
teamList: [{
teamName: '请选择',
teamType: '',
id: ''
}]
})
return
}
const para = {
pageIndex: 1,
pageSize: 99,
typeCode: this.data.teamType.typeCode
}
new_api.getAppTeamListByType(para).then(res => {
if (this.data.team.id) {
res.data.forEach((item, key) => {
if (this.data.team.id == item.id) {
this.setData({
teamList: this.data.teamList.concat(res.data),
'team.teamName': item.teamName,
'team.teamType': item.teamType,
teamIndex: parseInt(key)+1,
})
}
})
} else {
this.setData({
teamList: this.data.teamList.concat(res.data),
'team.teamName': res.data[0].teamName,
'team.teamType': res.data[0].teamType,
'team.id': res.data[0].id,
})
}
}).catch(err => {
this.setData({
teamList: []
})
console.log(err)
})
}
})