东风启辰小程序端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

637 行
18KB

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