myhome.js 4.0 KB

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