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

539 lines
16KB

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