东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

401 行
12KB

  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. res.data=null;
  124. if(res.data){
  125. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  126. this.setData({
  127. subscribeData: this.data.subscribeData
  128. })
  129. }
  130. } else {
  131. wx.showToast({
  132. title: res.msg,
  133. icon: "none"
  134. })
  135. }
  136. },this);
  137. }
  138. },
  139. getUserLocation:function(e){
  140. wx.getLocation({
  141. type: 'gcj02', //
  142. success:(res)=>{
  143. // console.log(res);
  144. this.getDistributorList(res.longitude, res.latitude);
  145. },
  146. fail:(res)=>{
  147. this.getDistributorList("", "");
  148. },
  149. complete:(res)=>{
  150. this.setData({
  151. siteSelect: true,
  152. })
  153. }
  154. })
  155. },
  156. prevImg(){//上一张图片
  157. if (this.data.swiperCurrent>0) {
  158. this.setData({
  159. swiperCurrent: this.data.swiperCurrent-=1,
  160. })
  161. }
  162. },
  163. nextImg() {//下一张图片
  164. if (this.data.swiperCurrent < this.data.bannerList.length-1) {
  165. this.setData({
  166. swiperCurrent: this.data.swiperCurrent+=1,
  167. })
  168. }
  169. },
  170. swiperChange(e){//通过鼠标滑动改变swiper时
  171. if (e.detail.source == "touch"){
  172. this.setData({
  173. swiperCurrent: e.detail.current,
  174. })
  175. }
  176. },
  177. getDistributorList: function (longitude, latitude){//获取经销商列表
  178. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude}, res => {
  179. if (res.code == 200) {
  180. this.setData({
  181. provinceArr: res.data.list,
  182. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  183. provinceValue: res.data.nearData.provinceIndex,
  184. storeValue: res.data.nearData.cityIndex
  185. })
  186. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  187. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  188. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  189. app.globalData.indexData.provinceArr = res.data.list;
  190. app.globalData.indexData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  191. app.globalData.indexData.provinceValue = res.data.nearData.provinceIndex;
  192. app.globalData.indexData.storeValue = res.data.nearData.cityIndex;
  193. } else {
  194. wx.showToast({
  195. title: res.msg,
  196. icon: "none"
  197. })
  198. }
  199. }, this);
  200. },
  201. getCode: function (e) {//获取验证码
  202. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  203. if (this.data.subscribeData.mobile){
  204. wx.showToast({
  205. title: '请输入正确的电话',
  206. icon: 'none'
  207. })
  208. }else{
  209. wx.showToast({
  210. title: '请输入电话',
  211. icon: 'none'
  212. })
  213. }
  214. return;
  215. }
  216. if (!this.data.sendCode){
  217. return;
  218. }
  219. this.data.sendCode = false;
  220. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  221. if (res.code == 200) {
  222. this.countDown();
  223. wx.showToast({
  224. title: '验证码获取成功',
  225. icon: "none"
  226. })
  227. this.setData({
  228. verificationCode:60
  229. })
  230. } else {
  231. this.data.sendCode = true;
  232. wx.showToast({
  233. title: res.msg,
  234. icon: "none"
  235. })
  236. }
  237. },this)
  238. },
  239. countDown: function () {//倒计时
  240. setTimeout(() => {
  241. this.setData({
  242. verificationCode: this.data.verificationCode - 1
  243. })
  244. if (this.data.verificationCode > 0) {
  245. this.countDown();
  246. } else {
  247. this.setData({
  248. verificationCode: "获取验证码"
  249. })
  250. this.data.sendCode = true;
  251. }
  252. }, 1000);
  253. },
  254. getRealname: function (e) {//获取用户输入的姓名
  255. this.data.subscribeData.realname = e.detail.value;
  256. },
  257. getMobile: function (e) {//获取用户输入的电话
  258. this.data.subscribeData.mobile = e.detail.value;
  259. },
  260. getCaptcha: function (e) {//获取用户输入的验证码
  261. this.data.subscribeData.captcha = e.detail.value;
  262. },
  263. subscribeFun: function (e) {//预约鉴赏
  264. if (!this.data.subscribeData.realname) {
  265. wx.showToast({
  266. title: '请输入姓名',
  267. icon: "none"
  268. })
  269. return;
  270. }
  271. if (!this.data.subscribeData.mobile) {
  272. wx.showToast({
  273. title: '请输入电话',
  274. icon: "none"
  275. })
  276. return;
  277. }
  278. if (!this.data.subscribeData.captcha) {
  279. wx.showToast({
  280. title: '请输入验证码',
  281. icon: "none"
  282. })
  283. return;
  284. }
  285. if (!this.data.appointment) {
  286. return;
  287. }
  288. this.data.appointment = false;
  289. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  290. this.data.appointment = true;
  291. if (res.code == 200) {
  292. wx.showToast({
  293. title: '预约成功'
  294. })
  295. this.data.subscribeData.realname = "";
  296. this.data.subscribeData.captcha = "";
  297. this.setData({
  298. subscribeData: this.data.subscribeData
  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. })