东风启辰小程序端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

699 lines
20KB

  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. imgUrl: app.globalData.urlStatic,//图片路径
  7. phoneInputShow:false,//是否显示电话输入框
  8. siteSelect: false,//是否显示位置选择框
  9. provinceArr:[],//省
  10. provinceValue: 0,//选中的省下标
  11. storeArr:[],//店铺
  12. storeValue:0,//选中的店铺下标
  13. swiperCurrent:0,//swiper选中的元素下标
  14. verificationCode: '获取验证码',//验证码文案
  15. sendCode: true,
  16. appointment:true,
  17. subscribeData: {
  18. realname:"",//姓名
  19. mobile:"",//手机号
  20. captcha:"",//验证码
  21. province:"",//省份
  22. agent_code: "",//经销商编码
  23. agentDetail: "",//经销商详细信息
  24. parentOpenid: app.globalData.parentOpenid,//好友openid
  25. },
  26. startAdvertisingUrl:'',//开屏广告路径
  27. isStartAdvertising: 1,//开屏广告透明度
  28. isStartAdvertisingShow: true,//是否显示开屏广告
  29. // isRegister:false,//查询是否已注册
  30. bannerList:[],//banner列表
  31. videoList:[],//视频列表
  32. videoVideoControls:false,//是否显示视频控件
  33. mainShow:false,
  34. isOnce:false,
  35. userData:null,
  36. kvurl: null,//顶部大图
  37. kvurlH:0,
  38. showAppointment:false,
  39. placing:false,//是否显示下定按钮
  40. buyState:false,//下订状态
  41. isStartAdvertisingFunState:false,
  42. playBtnDeg:0,
  43. videoShow: false,
  44. yuyueShow: false,
  45. swiperGroup:{
  46. one:{
  47. nums:4,
  48. current:0
  49. },
  50. two: {
  51. nums: 4,
  52. current: 0
  53. },
  54. three: {
  55. nums: 7,
  56. current: 0
  57. },
  58. four: {
  59. nums: 2,
  60. current: 0
  61. }
  62. },
  63. showMaskNum:0,//要显示的弹窗
  64. addressShow:false,
  65. isAddress:false,//是否有地址
  66. drawNum:0,//可用抽奖次数
  67. maskNewCard:false,
  68. },
  69. onLoad: function (options) {
  70. if (app.globalData.isFirstLogin) {
  71. // console.log("第一次进入");
  72. wx.reportAnalytics('event_source_launch', {
  73. source: options.source ? options.source :0
  74. });
  75. }
  76. app.globalData.nowPage = 1;
  77. if (app.globalData.isFirstLogin) {
  78. this.getStartAdvertising();
  79. }else{
  80. if (app.globalData.openid) {
  81. this.loadFun();
  82. } else {
  83. app.globalData.openidSuccessFuc = this.loadFun;
  84. }
  85. }
  86. },
  87. loadFun: function () {
  88. if (!app.globalData.addPageEnterState.index) {
  89. app.addPageEnter("2AF7D5B88BBFF4159C8079E963E72C9B");
  90. app.globalData.addPageEnterState.index = true;
  91. }
  92. this.setData({
  93. kvurl: app.globalData.kvurl,
  94. kvurlH: app.globalData.kvurlH
  95. })
  96. if (app.globalData.userInfoData) {
  97. this.setData({
  98. userData: app.globalData.userInfoData
  99. })
  100. }
  101. if (app.globalData.userMobile) {
  102. this.data.subscribeData.mobile = app.globalData.userMobile;
  103. this.setData({
  104. phoneInputShow: true,
  105. subscribeData: this.data.subscribeData
  106. })
  107. }
  108. if (app.globalData.isFirstLogin) {
  109. this.getHomeVideo();//获取视频
  110. } else {
  111. if (app.globalData.indexData.videoList) {
  112. this.setData({
  113. videoList: app.globalData.indexData.videoList
  114. })
  115. } else {
  116. this.getHomeVideo();//获取视频
  117. }
  118. }
  119. this.setData({
  120. mainShow: true,
  121. isStartAdvertisingShow: this.data.isOnce ? true : app.globalData.isFirstLogin,
  122. // isRegister: app.globalData.isRegister
  123. })
  124. this.getFirstMsg();
  125. },
  126. onShow:function () {
  127. if(app.globalData.luckyTokenList && app.globalData.luckyTokenList.length){
  128. this.setData({
  129. drawNum:app.globalData.luckyTokenList.length
  130. })
  131. }else{
  132. this.setData({
  133. drawNum: 0
  134. })
  135. }
  136. if (app.globalData.getBuyState) {
  137. this.getBuyStates();
  138. } else {
  139. app.globalData.buyStateSuccessFuc = this.getBuyStates;
  140. }
  141. this.setData({
  142. siteSelect: false
  143. })
  144. this.data.subscribeData.parentOpenid = app.globalData.parentOpenid;
  145. },
  146. getBuyStates:function(){
  147. this.setData({
  148. buyState: app.globalData.getBuyState.success
  149. })
  150. if(app.globalData.luckyTokenList && app.globalData.luckyTokenList.length){
  151. this.setData({
  152. drawNum:app.globalData.luckyTokenList.length
  153. })
  154. }
  155. },
  156. provinceChane: function (e) {//选中省
  157. this.setData({
  158. provinceValue: e.detail.value,
  159. storeArr: this.data.provinceArr[e.detail.value].children,
  160. storeValue:0
  161. })
  162. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  163. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  164. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  165. },
  166. storeChane: function (e) {//选中店铺
  167. this.setData({
  168. storeValue: e.detail.value,
  169. })
  170. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  171. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  172. },
  173. getUserPhone:function(e){//获取用户手机号
  174. this.setData({
  175. phoneInputShow: true
  176. })
  177. // if (!app.globalData.indexData.provinceArr) {
  178. // this.getUserLocation();//获取用户当前位置
  179. // }
  180. if (e.detail.errMsg=='getPhoneNumber:ok'){
  181. app.getMobile(e.detail.encryptedData, e.detail.iv,res=>{
  182. if (res.code == 200) {
  183. if (res.data && res.data.decodeData){
  184. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  185. this.setData({
  186. subscribeData: this.data.subscribeData
  187. })
  188. }
  189. } else {
  190. wx.showToast({
  191. title: res.msg,
  192. icon: "none"
  193. })
  194. }
  195. },this);
  196. }
  197. },
  198. getUserLocation:function(e){
  199. wx.getLocation({
  200. type: 'gcj02', //
  201. success:(res)=>{
  202. // console.log(res);
  203. this.getDistributorList(res.longitude, res.latitude);
  204. },
  205. fail:(res)=>{
  206. this.getDistributorList("", "");
  207. },
  208. complete:(res)=>{
  209. this.setData({
  210. siteSelect: true,
  211. })
  212. }
  213. })
  214. },
  215. prevImg(){//上一张图片
  216. if (this.data.swiperCurrent>0) {
  217. this.setData({
  218. swiperCurrent: this.data.swiperCurrent-=1,
  219. })
  220. }
  221. },
  222. nextImg() {//下一张图片
  223. if (this.data.swiperCurrent < this.data.bannerList.length-1) {
  224. this.setData({
  225. swiperCurrent: this.data.swiperCurrent+=1,
  226. })
  227. }
  228. },
  229. // swiperChange(e){//通过鼠标滑动改变swiper时
  230. // this.setData({
  231. // swiperCurrent: e.detail.current,
  232. // })
  233. // },
  234. getDistributorList: function (longitude, latitude){//获取经销商列表
  235. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude}, res => {
  236. if (res.code == 200) {
  237. this.setData({
  238. provinceArr: res.data.list,
  239. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  240. provinceValue: res.data.nearData.provinceIndex,
  241. storeValue: res.data.nearData.cityIndex
  242. })
  243. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  244. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  245. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  246. app.globalData.indexData.provinceArr = res.data.list;
  247. app.globalData.indexData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  248. app.globalData.indexData.provinceValue = res.data.nearData.provinceIndex;
  249. app.globalData.indexData.storeValue = res.data.nearData.cityIndex;
  250. } else {
  251. wx.showToast({
  252. title: res.msg,
  253. icon: "none"
  254. })
  255. }
  256. }, this);
  257. },
  258. getCode: function (e) {//获取验证码
  259. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  260. if (this.data.subscribeData.mobile){
  261. wx.showToast({
  262. title: '请输入正确的电话',
  263. icon: 'none'
  264. })
  265. }else{
  266. wx.showToast({
  267. title: '请输入电话',
  268. icon: 'none'
  269. })
  270. }
  271. return;
  272. }
  273. if (!this.data.sendCode){
  274. return;
  275. }
  276. this.data.sendCode = false;
  277. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  278. if (res.code == 200) {
  279. this.countDown();
  280. wx.showToast({
  281. title: '验证码获取成功',
  282. icon: "none"
  283. })
  284. this.setData({
  285. verificationCode:60
  286. })
  287. } else {
  288. this.data.sendCode = true;
  289. wx.showToast({
  290. title: res.msg,
  291. icon: "none"
  292. })
  293. }
  294. },this)
  295. },
  296. countDown: function () {//倒计时
  297. setTimeout(() => {
  298. this.setData({
  299. verificationCode: this.data.verificationCode - 1
  300. })
  301. if (this.data.verificationCode > 0) {
  302. this.countDown();
  303. } else {
  304. this.setData({
  305. verificationCode: "获取验证码"
  306. })
  307. this.data.sendCode = true;
  308. }
  309. }, 1000);
  310. },
  311. getRealname: function (e) {//获取用户输入的姓名
  312. this.data.subscribeData.realname = e.detail.value;
  313. },
  314. getMobile: function (e) {//获取用户输入的电话
  315. this.data.subscribeData.mobile = e.detail.value;
  316. },
  317. getCaptcha: function (e) {//获取用户输入的验证码
  318. this.data.subscribeData.captcha = e.detail.value;
  319. },
  320. subscribeFun: function (e) {//预约鉴赏
  321. if (!this.data.subscribeData.realname) {
  322. wx.showToast({
  323. title: '请输入姓名',
  324. icon: "none"
  325. })
  326. return;
  327. }
  328. if (!this.data.subscribeData.mobile) {
  329. wx.showToast({
  330. title: '请输入电话',
  331. icon: "none"
  332. })
  333. return;
  334. }
  335. if (!this.data.subscribeData.captcha) {
  336. wx.showToast({
  337. title: '请输入验证码',
  338. icon: "none"
  339. })
  340. return;
  341. }
  342. if (!this.data.appointment) {
  343. return;
  344. }
  345. this.data.appointment = false;
  346. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  347. this.data.appointment = true;
  348. if (res.code == 200) {
  349. wx.showToast({
  350. title: '预约成功'
  351. })
  352. this.data.subscribeData.realname = "";
  353. this.data.subscribeData.captcha = "";
  354. this.setData({
  355. subscribeData: this.data.subscribeData,
  356. verificationCode: '获取验证码',
  357. })
  358. this.setData({
  359. siteSelect: false
  360. })
  361. // this.setData({
  362. // isRegister:true
  363. // })
  364. // app.globalData.isRegister = true;
  365. app.globalData.userMobile = this.data.subscribeData.mobile;
  366. // wx.redirectTo({
  367. // url: "../myCenter/myCenter?sourcePage='home'"
  368. // })
  369. } else {
  370. wx.showToast({
  371. title: res.msg,
  372. icon: "none"
  373. })
  374. }
  375. }, this, "POST")
  376. },
  377. getStartAdvertising: function () {//获取开屏广告
  378. app.wxRequest(app.globalData.urlRoot + "home/getStartAdvertising", {}, res => {
  379. this.data.isOnce = true;
  380. if(res.code==200){
  381. this.setData({
  382. startAdvertisingUrl: res.data.picurl,
  383. mainShow:true,
  384. kvurl: res.data.kvurl
  385. })
  386. app.globalData.kvurl = res.data.kvurl;
  387. app.globalData.isFirstLogin = false;
  388. setTimeout(() => {
  389. this.isStartAdvertisingFun();
  390. }, 1000);
  391. }
  392. if (app.globalData.openid) {
  393. this.loadFun();
  394. } else {
  395. app.globalData.openidSuccessFuc = this.loadFun;
  396. }
  397. },this);
  398. },
  399. isStartAdvertisingFun:function(){
  400. if (this.data.isStartAdvertisingFunState){
  401. return;
  402. }
  403. this.data.isStartAdvertisingFunState = true;
  404. setTimeout(() => {
  405. const query = wx.createSelectorQuery()
  406. query.select('.kvurlImg').boundingClientRect()
  407. query.selectViewport().scrollOffset()
  408. query.exec((res) => {
  409. if (res.data && res.data[0]) {
  410. this.setData({
  411. kvurlH: res.data[0].height
  412. })
  413. app.globalData.kvurlH = res.data[0].height;
  414. }
  415. })
  416. }, 200)
  417. this.setData({
  418. isStartAdvertising: 0
  419. })
  420. setTimeout(() => {
  421. this.setData({
  422. isStartAdvertisingShow: false,
  423. })
  424. }, 1000);
  425. },
  426. getHomeBanner: function () {//获取banner
  427. app.wxRequest(app.globalData.urlRoot + "home/getHomeBanner", {}, res => {
  428. if (res.code == 200) {
  429. this.setData({
  430. bannerList:res.data
  431. })
  432. app.globalData.indexData.bannerList = res.data;
  433. }
  434. }, this);
  435. },
  436. getHomeVideo: function () {//获取视频
  437. app.wxRequest(app.globalData.urlRoot + "home/getHomeVideo", {}, res => {
  438. if (res.code == 200) {
  439. this.setData({
  440. videoList:res.data[0]
  441. })
  442. app.globalData.indexData.videoList = res.data[0];
  443. }
  444. }, this);
  445. },
  446. hideVideoControls: function () {//显示视频控件
  447. wx.createVideoContext("video").play();
  448. this.setData({
  449. videoVideoControls:true
  450. })
  451. },
  452. getOrderInfo: function () {//查询是否已注册
  453. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  454. if (res.code == 200) {
  455. if (res.data) {
  456. // this.setData({
  457. // isRegister: true
  458. // })
  459. // app.globalData.isRegister = true;
  460. app.globalData.userMobile = res.data.mobile;
  461. }else{
  462. if (app.globalData.userMobile) {
  463. this.data.subscribeData.mobile = app.globalData.userMobile;
  464. this.setData({
  465. phoneInputShow:true,
  466. subscribeData: this.data.subscribeData
  467. })
  468. }
  469. }
  470. } else {
  471. console.log(res.msg)
  472. }
  473. }, this);
  474. },
  475. /**
  476. * 用户点击右上角分享
  477. */
  478. onShareAppMessage: function () {
  479. return app.sharePack();
  480. },
  481. getUserWxMsg:function(e){
  482. if (e.detail.errMsg == "getUserInfo:ok") {
  483. this.setData({
  484. userData: e.detail.userInfo
  485. })
  486. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  487. }
  488. },
  489. showSite: function () {//显示地址选择框
  490. if (!this.data.siteSelect) {
  491. if (!app.globalData.indexData.provinceArr) {
  492. this.getUserLocation();//获取用户当前位置
  493. }else{
  494. this.setData({
  495. siteSelect:true
  496. })
  497. }
  498. }
  499. },
  500. lookMore: function () {
  501. wx.navigateTo({
  502. url: '/pages/moreType/moreType',
  503. })
  504. },
  505. navSkip:function(){
  506. wx.navigateToMiniProgram({
  507. appId: 'wx1d585c8c2fffe589',
  508. path:"package_activity/pages/mid_year_promotion/index"
  509. })
  510. },
  511. vrLookCar: function () {
  512. wx.navigateTo({
  513. url: '/pages/vrLookCar/vrLookCar',
  514. })
  515. },
  516. compute: function () {
  517. wx.navigateTo({
  518. url: '/pages/compute/compute',
  519. })
  520. },
  521. lookConfigure: function () {
  522. wx.navigateTo({
  523. url: '/pages/configure/configure',
  524. })
  525. },
  526. openAppointment:function(){//预约
  527. this.setData({
  528. showAppointment: !this.data.showAppointment
  529. })
  530. },
  531. placingControl:function(){
  532. console.log("是否已支付"+app.globalData.getBuyState.success);
  533. console.log("抽奖机会次数"+app.globalData.luckyTokenList.length);
  534. if(app.globalData.getBuyState.success && app.globalData.luckyTokenList.length){
  535. wx.navigateTo({
  536. url: '/pages/rotaryDraw/rotaryDraw',
  537. })
  538. }else{
  539. if(app.globalData.getBuyState.success && !app.globalData.luckyTokenList.length && !this.data.placing){
  540. this.maskNewControl();
  541. }else{
  542. this.setData({
  543. placing: !this.data.placing
  544. })
  545. }
  546. }
  547. return
  548. if(app.globalData.getBuyState){
  549. if(!app.globalData.getBuyState.success){
  550. this.setData({
  551. placing: !this.data.placing
  552. })
  553. }
  554. }
  555. if (this.data.buyState && !this.data.placing){
  556. wx.navigateTo({
  557. url: '/pages/rotaryDraw/rotaryDraw',
  558. })
  559. }else{
  560. if(this.data.buyState && !this.data.drawNum){
  561. this.maskNewControl();
  562. return;
  563. }else{
  564. this.setData({
  565. placing: !this.data.placing
  566. })
  567. }
  568. }
  569. console.log("是否打开了支付页面"+this.data.placing);
  570. console.log("是否已支付"+this.data.buyState);
  571. console.log("抽奖机会次数"+this.data.drawNum);
  572. },
  573. swiperChange:function(e){
  574. var num = e.currentTarget.dataset.num;
  575. if(num==1){
  576. this.data.swiperGroup.one.current = e.detail.current;
  577. } else if (num == 2) {
  578. this.data.swiperGroup.two.current = e.detail.current;
  579. } else if (num == 3) {
  580. this.data.swiperGroup.three.current = e.detail.current;
  581. } else if (num == 4) {
  582. this.data.swiperGroup.four.current = e.detail.current;
  583. }
  584. this.setData({
  585. swiperGroup: this.data.swiperGroup
  586. })
  587. },
  588. leftSlide:function(e){
  589. var num = e.currentTarget.dataset.num;
  590. if (num == 1 && this.data.swiperGroup.one.current>0) {
  591. this.data.swiperGroup.one.current-=1;
  592. } else if (num == 2 && this.data.swiperGroup.two.current > 0) {
  593. this.data.swiperGroup.two.current -= 1;
  594. } else if (num == 3 && this.data.swiperGroup.three.current > 0) {
  595. this.data.swiperGroup.three.current -= 1;
  596. } else if (num == 4 && this.data.swiperGroup.four.current > 0) {
  597. this.data.swiperGroup.four.current -= 1;
  598. }
  599. this.setData({
  600. swiperGroup: this.data.swiperGroup
  601. })
  602. },
  603. rightSlide: function (e) {
  604. var num = e.currentTarget.dataset.num;
  605. if (num == 1 && this.data.swiperGroup.one.current < this.data.swiperGroup.one.nums-1) {
  606. this.data.swiperGroup.one.current += 1;
  607. } else if (num == 2 && this.data.swiperGroup.two.current < this.data.swiperGroup.two.nums - 1) {
  608. this.data.swiperGroup.two.current += 1;
  609. } else if (num == 3 && this.data.swiperGroup.three.current < this.data.swiperGroup.three.nums - 1) {
  610. this.data.swiperGroup.three.current += 1;
  611. } else if (num == 4 && this.data.swiperGroup.four.current < this.data.swiperGroup.four.nums - 1) {
  612. this.data.swiperGroup.four.current += 1;
  613. }
  614. this.setData({
  615. swiperGroup: this.data.swiperGroup
  616. })
  617. },
  618. playVideo:function(){
  619. var animation = wx.createAnimation({
  620. duration: 300
  621. });
  622. animation.rotate(360).step();
  623. this.setData({
  624. playBtnDeg: animation.export()
  625. })
  626. setTimeout(()=>{
  627. this.setData({
  628. videoShow:true
  629. })
  630. var videoContext = wx.createVideoContext("myVideo");
  631. videoContext.requestFullScreen({ direction:0});
  632. videoContext.play();
  633. animation.rotate(0).step();
  634. this.setData({
  635. playBtnDeg: animation.export()
  636. })
  637. },300);
  638. },
  639. closeFull:function(e){
  640. if (!e.detail.fullScreen) {
  641. this.setData({
  642. videoShow: false
  643. })
  644. }
  645. },
  646. openYuyue: function () {//预约
  647. this.setData({
  648. yuyueShow: !this.data.yuyueShow
  649. })
  650. },
  651. getFirstMsg(){
  652. app.wxRequest(app.globalData.urlRoot + "msg/getFirstMsg", {}, res => {
  653. if(res.code == 200){
  654. if(res.data.msgId){
  655. this.getAddress();
  656. }
  657. this.setData({
  658. showMaskNum:res.data.msgId
  659. })
  660. }
  661. },this)
  662. },
  663. hiddenMask: function () {
  664. this.setData({
  665. showMaskNum: 0
  666. })
  667. },
  668. addressControl: function () {//跳转到地址管理
  669. this.setData({
  670. addressShow: !this.data.addressShow
  671. })
  672. this.hiddenMask();
  673. // if (this.data.addressShow) {
  674. // app.globalData.skipType = 'mycenter';
  675. // }
  676. },
  677. getAddress: function () {//获取地址
  678. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  679. if (res.code == 200) {
  680. if (res.data) {
  681. this.setData({
  682. isAddress:true
  683. })
  684. }
  685. }
  686. }, this)
  687. },
  688. maskNewControl(){
  689. this.setData({
  690. maskNewCard:!this.data.maskNewCard
  691. })
  692. }
  693. })