123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- // pages/handOutBonus/handOutBonus.js
- const getReq = require('../../config.js').getReq;
- const app = getApp();
- import recordSource from '../../utils/recordSource';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- bonusType: 'pin',
- canShare: false,
- btnFlag: false,
- datas: {},
- total: 0,
- count: 0,
- money: 0,
- tempCount: '',
- tempMoney: '',
- sendFlag: false,
- calcFlag: true,
- path: '',
- img_url: '',
- title: '',
- tempBless: '',
- bless: '',
- userInfo: app.globalData.userInfo
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (app.globalData.userInfo) {
- this.getDatas()
- this.setData({
- userInfo: app.globalData.userInfo
- })
- }
- },
- getAuth(e) {
- let { userInfo } = e.detail
- if (userInfo) {
- this.getDatas()
- this.setData({
- userInfo: app.globalData.userInfo
- })
- }
- },
- getDatas() {
- let params = {
- act: 'member_bonus',
- op: 'predepositex'
- }
- getReq(params, res => {
- if (res.code == 200) {
- let { datas } = res
- let tempBless = datas['send_bless']
- this.setData({
- datas,
- tempBless
- })
- }
- })
- },
- bindKeyInput(e) {
- let { type } = e.currentTarget.dataset
- let value = e.detail.value
- this.checkBindInput(type, value)
- },
- checkBindInput(type, value) {
- let currentType = type
- let currentValue = this.trim(value)
- if (type == 'count') {
- if (currentValue[0] == 0) {
- this.setData({
- tempCount: ''
- })
- }
- if (currentValue > 500) {
- currentValue = value.substring(0, currentValue.length - 1) || 0
- wx.showToast({
- icon: 'none',
- title: '一次最多发送红包500个',
- duration: 2000
- })
- }
- this.checkBindTotal(parseFloat(currentValue) || 0, this.data.money)
- this.setData({
- tempCount: parseFloat(currentValue),
- count: parseFloat(currentValue) || 0
- })
- }
- else if (type == 'money') {
- let index = currentValue.indexOf('.')
- if (index != -1) {
- if (index == 0) {
- this.setData({
- tempMoney: ''
- })
- return
- }
- let secondIndex = currentValue.substring(index + 1).indexOf('.')
- if (secondIndex != -1) {
- currentValue = currentValue.substring(0, index + 1)
- }
- if (currentValue.length - index - 1 > 2) {
- currentValue = currentValue.substring(0, index + 1 + 2)
- }
- }
- if (currentValue[0] == 0 && currentValue[1] != '.') {
- currentValue = currentValue.substring(1) || 0
- }
- if (currentValue > this.data.datas['share_bonus_rate'][0]['total']) {
- currentValue = value.substring(0, value.length - 1)
- wx.showToast({
- icon: 'none',
- title: '不能大于可分享的最大金额!',
- duration: 2000
- })
- }
- this.checkBindTotal(this.data.count, parseFloat(currentValue) || 0)
- this.setData({
- tempMoney: currentValue,
- money: parseFloat(currentValue) || 0
- })
- }
- },
- checkBindTotal(count, money) {
- let flag = true
- if (this.data.bonusType == 'pin') {
- flag = this.checkTotal(money)
- if (!count) {
- this.setData({
- total: 0
- })
- }
- else {
- this.setData({
- total: money
- })
- }
-
- }
- else {
- let bonus = count * money
- let total = parseInt(bonus * 100 + 0.5) / 100
- flag = this.checkTotal(total)
- this.setData({
- total
- })
- }
- if (count && money && this.data.bonusType == 'pin') {
- let single = money / count
- if (single < 0.01) {
- wx.showToast({
- icon: 'none',
- title: '单个红包金额小于0.01!',
- duration: 2000
- })
- flag = false
- }
- }
-
- if (!count || !money) {
- flag = false
- }
- this.setData({
- btnFlag: flag
- })
- return flag
- },
- checkTotal(money) {
- let flag = money < this.data.datas['share_bonus_rate'][0]['total']
- if (!flag) {
- wx.showToast({
- icon: 'none',
- title: '不能大于可分享的最大金额!',
- duration: 2000
- })
- }
- return flag
- },
- secBonusType(e) {
- let { type } = e.currentTarget.dataset
- this.setData({
- bonusType: type,
- })
- this.checkBindTotal(this.data.count || 0, this.data.money || 0)
- },
- checkBonus() {
- let flag = this.checkBindTotal(this.data.count || 0, this.data.money || 0)
- if (!flag){
- return
- }
- this.shareBonus()
- },
- shareBonus() {
- let params = {
- act: 'member_bonus',
- op: 'make',
- bonus_rate: this.data.datas['share_bonus_rate'][0]['rate'],
- total_num: this.data.count,
- type_bless: this.data.bless || this.data.datas['send_bless']
- }
- if (this.data.bonusType == "pin") {
- let data = {
- total_amount: this.data.money,
- send_type: 1
- }
- params = Object.assign({}, params, data)
- }
- else {
- let data = {
- fixed_money: this.data.money,
- send_type: 2
- }
- params = Object.assign({}, params, data)
- }
- getReq(params, res => {
- if (res.code == 200) {
- let { title, path } = res.datas
- this.setData({
- canShare: true,
- title,
- path
- })
- }
- else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 2000
- })
- return false
- }
- })
- },
- close() {
- this.setData({
- canShare: false
- })
- },
- blessFocus(e) {
- let { value } = e.detail
- if (value == this.data.datas['send_bless']) {
- this.setData({
- tempBless: ''
- })
- }
- },
- blessBlur(e) {
- let { value } = e.detail
- if(!this.trim(value)) {
- this.setData({
- tempBless: this.data.datas['send_bless']
- })
- }
- },
- blessInput(e) {
- let { value } = e.detail
- this.setData({
- bless: value
- })
- },
- trim(str) {
- str = str.replace(/\s+/g, "")
- return str
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- let self = this
- if (res.from == "button") {
- this.getDatas()
- this.setData({
- canShare: false
- })
- let imageUrl = '../../image/share_bonus.png'
- let { title, path } = this.data
- return {
- title,
- imageUrl: imageUrl,
- path: `/${path}`
- }
- }
- }
- })
|