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

552 line
16KB

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