count.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var _request = require('../../../utils/request.js')
  2. Page({
  3. data: {
  4. price: 0,
  5. count: 0,
  6. min: 0,
  7. retrieve: 0,
  8. sell: 0,
  9. self_count: 1,
  10. re_count: 1,
  11. re_max: 0,
  12. re_price: 0,
  13. sell_sount: 0,
  14. all: 0
  15. },
  16. onLoad: function (options) {
  17. console.log(options)
  18. this.setData({
  19. price: Number(options.price),
  20. count: Number(options.count),
  21. min: Number(options.min) * ((Number(options.count) - Number(options.minlimit)) / Number(options.limit) + 1),
  22. retrieve: Number(options.retrieve),
  23. sell: Number(options.sell),
  24. re_max: Number(options.remax),
  25. re_price: Number(options.reprice)
  26. })
  27. this.setData({
  28. self_count: this.data.min
  29. })
  30. if (Number(options.count) - this.data.min > this.data.re_max) {
  31. this.setData({
  32. re_count: this.data.re_max
  33. })
  34. } else {
  35. this.setData({
  36. re_count: Number(options.count) - this.data.min
  37. })
  38. }
  39. this.setData({
  40. sell_sount: this.data.count - this.data.self_count - this.data.re_count
  41. })
  42. this.changeSell()
  43. },
  44. selfSub: function () {
  45. if (this.data.self_count > this.data.min) {
  46. let count = this.data.self_count - 1
  47. this.setData({
  48. self_count: count
  49. })
  50. this.changeSell()
  51. }
  52. },
  53. selfAdd: function () {
  54. if (this.data.self_count + this.data.re_count >= this.data.count && this.data.re_count > 0) {
  55. let add = this.data.self_count + 1
  56. let sub = this.data.re_count - 1
  57. this.setData({
  58. self_count: add,
  59. re_count: sub
  60. })
  61. this.changeSell()
  62. } else if (this.data.self_count + this.data.re_count < this.data.count) {
  63. let add = this.data.self_count + 1
  64. this.setData({
  65. self_count: add
  66. })
  67. this.changeSell()
  68. }
  69. },
  70. reSub: function () {
  71. if (this.data.re_count > 0) {
  72. let count = this.data.re_count - 1
  73. this.setData({
  74. re_count: count
  75. })
  76. this.changeSell()
  77. }
  78. },
  79. reAdd: function () {
  80. if (this.data.re_count < this.data.re_max) {
  81. if (this.data.self_count + this.data.re_count >= this.data.count && this.data.self_count > this.data.min) {
  82. let add = this.data.re_count + 1
  83. let sub = this.data.self_count - 1
  84. this.setData({
  85. re_count: add,
  86. self_count: sub
  87. })
  88. this.changeSell()
  89. } else if (this.data.self_count + this.data.re_count < this.data.count) {
  90. let add = this.data.re_count + 1
  91. this.setData({
  92. re_count: add
  93. })
  94. this.changeSell()
  95. }
  96. }
  97. },
  98. changeSell: function () {
  99. this.setData({
  100. sell_sount: this.data.count - this.data.self_count - this.data.re_count
  101. })
  102. // var a = ((((this.data.price / this.data.count * (this.data.re_count * (this.data.retrieve + 1) + this.data.self_count) + this.data.sell * this.data.sell_sount) / this.data.price) - 1) * 100).toFixed(2)
  103. var a = ((((this.data.price / this.data.count * this.data.self_count + this.data.re_count * this.data.re_price + this.data.sell * this.data.sell_sount) / this.data.price) - 1) * 100).toFixed(2)
  104. this.setData({
  105. all: a
  106. })
  107. },
  108. onShareAppMessage: function (val) {
  109. return _request.share({
  110. sc: 'helpfarm_calculate'
  111. })
  112. }
  113. })