东风启辰小程序端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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