Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

211 lines
4.8KB

  1. // pages/personalCenter/personalCenter.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. myTicketArrows: false,
  9. historyTicketArrows: false,
  10. getUser:false,
  11. getUserArr: [],//用户信息
  12. userChuan:[],
  13. userPhone:"",//用户手机号
  14. mydeg: -90,
  15. historydeg: -90,
  16. pageNum:1,
  17. pageCount:5,
  18. historyArr: [],//优惠券使用记录列表
  19. getHistory: [],//每次接口拉取的数据
  20. getHistoryArr: [],//全部使用数据
  21. myTicketArr: [],//我的优惠券列表
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. if (app.globalData.openId) {
  28. this.myTicket();
  29. this.historyTicket();
  30. } else {
  31. app.globalData.openidSuccessFuc = this.myTicket;
  32. app.globalData.openidSuccessFuc = this.historyTicket;
  33. }
  34. console.log(app.globalData.userInfo)
  35. if (app.globalData.userInfo.item_state == 2) {
  36. var userArr = [];
  37. var phone="";
  38. userArr.push(app.globalData.userInfo.headimgurl);
  39. userArr.push(app.globalData.userInfo.nickname);
  40. phone = app.globalData.userInfo.user_phone
  41. this.setData({
  42. getUserArr: userArr,
  43. getUser: true,
  44. userPhone: phone
  45. })
  46. }
  47. console.log(this.data.getUserArr)
  48. },
  49. myTicket:function(){//获取我的优惠券列表
  50. app.wxRequest(app.globalData.httpUrl + 'couponbuy/validtype', {}, e => {
  51. console.log(e)
  52. if (e.code == 200) {
  53. this.setData({
  54. myTicketArr: e.data
  55. })
  56. }
  57. }, this)
  58. },
  59. historyTicket: function () {//获取优惠券使用列表
  60. this.data.getHistory = [];
  61. app.wxRequest(app.globalData.httpUrl + 'couponbuy/historyuse', {cur_page: this.data.pageNum, show_num: this.data.pageCount}, e => {
  62. console.log(e)
  63. if (e.code == 200) {
  64. for(var i=0;i<e.data.length;i++){
  65. this.data.getHistoryArr.push(e.data[i]);
  66. }
  67. this.data.getHistory = e.data
  68. this.setData({
  69. historyArr: this.data.getHistoryArr,
  70. })
  71. }
  72. }, this)
  73. },
  74. lower:function(){//检测上拉是否到底
  75. console.log("到底了")
  76. if (this.data.getHistory.length!=0){
  77. this.data.pageNum++;
  78. this.historyTicket()
  79. }else{
  80. wx.showToast({
  81. title: '没有更多数据了',
  82. icon: "none",
  83. duration: 1000
  84. })
  85. }
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面隐藏
  99. */
  100. onHide: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面卸载
  104. */
  105. onUnload: function () {
  106. },
  107. /**
  108. * 页面相关事件处理函数--监听用户下拉动作
  109. */
  110. onPullDownRefresh: function () {
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function () {
  116. },
  117. /**
  118. * 用户点击右上角分享
  119. */
  120. onShareAppMessage: function () {
  121. },
  122. lookMyTicket:function(){
  123. this.setData({
  124. myTicketArrows: !this.data.myTicketArrows,
  125. })
  126. if (this.data.myTicketArrows){
  127. this.setData({
  128. mydeg: 0,
  129. })
  130. }else{
  131. this.setData({
  132. mydeg: -90,
  133. })
  134. }
  135. },
  136. lookHistory:function(){
  137. this.setData({
  138. historyTicketArrows: !this.data.historyTicketArrows,
  139. })
  140. if (this.data.historyTicketArrows) {
  141. this.setData({
  142. historydeg: 0,
  143. })
  144. } else {
  145. this.setData({
  146. historydeg: -90,
  147. })
  148. }
  149. },
  150. lookTicket: function (e) {//查看优惠券
  151. console.log(e)
  152. var id = e.currentTarget.dataset.id;
  153. wx.navigateTo({
  154. url: '../TicketDetails/TicketDetails?id=' + id,
  155. })
  156. },
  157. giveTicket:function(e){//赠送优惠券
  158. var id = e.target.dataset.id;
  159. wx.navigateTo({
  160. url: '../givePage/givePage?id=' + id,
  161. })
  162. },
  163. getUser:function(e){//点击登陆获取用户信息
  164. console.log(e)
  165. var userArr = [];
  166. var phone = "";
  167. userArr.push(e.detail.userInfo.avatarUrl);
  168. userArr.push(e.detail.userInfo.nickName);
  169. phone = app.globalData.userInfo.user_phone
  170. this.data.userChuan = e.detail.userInfo;
  171. this.setData({
  172. getUserArr: userArr,
  173. getUser: true,
  174. userPhone: phone
  175. })
  176. this.submitUser();
  177. console.log(this.data.getUserArr)
  178. },
  179. submitUser:function(){//提交用户信息
  180. var params={
  181. "province": this.data.userChuan.province,
  182. "language": this.data.userChuan.language,
  183. "city": this.data.userChuan.city,
  184. "gender": this.data.userChuan.gender,
  185. "nickname": this.data.userChuan.nickName,
  186. "headimgurl": this.data.userChuan.avatarUrl,
  187. }
  188. app.wxRequest(app.globalData.httpUrl + 'submit', params, e => {
  189. console.log(e)
  190. if (e.code == 200) {
  191. }
  192. }, this,"POST")
  193. }
  194. })