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

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