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

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