东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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