东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. }
  62. if (app.globalData.isFirstLogin) {
  63. this.getHomeBanner();//获取banner
  64. this.getHomeVideo();//获取视频
  65. } else {
  66. if (app.globalData.indexData.bannerList){
  67. this.setData({
  68. bannerList: app.globalData.indexData.bannerList
  69. })
  70. } else {
  71. this.getHomeBanner();//获取banner
  72. }
  73. if (app.globalData.indexData.videoList) {
  74. this.setData({
  75. videoList: app.globalData.indexData.videoList
  76. })
  77. } else {
  78. this.getHomeVideo();//获取视频
  79. }
  80. if (app.globalData.indexData.provinceArr){
  81. this.setData({
  82. provinceArr: app.globalData.indexData.provinceArr,
  83. storeArr: app.globalData.indexData.storeArr,
  84. provinceValue: app.globalData.indexData.provinceValue,
  85. storeValue: app.globalData.indexData.storeValue
  86. })
  87. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  88. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  89. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  90. }
  91. }
  92. // if (!app.globalData.isRegister) {
  93. // this.getOrderInfo();
  94. // }
  95. this.setData({
  96. mainShow: true,
  97. isStartAdvertisingShow: this.data.isOnce ? true : app.globalData.isFirstLogin,
  98. // isRegister: app.globalData.isRegister
  99. })
  100. },
  101. onShow:function(){
  102. this.setData({
  103. siteSelect: false
  104. })
  105. this.data.subscribeData.parentOpenid = app.globalData.friendOpenid;
  106. },
  107. provinceChane: function (e) {//选中省
  108. this.setData({
  109. provinceValue: e.detail.value,
  110. storeArr: this.data.provinceArr[e.detail.value].children,
  111. storeValue:0
  112. })
  113. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  114. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  115. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  116. },
  117. storeChane: function (e) {//选中店铺
  118. this.setData({
  119. storeValue: e.detail.value,
  120. })
  121. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  122. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  123. },
  124. getUserPhone:function(e){//获取用户手机号
  125. this.setData({
  126. phoneInputShow: true
  127. })
  128. // if (!app.globalData.indexData.provinceArr) {
  129. // this.getUserLocation();//获取用户当前位置
  130. // }
  131. if (e.detail.errMsg=='getPhoneNumber:ok'){
  132. app.getMobile(e.detail.encryptedData, e.detail.iv,res=>{
  133. if (res.code == 200) {
  134. if (res.data && res.data.decodeData){
  135. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  136. this.setData({
  137. subscribeData: this.data.subscribeData
  138. })
  139. }
  140. } else {
  141. wx.showToast({
  142. title: res.msg,
  143. icon: "none"
  144. })
  145. }
  146. },this);
  147. }
  148. },
  149. getUserLocation:function(e){
  150. wx.getLocation({
  151. type: 'gcj02', //
  152. success:(res)=>{
  153. // console.log(res);
  154. this.getDistributorList(res.longitude, res.latitude);
  155. },
  156. fail:(res)=>{
  157. this.getDistributorList("", "");
  158. },
  159. complete:(res)=>{
  160. this.setData({
  161. siteSelect: true,
  162. })
  163. }
  164. })
  165. },
  166. prevImg(){//上一张图片
  167. if (this.data.swiperCurrent>0) {
  168. this.setData({
  169. swiperCurrent: this.data.swiperCurrent-=1,
  170. })
  171. }
  172. },
  173. nextImg() {//下一张图片
  174. if (this.data.swiperCurrent < this.data.bannerList.length-1) {
  175. this.setData({
  176. swiperCurrent: this.data.swiperCurrent+=1,
  177. })
  178. }
  179. },
  180. swiperChange(e){//通过鼠标滑动改变swiper时
  181. this.setData({
  182. swiperCurrent: e.detail.current,
  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. siteSelect: false
  311. })
  312. // this.setData({
  313. // isRegister:true
  314. // })
  315. // app.globalData.isRegister = true;
  316. app.globalData.userMobile = this.data.subscribeData.mobile;
  317. // wx.redirectTo({
  318. // url: "../myCenter/myCenter?sourcePage='home'"
  319. // })
  320. } else {
  321. wx.showToast({
  322. title: res.msg,
  323. icon: "none"
  324. })
  325. }
  326. }, this, "POST")
  327. },
  328. getStartAdvertising: function () {//获取开屏广告
  329. app.wxRequest(app.globalData.urlRoot + "home/getStartAdvertising", {}, res => {
  330. this.data.isOnce = true;
  331. if (app.globalData.openid) {
  332. this.loadFun();
  333. } else {
  334. app.globalData.openidSuccessFuc = this.loadFun;
  335. }
  336. if(res.code==200){
  337. this.setData({
  338. startAdvertisingUrl: res.data.picurl,
  339. mainShow:true
  340. })
  341. app.globalData.isFirstLogin = false;
  342. setTimeout(() => {
  343. this.setData({
  344. isStartAdvertising: 0
  345. })
  346. setTimeout(()=>{
  347. this.setData({
  348. isStartAdvertisingShow:false,
  349. })
  350. },1000);
  351. }, 3000);
  352. }
  353. },this);
  354. },
  355. getHomeBanner: function () {//获取banner
  356. app.wxRequest(app.globalData.urlRoot + "home/getHomeBanner", {}, res => {
  357. if (res.code == 200) {
  358. this.setData({
  359. bannerList:res.data
  360. })
  361. app.globalData.indexData.bannerList = res.data;
  362. }
  363. }, this);
  364. },
  365. getHomeVideo: function () {//获取视频
  366. app.wxRequest(app.globalData.urlRoot + "home/getHomeVideo", {}, res => {
  367. if (res.code == 200) {
  368. this.setData({
  369. videoList:res.data[0]
  370. })
  371. app.globalData.indexData.videoList = res.data[0];
  372. }
  373. }, this);
  374. },
  375. hideVideoControls: function () {//显示视频控件
  376. wx.createVideoContext("video").play();
  377. this.setData({
  378. videoVideoControls:true
  379. })
  380. },
  381. getOrderInfo: function () {//查询是否已注册
  382. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  383. if (res.code == 200) {
  384. if (res.data) {
  385. // this.setData({
  386. // isRegister: true
  387. // })
  388. // app.globalData.isRegister = true;
  389. app.globalData.userMobile = res.data.mobile;
  390. }else{
  391. if (app.globalData.userMobile) {
  392. this.data.subscribeData.mobile = app.globalData.userMobile;
  393. this.setData({
  394. phoneInputShow:true,
  395. subscribeData: this.data.subscribeData
  396. })
  397. }
  398. }
  399. } else {
  400. console.log(res.msg)
  401. }
  402. }, this);
  403. },
  404. /**
  405. * 用户点击右上角分享
  406. */
  407. onShareAppMessage: function () {
  408. return app.sharePack();
  409. },
  410. getUserWxMsg:function(e){
  411. if (e.detail.errMsg == "getUserInfo:ok") {
  412. this.setData({
  413. userData: e.detail.userInfo
  414. })
  415. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  416. }
  417. },
  418. showSite: function () {//显示地址选择框
  419. if (!this.data.siteSelect) {
  420. if (!app.globalData.indexData.provinceArr) {
  421. this.getUserLocation();//获取用户当前位置
  422. }else{
  423. this.setData({
  424. siteSelect:true
  425. })
  426. }
  427. }
  428. },
  429. lookMore: function () {
  430. wx.navigateTo({
  431. url: '/pages/moreType/moreType',
  432. })
  433. }
  434. })