东风启辰小程序端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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