// pages/serve/settle.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { token: app.globalData.token, sourceUrl: app.baseUrls.sourceUrl, pageType: '1', // 区县 areaList: [], areaIndex: 0, areaAll: [], areaSelected: '', // 街道 streetList: [], streetIndex: 0, streetAll: [], streetSelected: '', // 社区 communityList: [], communityIndex: 0, communityAll: [], communitySelected: '', // 小区 xqList: [], xqIndex: 0, xqAll: [], xqSelected: '', officeAddress: '', orgIntro: '', imageList: [], serviceUrl: app.baseUrls.serviceUrl, baseImgUrl: app.baseUrls.baseImgUrl, locationCode: '', unitName: '', serviceMode: '', shopType: '', phone: '', chargePerson: '', residential: '', curType: [], typeIndex: 0, typeAll: [], typeSelected: '', typeSelectedName: '', isLoading: false }, // 选择入驻类型 bindTypePickerChange: function (e) { var self = this self.setData({ typeIndex: e.detail.value, typeSelected: self.data.typeAll[e.detail.value].dataId, typeSelectedName: self.data.typeAll[e.detail.value].dataName, pageType: self.data.typeAll[e.detail.value].dataId }) }, // 获取区县 getArea: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getArea, [app.baseUrls.serviceUrl, '110889']), {}, { headers: { token: self.data.token } }, function (code, data) { var arr = ['请选择区县'] for (let i = 0; i < data.length; i++) { arr.push(data[i].areaName) } self.setData({ areaList: arr, areaAll: data }) }, function (code, data) { console.log(data) }) }, // 选择区县 bindAreaPickerChange: function(e) { var self = this this.setData({ areaIndex: e.detail.value, areaSelected: self.data.areaAll[e.detail.value - 1].areaId }) this.getStreet() }, // 获取街道 getStreet: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getArea, [app.baseUrls.serviceUrl, self.data.areaSelected]), {}, { headers: { token: self.data.token } }, function (code, data) { var arr = ['请选择街道'] for (let i = 0; i < data.length; i++) { arr.push(data[i].areaName) } self.setData({ streetList: arr, streetAll: data }) }, function (code, data) { console.log(data) }) }, // 选择街道 bindStreetPickerChange: function (e) { var self = this self.setData({ streetIndex: e.detail.value, streetSelected: self.data.streetAll[e.detail.value - 1].areaId }) self.getCommunity() }, // 获取社区 getCommunity: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getCommunityList, [app.baseUrls.communityUrl]), { parentCode: self.data.streetSelected }, { headers: { token: self.data.token } }, function (code, data) { var arr = ['请选择社区'] for (let i = 0; i < data.length; i++) { arr.push(data[i].communityName) } self.setData({ communityList: arr, communityAll: data }) console.log(data) }, function (code, data) { console.log(data) }) }, // 选择社区 bindCommunityPickerChange: function (e) { var self = this self.setData({ communityIndex: e.detail.value, communitySelected: self.data.communityAll[e.detail.value - 1].communityId, locationCode: self.data.communityAll[e.detail.value - 1].locationCode, }) self.getHouseList() }, // 上传图片 uploadImage: function () { var self = this if (!self.data.isLoading) { wx.chooseImage({ count: 9 - self.data.imageList.length, sourceType: ['album', 'camera'], success: function (res) { wx.showToast({ title: '上传中', icon: 'loading' }) self.setData({ isLoading: true }) for (let i = 0; i < res.tempFiles.length; i++) { var path = res.tempFiles[i].path; app.restAjax.file(app.restAjax.path(app.apis.uploadImg, [app.baseUrls.serviceUrl]), path, 'image', { headers: { token: app.globalData.token } }, function (code, data) { if (code == '200') { var id = JSON.parse(data).data var arr = self.data.imageList arr.push(id) self.setData({ imageList: arr }) if (i == res.tempFiles.length - 1) { self.setData({ isLoading: false }) } wx.hideToast() } }, function (code, data) { console.log(data) }) } } }) } }, // 获取小区 getHouseList: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getHouse, [app.baseUrls.communityUrl]), { areaCode: self.data.locationCode }, { 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].residentialName) } self.setData({ xqList: arr, xqAll: data }) }, function (code, data) { console.log(data) }) }, // 选择小区 bindXqPickerChange: function (e) { var self = this self.setData({ xqIndex: e.detail.value, xqSelected: self.data.xqAll[e.detail.value - 1].residentialId }) }, // 提交入驻 submitSettle: function () { var self = this if (!self.data.isLoading) { if (self.data.areaIndex == '0') { wx.showToast({ title: '请选择区县', icon: 'error' }) return } if (self.data.streetIndex == '0' && self.data.streetAll.length > 1) { wx.showToast({ title: '请选择街道', icon: 'error' }) return } if (self.data.communityIndex == '0' && self.data.communityAll.length > 1) { wx.showToast({ title: '请选择社区', icon: 'error' }) return } if (!self.data.unitName) { wx.showToast({ title: '请填写单位名称', icon: 'error' }) return } if (!self.data.officeAddress && self.data.pageType == '612be328-bb06-48b7-877c-7d816012f273') { wx.showToast({ title: '请填写办公地址', icon: 'error' }) return } if (!self.data.officeAddress && self.data.pageType == '3c97be91-b7e5-498f-b0dd-cd097521549f') { wx.showToast({ title: '请填写营业地址', icon: 'error' }) return } if (!self.data.unitName && self.data.pageType == '612be328-bb06-48b7-877c-7d816012f273') { wx.showToast({ title: '请填写单位名称', icon: 'error' }) return } if (!self.data.unitName && self.data.pageType == '3c97be91-b7e5-498f-b0dd-cd097521549f') { wx.showToast({ title: '请填写店铺名称', icon: 'error' }) return } if (!self.data.shopType && self.data.pageType == '3c97be91-b7e5-498f-b0dd-cd097521549f') { wx.showToast({ title: '请填写店铺品类', icon: 'error' }) return } if (!self.data.orgIntro) { wx.showToast({ title: '请填写机构简介', icon: 'error' }) return } if (!self.data.phone) { wx.showToast({ title: '请填写联系电话', icon: 'error' }) return } if (!self.data.chargePerson) { wx.showToast({ title: '请填写负责人姓名', icon: 'error' }) return } var file = '' for (let i = 0; i < self.data.imageList.length; i++) { file += self.data.imageList[i] if (i != self.data.imageList.length - 1) { file += ',' } } if (self.data.pageType == '3c97be91-b7e5-498f-b0dd-cd097521549f' && !self.data.shopType) { wx.showToast({ title: '请填写品类', }) } var residentialInfo = '' var residentialValue = '非ID' if (self.data.pageType == '6c290901-39dd-4b69-a7aa-c27d253ab152' || self.data.pageType == '45ad4873-af80-4d03-973d-3b746a889948') { if (self.data.xqIndex == '0') { if (!self.data.residential) { wx.showToast({ title: '请选择或填写您的小区名称', icon: 'error' }) return } else { residentialValue = self.data.residential } } else { residentialInfo = self.data.xqSelected residentialValue = 'ID' } } var info = { organizationTypeId: self.data.pageType, organizationTypeName: self.data.pageName, cityId: self.data.areaSelected, cityCode: self.data.areaAll[self.data.areaIndex - 1].areaCode, cityName: self.data.areaAll[self.data.areaIndex - 1].areaName, streetId: self.data.streetSelected, streetCode: self.data.streetAll[self.data.streetIndex - 1].areaCode, streetName:self.data.streetAll[self.data.streetIndex - 1].areaName, communityId: self.data.communitySelected, communityCode: self.data.communityAll[self.data.communityIndex - 1].locationCode, communityName: self.data.communityAll[self.data.communityIndex - 1].communityName, address: self.data.officeAddress, introduction: self.data.orgIntro, fileIds: file, residential: residentialInfo, serviceMode: self.data.serviceMode, unitName: self.data.unitName, shopType: self.data.shopType, shopTypeName: self.data.shopType, phone: self.data.phone, chargePerson: self.data.chargePerson, residentialValue: residentialValue } self.setData({ isLoading: true }) app.restAjax.post(app.restAjax.path(app.apis.submitSettle, [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 }) }) } }, // 删除图片 deleteImg: function (e) { var self = this var idx = e.currentTarget.dataset.cur var arr = this.data.imageList arr.splice(idx, 1) this.setData({ imageList: arr }) }, // 获取社区机构入驻种类 getOrgList: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getDictionary, [app.baseUrls.serviceUrl, '8e981a56-afa1-4934-9d90-16aa1b8113ca']), {}, { headers: { token: self.data.token } }, function (code, data) { var arr = [] for (let i = 0; i < data.length; i++) { arr.push(data[i].dataName) } self.setData({ curType: arr, typeAll: data, typeSelected: data[0].dataId, typeSelectedName: data[0].dataName, pageType: data[0].dataId }) }, function (code, data) { console.log(data) }) }, // 获取单位/店铺入驻种类 getStoreList: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getDictionary, [app.baseUrls.serviceUrl, '4a44a891-8a0c-4cad-ada6-09ce99118e27']), {}, { headers: { token: self.data.token } }, function (code, data) { var arr = [] for (let i = 0; i < data.length; i++) { arr.push(data[i].dataName) } self.setData({ curType: arr, typeAll: data, typeSelected: data[0].dataId, typeSelectedName: data[0].dataName, pageType: data[0].dataId }) }, function (code, data) { console.log(data) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var self = this if (options.type == '1') { this.getOrgList() } else { this.getStoreList() } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { this.getArea() }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })