|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- //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,
- appointment:true,
- subscribeData: {
- realname:"",//姓名
- mobile:"",//手机号
- captcha:"",//验证码
- province:"",//省份
- agent_code: "",//经销商编码
- agentDetail: "",//经销商详细信息
- parentOpenid: app.globalData.parentOpenid,//好友openid
- },
- startAdvertisingUrl:'',//开屏广告路径
- isStartAdvertising: 1,//开屏广告透明度
- isStartAdvertisingShow: true,//是否显示开屏广告
- // isRegister:false,//查询是否已注册
- bannerList:[],//banner列表
- videoList:[],//视频列表
- videoVideoControls:false,//是否显示视频控件
- mainShow:false,
- isOnce:false,
- userData:null,
- kvurl: null,//顶部大图
- kvurlH:0,
- showAppointment:false,
- placing:false,//是否显示下定按钮
- buyState:false,//下订状态
- isStartAdvertisingFunState:false,
- playBtnDeg:0,
- videoShow: false,
- yuyueShow: false,
- swiperGroup:{
- one:{
- nums:4,
- current:0
- },
- two: {
- nums: 4,
- current: 0
- },
- three: {
- nums: 7,
- current: 0
- },
- four: {
- nums: 2,
- current: 0
- }
- },
- showMaskNum:0,//要显示的弹窗
- addressShow:false,
- isAddress:false,//是否有地址
- drawNum:0,//可用抽奖次数
- },
- onLoad: function (options) {
- if (app.globalData.isFirstLogin) {
- // console.log("第一次进入");
- wx.reportAnalytics('event_source_launch', {
- source: options.source ? options.source :0
- });
- }
- app.globalData.nowPage = 1;
- if (app.globalData.isFirstLogin) {
- this.getStartAdvertising();
- }else{
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- }
- },
- loadFun: function () {
- if(app.globalData.luckyTokenList && app.globalData.luckyTokenList.length){
- this.setData({
- drawNum:app.globalData.luckyTokenList.length
- })
- }
- if (!app.globalData.addPageEnterState.index) {
- app.addPageEnter("2AF7D5B88BBFF4159C8079E963E72C9B");
- app.globalData.addPageEnterState.index = true;
- }
- this.setData({
- kvurl: app.globalData.kvurl,
- kvurlH: app.globalData.kvurlH
- })
- if (app.globalData.userInfoData) {
- this.setData({
- userData: app.globalData.userInfoData
- })
- }
- if (app.globalData.userMobile) {
- this.data.subscribeData.mobile = app.globalData.userMobile;
- this.setData({
- phoneInputShow: true,
- subscribeData: this.data.subscribeData
- })
- }
- if (app.globalData.isFirstLogin) {
- this.getHomeVideo();//获取视频
- } else {
- if (app.globalData.indexData.videoList) {
- this.setData({
- videoList: app.globalData.indexData.videoList
- })
- } else {
- this.getHomeVideo();//获取视频
- }
- }
- this.setData({
- mainShow: true,
- isStartAdvertisingShow: this.data.isOnce ? true : app.globalData.isFirstLogin,
- // isRegister: app.globalData.isRegister
- })
- this.getFirstMsg();
- },
- onShow:function () {
- if(app.globalData.luckyTokenList && app.globalData.luckyTokenList.length){
- this.setData({
- drawNum:app.globalData.luckyTokenList.length
- })
- }else{
- this.setData({
- drawNum: 0
- })
- }
- if (app.globalData.getBuyState) {
- this.getBuyStates();
- } else {
- app.globalData.buyStateSuccessFuc = this.getBuyStates;
- }
- this.setData({
- siteSelect: false
- })
- this.data.subscribeData.parentOpenid = app.globalData.parentOpenid;
- },
- getBuyStates:function(){
- this.setData({
- buyState: app.globalData.getBuyState.success
- })
- },
- 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
- })
- // if (!app.globalData.indexData.provinceArr) {
- // this.getUserLocation();//获取用户当前位置
- // }
- if (e.detail.errMsg=='getPhoneNumber:ok'){
- app.getMobile(e.detail.encryptedData, e.detail.iv,res=>{
- if (res.code == 200) {
- if (res.data && res.data.decodeData){
- this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
- this.setData({
- subscribeData: this.data.subscribeData
- })
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- },this);
- }
- },
- getUserLocation:function(e){
- wx.getLocation({
- type: 'gcj02', //
- success:(res)=>{
- // console.log(res);
- this.getDistributorList(res.longitude, res.latitude);
- },
- fail:(res)=>{
- this.getDistributorList("", "");
- },
- complete:(res)=>{
- this.setData({
- siteSelect: true,
- })
- }
- })
- },
- 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时
- // 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;
- }
- this.data.sendCode = false;
- app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, 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);
- },
- 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;
- }
- if (!this.data.appointment) {
- return;
- }
- this.data.appointment = false;
- app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
- this.data.appointment = true;
- if (res.code == 200) {
- wx.showToast({
- title: '预约成功'
- })
- this.data.subscribeData.realname = "";
- this.data.subscribeData.captcha = "";
- this.setData({
- subscribeData: this.data.subscribeData,
- verificationCode: '获取验证码',
- })
- this.setData({
- siteSelect: false
- })
- // 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 => {
- this.data.isOnce = true;
- if(res.code==200){
- this.setData({
- startAdvertisingUrl: res.data.picurl,
- mainShow:true,
- kvurl: res.data.kvurl
- })
- app.globalData.kvurl = res.data.kvurl;
- app.globalData.isFirstLogin = false;
- setTimeout(() => {
- this.isStartAdvertisingFun();
- }, 1000);
- }
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },this);
- },
- isStartAdvertisingFun:function(){
- if (this.data.isStartAdvertisingFunState){
- return;
- }
- this.data.isStartAdvertisingFunState = true;
- setTimeout(() => {
- const query = wx.createSelectorQuery()
- query.select('.kvurlImg').boundingClientRect()
- query.selectViewport().scrollOffset()
- query.exec((res) => {
- if (res.data && res.data[0]) {
- this.setData({
- kvurlH: res.data[0].height
- })
- app.globalData.kvurlH = res.data[0].height;
- }
- })
- }, 200)
- this.setData({
- isStartAdvertising: 0
- })
- setTimeout(() => {
- this.setData({
- isStartAdvertisingShow: false,
- })
- }, 1000);
- },
- 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{
- if (app.globalData.userMobile) {
- this.data.subscribeData.mobile = app.globalData.userMobile;
- this.setData({
- phoneInputShow:true,
- subscribeData: this.data.subscribeData
- })
- }
- }
- } else {
- console.log(res.msg)
- }
- }, this);
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return app.sharePack();
- },
- getUserWxMsg:function(e){
- if (e.detail.errMsg == "getUserInfo:ok") {
- this.setData({
- userData: e.detail.userInfo
- })
- app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
- }
- },
- showSite: function () {//显示地址选择框
- if (!this.data.siteSelect) {
- if (!app.globalData.indexData.provinceArr) {
- this.getUserLocation();//获取用户当前位置
- }else{
- this.setData({
- siteSelect:true
- })
- }
- }
- },
- lookMore: function () {
- wx.navigateTo({
- url: '/pages/moreType/moreType',
- })
- },
- vrLookCar: function () {
- wx.navigateTo({
- url: '/pages/vrLookCar/vrLookCar',
- })
- },
- compute: function () {
- wx.navigateTo({
- url: '/pages/compute/compute',
- })
- },
- lookConfigure: function () {
- wx.navigateTo({
- url: '/pages/configure/configure',
- })
- },
- openAppointment:function(){//预约
- this.setData({
- showAppointment: !this.data.showAppointment
- })
- },
- placingControl:function(){
- // if (app.globalData.getBuyState.success != this.data.buyState){
- // this.setData({
- // buyState: app.globalData.getBuyState.success
- // })
- // }
- if (this.data.buyState && !this.data.placing){
- wx.navigateTo({
- url: '/pages/rotaryDraw/rotaryDraw',
- })
- }else{
- this.setData({
- placing: !this.data.placing
- })
- }
- },
- swiperChange:function(e){
- var num = e.currentTarget.dataset.num;
- if(num==1){
- this.data.swiperGroup.one.current = e.detail.current;
- } else if (num == 2) {
- this.data.swiperGroup.two.current = e.detail.current;
- } else if (num == 3) {
- this.data.swiperGroup.three.current = e.detail.current;
- } else if (num == 4) {
- this.data.swiperGroup.four.current = e.detail.current;
- }
- this.setData({
- swiperGroup: this.data.swiperGroup
- })
- },
- leftSlide:function(e){
- var num = e.currentTarget.dataset.num;
- if (num == 1 && this.data.swiperGroup.one.current>0) {
- this.data.swiperGroup.one.current-=1;
- } else if (num == 2 && this.data.swiperGroup.two.current > 0) {
- this.data.swiperGroup.two.current -= 1;
- } else if (num == 3 && this.data.swiperGroup.three.current > 0) {
- this.data.swiperGroup.three.current -= 1;
- } else if (num == 4 && this.data.swiperGroup.four.current > 0) {
- this.data.swiperGroup.four.current -= 1;
- }
- this.setData({
- swiperGroup: this.data.swiperGroup
- })
- },
- rightSlide: function (e) {
- var num = e.currentTarget.dataset.num;
- if (num == 1 && this.data.swiperGroup.one.current < this.data.swiperGroup.one.nums-1) {
- this.data.swiperGroup.one.current += 1;
- } else if (num == 2 && this.data.swiperGroup.two.current < this.data.swiperGroup.two.nums - 1) {
- this.data.swiperGroup.two.current += 1;
- } else if (num == 3 && this.data.swiperGroup.three.current < this.data.swiperGroup.three.nums - 1) {
- this.data.swiperGroup.three.current += 1;
- } else if (num == 4 && this.data.swiperGroup.four.current < this.data.swiperGroup.four.nums - 1) {
- this.data.swiperGroup.four.current += 1;
- }
- this.setData({
- swiperGroup: this.data.swiperGroup
- })
- },
- playVideo:function(){
- var animation = wx.createAnimation({
- duration: 300
- });
- animation.rotate(360).step();
- this.setData({
- playBtnDeg: animation.export()
- })
- setTimeout(()=>{
- this.setData({
- videoShow:true
- })
- var videoContext = wx.createVideoContext("myVideo");
- videoContext.requestFullScreen({ direction:0});
- videoContext.play();
-
- animation.rotate(0).step();
- this.setData({
- playBtnDeg: animation.export()
- })
- },300);
- },
- closeFull:function(e){
- if (!e.detail.fullScreen) {
- this.setData({
- videoShow: false
- })
- }
- },
- openYuyue: function () {//预约
- this.setData({
- yuyueShow: !this.data.yuyueShow
- })
- },
- getFirstMsg(){
- app.wxRequest(app.globalData.urlRoot + "msg/getFirstMsg", {}, res => {
- if(res.code == 200){
- if(res.data.msgId){
- this.getAddress();
- }
- this.setData({
- showMaskNum:res.data.msgId
- })
- }
- },this)
- },
- hiddenMask: function () {
- this.setData({
- showMaskNum: 0
- })
- },
- addressControl: function () {//跳转到地址管理
- this.setData({
- addressShow: !this.data.addressShow
- })
- this.hiddenMask();
- // if (this.data.addressShow) {
- // app.globalData.skipType = 'mycenter';
- // }
- },
- getAddress: function () {//获取地址
- app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.setData({
- isAddress:true
- })
- }
- }
- }, this)
- }
- })
|