index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. var app = getApp(),
  2. api = app.api;
  3. Page({
  4. data: {
  5. total_price: 0,
  6. price: 0,
  7. cash_price: 0,
  8. total_cash: 0,
  9. team_count: 0,
  10. order_money: 0
  11. },
  12. onLoad: function (e) {
  13. getApp().page.onLoad(this, e);
  14. this.setData({
  15. custom: getApp().core.getStorageSync(getApp().const.CUSTOM)
  16. })
  17. },
  18. onReady: function () {
  19. getApp().page.onReady(this)
  20. },
  21. onShow: function () {
  22. getApp().page.onShow(this);
  23. var e = this,
  24. t = getApp().core.getStorageSync(getApp().const.SHARE_SETTING),
  25. a = e.data.__user_info;
  26. e.setData({
  27. share_setting: t,
  28. custom: e.data.store.share_custom_data
  29. }),
  30. a && 1 == a.is_distributor ? e.checkUser() : e.loadData()
  31. },
  32. checkUser: function () {
  33. var t = this;
  34. getApp().core.showLoading({
  35. title: "正在加载",
  36. mask: !0
  37. }), getApp().request({
  38. url: getApp().api.share.get_info,
  39. success: function (e) {
  40. 0 == e.code && (t.setData({
  41. total_price: e.data.price.total_price,
  42. price: e.data.price.price,
  43. cash_price: e.data.price.cash_price,
  44. total_cash: e.data.price.total_cash,
  45. team_count: e.data.team_count,
  46. order_money: e.data.order_money,
  47. custom: e.data.custom,
  48. order_money_un: e.data.order_money_un
  49. }), getApp().core.setStorageSync(getApp().const.CUSTOM, e.data.custom), t.loadData()), 1 == e.code && (__user_info.is_distributor = e.data.is_distributor, t.setData({
  50. __user_info: __user_info
  51. }), getApp().setUser(__user_info))
  52. },
  53. complete: function () {
  54. getApp().core.hideLoading()
  55. }
  56. })
  57. },
  58. loadData: function () {
  59. var a = this;
  60. getApp().core.showLoading({
  61. title: "正在加载",
  62. mask: !0
  63. }), getApp().request({
  64. url: getApp().api.share.index,
  65. success: function (e) {
  66. if (0 == e.code) {
  67. if (e.data.share_setting) var t = e.data.share_setting;
  68. else t = e.data;
  69. getApp().core.setStorageSync(getApp().const.SHARE_SETTING, t), a.setData({
  70. share_setting: t
  71. })
  72. }
  73. },
  74. complete: function () {
  75. getApp().core.hideLoading()
  76. }
  77. })
  78. },
  79. onHide: function () {
  80. getApp().page.onHide(this)
  81. },
  82. onUnload: function () {
  83. getApp().page.onUnload(this)
  84. },
  85. onPullDownRefresh: function () {},
  86. onReachBottom: function () {},
  87. apply: function (t) {
  88. var a = getApp().core.getStorageSync(getApp().const.SHARE_SETTING),
  89. o = getApp().getUser();
  90. 1 == a.share_condition ? getApp().core.navigateTo({
  91. url: "/pages/add-share/index"
  92. }) : 0 != a.share_condition && 2 != a.share_condition || (0 == o.is_distributor ? getApp().core.showModal({
  93. title: "申请成为" + (this.data.custom.words.share_name.name || "分销商"),
  94. content: "是否申请?",
  95. success: function (e) {
  96. e.confirm && (getApp().core.showLoading({
  97. title: "正在加载",
  98. mask: !0
  99. }), getApp().request({
  100. url: getApp().api.share.join,
  101. method: "POST",
  102. data: {
  103. form_id: t.detail.formId
  104. },
  105. success: function (e) {
  106. 0 == e.code && (0 == a.share_condition ? (o.is_distributor = 2, getApp().core.navigateTo({
  107. url: "/pages/add-share/index"
  108. })) : (o.is_distributor = 1, getApp().core.redirectTo({
  109. url: "/pages/share/index"
  110. })), getApp().setUser(o))
  111. },
  112. complete: function () {
  113. getApp().core.hideLoading()
  114. }
  115. }))
  116. }
  117. }) : getApp().core.navigateTo({
  118. url: "/pages/add-share/index"
  119. }))
  120. }
  121. });