东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

591 lines
17KB

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