东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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