var _request = require('../../../utils/request.js') Page({ data: { price: 0, count: 0, min: 0, retrieve: 0, sell: 0, self_count: 1, re_count: 1, re_max: 0, re_price: 0, sell_sount: 0, all: 0 }, onLoad: function (options) { console.log(options) this.setData({ price: Number(options.price), count: Number(options.count), min: Number(options.min) * ((Number(options.count) - Number(options.minlimit)) / Number(options.limit) + 1), retrieve: Number(options.retrieve), sell: Number(options.sell), re_max: Number(options.remax), re_price: Number(options.reprice) }) this.setData({ self_count: this.data.min }) if (Number(options.count) - this.data.min > this.data.re_max) { this.setData({ re_count: this.data.re_max }) } else { this.setData({ re_count: Number(options.count) - this.data.min }) } this.setData({ sell_sount: this.data.count - this.data.self_count - this.data.re_count }) this.changeSell() }, selfSub: function () { if (this.data.self_count > this.data.min) { let count = this.data.self_count - 1 this.setData({ self_count: count }) this.changeSell() } }, selfAdd: function () { if (this.data.self_count + this.data.re_count >= this.data.count && this.data.re_count > 0) { let add = this.data.self_count + 1 let sub = this.data.re_count - 1 this.setData({ self_count: add, re_count: sub }) this.changeSell() } else if (this.data.self_count + this.data.re_count < this.data.count) { let add = this.data.self_count + 1 this.setData({ self_count: add }) this.changeSell() } }, reSub: function () { if (this.data.re_count > 0) { let count = this.data.re_count - 1 this.setData({ re_count: count }) this.changeSell() } }, reAdd: function () { if (this.data.re_count < this.data.re_max) { if (this.data.self_count + this.data.re_count >= this.data.count && this.data.self_count > this.data.min) { let add = this.data.re_count + 1 let sub = this.data.self_count - 1 this.setData({ re_count: add, self_count: sub }) this.changeSell() } else if (this.data.self_count + this.data.re_count < this.data.count) { let add = this.data.re_count + 1 this.setData({ re_count: add }) this.changeSell() } } }, changeSell: function () { this.setData({ sell_sount: this.data.count - this.data.self_count - this.data.re_count }) // 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) 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) this.setData({ all: a }) }, onShareAppMessage: function (val) { return _request.share({ sc: 'helpfarm_calculate' }) } })