市北党建引领小程序初始化
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.
 

560 lines
18 KiB

var api = require('../../utils/api.js')
var global = require('../../utils/config.js')
const QQMapWX = require('../../utils/qqmap-wx-jssdk')
import {
gcj02_to_wgs84
} from "../../utils/wgs84_to_gcj02";
const app = getApp()
Page({
data: {
gridId: '',
gridName: '',
gridNameArr: [],
formid: '',
resToken: '',
resGridName: '',
inviteUserId: '',
GridNameId: "",
qqMapWX: '',
streetList: [],
addressContent: '',
address: '',
form: {
realName: '',
identityNo: '',
mobile: '',
villageName: '',//居住小区名称
workUnit: '',//工作单位
workType: '',//单位性质
workIndustry: '',//所属行业
partyFlag: 1,//是否为党员
allDeptIds: [],//社区id
shibei:'1',//是否居住在市北
workIndustryText:''//所属行业其他输入框
},
selectedStatus:false,
selectOption: [
{ label: '党政机关', value: '0' },
{ label: '事业单位', value: '1' },
{ label: '国有企业', value: '2' },
{ label: '私营企业', value: '3' },
{ label: '集体企业', value: '4' },
{ label: '外资企业、合资企业', value: '5' },
{ label: '社会组织', value: '6' },
{ label: '其他', value: '7' }
],
workIndustryArr:[{label:'直播电商',value:'0'}, {label:'网约车司机',value:'1'}, {label:'外卖配送人员',value:'2'}, {label:'快递小哥',value:'3'} , {label:'道路运输行业',value:'4'},{label:'其他',value:'5'}],
workTypeInput:false,
workTypeText:'',//单位类型为其他的输入框值
newArr:[],
multiIds:[],
multiIndex: [0, 0],
changeFlag:false,
title:'',
WorkIndustryInput:false
},
onLoad(options) {
if(options.title){
wx.setNavigationBarTitle({
title: options.title,
})
let obj = JSON.parse(wx.getStorageSync('userInfo') )
for (let key in obj) {
if (!this.data.form.hasOwnProperty(key)) {
delete obj[key];
}
}
obj.allDeptIds = obj.allDeptIds.split(',')
this.setData({
form:{...obj},
title:options.title,
})
console.log(this.data.form);
}else{
wx.setNavigationBarTitle({
title: '注册'
})
}
// this.data.qqMapWX = new QQMapWX({
// key: 'CMJBZ-4DECI-JXGGN-5B4WU-QLV2H-B5BEJ'
// })
// this.getLocation().then(() => {
// this.reverseLocation()
// })
this.getDeptTree()
// if (options.gid) {
// this.setData({
// gridId:'1221751857028825090',
// inviteUserId: options.inviteUserId
// })
// }
// this.getToken(options.gid)
// this.getInvitation()
},
// 获取经纬度
getLocation() {
return new Promise((resolve, reject) => {
const _this = this
wx.getLocation({
type: 'gcj02',
success(res) {
if (res.latitude && res.longitude) {
_this.setData({
'form.issueLatitude': res.latitude,
'form.issueLongitude': res.longitude
})
_this.getDeptIdByItude()
resolve(true)
}
},
fail(err) {
reject(err)
}
})
})
},
getDeptIdByItude() {
let transfromlnglat = gcj02_to_wgs84(this.data.form.issueLongitude, this.data.form.issueLatitude)
const para = {
longitude: transfromlnglat[0],
latitude: transfromlnglat[1]
}
api.getDeptIdByItude(para).then(res => {
// 返回成功以后再调用 列表
this.setData({
'form.streetId': res.data && res.data.streetId ? res.data.streetId : '',
'form.communityId': res.data && res.data.communityId ? res.data.communityId : '',
'form.gridId': res.data && res.data.gridId ? res.data.gridId : '',
'form.grid': res.data && res.data.gridName ? res.data.gridName : ''
})
this.getDeptTree()
}).catch(err => {
this.getDeptTree()
console.log(err)
})
},
//获取街道树
getDeptTree() {
api.getDeptTree().then(res => {
this.setData({
streetList: res.data[0].children
})
console.log(this.data.streetList);
let state = {
arr: [],
arr1: [],
arr2: [],
multiIds: []
}
let str = this.data.form.allDeptIds.slice(1,3)
this.data.streetList.map((v, vk) => {
state.arr1.push(v.label);
if (this.data.multiIndex[0] === vk) {
state.multiIds[0] = v;
}
if(str[0] == v.value){
if (state.arr2.length <= 0) {
v.children.map((c, ck) => {
state.arr2.push(c.label);
if (this.data.multiIndex[1] === ck) {
state.multiIds[1] = c;
}
});
}
}
});
state.arr[0] = state.arr1;
state.arr[1] = state.arr2;
this.setData({
newArr: state.arr,
multiIds: state.multiIds,
});
if (this.data.form.streetId && this.data.form.communityId) {
this.data.streetList.forEach(element => {
if (element.value == this.data.form.streetId) {
this.setData({
'form.street': element.label,
communityList: element.children.filter(item=>item.label!= '武定路社区'&&item.label!= '陵县路社区') // 社区
})
// 循环社区
element.children.forEach(community => {
if (community.value == this.data.form.communityId) {
this.setData({
'form.community': community.label,
gridList: community.children,
// 'form.grid': community.children[0].label, // 网格默认选择第一个
// 'form.gridId': community.children[0].value // 网格
})
}
});
}
});
}
this.data.streetList.forEach((item,index)=>{
if(item.value == str[0]){
item.children.forEach((c,i)=>{
if(c.value == str[1]){
this.setData({
multiIndex:[index,i],
changeFlag:true
})
}
})
}
})
console.log(str);
}).catch(err => {
console.log(err)
})
},
//确定选择社区
bindMultiPickerChange() {
this.setData({
'form.allDeptIds':['1175270520603930625',this.data.multiIds[0].value,this.data.multiIds[1].value,this.data.streetList.filter(item=>item.value == this.data.multiIds[0].value)[0].children.filter(item=>item.value== this.data.multiIds[1].value)[0].children[0].value],
changeFlag:true
})
console.log(this.data.streetList);
console.log(this.data.form.allDeptIds);
},
//滑动社区
bindMultiPickerColumnChange(e) {
let data = {
newArr: this.data.newArr,
multiIndex: this.data.multiIndex,
multiIds: this.data.multiIds,
};
data.multiIndex[e.detail.column] = e.detail.value;
let searchColumn = () => {
let arr1 = [];
let arr2 = [];
this.data.streetList.map((v, vk) => {
if (data.multiIndex[0] === vk) {
data.multiIds[0] = {
...v,
};
v.children.map((c, ck) => {
arr1.push(c.label);
if (data.multiIndex[1] === ck) {
data.multiIds[1] = {
...c,
};
}
});
}
});
data.newArr[1] = arr1;
data.newArr[2] = arr2;
};
switch (e.detail.column) {
case 0:
// 每次切换还原初始值
data.multiIndex[1] = 0;
// data.multiIndex[2] = 0;
// 执行函数处理
searchColumn();
break;
case 1:
// data.multiIndex[2] = 0;
searchColumn();
break;
case 2:
searchColumn();
break;
}
this.setData(data);
this.setData({
newArr:this.data.newArr.splice(0,2),
changeFlag:true
})
},
reverseLocation() {
const _this = this
this.data.qqMapWX.reverseGeocoder({
location: {
latitude: _this.data.form.issueLatitude,
longitude: _this.data.form.issueLongitude
},
success(res) {
_this.setData({
addressContent: res.result.address,
address: res.result.address
// 'form.issueAddress': res.result.address,
})
},
fail(err) {
console.debug(err)
}
})
},
//姓名双向绑定
bindRealNameInput(e) {
this.setData({
'form.realName': e.detail.value
})
console.log(this.data.form)
},
//身份证双向绑定
bindRealidentityNoInput(e) {
this.setData({
'form.identityNo': e.detail.value
})
console.log(this.data.form)
},
//工作单位
bindWorkUnitInput(e) {
this.setData({
'form.workUnit': e.detail.value
})
console.log(this.data.form)
},
//所属行业
bindWorkIndustryInput(e) {
this.setData({
'form.workIndustry': e.detail.value
})
console.log(this.data.form)
},
//以防下拉
bindMultiPickerWorkIndustryChange(e) {
if(e.detail.value == '5'){
this.setData({
WorkIndustryInput:true
})
}
this.setData({
'form.workIndustry': e.detail.value
})
console.log(this.data.form)
},
//手机号双向绑定
bindRealMobileInput(e) {
this.setData({
'form.mobile': e.detail.value
})
console.log(this.data.form)
},
//居住小区名称
bindvillageNameInput(e) {
this.setData({
'form.villageName': e.detail.value
})
},
//单选框
bindFlagshibeiChange(e){
this.setData({
'form.shibei': e.detail.value
})
},
bindworkIndustryTextInput(e){
this.setData({
'form.workIndustryText': e.detail.value
})
},
handleChangeWorkType(e) {
console.log(e);
if(e.detail.value == '7'){
this.setData({
workTypeInput:true
})
}
this.setData({
'form.workType': this.data.selectOption[e.detail.value].label,
})
console.log(this.data.form);
},
bindWorkTypeTextInput(e){
console.log(e,'cccccc');
this.setData({
workTypeText: e.detail.value
})
console.log(this.data.workTypeText);
},
//单位性质弹框确定
confirmDlaog(e){
console.log(e);
this.setData({
workTypeInput:false,
WorkIndustryInput:false
})
},
//单位性质弹框取消
cancelDlaog(){
this.setData({
workTypeInput:false,
WorkIndustryInput:false
})
},
getToken: function (gid) {
let that = this
wx.login({
success(res) {
if (res.code) {
console.log('微信CODE: ' + res.code)
let wxCode = res.code
const para = {
// inviteUserId: that.data.inviteUserId,
//写死四机社区第一网格
// gridId: '1224104693058306049',
wxCode: res.code
}
console.log(wxCode);
api.getTokenV3(para).then(function (res) {
global.Token = res.data.token
wx.removeStorageSync('token')
wx.setStorageSync('token', res.data.token)
that.setData({
resToken: res.data.token,
resGridName: res.data.grid
})
})
}
}
})
},
// 单选点击事件
showToast (title) {
wx.showToast({
title: title,
icon: 'none',
duration: 2000
})
},
// 获取用户信息
getUserInfo() {
api.getUserInfo().then(res => {
console.log("用户信息", res)
let userInfoString = JSON.stringify(res.data);
wx.setStorageSync('userInfo', userInfoString);
wx.navigateBack({
delta: 1
})
}).catch(err => {
console.log(err)
})
},
navigateToIndex() {
if (!this.data.form.realName) {
this.showToast('请输入姓名')
return false
}
if (!this.data.form.identityNo) {
this.showToast('请填写身份证号')
return false
}
if(!this.data.form.workUnit){
this.showToast('请填写工作单位')
return false
}
if (!this.data.form.mobile) {
this.showToast('请填写手机号')
return false
}
if(this.data.form.shibei == '1'){
if (this.data.form.allDeptIds.length == 0) {
this.showToast('请选择报到常住社区名称')
return false
}
if (!this.data.form.villageName) {
this.showToast('请填写居住小区名称')
return false
}
}else if(this.data.form.shibei == '0'){
if (this.data.form.allDeptIds.length == 0) {
this.showToast('请填写单位报到联系社区名称')
return false
}
}
const para = {
...this.data.form
}
if(this.data.workTypeText){
para.workType = this.data.workTypeText
}
para.partyFlag = parseInt(para.partyFlag)
wx.showLoading({
title: "提交中..."
})
let than = this
if(this.data.title){
wx.login({
success: (res) => {
para.userId = wx.getStorageSync('userId')
para.wxCode = res.code
if(res.code){
api.userInfoUpdate(para).then(res=>{
if(res.code == 0){
wx.removeStorageSync('userInfo')
this.getUserInfo()
than.showToast('修改成功')
}else{
than.showToast(res.msg)
}
wx.hideLoading()
}).catch(err=>{
console.log(err);
})
}
},
})
}else{
let than = this
wx.login({
success(res) {
if (res.code) {
console.log('微信CODE: ' + res.code)
const para = {
...than.data.form,
wxCode: res.code
}
console.log(para);
api.getTokenV3(para).then(function (res) {
if(res.code == '0'){
let userInfoString = JSON.stringify(res.data);
wx.setStorageSync("userInfo", userInfoString);
wx.reLaunch({
url: '/pages/home/home'
})
}else{
this.showToast(res.msg)
}
// global.Token = res.data.token
// wx.removeStorageSync('token')
// wx.setStorageSync('token', res.data.token)
// that.setData({
// resToken: res.data.token,
// resGridName: res.data.grid
// })
})
}
}
})
}
// api.submitReportpartyFlag(para).then(res => {
// wx.hideLoading()
// if(res.code == '0'){
// than.setData({
// submitStatus:true
// })
// }else{
// than.showToast(res.msg)
// }
// }).catch(err => {
// wx.hideLoading()
// console.log(err);
// })
console.log(this.data.form);
}
})