mys.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import httpRequestApi from '../../utils/APIRequest';
  2. export function myInit(that) {
  3. that.setData({
  4. myData: {
  5. nav: ['我的娃', '收藏', '历史'],
  6. myInd: 0,
  7. favoritesList: [],
  8. playLogList: [],
  9. userName: '',
  10. avatar: '../../static/image/default.png'
  11. }
  12. })
  13. //点击切换
  14. that.myChoice = ({ currentTarget }) => {
  15. that.data.myData.myInd = currentTarget.dataset.index;
  16. that.setData({
  17. myData: that.data.myData
  18. })
  19. //获取个人信息
  20. if(currentTarget.dataset.index == 0) {
  21. that.getUserInfo();
  22. }
  23. //获取收藏列表
  24. if(currentTarget.dataset.index == 1) {
  25. that.getFavoritesList();
  26. }
  27. //获取播放记录
  28. if(currentTarget.dataset.index == 2) {
  29. that.getPlayLogList();
  30. }
  31. }
  32. //滑动切换
  33. that.mySlide = ({detail}) => {
  34. that.data.myData.myInd = detail.current;
  35. // console.log(detail.current);
  36. that.setData({
  37. myData: that.data.myData
  38. })
  39. //获取个人信息
  40. if(detail.current == 0) {
  41. that.getUserInfo();
  42. }
  43. //获取收藏列表
  44. if(detail.current == 1) {
  45. that.getFavoritesList();
  46. }
  47. //获取播放记录
  48. if(detail.current == 2) {
  49. that.getPlayLogList();
  50. }
  51. }
  52. //点击跳转页面
  53. that.setName = () => {
  54. wx.navigateTo({
  55. url: '/pages/setName/setName'
  56. })
  57. }
  58. //获取收藏列表
  59. that.getFavoritesList = () => {
  60. httpRequestApi.getFavoritesList({
  61. pageNo: 1,
  62. pageSize: 10
  63. }).success((res)=>{
  64. console.log('收藏列表', res);
  65. that.data.myData.favoritesList = res.data.data.list;
  66. that.setData({
  67. myData: that.data.myData
  68. })
  69. })
  70. }
  71. //获取播放记录
  72. that.getPlayLogList = () => {
  73. httpRequestApi.getPlayLogList({
  74. pageNo: 1,
  75. pageSize: 10
  76. }).success((res)=>{
  77. console.log('播放记录', res);
  78. that.data.myData.playLogList = res.data.data.list;
  79. that.setData({
  80. myData: that.data.myData
  81. })
  82. })
  83. }
  84. //跳转到说明页
  85. that.Instructions = () => {
  86. wx.navigateTo({
  87. url: '/pages/Instructions/Instructions'
  88. })
  89. }
  90. //跳转到相册
  91. that.album = ({ currentTarget }) => {
  92. //const id = currentTarget.dataset.id;
  93. wx.navigateTo({
  94. url: '/pages/album/album'
  95. })
  96. }
  97. //跳转到比赛页
  98. that.childMatch = () => {
  99. wx.navigateTo({
  100. url: '/pages/childMatch/childMatch'
  101. })
  102. }
  103. //跳转到详情页
  104. that.detail = ({ currentTarget }) => {
  105. const id = currentTarget.dataset.id;
  106. wx.navigateTo({
  107. url: '/pages/details/details?id=' + id
  108. })
  109. }
  110. //获取个人信息
  111. that.getUserInfo = () => {
  112. httpRequestApi.getUserInfo().success(res => {
  113. console.log('七彩童年的用户信息', res);
  114. wx.setStorageSync('photoBox', res.data.data.photoBox);
  115. wx.setStorageSync('userInfo', res);
  116. that.data.myData.userName = res.data.data.nickName;
  117. that.data.myData.avatar = res.data.data.avatar
  118. that.setData({
  119. myData: that.data.myData
  120. })
  121. });
  122. }
  123. //初始化调用个人信息
  124. that.getUserInfo();
  125. }