// pages/supplement/supplement.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.urlStatic,//图片路径 agreement: false, isAgreement: true,//是否同意协议 jobList: [], jobValue: 0, provinceDataAll: null,//地区所有数据 provinceDataArr: [[""], [""]],//省市数据 provinceDataValue: [0, 0],//选中的省市下标 nowProvince: "",//选中的省市文字 storeArr: [],//专营店数据 storeValue: 0,//选中的专营店下标 realname: "", // jobDetail: "", httpState: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { app.globalData.nowPage = 2; if (app.globalData.openid) { this.loadFun(); } else { app.globalData.openidSuccessFuc = this.loadFun; } }, loadFun: function () { // this.getJobList(); this.getUserLocation(); var authenticationStatus = app.globalData.authenticationStatus; if (authenticationStatus && authenticationStatus.realName) { this.setData({ realname: authenticationStatus.realName }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return app.sharePack(); }, agreementState: function () {//协议 this.setData({ isAgreement: !this.data.isAgreement }) }, agreementControl: function () { this.setData({ agreement: !this.data.agreement }) }, getJobList: function () { app.wxRequest(app.globalData.urlRoot + "userInfo/getJobList", {}, res => { if (res.code == 200) { this.setData({ jobList: res.data }) var authenticationStatus = app.globalData.authenticationStatus; if (authenticationStatus && authenticationStatus.jobId) { for (let i = 0; i < res.data.length; i++) { if (res.data[i].jobId == authenticationStatus.jobId) { this.setData({ jobValue: i, jobDetail: res.data[i].jobDetail }) break; } } } } }, this) }, jobChange: function (e) { this.setData({ jobValue: e.detail.value }) }, getUserLocation: function (e) { wx.getLocation({ type: 'gcj02', //wgs84 success: (res) => { this.getDistributorList(res.longitude, res.latitude); }, fail: (res) => { this.getDistributorList("", ""); } }) }, getDistributorList: function (longitude, latitude) {//获取经销商列表 app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => { if (res.code == 200) { //整理数据 var datas = res.data; var province = []; var city = []; for (let i = 0; i < res.data.list.length; i++) { province.push(res.data.list[i].province); } for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) { city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city) } //将数据赋值给变量 this.setData({ provinceDataAll: res.data.list, provinceDataArr: [province, city], provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex], nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex], storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children, storeValue: res.data.nearData.agentIndex }) } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this); }, getRealname: function (e) {//获取用户输入的姓名 this.data.realname = e.detail.value; }, // getJobDetail: function (e) {//获取用户输入的姓名 // this.data.jobDetail = e.detail.value; // }, submitMsg: function () { if (!this.data.realname) { wx.showToast({ title: '请输入姓名', icon: 'none' }) return; } // if (!this.data.jobDetail) { // wx.showToast({ // title: '请输入职业', // icon: 'none' // }) // return; // } if (!this.data.isAgreement) { wx.showToast({ title: '请同意协议', icon: 'none' }) return; } if (this.data.httpState) { return; } this.data.httpState = true; var data = { realName: this.data.realname, // jobId: this.data.jobList[this.data.jobValue].jobId, // jobDetail: this.data.jobDetail, agentDetail: this.data.storeArr[this.data.storeValue]['agent_detail'], agentCode: this.data.storeArr[this.data.storeValue]['agent_code'], city: this.data.provinceDataArr[1][this.data.provinceDataValue[1]], province: this.data.provinceDataArr[0][this.data.provinceDataValue[0]] } app.wxRequest(app.globalData.urlRoot + "certificationInfo/submitCertificationInfoData", data, res => { this.data.httpState = false; if (res.code == 200) { if (!app.globalData.authenticationStatus) { app.globalData.authenticationStatus = {}; } app.globalData.authenticationStatus.realName = this.data.realname // app.globalData.authenticationStatus.jobDetail = this.data.storeArr[this.data.storeValue]['agent_detail'] app.globalData.authenticationStatus.city = data.city app.globalData.authenticationStatus.agentDetail = data.agentDetail // wx.navigateBack({ // delta: 1, // }) app.globalData.isStar.agentDetail = data.agentDetail; app.globalData.isStar.realName = data.realName; app.globalData.isStar.province = data.province; app.globalData.isStar.city = data.city; var isStar = wx.getStorageSync('isStar'); isStar.agentDetail = data.agentDetail; isStar.realName = data.realName; isStar.province = data.province; isStar.city = data.city; wx.setStorageSync('isStar', isStar); wx.redirectTo({ url: '../poster/poster', }) } else { wx.showToast({ title: res.msg, icon: 'none' }) } }, this, "POST"); }, provinceDataChange: function (e) { if (e.detail.column == 0) { var city = []; for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) { city.push(this.data.provinceDataAll[e.detail.value].children[i].city); } this.data.provinceDataArr[1] = city; this.setData({ provinceDataArr: this.data.provinceDataArr }) } }, provinceDataChane: function (e) { this.setData({ provinceDataValue: e.detail.value, nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]], storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children, storeValue: 0 }) }, storeChane: function (e) {//选中店铺 this.setData({ storeValue: e.detail.value, }) } })