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

384 lines
11KB

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