// pages/recruit/referto/referto.js Page({ /** * 页面的初始数据 */ data: { notice : '', //地区提示 areaData : '', //地区数据 paySuccess : false, experienceId: '', typesArr : [], typesIndex : 0, refertoStatus: false, checkStatus : false, // 省份选择 areasArr : [], areaId : 0, areaIndex : 0, // 市级选择 cityArr : [], cityId : 0, cityIndex : 0, // 区域选择 regiArr : [], regiId : 0, regiIndex : 0, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ experienceId: options.id }) // 获取申请前置接口 this.recruitInfo(options.id); }, /** * 生命周期函数--监听页面显示 */ onShow() { // 获取省市区列表 this.createInfo(); }, /** * 省市区列表 */ createInfo() { wx.$api.site.create().then(res => { let areas = res.data, areaIndex = this.data.areaIndex this.setData({ areasArr : areas, areaId : areas[areaIndex].id, }) this.citylist(areas[areaIndex].id) }).catch(err => {}) }, /** * 所在省份-下拉 */ areasChange(e) { let area = this.data.areasArr, index = e.detail.value, atcode = area[index].id if (index != this.data.areaIndex) { this.setData({ areaIndex : index, areaId : atcode }) // 获取市级列表 this.citylist(atcode) } }, /** * 市级列表 */ citylist(cityId) { wx.$api.site.create({ parent_id: cityId }).then(res=>{ let cityArr = res.data this.setData({ cityId : cityArr[0].id, cityIndex : 0, cityArr : cityArr }) // 获取区级列表 this.regilist(cityArr[0].id) }) }, /** * 市级下拉筛选 */ cityDrop(e) { let city = this.data.cityArr, index = e.detail.value, citycode = city[index].id if (index != this.data.cityIndex) { this.setData({ cityIndex : index, cityId : citycode }) // 获取市级列表 this.regilist(citycode) } }, /** * 区列表 */ regilist(areaId) { wx.$api.site.create({ parent_id: areaId }).then(res=>{ this.setData({ regiArr : res.data, regiId : res.data[0].id, regiIndex : 0 }) }) }, /** * 区下拉筛选 */ regiDrop(e) { let newIndex = e.detail.value this.setData({ regiIndex : newIndex, regiId : this.data.regiArr[newIndex].id }) }, /** * 申请前置接口 */ recruitInfo(id) { wx.$api.recruit.Enroll(id, { experience_area_id: getApp().globalData.experienceAreaId }).then(res => { this.setData({ areaData : res.data.areas, notice : res.data.experience_notice, typesArr : [{experience_type_id: null, name: "请选择体验内容"}, ...res.data.types], paySuccess : false }) }).catch(err => {}) }, /** * 体验内容筛选 */ tasteDrop(e) { let newIndex = e.detail.value this.setData({ typesIndex : newIndex }) }, /** * 提交表单 */ siteform(e) { let value = e.detail.value let errMsg = '' if(this.data.typesArr[this.data.typesIndex].experience_type_id === null) errMsg = "请选择体验内容" if(errMsg != ''){ wx.showToast({ title: errMsg, icon : 'none' }) return } let data = { name : value.name, address : value.address, province_id : this.data.areaId, city_id : this.data.cityId, district_id : this.data.regiId, experience_id : this.data.experienceId, experience_area_id : this.data.areaData.experience_area_id, experience_type_id : this.data.typesArr[this.data.typesIndex].experience_type_id, invite : getApp().globalData.inviteText } this.setData({ disabled: true }) wx.$api.recruit.recruitAdd(data).then(res => { this.setData({ checkStatus: true, disabled: false }) }).catch(() =>{ this.setData({ disabled: false }) }) }, /** * 关闭弹框,跳转首页 */ refertoTap() { this.setData({ refertoStatus: false }) wx.switchTab({ url: '/pages/recruit/index' }) }, /** * 申请体验官成功后,弹出 */ checkTap() { this.setData({ refertoStatus: true, checkStatus: false }) } })