syshxcx/pages/checkIn/checkInDetail.js
dong_bo0602 a1f9e23f6d 0607
2022-06-07 15:43:05 +08:00

235 lines
5.6 KiB
JavaScript

// pages/checkIn/checkInDetail.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
token: app.globalData.token,
array: [],
index: 0,
sexSelected: '',
communityArray: [],
communityIndex: 0,
communitySelected: '',
neighbourArray: ['请选择所在小区'],
neighbourIndex: 0,
date: '请选择出生日期',
partyDate: '请选择入党时间',
floorNum: '',
roomNum: '',
affair: '',
realName: '',
workUnit: '',
isLoading: false
},
// 选择性别
bindPickerChange: function(e) {
var self = this
this.setData({
index: e.detail.value,
sexSelected: self.data.sexAll[e.detail.value - 1].dataId
})
},
// 选择出生日期
bindDateChange: function(e) {
this.setData({
date: e.detail.value
})
},
// 选择入党时间
bindPartyDateChange: function(e) {
this.setData({
partyDate: e.detail.value
})
},
// 选择社区
bindCommunityPickerChange: function (e) {
var self = this
this.setData({
communityIndex: e.detail.value,
communitySelected: self.data.communityAll[e.detail.value - 1].communityId
})
},
// 选择小区
bindNeighbourPickerChange: function (e) {
this.setData({
neighbourIndex: e.detail.value
})
},
// 提交报到
submitCheckIn: function () {
var self = this
if (!self.data.isLoading) {
var info = {
userName: self.data.realName,
sexId: self.data.sexSelected,
sexName: self.data.sexAll[self.data.index - 1].dataName,
birthday: self.data.date,
joinTime: self.data.partyDate,
workUnit: self.data.workUnit,
workUnitValue: '非ID',
community: self.data.communitySelected,
residential: self.data.communityAll[self.data.neighbourIndex - 1].residential,
residentialValue: self.data.communityAll[self.data.neighbourIndex - 1].residentialValue,
building: self.data.floorNum,
buildingValue: '非ID',
houseNumber: self.data.roomNum,
houseNumberValue: '非ID',
ability: self.data.affair,
// areaId: wx.getStorageSync('areaId'),
areaCode: wx.getStorageSync('areaCode')
}
self.setData({
isLoading: true
})
app.restAjax.post(app.restAjax.path(app.apis.submitCheckIn, [app.baseUrls.requestUrl]), info, {
headers: {
token: self.data.token
}
}, function (code, data) {
wx.showToast({
title: '报到成功',
icon: 'success'
})
setTimeout(function () {
self.setData({
isLoading: false
})
wx.navigateBack({
delta: 1
})
}, 1500)
}, function (code, data) {
console.log(data)
self.setData({
isLoading: false
})
})
}
},
// 获取性别
getSex: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.getDictionary, [app.baseUrls.serviceUrl, '4ef46940-76ab-4758-b5f0-0cbc93ffc660']), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
console.log(data)
var arr = ['请选择性别']
for (let i = 0; i < data.length; i++) {
arr.push(data[i].dataName)
}
self.setData({
array: arr,
sexAll: data
})
}, function (code, data) {
console.log(data)
})
},
// 获取我的社区
getMyCommunity: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.mycommunity, [app.baseUrls.requestUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
var arr = ['请选择所在社区']
var arr1 = self.data.neighbourArray
for (let i = 0; i < data.length; i++) {
arr.push(data[i].communityName)
if (data[i].residentialValue == 'ID') {
self.getResidential(data[i].residential)
} else {
arr1.push(data[i].residential)
}
}
self.setData({
communityArray: arr,
communityAll: data
})
}, function (code, data) {
console.log(data)
})
},
getResidential: function (id) {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.getResidential, [app.baseUrls.communityUrl, id]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
var arr = self.data.neighbourArray
arr.push(data.residentialName)
self.setData({
neighbourArray: arr
})
}, function (code, data) {
console.log(data)
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getSex()
this.getMyCommunity()
this.setData({
curCommunityName: wx.getStorageSync('curCommunityName') ? wx.getStorageSync('curCommunityName'): '切换社区',
curCommunityId: wx.getStorageSync('curCommunityId') ? wx.getStorageSync('curCommunityId') : ''
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})