// subpages/volunteer/components/volunteerComponents/index.js const app = getApp() const api = require("../../../../utils/api.js") import shequ from './shequ' Page({ /** * 页面的初始数据 */ data: { statusHeight: app.globalData.deviceInfo.statusHeight, // 自定义头部状态栏高度 navigationHeight: app.globalData.deviceInfo.navigationHeight, type: 0, volunteerTypeArr: ['街道服务队', '社区服务队'], volunteerType: 0, volunteerTypeOneInfo: { name: "", idCard: "", mobile: "", street: "", deptId: "", workUnit: "", //工作单位 specialty: "", //特长 serviceType: 0, workAddr: "", community: "" }, streetArr: [], communityArr: [], options: null, newArr: [], multiIds: [], multiIndex: [0, 0], orgOptions: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ orgOptions: shequ[0].data }) let street = []; let community = [] this.data.orgOptions.forEach(f => { street.push(f.lable) f.children.forEach(item => { community.push(item.lable) }) }) this.setData({ streetArr: street, communityArr: community }) // this.getByLoginUser() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, back() { //返回上一级,关闭当前页面 wx.navigateBack({ delta: 1 }) }, change(e) { this.setData({ type: e.target.dataset.type == "0" ? 1 : 0 }) }, bindPickerChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail) this.setData({ volunteerType: e.detail.value, }) this.data.volunteerTypeOneInfo.allDeptIds = []; }, bindPickerStreet: function(e) { if(this.data.volunteerType == 1){ let temp = this.data.orgOptions.filter((item,index) => index == e.detail.value)[0].children.map(item=>item.lable) this.setData({ communityArr:temp }) } this.setData({ ["volunteerTypeOneInfo.street"]: this.data.streetArr[e.detail.value] }) }, bindPickerCommunity: function(e) { this.setData({ ["volunteerTypeOneInfo.community"]: this.data.communityArr[e.detail.value] }) }, bindNameInput: function(e) { this.setData({ ["volunteerTypeOneInfo.name"]: e.detail.value }) }, bindIDnumberInput: function(e) { this.setData({ ["volunteerTypeOneInfo.idCard"]: e.detail.value }) }, bindphoneInput: function(e) { this.setData({ ["volunteerTypeOneInfo.mobile"]: e.detail.value }) }, bindworkUnitInput: function(e) { this.setData({ ["volunteerTypeOneInfo.workUnit"]: e.detail.value }) }, bindspecialityInput: function(e) { this.setData({ ["volunteerTypeOneInfo.specialty"]: e.detail.value }) }, submit() { if (!this.data.volunteerTypeOneInfo.name || !this.data .volunteerTypeOneInfo.idCard || !this.data .volunteerTypeOneInfo.mobile || !this.data .volunteerTypeOneInfo.mobile) { wx.showToast({ title: "请填写必填项", duration: 2000 //持续的时间 }) return } this.data.volunteerTypeOneInfo.serviceType = this.data.volunteerType; this.data.volunteerTypeOneInfo.allDeptIds = [] this.data.volunteerTypeOneInfo.allDeptIds.push("1175270520603930625") if (this.data.volunteerType == 0) { this.data.orgOptions.forEach(f => { if (f.lable == this.data.volunteerTypeOneInfo.street) { this.data.volunteerTypeOneInfo.allDeptIds.push(f.value) } }) } if (this.data.volunteerType == 1) { this.data.orgOptions.forEach(f => { f.children.forEach(item => { if (item.lable == this.data.volunteerTypeOneInfo.community) { this.data.volunteerTypeOneInfo.allDeptIds.push(f.value) this.data.volunteerTypeOneInfo.allDeptIds.push(item.value) } }) }) } delete this.data.volunteerTypeOneInfo.community; delete this.data.volunteerTypeOneInfo.street; const _this = this; api.saveOrder(_this.data.volunteerTypeOneInfo).then(res => { wx.showToast({ title: "提交成功", icon: 'success', duration: 2000 //持续的时间 }) setTimeout(() => { _this.back() }, 2000) }).catch(err => { wx.showToast({ title: err.msg, duration: 2000 //持续的时间 }) }) }, getByLoginUser() { api.getByLoginUser().then(res => { if (res.code !== 0) { return } let arr = res.data.options[0].children.filter((item) => (item.children)); arr.forEach((f => { f.children[0].children.forEach(s => { this.data.streetData.push({ allDeptIds: s.value, label: f.label }) }) })) }).catch(err => { console.log(err) }) }, })