myhome.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/myhome/myhome.js
  2. const config = require('../../config.js')
  3. const getReq = config.getReq
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. memberInfo: {},
  11. sinopec:{},
  12. petrochina:{},
  13. phone: {},
  14. mini_code:'',
  15. pre_pay_count: 0, // 待付款 10
  16. pre_send_count: 0, // 待发货 20
  17. pre_receive_count: 0, // 待收货 30
  18. evaluate_count: 0, // 已收货 40
  19. userInfo: app.globalData.userInfo,
  20. showRCode: false
  21. },
  22. handleMore(e) {
  23. const { cardtype } = e.currentTarget.dataset
  24. if(cardtype === 'invitees') {
  25. app.navigateto('/pages/invitees/invitees')
  26. } else {
  27. app.navigateto(`/pages/postageManage/postageManage?card_type=${cardtype}`)
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function ()
  44. {
  45. if(!app.globalData.userInfo) {
  46. return;
  47. }
  48. this.setData({
  49. userInfo: app.globalData.userInfo
  50. })
  51. this.getData()
  52. },
  53. getData(){
  54. let self = this;
  55. getReq(app,{
  56. act: 'member_info',
  57. op: 'index',
  58. page_type: 'oil'
  59. }, (res) => {
  60. this.setData({
  61. firstLoad: false
  62. });
  63. if (res.code == 200) {
  64. console.log(res.datas)
  65. if(res.datas) {
  66. const { cards, sub_titles, mini_code } = res.datas
  67. const phone = app.getValueByKey('phone', cards)
  68. const petrochina = app.getValueByKey('petrochina', cards)
  69. const sinopec = app.getValueByKey('sinopec', cards)
  70. this.setData({ memberInfo: { ...res.datas }, phone, petrochina, sinopec, mini_code })
  71. }
  72. } else {
  73. app.showToast(res.message)
  74. }
  75. })
  76. getReq(app, {
  77. act: 'member_vorder',
  78. op: 'orderCountState'
  79. }, function (res) {
  80. if (res.code == 200) {
  81. self.setData({
  82. pre_pay_count: 0, // 待付款 10
  83. pre_send_count: 0, // 待发货 20
  84. pre_receive_count: 0, // 待收货 30
  85. evaluate_count: 0,
  86. firstLoad: false
  87. })
  88. let { order_count } = res.datas
  89. if (order_count.length) {
  90. let length = order_count.length
  91. for (let i = 0; i < length; i++) {
  92. let state_name = ''
  93. if (order_count[i]['order_state'] == 10) {
  94. state_name = 'pre_pay_count'
  95. }
  96. if (order_count[i]['order_state'] == 20) {
  97. state_name = 'pre_send_count'
  98. }
  99. if (order_count[i]['order_state'] == 30) {
  100. state_name = 'pre_receive_count'
  101. }
  102. if (order_count[i]['order_state'] == 40) {
  103. state_name = 'evaluate_count'
  104. }
  105. if (state_name) {
  106. self.setData({
  107. [state_name]: order_count[i]['count']
  108. })
  109. }
  110. }
  111. }
  112. }
  113. })
  114. },
  115. getAuth(e) {
  116. let { userInfo } = e.detail
  117. if (userInfo) {
  118. this.setData({
  119. userInfo:userInfo
  120. })
  121. wx.reLaunch({
  122. url: '/pages/index/index'
  123. });
  124. }
  125. },
  126. onShowMiniCode(e) {
  127. console.log('onShowMiniCode',this.mini_code)
  128. this.setData({ showRCode:true })
  129. },
  130. onCloseMiniDialog() {
  131. console.log('myhome,onCloseMiniDialog')
  132. this.setData({ showRCode: false })
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function () {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function () {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function () {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function () {
  158. // return app.cardShareInfo();
  159. }
  160. })