red-dot.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var url = require('../constant/url.js')
  2. import Net from '../tool/net.js'
  3. var net = new Net()
  4. var app = getApp()
  5. function getRedDot() {
  6. net.connectNeedLogin({
  7. url: url.app_host + url.getPersonalPageCount,
  8. data: {},
  9. success: (err, res) => {
  10. var all = 0
  11. if (res.data.buy > 99) {
  12. app.redDotArray[0] = '99+'
  13. } else {
  14. app.redDotArray[0] = String(res.data.buy)
  15. }
  16. all += res.data.buy
  17. if (res.data.wage > 99) {
  18. app.redDotArray[1] = '99+'
  19. } else {
  20. app.redDotArray[1] = String(res.data.wage)
  21. }
  22. all += res.data.wage
  23. if (res.data.added > 99) {
  24. app.redDotArray[2] = '99+'
  25. } else {
  26. app.redDotArray[2] = String(res.data.added)
  27. }
  28. all += res.data.added
  29. if (res.data.material_flow > 99) {
  30. app.redDotArray[3] = '99+'
  31. } else {
  32. app.redDotArray[3] = String(res.data.material_flow)
  33. }
  34. all += res.data.material_flow
  35. var pages = getCurrentPages()
  36. var page = pages[0]
  37. if (typeof page.refreshRedDot === 'function') {
  38. page.refreshRedDot()
  39. }
  40. if (all > 99) {
  41. all = '99+'
  42. } else {
  43. all = String(all)
  44. }
  45. app.tabRedDot = all
  46. if (all != 0) {
  47. swan.setTabBarBadge({
  48. index: 2,
  49. text: all,
  50. });
  51. }else{
  52. swan.removeTabBarBadge({
  53. index: 2
  54. });
  55. }
  56. app.bankCardTips = {}
  57. outer:
  58. for (var i = 0; i < res.data.sbuids.length; i++) {
  59. var id = res.data.sbuids[i]
  60. for (var j = 0; j < app.globalData.customerList.length; j++) {
  61. var customer = app.globalData.customerList[j]
  62. if (id == customer.id) {
  63. app.bankCardTips = {
  64. 't': '请添加 ' + customer.user_name + ' 的银行卡,否则会影响流水费返还。',
  65. 'c': customer
  66. }
  67. break outer
  68. }
  69. }
  70. }
  71. if (typeof page.judgeBankCardTips === 'function') {
  72. page.judgeBankCardTips()
  73. }
  74. },
  75. fail: (err, res) => {
  76. console.log('failed')
  77. }
  78. }, true)
  79. }
  80. module.exports = {
  81. getRedDot: getRedDot,
  82. }