东风启辰小程序端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

693 lines
19KB

  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. vrLookCar: function () {
  506. wx.navigateTo({
  507. url: '/pages/vrLookCar/vrLookCar',
  508. })
  509. },
  510. compute: function () {
  511. wx.navigateTo({
  512. url: '/pages/compute/compute',
  513. })
  514. },
  515. lookConfigure: function () {
  516. wx.navigateTo({
  517. url: '/pages/configure/configure',
  518. })
  519. },
  520. openAppointment:function(){//预约
  521. this.setData({
  522. showAppointment: !this.data.showAppointment
  523. })
  524. },
  525. placingControl:function(){
  526. console.log("是否已支付"+app.globalData.getBuyState.success);
  527. console.log("抽奖机会次数"+app.globalData.luckyTokenList.length);
  528. if(app.globalData.getBuyState.success && app.globalData.luckyTokenList.length){
  529. wx.navigateTo({
  530. url: '/pages/rotaryDraw/rotaryDraw',
  531. })
  532. }else{
  533. if(app.globalData.getBuyState.success && !app.globalData.luckyTokenList.length && !this.data.placing){
  534. this.maskNewControl();
  535. }else{
  536. this.setData({
  537. placing: !this.data.placing
  538. })
  539. }
  540. }
  541. return
  542. if(app.globalData.getBuyState){
  543. if(!app.globalData.getBuyState.success){
  544. this.setData({
  545. placing: !this.data.placing
  546. })
  547. }
  548. }
  549. if (this.data.buyState && !this.data.placing){
  550. wx.navigateTo({
  551. url: '/pages/rotaryDraw/rotaryDraw',
  552. })
  553. }else{
  554. if(this.data.buyState && !this.data.drawNum){
  555. this.maskNewControl();
  556. return;
  557. }else{
  558. this.setData({
  559. placing: !this.data.placing
  560. })
  561. }
  562. }
  563. console.log("是否打开了支付页面"+this.data.placing);
  564. console.log("是否已支付"+this.data.buyState);
  565. console.log("抽奖机会次数"+this.data.drawNum);
  566. },
  567. swiperChange:function(e){
  568. var num = e.currentTarget.dataset.num;
  569. if(num==1){
  570. this.data.swiperGroup.one.current = e.detail.current;
  571. } else if (num == 2) {
  572. this.data.swiperGroup.two.current = e.detail.current;
  573. } else if (num == 3) {
  574. this.data.swiperGroup.three.current = e.detail.current;
  575. } else if (num == 4) {
  576. this.data.swiperGroup.four.current = e.detail.current;
  577. }
  578. this.setData({
  579. swiperGroup: this.data.swiperGroup
  580. })
  581. },
  582. leftSlide:function(e){
  583. var num = e.currentTarget.dataset.num;
  584. if (num == 1 && this.data.swiperGroup.one.current>0) {
  585. this.data.swiperGroup.one.current-=1;
  586. } else if (num == 2 && this.data.swiperGroup.two.current > 0) {
  587. this.data.swiperGroup.two.current -= 1;
  588. } else if (num == 3 && this.data.swiperGroup.three.current > 0) {
  589. this.data.swiperGroup.three.current -= 1;
  590. } else if (num == 4 && this.data.swiperGroup.four.current > 0) {
  591. this.data.swiperGroup.four.current -= 1;
  592. }
  593. this.setData({
  594. swiperGroup: this.data.swiperGroup
  595. })
  596. },
  597. rightSlide: function (e) {
  598. var num = e.currentTarget.dataset.num;
  599. if (num == 1 && this.data.swiperGroup.one.current < this.data.swiperGroup.one.nums-1) {
  600. this.data.swiperGroup.one.current += 1;
  601. } else if (num == 2 && this.data.swiperGroup.two.current < this.data.swiperGroup.two.nums - 1) {
  602. this.data.swiperGroup.two.current += 1;
  603. } else if (num == 3 && this.data.swiperGroup.three.current < this.data.swiperGroup.three.nums - 1) {
  604. this.data.swiperGroup.three.current += 1;
  605. } else if (num == 4 && this.data.swiperGroup.four.current < this.data.swiperGroup.four.nums - 1) {
  606. this.data.swiperGroup.four.current += 1;
  607. }
  608. this.setData({
  609. swiperGroup: this.data.swiperGroup
  610. })
  611. },
  612. playVideo:function(){
  613. var animation = wx.createAnimation({
  614. duration: 300
  615. });
  616. animation.rotate(360).step();
  617. this.setData({
  618. playBtnDeg: animation.export()
  619. })
  620. setTimeout(()=>{
  621. this.setData({
  622. videoShow:true
  623. })
  624. var videoContext = wx.createVideoContext("myVideo");
  625. videoContext.requestFullScreen({ direction:0});
  626. videoContext.play();
  627. animation.rotate(0).step();
  628. this.setData({
  629. playBtnDeg: animation.export()
  630. })
  631. },300);
  632. },
  633. closeFull:function(e){
  634. if (!e.detail.fullScreen) {
  635. this.setData({
  636. videoShow: false
  637. })
  638. }
  639. },
  640. openYuyue: function () {//预约
  641. this.setData({
  642. yuyueShow: !this.data.yuyueShow
  643. })
  644. },
  645. getFirstMsg(){
  646. app.wxRequest(app.globalData.urlRoot + "msg/getFirstMsg", {}, res => {
  647. if(res.code == 200){
  648. if(res.data.msgId){
  649. this.getAddress();
  650. }
  651. this.setData({
  652. showMaskNum:res.data.msgId
  653. })
  654. }
  655. },this)
  656. },
  657. hiddenMask: function () {
  658. this.setData({
  659. showMaskNum: 0
  660. })
  661. },
  662. addressControl: function () {//跳转到地址管理
  663. this.setData({
  664. addressShow: !this.data.addressShow
  665. })
  666. this.hiddenMask();
  667. // if (this.data.addressShow) {
  668. // app.globalData.skipType = 'mycenter';
  669. // }
  670. },
  671. getAddress: function () {//获取地址
  672. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  673. if (res.code == 200) {
  674. if (res.data) {
  675. this.setData({
  676. isAddress:true
  677. })
  678. }
  679. }
  680. }, this)
  681. },
  682. maskNewControl(){
  683. this.setData({
  684. maskNewCard:!this.data.maskNewCard
  685. })
  686. }
  687. })