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.

222 lines
5.1KB

  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. var userInfo = wx.getStorageSync('userInfo');
  35. var phone = wx.getStorageSync('user_phone');
  36. console.log(userInfo)
  37. if (userInfo) {
  38. var userArr = [];
  39. userArr.push(userInfo.avatarUrl);
  40. userArr.push(userInfo.nickName);
  41. phone = app.globalData.userInfo.user_phone
  42. console.log(phone)
  43. this.setData({
  44. getUserArr: userArr,
  45. getUser: true,
  46. userPhone: phone
  47. })
  48. }
  49. console.log(this.data.getUserArr)
  50. },
  51. myTicket:function(){//获取我的优惠券列表
  52. app.wxRequest(app.globalData.httpUrl + 'couponbuy/validtype', {}, e => {
  53. console.log(e)
  54. if (e.code == 200) {
  55. this.setData({
  56. myTicketArr: e.data
  57. })
  58. }
  59. }, this)
  60. },
  61. historyTicket: function () {//获取优惠券使用列表
  62. this.data.getHistory = [];
  63. app.wxRequest(app.globalData.httpUrl + 'couponbuy/historyuse', {cur_page: this.data.pageNum, show_num: this.data.pageCount}, e => {
  64. console.log(e)
  65. if (e.code == 200) {
  66. for(var i=0;i<e.data.length;i++){
  67. this.data.getHistoryArr.push(e.data[i]);
  68. }
  69. this.data.getHistory = e.data
  70. this.setData({
  71. historyArr: this.data.getHistoryArr,
  72. })
  73. }
  74. }, this)
  75. },
  76. lower:function(){//检测上拉是否到底
  77. console.log("到底了")
  78. if (this.data.getHistory.length!=0){
  79. this.data.pageNum++;
  80. this.historyTicket()
  81. }else{
  82. wx.showToast({
  83. title: '没有更多数据了',
  84. icon: "none",
  85. duration: 1000
  86. })
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. return {
  124. title: "老门框爆肚会员",
  125. path: "/pages/register/register",
  126. success: res => {
  127. console.log(res, "转发成功")
  128. },
  129. }
  130. },
  131. lookMyTicket:function(){
  132. this.setData({
  133. myTicketArrows: !this.data.myTicketArrows,
  134. })
  135. if (this.data.myTicketArrows){
  136. this.setData({
  137. mydeg: 0,
  138. })
  139. }else{
  140. this.setData({
  141. mydeg: -90,
  142. })
  143. }
  144. },
  145. lookHistory:function(){
  146. this.setData({
  147. historyTicketArrows: !this.data.historyTicketArrows,
  148. })
  149. if (this.data.historyTicketArrows) {
  150. this.setData({
  151. historydeg: 0,
  152. })
  153. } else {
  154. this.setData({
  155. historydeg: -90,
  156. })
  157. }
  158. },
  159. lookTicket: function (e) {//查看优惠券
  160. console.log(e)
  161. var id = e.currentTarget.dataset.id;
  162. wx.navigateTo({
  163. url: '../TicketDetails/TicketDetails?id=' + id,
  164. })
  165. },
  166. giveTicket:function(e){//赠送优惠券
  167. var id = e.target.dataset.id;
  168. wx.navigateTo({
  169. url: '../givePage/givePage?id=' + id,
  170. })
  171. },
  172. getUser:function(e){//点击登陆获取用户信息
  173. console.log(e)
  174. wx.setStorageSync('userInfo', e.detail.userInfo);
  175. var phone = wx.getStorageSync('user_phone');
  176. var userArr = [];
  177. userArr.push(e.detail.userInfo.avatarUrl);
  178. userArr.push(e.detail.userInfo.nickName);
  179. // phone = app.globalData.user_phone
  180. console.log(phone)
  181. this.data.userChuan = e.detail.userInfo;
  182. this.setData({
  183. getUserArr: userArr,
  184. getUser: true,
  185. userPhone: phone
  186. })
  187. this.submitUser();
  188. console.log(this.data.getUserArr)
  189. },
  190. submitUser:function(){//提交用户信息
  191. var params={
  192. "province": this.data.userChuan.province,
  193. "language": this.data.userChuan.language,
  194. "city": this.data.userChuan.city,
  195. "gender": this.data.userChuan.gender,
  196. "nickname": this.data.userChuan.nickName,
  197. "headimgurl": this.data.userChuan.avatarUrl,
  198. }
  199. app.wxRequest(app.globalData.httpUrl + 'submit', params, e => {
  200. console.log(e)
  201. if (e.code == 200) {
  202. }
  203. }, this,"POST")
  204. }
  205. })