东风启辰小程序端
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.

index.js 18KB

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