handOutBonus.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // pages/handOutBonus/handOutBonus.js
  2. const getReq = require('./../../config.js').getReq;
  3. const app = getApp();
  4. import recordSource from '../../utils/recordSource';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. bonusType: 'pin',
  11. canShare: false,
  12. datas: {},
  13. total: 0,
  14. count: 0,
  15. money: 0,
  16. tempCount: '',
  17. tempMoney: '',
  18. sendFlag: false,
  19. calcFlag: true,
  20. path: '',
  21. img_url: '',
  22. title: '',
  23. tempBless: '',
  24. bless: '',
  25. userInfo: app.globalData.userInfo
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. if (app.globalData.userInfo) {
  32. this.getDatas()
  33. this.setData({
  34. userInfo: app.globalData.userInfo
  35. })
  36. }
  37. },
  38. getAuth(e) {
  39. let { userInfo } = e.detail
  40. if (userInfo) {
  41. this.getDatas()
  42. this.setData({
  43. userInfo: app.globalData.userInfo
  44. })
  45. }
  46. },
  47. getDatas() {
  48. let params = {
  49. act: 'member_bonus',
  50. op: 'predepositex'
  51. }
  52. getReq(params, res => {
  53. if (res.code == 200) {
  54. let { datas } = res
  55. let tempBless = datas['send_bless']
  56. this.setData({
  57. datas,
  58. tempBless
  59. })
  60. }
  61. })
  62. },
  63. bindKeyInput(e) {
  64. let { type } = e.currentTarget.dataset
  65. let value = e.detail.value
  66. this.checkBindInput(type, value)
  67. },
  68. checkBindInput(type, value) {
  69. let currentType = type
  70. let currentValue = this.trim(value)
  71. if (type == 'count') {
  72. if (currentValue[0] == 0) {
  73. this.setData({
  74. tempCount: ''
  75. })
  76. }
  77. if (currentValue > 500) {
  78. currentValue = value.substring(0, currentValue.length - 1) || 0
  79. wx.showToast({
  80. icon: 'none',
  81. title: '一次最多发送红包500个',
  82. duration: 2000
  83. })
  84. }
  85. this.checkBindTotal(parseFloat(currentValue) || 0, this.data.money)
  86. this.setData({
  87. tempCount: parseFloat(currentValue),
  88. count: parseFloat(currentValue) || 0
  89. })
  90. }
  91. else if (type == 'money') {
  92. let index = currentValue.indexOf('.')
  93. if (index != -1) {
  94. if (index == 0) {
  95. this.setData({
  96. tempMoney: ''
  97. })
  98. return
  99. }
  100. let tempArr = currentValue.split('.')
  101. if (tempArr[1].length > 2) {
  102. tempArr[1] = tempArr[1].substring(0, tempArr[1].length - 1)
  103. }
  104. currentValue = tempArr[0] + '.' + tempArr[1] || 0
  105. }
  106. if (currentValue[0] == 0 && currentValue[1] != '.') {
  107. currentValue = currentValue.substring(1) || 0
  108. }
  109. if (currentValue > this.data.datas['usable']) {
  110. currentValue = value.substring(0, value.length - 1)
  111. wx.showToast({
  112. icon: 'none',
  113. title: '不能大于可分享的最大金额!',
  114. duration: 2000
  115. })
  116. }
  117. this.checkBindTotal(this.data.count, parseFloat(currentValue) || 0)
  118. this.setData({
  119. tempMoney: currentValue,
  120. money: parseFloat(currentValue) || 0
  121. })
  122. }
  123. },
  124. checkBindTotal(count, money) {
  125. let flag = true
  126. if (this.data.bonusType == 'pin') {
  127. flag = this.checkTotal(money)
  128. this.setData({
  129. total: money
  130. })
  131. }
  132. else {
  133. let bonus = count * money
  134. let total = parseInt(bonus * 100 + 0.5) / 100
  135. flag = this.checkTotal(total)
  136. this.setData({
  137. total
  138. })
  139. }
  140. if (count && money && this.data.bonusType == 'pin') {
  141. let single = money / count
  142. if (single < 0.01) {
  143. wx.showToast({
  144. icon: 'none',
  145. title: '单个红包金额小于0.01!',
  146. duration: 2000
  147. })
  148. flag = false
  149. }
  150. }
  151. if (!count || !money) {
  152. flag = false
  153. }
  154. return flag
  155. },
  156. checkTotal(money) {
  157. let flag = money < this.data.datas['usable']
  158. if (!flag) {
  159. wx.showToast({
  160. icon: 'none',
  161. title: '不能大于可分享的最大金额!',
  162. duration: 2000
  163. })
  164. }
  165. return flag
  166. },
  167. secBonusType(e) {
  168. let { type } = e.currentTarget.dataset
  169. this.setData({
  170. bonusType: type,
  171. })
  172. this.checkBindTotal(this.data.count || 0, this.data.money || 0)
  173. },
  174. checkBonus() {
  175. let flag = this.checkBindTotal(this.data.count || 0, this.data.money || 0)
  176. console.log(flag);
  177. if (!flag){
  178. return
  179. }
  180. this.shareBonus()
  181. },
  182. shareBonus() {
  183. let params = {
  184. act: 'member_bonus',
  185. op: 'make',
  186. bonus_rate: this.data.datas['share_bonus_rate'][0]['rate'],
  187. total_num: this.data.count,
  188. type_bless: this.data.bless || this.data.datas['send_bless']
  189. }
  190. if (this.data.bonusType == "pin") {
  191. let data = {
  192. total_amount: this.data.money,
  193. send_type: 1
  194. }
  195. params = Object.assign({}, params, data)
  196. }
  197. else {
  198. let data = {
  199. fixed_money: this.data.money,
  200. send_type: 2
  201. }
  202. params = Object.assign({}, params, data)
  203. }
  204. getReq(params, res => {
  205. if (res.code == 200) {
  206. let { title, path } = res.datas
  207. this.setData({
  208. canShare: true,
  209. title,
  210. path
  211. })
  212. }
  213. else {
  214. wx.showToast({
  215. icon: 'none',
  216. title: res.message,
  217. duration: 2000
  218. })
  219. return false
  220. }
  221. })
  222. },
  223. close() {
  224. this.setData({
  225. canShare: false
  226. })
  227. },
  228. blessFocus(e) {
  229. let { value } = e.detail
  230. if (value == this.data.datas['send_bless']) {
  231. this.setData({
  232. tempBless: ''
  233. })
  234. }
  235. },
  236. blessBlur(e) {
  237. let { value } = e.detail
  238. if(!this.trim(value)) {
  239. this.setData({
  240. tempBless: this.data.datas['send_bless']
  241. })
  242. }
  243. },
  244. blessInput(e) {
  245. let { value } = e.detail
  246. this.setData({
  247. bless: value
  248. })
  249. },
  250. trim(str) {
  251. str = str.replace(/\s+/g, "")
  252. return str
  253. },
  254. testBonus() {
  255. wx.navigateTo({
  256. url: '/pages/shareBonus/shareBonus?type_sn=23641538992987220059'
  257. });
  258. },
  259. /**
  260. * 生命周期函数--监听页面初次渲染完成
  261. */
  262. onReady: function () {
  263. },
  264. /**
  265. * 生命周期函数--监听页面显示
  266. */
  267. onShow: function () {
  268. },
  269. /**
  270. * 生命周期函数--监听页面隐藏
  271. */
  272. onHide: function () {
  273. },
  274. /**
  275. * 生命周期函数--监听页面卸载
  276. */
  277. onUnload: function () {
  278. },
  279. /**
  280. * 页面相关事件处理函数--监听用户下拉动作
  281. */
  282. onPullDownRefresh: function () {
  283. },
  284. /**
  285. * 页面上拉触底事件的处理函数
  286. */
  287. onReachBottom: function () {
  288. },
  289. /**
  290. * 用户点击右上角分享
  291. */
  292. onShareAppMessage: function (res) {
  293. let self = this
  294. if (res.from == "button") {
  295. this.setData({
  296. canShare: false
  297. })
  298. let imageUrl = '../../image/share_bonus.png'
  299. let { title, path } = this.data
  300. return {
  301. title,
  302. imageUrl: imageUrl,
  303. path: `/${path}`,
  304. complete: function(res) {
  305. self.getDatas()
  306. }
  307. }
  308. }
  309. }
  310. })