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

5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile:this.data.subscribeData.mobile},res=>{
  206. console.log(res);
  207. if (res.code == 200) {
  208. this.countDown();
  209. wx.showToast({
  210. title: '验证码获取成功',
  211. icon: "none"
  212. })
  213. this.setData({
  214. verificationCode:60
  215. })
  216. this.data.sendCode = false;
  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. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  272. if (res.code == 200) {
  273. wx.showToast({
  274. title: '预约成功'
  275. })
  276. this.setData({
  277. isRegister:true
  278. })
  279. app.globalData.isRegister = true;
  280. app.globalData.userMobile = this.data.subscribeData.mobile;
  281. // wx.redirectTo({
  282. // url: "../myCenter/myCenter?sourcePage='home'"
  283. // })
  284. } else {
  285. wx.showToast({
  286. title: res.msg,
  287. icon: "none"
  288. })
  289. }
  290. }, this, "POST")
  291. },
  292. getStartAdvertising: function () {//获取开屏广告
  293. app.wxRequest(app.globalData.urlRoot +"home/getStartAdvertising",{},res=>{
  294. if (app.globalData.openid) {
  295. this.loadFun();
  296. } else {
  297. app.globalData.openidSuccessFuc = this.loadFun;
  298. }
  299. if(res.code==200){
  300. this.setData({
  301. startAdvertisingUrl: res.data.picurl,
  302. mainShow:true
  303. })
  304. app.globalData.isFirstLogin = false;
  305. setTimeout(() => {
  306. this.setData({
  307. isStartAdvertising: 0
  308. })
  309. setTimeout(()=>{
  310. this.setData({
  311. isStartAdvertisingShow:false
  312. })
  313. },1000);
  314. }, 3000);
  315. }
  316. },this);
  317. },
  318. getHomeBanner: function () {//获取banner
  319. app.wxRequest(app.globalData.urlRoot + "home/getHomeBanner", {}, res => {
  320. if (res.code == 200) {
  321. this.setData({
  322. bannerList:res.data
  323. })
  324. app.globalData.indexData.bannerList = res.data;
  325. }
  326. }, this);
  327. },
  328. getHomeVideo: function () {//获取视频
  329. app.wxRequest(app.globalData.urlRoot + "home/getHomeVideo", {}, res => {
  330. if (res.code == 200) {
  331. this.setData({
  332. videoList:res.data[0]
  333. })
  334. app.globalData.indexData.videoList = res.data[0];
  335. }
  336. }, this);
  337. },
  338. hideVideoControls: function () {//显示视频控件
  339. wx.createVideoContext("video").play();
  340. this.setData({
  341. videoVideoControls:true
  342. })
  343. },
  344. getOrderInfo: function () {//查询是否已注册
  345. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  346. if (res.code == 200) {
  347. if (res.data) {
  348. this.setData({
  349. isRegister: true
  350. })
  351. app.globalData.isRegister = true;
  352. app.globalData.userMobile = res.data.mobile;
  353. }
  354. } else {
  355. console.log(res.msg)
  356. }
  357. }, this);
  358. },
  359. /**
  360. * 用户点击右上角分享
  361. */
  362. onShareAppMessage: function () {
  363. return app.sharePack();
  364. }
  365. })