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

index.js 12KB

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