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

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