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

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