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

341 行
10KB

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