东风启辰小程序端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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