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

684 行
20KB

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