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

295 行
7.1KB

  1. // pages/personalCenter/personalCenter.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. myTicketArrows: true,
  9. historyTicketArrows: false,
  10. getUser:false,
  11. getUserArr: [],//用户信息
  12. userChuan:[],
  13. userPhone:"",//用户手机号
  14. mydeg: 0,
  15. historydeg: -90,
  16. pageNum:1,
  17. pageCount:5,
  18. historyArr: [],//优惠券使用记录列表
  19. getHistory: [],//每次接口拉取的数据
  20. getHistoryArr: [],//全部使用数据
  21. myTicketArr: [],//我的优惠券列表
  22. headerImg:"../images/headerImg.png",//默认头像
  23. userName:"",//昵称
  24. noUser:false,
  25. topNum:0,
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. },
  32. getToRsgisterFn:function(){//未注册点击跳到注册页
  33. wx.navigateTo({
  34. url: '/pages/register/register',
  35. })
  36. },
  37. myTicket:function(){//获取我的优惠券列表
  38. app.wxRequest(app.globalData.httpUrl + 'couponbuy/validtype', {}, e => {
  39. console.log(e)
  40. if (e.code == 200) {
  41. this.setData({
  42. myTicketArr: e.data
  43. })
  44. }
  45. }, this)
  46. },
  47. historyTicket: function () {//获取优惠券使用列表
  48. this.data.getHistory = [];
  49. app.wxRequest(app.globalData.httpUrl + 'couponbuy/historyuse', {cur_page: this.data.pageNum, show_num: this.data.pageCount}, e => {
  50. console.log(e)
  51. if (e.code == 200) {
  52. for(var i=0;i<e.data.length;i++){
  53. this.data.getHistoryArr.push(e.data[i]);
  54. }
  55. this.data.getHistory = e.data
  56. this.setData({
  57. historyArr: this.data.getHistoryArr,
  58. })
  59. }
  60. console.log(this.data.getHistoryArr)
  61. }, this)
  62. },
  63. lower:function(){//检测上拉是否到底
  64. console.log("到底了")
  65. if (this.data.getHistory.length!=0){
  66. this.data.pageNum++;
  67. this.historyTicket()
  68. }else{
  69. wx.showToast({
  70. title: '没有更多数据了',
  71. icon: "none",
  72. duration: 1000
  73. })
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow: function () {
  85. this.setData({
  86. topNum:0
  87. })
  88. this.data.pageNum = 1;
  89. this.data.getHistoryArr = [];
  90. if (app.globalData.openId) {
  91. this.myTicket();
  92. this.historyTicket();
  93. } else {
  94. app.globalData.openidSuccessFuc = this.myTicket;
  95. app.globalData.openidSuccessFuc = this.historyTicket;
  96. }
  97. if (!this.data.getUser) {
  98. var state = wx.getStorageSync('state');
  99. if (state == 1) {//已注册
  100. var userInfo = wx.getStorageSync('userInfo');
  101. var phone = wx.getStorageSync('user_phone');
  102. if (!userInfo.avatarUrl){
  103. this.setData({
  104. headerImg: "../images/headerImg.png",
  105. userName: userInfo.nickName,
  106. userPhone: phone,
  107. getUser: true
  108. })
  109. }else{
  110. this.setData({
  111. headerImg: userInfo.avatarUrl,
  112. userName: userInfo.nickName,
  113. userPhone: phone,
  114. getUser: true
  115. })
  116. }
  117. console.log(wx.getStorageSync('noUser'))
  118. if (wx.getStorageSync('noUser')==0) {
  119. this.setData({
  120. noUser: true
  121. })
  122. } else if (wx.getStorageSync('noUser') == 1) {
  123. this.setData({
  124. noUser: false
  125. })
  126. }
  127. } else if (state == 0) {//未注册
  128. console.log(app.globalData.noUser)
  129. this.setData({
  130. getUser: false,
  131. noUser: false
  132. })
  133. } else if (state == -1) {
  134. app.globalData.userInfoBackFn = res => {//等待结果
  135. console.log(res)
  136. if (res) {
  137. var userInfo = wx.getStorageSync('userInfo');
  138. var phone = wx.getStorageSync('user_phone');
  139. if (!userInfo.avatarUrl) {
  140. this.setData({
  141. headerImg: "../images/headerImg.png",
  142. userName: userInfo.nickName,
  143. userPhone: phone,
  144. getUser: true
  145. })
  146. } else {
  147. this.setData({
  148. headerImg: userInfo.avatarUrl,
  149. userName: userInfo.nickName,
  150. userPhone: phone,
  151. getUser: true
  152. })
  153. }
  154. if (wx.getStorageSync('noUser') == 0) {
  155. this.setData({
  156. noUser: true
  157. })
  158. } else if (wx.getStorageSync('noUser') == 1) {
  159. this.setData({
  160. noUser: false
  161. })
  162. }
  163. } else {
  164. this.setData({
  165. getUser: false,
  166. noUser: false
  167. })
  168. }
  169. }
  170. }
  171. }
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function () {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function () {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function () {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage: function () {
  197. return {
  198. title: "老门框爆肚会员",
  199. success: res => {
  200. console.log(res, "转发成功")
  201. },
  202. }
  203. },
  204. lookMyTicket:function(){
  205. this.setData({
  206. myTicketArrows: !this.data.myTicketArrows,
  207. })
  208. if (this.data.myTicketArrows){
  209. this.setData({
  210. mydeg: 0,
  211. })
  212. }else{
  213. this.setData({
  214. mydeg: -90,
  215. })
  216. }
  217. },
  218. lookHistory:function(){
  219. this.setData({
  220. historyTicketArrows: !this.data.historyTicketArrows,
  221. })
  222. if (this.data.historyTicketArrows) {
  223. this.setData({
  224. historydeg: 0,
  225. })
  226. } else {
  227. this.setData({
  228. historydeg: -90,
  229. })
  230. }
  231. },
  232. lookTicket: function (e) {//查看优惠券
  233. console.log(e)
  234. var id = e.currentTarget.dataset.id;
  235. wx.navigateTo({
  236. url: '../TicketDetails/TicketDetails?id=' + id,
  237. })
  238. },
  239. giveTicket:function(e){//赠送优惠券
  240. var id = e.target.dataset.id;
  241. wx.navigateTo({
  242. url: '../givePage/givePage?id=' + id,
  243. })
  244. },
  245. getUser:function(e){//点击登陆获取用户信息
  246. console.log(e)
  247. if (e.detail.userInfo) {
  248. this.data.userChuan = e.detail.userInfo;
  249. wx.setStorageSync('noUser', 1);
  250. wx.setStorageSync("userInfo", e.detail.userInfo)
  251. this.setData({
  252. headerImg: e.detail.userInfo.avatarUrl,
  253. userName: e.detail.userInfo.nickName,
  254. getUser: true,
  255. noUser: false
  256. })
  257. this.submitUser();
  258. }
  259. },
  260. submitUser: function () {//提交用户信息
  261. if (this.data.userChuan) {
  262. var params = {
  263. "province": this.data.userChuan.province,
  264. "language": this.data.userChuan.language,
  265. "city": this.data.userChuan.city,
  266. "gender": this.data.userChuan.gender,
  267. "nickname": this.data.userChuan.nickName,
  268. "headimgurl": this.data.userChuan.avatarUrl,
  269. }
  270. app.wxRequest(app.globalData.httpUrl + 'submit', params, e => {
  271. console.log(e)
  272. if (e.code == 200) {
  273. }
  274. }, this, "POST")
  275. }
  276. },
  277. })