东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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