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

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