东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

491 linhas
14KB

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