123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- // pages/handOutBonus/handOutBonus.js
- const getReq = require('./../../config.js').getReq;
- const app = getApp();
- import recordSource from '../../utils/recordSource';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- bonusType: 'pin',
- canShare: 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
- })
- }
- })
- },
- calcTotal(count, money) {
- if (count && money && this.data.bonusType == 'pin') {
- let single = money / count
- if (single < 0.01) {
- wx.showToast({
- icon: 'none',
- title: '单个红包金额小于0.01!',
- duration: 2000
- })
- this.setData({
- calcFlag: false
- })
- return false
- }
- }
- if (this.data.bonusType == 'pin') {
- let calcFlag = this.checkTotal(money)
- this.setData({
- total: money,
- calcFlag
- })
- }
- else {
- let bonus = count * money
- let total = parseInt(bonus * 100 + 0.5) / 100
- let calcFlag = this.checkTotal(total)
- this.setData({
- total,
- calcFlag
- })
- }
- },
- checkTotal(money) {
- return money < this.data.datas['usable']
- },
- bindKeyInput(e) {
- let { type } = e.currentTarget.dataset
- let value = e.detail.value
- let flag = this.checkInput(type, value)
- if (!flag) {
- return
- }
- this.setData({
- sendFlag: true
- })
- },
- checkInput(type, value) {
- if (type == 'count') {
- if (value[0] == 0) {
- this.setData({
- tempCount: ''
- })
- return false
- }
- else if (value > 500) {
- let tempCount = value.substring(0, value.length - 1)
- this.setData({
- tempCount,
- count: tempCount
- })
- wx.showToast({
- icon: 'none',
- title: '一次最多发送红包500个',
- duration: 2000
- })
- this.calcTotal(tempCount || 0, this.data.money || 0)
- }
- else {
- this.setData({
- count: value
- })
- this.calcTotal(value || 0, this.data.money || 0)
- }
- }
- else if (type == 'money') {
- if (value.indexOf('.') != -1) {
- let tempArr = value.split('.')
- if (tempArr[1].length > 2) {
- tempArr[1] = tempArr[1].substring(0, tempArr[1].length - 1)
- }
- value = tempArr[0] + '.' + tempArr[1] || 0
- this.setData({
- tempMoney: value,
- money: parseFloat(value)
- })
- this.calcTotal(this.data.count || 0, parseFloat(value) || 0)
- }
- else if (value > this.data.datas['usable']) {
- let tempMoney = value.substring(0, value.length - 1)
- this.setData({
- tempMoney: tempMoney,
- money: parseFloat(tempMoney)
- })
- this.calcTotal(this.data.count || 0, parseFloat(tempMoney) || 0)
- wx.showToast({
- icon: 'none',
- title: '不能大于可分享的最大金额!',
- duration: 2000
- })
- return false
- }
- else {
- this.setData({
- money: parseFloat(value)
- })
- this.calcTotal(this.data.count || 0, parseFloat(value) || 0)
- }
- }
- return true
- },
- secBonusType(e) {
- let { type } = e.currentTarget.dataset
- this.setData({
- bonusType: type,
- })
- this.calcTotal(this.data.count || 0, this.data.money || 0)
- },
- checkBonus() {
- if (!this.data.sendFlag || !this.data.calcFlag) {
- 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
- },
- testBonus() {
- wx.navigateTo({
- url: '/pages/shareBonus/shareBonus?type_sn=23641538992987220059'
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- let self = this
- if (res.from == "button") {
- this.setData({
- canShare: false
- })
- let imageUrl = '../../image/share_bonus.png'
- let { title, path } = this.data
- return {
- title,
- imageUrl: imageUrl,
- path: `/${path}`,
- complete: function(res) {
- self.getDatas()
- }
- }
- }
- }
- })
|