|
- // pages/perfectMsg/perfectMsg.js
- const app = getApp();
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- selectType:2,//选中的手机号类型
- marginT: 0,
- verificationCode:"获取验证码",
- sendCode:true,
- mobile2:"",
- phoneInputShow: false,
- isUserAddress:true,//用户是否有地址
- submitData:{
- realName:"",//姓名
- mobile:"",//手机号
- province:"",//经销商省份
- city:"",//经销商城市
- agent_code:"",//经销商编码
- agentDetail:"",//经销商详情
- addressDetail:"",//地址详情
- scene:"",//场景值名称
- captcha:"",//验证码(若非微信绑定手机号需要传入)
- },
- provinceDataAll: null,//地区所有数据
- provinceDataArr: [[""], [""]],//省市数据
- provinceDataValue: [0, 0],//选中的省市下标
- nowProvince: "",//选中的省市文字
- storeArr: [],//专营店数据
- storeValue: 0,//选中的专营店下标
- httpState:false,//是否正在进行http请求
- windowTipShow:false,//是否显示完善信息后的弹窗
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.globalData.nowPage = 3;
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- if (app.globalData.userPhoneType == "ios") {
- this.setData({
- marginT: -20
- })
- }
- },
- loadFun:function(){
- if (app.globalData.userMobile) {
- this.data.submitData.mobile = app.globalData.userMobile;
- this.setData({
- phoneInputShow: true,
- submitData: this.data.submitData
- })
- }
- this.getAddress();
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- },
- enterLucky:function(){//每日抽奖
- wx.navigateTo({
- url: '/pages/luckyStar/luckyStar'
- })
- },
- ruleControl:function(){//规则显示控制
- this.setData({
- ruleShow:!this.data.ruleShow
- })
- },
- chooseType:function(e){//选中的手机号类型
- if(e){
- this.setData({
- selectType:e.currentTarget.dataset.type
- })
- }else{
- this.setData({
- selectType:1
- })
- }
- },
- getAddressDetail: function (e) {//获取详细地址
- this.data.submitData.addressDetail = e.detail.value;
- this.setData({
- submitData:this.data.submitData
- })
- },
- getRealName:function(e){//获取用户输入的姓名
- this.data.submitData.realName = e.detail.value;
- this.setData({
- submitData:this.data.submitData
- })
- },
- getMobile:function(e){//获取用户输入的电话
- this.setData({
- mobile2:e.detail.value
- })
- },
- getCaptcha: function (e) {//获取用户输入的验证码
- this.data.submitData.captcha = e.detail.value;
- this.setData({
- submitData:this.data.submitData
- })
- },
- getCode: function (e) {//获取验证码
- if (!app.mobileVerify(this.data.mobile2)) {
- if (this.data.mobile2) {
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.sendCode) {
- return;
- }
- this.data.sendCode = false;
- app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
- if (res.code == 200) {
- this.countDown();
- wx.showToast({
- title: '验证码获取成功',
- icon: "none"
- })
- this.setData({
- verificationCode: 60
- })
- } else {
- this.data.sendCode = true;
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this)
- },
- countDown: function () {//倒计时
- setTimeout(() => {
- this.setData({
- verificationCode: this.data.verificationCode - 1
- })
- if (this.data.verificationCode > 0) {
- this.countDown();
- } else {
- this.setData({
- verificationCode: "获取验证码"
- })
- this.data.sendCode = true;
- }
- }, 1000);
- },
- getUserPhone: function (e) {//获取用户手机号
- if (e.detail.errMsg == 'getPhoneNumber:ok') {
- app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
- if (res.code == 200) {
- this.setData({
- phoneInputShow: true
- })
- this.chooseType();
- if (res.data && res.data.decodeData) {
- this.data.submitData.mobile = res.data.decodeData.phoneNumber;
- this.setData({
- submitData: this.data.submitData
- })
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- }
- },
- getAddress: function () {//获取地址
- app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
- console.log(res);
- if (res.code == 200) {
- if (res.data) {
- this.data.submitData.realName = res.data.realName;
- this.data.submitData.mobile = res.data.mobile;
- this.data.submitData.province = res.data.province;
- this.data.submitData.city = res.data.city;
- this.data.submitData.addressDetail = res.data.addressDetail;
- this.setData({
- submitData: this.data.submitData,
- mobile2:res.data.mobile
- })
- if(!res.data.agentDetail){
- this.getUserLocation();//获取用户当前位置
- }
- }else{
- this.getUserLocation();//获取用户当前位置
- this.setData({
- isUserAddress:false
- })
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- getUserLocation: function (e) {//获取用户地理位置
- wx.getLocation({
- type: 'wgs84', //wgs84 gcj02
- 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)
- }
- //将数据赋值给变量
- var storeArr = res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children;
- var storeValue = res.data.nearData.agentIndex;
- this.data.submitData.agentDetail = storeArr[storeValue].agent_detail;
- this.data.submitData.agent_code = storeArr[storeValue].agent_code;
- this.data.submitData.province = province[res.data.nearData.provinceIndex];
- this.data.submitData.city = city[res.data.nearData.cityIndex];
- 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: storeArr,
- storeValue: storeValue
- })
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- 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
- })
- },
- submitUserMsg:function(){//数据提交
- if (!this.data.submitData.realName) {
- wx.showToast({
- title: '请输入姓名',
- icon: "none"
- })
- return;
- }
- if (!this.data.mobile2 && this.data.selectType==2) {
- wx.showToast({
- title: '请输入电话',
- icon: "none"
- })
- return;
- }
- if (this.data.selectType == 2) {
- if (!this.data.submitData.captcha) {
- wx.showToast({
- title: '请输入验证码',
- icon: "none"
- })
- return;
- }
- }
- if(this.data.httpState){
- return;
- }
- this.data.httpState = true;
- this.data.submitData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
- this.data.submitData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
- this.data.submitData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- this.data.submitData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- this.data.submitData.scene = app.globalData.sceneSource;
- if(this.data.isUserAddress){
- this.updateAddress();
- }else{
- this.addAddress();
- }
- },
- addAddress: function () {//添加地址
- var mobile = this.data.submitData.mobile;
- if(this.data.selectType==2){
- this.data.submitData.mobile = this.data.mobile2;
- }
- app.wxRequest(app.globalData.urlRoot + "address/addAddressV2", this.data.submitData, res => {
- this.data.httpState = false;
- if (res.code == 200) {
- this.windowTipControl();
- }else{
- this.data.submitData.mobile = mobile;
- wx.showToast({
- title: res.msg,
- })
- }
- }, this, "POST")
- },
- updateAddress: function () {//更新地址
- var mobile = this.data.submitData.mobile;
- if(this.data.selectType==2){
- this.data.submitData.mobile = this.data.mobile2;
- }
- app.wxRequest(app.globalData.urlRoot + "address/updateAddressV2", this.data.submitData, res => {
- this.data.httpState = false;
- if (res.code == 200) {
- this.windowTipControl();
- }else{
- this.data.submitData.mobile = mobile;
- wx.showToast({
- title: res.msg,
- })
- }
- }, this, "POST");
- },
- windowTipControl:function(){
- this.setData({
- windowTipShow:!this.data.windowTipShow
- })
- },
- enterGuess:function(){//去竞猜
- wx.redirectTo({
- url: '/pages/guessSecondPrize/guessSecondPrize',
- })
- }
- })
|