东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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