东风启辰小程序端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

494 行
14KB

  1. // pages/myCenter/myCenter.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. phoneInputShow: false,//是否显示电话输入框
  10. siteSelect: false,//是否显示位置选择框
  11. isLogin:false,//登录状态
  12. selectNow:0,//现在的选项
  13. taskNow:1,//现在的任务类型
  14. recordNow: 1,//现在的记录类型
  15. taskList: [],//任务列表
  16. shareFriendList:[],//星探小分队列表
  17. recordList:[],//获奖记录列表
  18. provinceArr: [],//省
  19. provinceValue: 0,//选中的省下标
  20. storeArr: [],//店铺
  21. storeValue: 0,//选中的店铺下标
  22. verificationCode: '获取验证码',//验证码文案
  23. sendCode: true,
  24. appointment: true,
  25. subscribeData: {
  26. realname: "",//姓名
  27. mobile: "",//手机号
  28. captcha: "",//验证码
  29. province: "",//省份
  30. agent_code: "",//经销商编码
  31. agentDetail: "",//经销商详细信息
  32. parentOpenid: app.globalData.friendOpenid,//好友openid
  33. },
  34. userData:{
  35. avatarUrl: null,
  36. nickName: null,
  37. userLevel: 0
  38. },
  39. descFrameShow:false,//是否显示奖品详情
  40. ruleShow: false,//是否显示星探等级规则
  41. // isRegister: false,//查询是否已注册
  42. parames:{
  43. page:1,
  44. count:20
  45. },
  46. noData:false,
  47. optionsData:null,
  48. lookDescId:null,
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. app.globalData.nowPage = 4;
  55. if (options.sourcePage){
  56. this.data.optionsData = options.sourcePage;
  57. }
  58. if (app.globalData.openid) {
  59. this.loadFun();
  60. } else {
  61. app.globalData.openidSuccessFuc = this.loadFun;
  62. }
  63. },
  64. loadFun: function () {
  65. this.getUserInfo();
  66. if (app.globalData.userMobile) {
  67. this.data.subscribeData.mobile = app.globalData.userMobile;
  68. this.setData({
  69. phoneInputShow: true,
  70. subscribeData: this.data.subscribeData
  71. })
  72. this.getUserLocation();
  73. }
  74. if (app.globalData.myCenterData) {
  75. this.setData({
  76. provinceArr: app.globalData.myCenterData.provinceArr,
  77. storeArr: app.globalData.myCenterData.storeArr,
  78. provinceValue: app.globalData.myCenterData.provinceValue,
  79. storeValue: app.globalData.myCenterData.storeValue,
  80. // isRegister: app.globalData.isRegister
  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. // if (!app.globalData.isRegister) {
  87. // this.getOrderInfo();
  88. // }
  89. if (app.globalData.userInfoData) {
  90. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  91. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  92. this.setData({
  93. userData: this.data.userData
  94. })
  95. }
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload: function () {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh: function () {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom: function () {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage: function () {
  131. return app.sharePack();
  132. },
  133. selectChange:function(e){
  134. this.setData({
  135. selectNow: e.currentTarget.dataset.value
  136. })
  137. if (e.currentTarget.dataset.value == 1) {
  138. this.getTaskProgress();
  139. } else if (e.currentTarget.dataset.value == 2) {
  140. this.getMyAwardList();
  141. } else if (e.currentTarget.dataset.value == 3){
  142. this.data.parames.page = 0;
  143. this.setData({
  144. parames: this.data.parames,
  145. shareFriendList:[]
  146. })
  147. this.getShareList();
  148. }
  149. },
  150. selectTask: function (e) {
  151. if (e.currentTarget.dataset.type==2){
  152. return;
  153. }
  154. this.setData({
  155. taskNow: e.currentTarget.dataset.type
  156. })
  157. },
  158. selectRecord: function (e) {
  159. if (this.data.recordNow == e.currentTarget.dataset.type) {
  160. return;
  161. }
  162. this.setData({
  163. recordList:[],
  164. recordNow: e.currentTarget.dataset.type
  165. })
  166. this.getMyAwardList();
  167. },
  168. getUserLocation: function (e) {
  169. wx.getLocation({
  170. type: 'gcj02', //wgs84
  171. success: (res) => {
  172. this.getDistributorList(res.longitude, res.latitude);
  173. },
  174. fail: (res) => {
  175. this.getDistributorList("", "");
  176. },
  177. complete: (res) => {
  178. this.setData({
  179. siteSelect: true,
  180. })
  181. }
  182. })
  183. },
  184. getDistributorList: function (longitude, latitude) {//获取经销商列表
  185. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  186. if (res.code == 200) {
  187. app.globalData.myCenterData = {};
  188. this.setData({
  189. provinceArr: res.data.list,
  190. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  191. provinceValue: res.data.nearData.provinceIndex,
  192. storeValue: res.data.nearData.cityIndex
  193. })
  194. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  195. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  196. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  197. app.globalData.myCenterData.provinceArr = res.data.list;
  198. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  199. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  200. app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex;
  201. } else {
  202. wx.showToast({
  203. title: res.msg,
  204. icon: "none"
  205. })
  206. }
  207. }, this);
  208. },
  209. provinceChane: function (e) {//选中省
  210. this.setData({
  211. provinceValue: e.detail.value,
  212. storeArr: this.data.provinceArr[e.detail.value].children,
  213. storeValue: 0
  214. })
  215. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  216. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  217. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  218. },
  219. storeChane: function (e) {//选中店铺
  220. this.setData({
  221. storeValue: e.detail.value,
  222. })
  223. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  224. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  225. },
  226. getCode: function (e) {//获取验证码
  227. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  228. if (this.data.subscribeData.mobile) {
  229. wx.showToast({
  230. title: '请输入正确的电话',
  231. icon: 'none'
  232. })
  233. } else {
  234. wx.showToast({
  235. title: '请输入电话',
  236. icon: 'none'
  237. })
  238. }
  239. return;
  240. }
  241. if (!this.data.sendCode) {
  242. return;
  243. }
  244. this.data.sendCode = false;
  245. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  246. if (res.code == 200) {
  247. this.countDown();
  248. wx.showToast({
  249. title: '验证码获取成功',
  250. icon: "none"
  251. })
  252. this.setData({
  253. verificationCode: 60
  254. })
  255. } else {
  256. this.data.sendCode = true;
  257. wx.showToast({
  258. title: res.msg,
  259. icon: "none"
  260. })
  261. }
  262. }, this)
  263. },
  264. countDown: function () {//倒计时
  265. setTimeout(() => {
  266. this.setData({
  267. verificationCode: this.data.verificationCode - 1
  268. })
  269. if (this.data.verificationCode > 0) {
  270. this.countDown();
  271. } else {
  272. this.setData({
  273. verificationCode: "获取验证码"
  274. })
  275. this.data.sendCode = true;
  276. }
  277. }, 1000);
  278. },
  279. getRealname: function (e) {//获取用户输入的姓名
  280. this.data.subscribeData.realname = e.detail.value;
  281. },
  282. getMobile: function (e) {//获取用户输入的电话
  283. this.data.subscribeData.mobile = e.detail.value;
  284. },
  285. getCaptcha: function (e) {//获取用户输入的验证码
  286. this.data.subscribeData.captcha = e.detail.value;
  287. },
  288. subscribeFun: function (e) {//预约鉴赏
  289. if(!this.data.subscribeData.realname){
  290. wx.showToast({
  291. title: '请输入姓名',
  292. icon:"none"
  293. })
  294. return;
  295. }
  296. if (!this.data.subscribeData.mobile) {
  297. wx.showToast({
  298. title: '请输入电话',
  299. icon: "none"
  300. })
  301. return;
  302. }
  303. if (!this.data.subscribeData.captcha) {
  304. wx.showToast({
  305. title: '请输入验证码',
  306. icon: "none"
  307. })
  308. return;
  309. }
  310. if (!this.data.appointment) {
  311. return;
  312. }
  313. this.data.appointment = false;
  314. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  315. this.data.appointment = true;
  316. if (res.code == 200) {
  317. wx.showToast({
  318. title: '预约成功'
  319. })
  320. this.data.subscribeData.realname = "";
  321. this.data.subscribeData.captcha = "";
  322. this.setData({
  323. subscribeData: this.data.subscribeData
  324. })
  325. // this.setData({
  326. // isRegister: true
  327. // })
  328. // app.globalData.isRegister = true;
  329. app.globalData.userMobile = this.data.subscribeData.mobile;
  330. } else {
  331. wx.showToast({
  332. title: res.msg,
  333. icon: "none"
  334. })
  335. }
  336. }, this, "POST")
  337. },
  338. getUserWxMsg:function(e){//通过微信获取用户信息
  339. if (e.detail.errMsg == "getUserInfo:ok") {
  340. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  341. this.data.userData.nickName = e.detail.userInfo.nickName;
  342. this.data.userData.userLevel = 0;
  343. this.setData({
  344. userData: this.data.userData,
  345. isLogin: true
  346. })
  347. app.globalData.userInfoData = {};
  348. app.globalData.userInfoData.avatarUrl = e.detail.userInfo.avatarUrl;
  349. app.globalData.userInfoData.nickName = e.detail.userInfo.nickName;
  350. wx.setStorageSync('userInfoData', {
  351. avatarUrl: e.detail.userInfo.avatarUrl,
  352. nickName: e.detail.userInfo.nickName
  353. })
  354. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  355. }
  356. },
  357. getUserInfo:function(e){//获取个人信息
  358. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  359. if(res.code==200){
  360. if (res.data) {
  361. this.data.userData.userLevel = res.data.userLevel;
  362. if (!app.globalData.userInfoData) {
  363. this.data.userData.avatarUrl = res.data.avatarUrl;
  364. this.data.userData.nickName = res.data.nickName;
  365. app.globalData.userInfoData = {};
  366. app.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  367. app.globalData.userInfoData.nickName = res.data.nickName;
  368. wx.setStorageSync('userInfoData', {
  369. avatarUrl: res.data.avatarUrl,
  370. nickName: res.data.nickName
  371. })
  372. }
  373. this.setData({
  374. userData: this.data.userData,
  375. isLogin: true
  376. })
  377. }
  378. }
  379. },this)
  380. },
  381. getTaskProgress: function () {//获取任务完成度 1每日任务
  382. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  383. if(res.code==200){
  384. this.setData({
  385. taskList:res.data
  386. })
  387. }
  388. },this)
  389. },
  390. lookDesc:function(e){//查看奖品详情
  391. this.setData({
  392. descFrameShow: !this.data.descFrameShow,
  393. lookDescId: e.currentTarget.dataset.value || e.currentTarget.dataset.value==0 ? e.currentTarget.dataset.value:null
  394. })
  395. },
  396. lookRule: function (e) {//查看奖品详情
  397. this.setData({
  398. ruleShow: e.currentTarget.dataset.value
  399. })
  400. },
  401. getShareList: function () {//星探小分队
  402. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  403. if(res.code==200){
  404. for(let i=0;i<res.data.length;i++){
  405. this.data.shareFriendList.push(res.data[i]);
  406. }
  407. this.setData({
  408. shareFriendList: this.data.shareFriendList
  409. })
  410. if (res.data.length<this.data.parames.count){
  411. this.setData({
  412. noData: true
  413. })
  414. }
  415. }
  416. },this);
  417. },
  418. getOrderInfo: function () {//查询是否已注册
  419. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  420. if (res.code == 200) {
  421. if (res.data) {
  422. this.setData({
  423. isRegister: true
  424. })
  425. app.globalData.isRegister = true;
  426. app.globalData.userMobile = res.data.mobile;
  427. } else {
  428. if (app.globalData.userMobile) {
  429. this.data.subscribeData.mobile = app.globalData.userMobile;
  430. this.setData({
  431. phoneInputShow: true,
  432. subscribeData: this.data.subscribeData
  433. })
  434. this.getUserLocation();
  435. }
  436. }
  437. } else {
  438. console.log(res.msg)
  439. }
  440. }, this);
  441. },
  442. scrolltolower:function(){//星探小分队滚动条触底时执行
  443. if(!this.data.noData){
  444. this.data.parames.page+=1;
  445. this.getShareList();
  446. }
  447. },
  448. getMyAwardList: function () {//获取获奖记录
  449. app.wxRequest(app.globalData.urlRoot + "award/getMyAwardList", { awardType: this.data.recordNow},res=>{
  450. if(res.code == 200){
  451. this.setData({
  452. recordList:res.data
  453. })
  454. }
  455. },this)
  456. },
  457. getUserPhone: function (e) {//获取用户手机号
  458. this.setData({
  459. phoneInputShow: true
  460. })
  461. if (!app.globalData.myCenterData) {
  462. this.getUserLocation();//获取用户当前位置
  463. }
  464. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  465. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  466. if (res.code == 200) {
  467. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  468. this.setData({
  469. subscribeData: this.data.subscribeData
  470. })
  471. } else {
  472. wx.showToast({
  473. title: res.msg,
  474. icon: "none"
  475. })
  476. }
  477. }, this);
  478. }
  479. }
  480. })