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

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