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

442 lines
13KB

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