|
- //index.js
- //获取应用实例
- const app = getApp()
- Page({
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- phoneInputShow:false,//是否显示电话输入框
- siteSelect: false,//是否显示位置选择框
- provinceArr:[],//省
- provinceValue: 0,//选中的省下标
- storeArr:[],//店铺
- storeValue:0,//选中的店铺下标
- swiperCurrent:0,//swiper选中的元素下标
- verificationCode: '获取验证码',//验证码文案
- sendCode: true,
- subscribeData: {
- realname:"",//姓名
- mobile:"",//手机号
- captcha:"",//验证码
- province:"",//省份
- agent_code: "",//经销商编码
- agentDetail: "",//经销商详细信息
- parentOpenid: "",//好友openid
- },
- startAdvertisingUrl:'',//开屏广告路径
- isStartAdvertising: 1,//开屏广告透明度
- isStartAdvertisingShow: true,//是否显示开屏广告
- isRegister:false,//查询是否已注册
- bannerList:[],//banner列表
- videoList:[],//视频列表
- videoVideoControls:false,//是否显示视频控件
- mainShow:false,
- },
- onLoad: function () {
- if (app.globalData.isFirstLogin) {
- this.getStartAdvertising();
- }
- },
- loadFun: function () {
- if (app.globalData.isFirstLogin) {
- this.getHomeBanner();//获取banner
- this.getHomeVideo();//获取视频
- this.getOrderInfo();
- } else {
- this.setData({
- mainShow:true,
- isStartAdvertisingShow:false,
- bannerList: app.globalData.indexData.bannerList,
- videoList: app.globalData.indexData.videoList,
- provinceArr: app.globalData.indexData.provinceArr,
- storeArr: app.globalData.indexData.storeArr,
- provinceValue: app.globalData.indexData.provinceValue,
- storeValue: app.globalData.indexData.storeValue,
- isRegister: app.globalData.isRegister
- })
- this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
- this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- }
- },
- provinceChane: function (e) {//选中省
- this.setData({
- provinceValue: e.detail.value,
- storeArr: this.data.provinceArr[e.detail.value].children,
- storeValue:0
- })
- this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
- this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- },
- storeChane: function (e) {//选中店铺
- this.setData({
- storeValue: e.detail.value,
- })
- this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- },
- getUserPhone:function(e){//获取用户手机号
- this.setData({
- phoneInputShow: true
- })
- this.getUserLocation();//获取用户当前位置
- if (e.detail.errMsg=='getPhoneNumber:ok'){
- this.setData({
- siteSelect: true,
- })
- app.wxRequest(app.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: e.detail.encryptedData, iv: e.detail.iv }, res => {
- if (res.code == 200) {
- this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
- this.setData({
- subscribeData: this.data.subscribeData
- })
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this,"POST");
- }else{
- this.setData({
- siteSelect: true,
- })
- }
- },
- getUserLocation:function(e){
- wx.getLocation({
- type: 'gcj02', //wgs84
- success:(res)=>{
- // console.log(res);
- this.getDistributorList(res.longitude, res.latitude);
- },
- fail:(res)=>{
- this.getDistributorList("", "");
- }
- })
- },
- prevImg(){//上一张图片
- if (this.data.swiperCurrent>0) {
- this.setData({
- swiperCurrent: this.data.swiperCurrent-=1,
- })
- }
- },
- nextImg() {//下一张图片
- if (this.data.swiperCurrent < this.data.bannerList.length-1) {
- this.setData({
- swiperCurrent: this.data.swiperCurrent+=1,
- })
- }
- },
- swiperChange(e){//通过鼠标滑动改变swiper时
- if (e.detail.source == "touch"){
- this.setData({
- swiperCurrent: e.detail.current,
- })
- }
- },
- getDistributorList: function (longitude, latitude){//获取经销商列表
- app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude}, res => {
- if (res.code == 200) {
- this.setData({
- provinceArr: res.data.list,
- storeArr: res.data.list[res.data.nearData.provinceIndex].children,
- provinceValue: res.data.nearData.provinceIndex,
- storeValue: res.data.nearData.cityIndex
- })
- this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
- this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- app.globalData.indexData.provinceArr = res.data.list;
- app.globalData.indexData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
- app.globalData.indexData.provinceValue = res.data.nearData.provinceIndex;
- app.globalData.indexData.storeValue = res.data.nearData.cityIndex;
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- getCode: function (e) {//获取验证码
- if (!app.mobileVerify(this.data.subscribeData.mobile)) {
- if (this.data.subscribeData.mobile){
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- }else{
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.sendCode){
- return;
- }
- app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile:this.data.subscribeData.mobile},res=>{
- console.log(res);
- if (res.code == 200) {
- this.countDown();
- wx.showToast({
- title: '验证码获取成功',
- icon: "none"
- })
- this.setData({
- verificationCode:60
- })
- this.data.sendCode = false;
- }else{
- 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);
- },
- getRealname: function (e) {//获取用户输入的姓名
- this.data.subscribeData.realname = e.detail.value;
- },
- getMobile: function (e) {//获取用户输入的电话
- this.data.subscribeData.mobile = e.detail.value;
- },
- getCaptcha: function (e) {//获取用户输入的验证码
- this.data.subscribeData.captcha = e.detail.value;
- },
- subscribeFun: function (e) {//预约鉴赏
- if (!this.data.subscribeData.realname) {
- wx.showToast({
- title: '请输入姓名',
- icon: "none"
- })
- return;
- }
- if (!this.data.subscribeData.mobile) {
- wx.showToast({
- title: '请输入电话',
- icon: "none"
- })
- return;
- }
- if (!this.data.subscribeData.captcha) {
- wx.showToast({
- title: '请输入验证码',
- icon: "none"
- })
- return;
- }
- app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
- if (res.code == 200) {
- wx.showToast({
- title: '预约成功'
- })
- this.setData({
- isRegister:true
- })
- app.globalData.isRegister = true;
- app.globalData.userMobile = this.data.subscribeData.mobile;
- // wx.redirectTo({
- // url: "../myCenter/myCenter?sourcePage='home'"
- // })
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this, "POST")
- },
- getStartAdvertising: function () {//获取开屏广告
- app.wxRequest(app.globalData.urlRoot +"home/getStartAdvertising",{},res=>{
- if(res.code==200){
-
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
-
- this.setData({
- startAdvertisingUrl: res.data.picurl,
- mainShow:true
- })
- app.globalData.isFirstLogin = false;
- setTimeout(() => {
- this.setData({
- isStartAdvertising: 0
- })
- setTimeout(()=>{
- this.setData({
- isStartAdvertisingShow:false
- })
- },1000);
- }, 3000);
- }
- },this);
- },
- getHomeBanner: function () {//获取banner
- app.wxRequest(app.globalData.urlRoot + "home/getHomeBanner", {}, res => {
- if (res.code == 200) {
- this.setData({
- bannerList:res.data
- })
- app.globalData.indexData.bannerList = res.data;
- }
- }, this);
- },
- getHomeVideo: function () {//获取视频
- app.wxRequest(app.globalData.urlRoot + "home/getHomeVideo", {}, res => {
- if (res.code == 200) {
- this.setData({
- videoList:res.data[0]
- })
- app.globalData.indexData.videoList = res.data[0];
- }
- }, this);
- },
- hideVideoControls: function () {//显示视频控件
- wx.createVideoContext("video").play();
- this.setData({
- videoVideoControls:true
- })
- },
- getOrderInfo: function () {//查询是否已注册
- app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.setData({
- isRegister: true
- })
- app.globalData.isRegister = true;
- app.globalData.userMobile = res.data.mobile;
- }
- } else {
- console.log(res.msg)
- }
- }, this);
- }
- })
|