东风启辰小程序端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

402 行
12KB

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