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.

298 lines
7.2KB

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