index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {
  2. getSaleData,
  3. cashOut
  4. } from '~/api/sale'
  5. import event from '~/mixins/event'
  6. Page({
  7. behaviors: [event],
  8. data: {
  9. allIncome: {},
  10. money: '',
  11. errMsg: '',
  12. activationModal: false,
  13. },
  14. onShow() {
  15. this.getIncome()
  16. },
  17. async getIncome() {
  18. let allIncome = await getSaleData()
  19. this.setData({
  20. allIncome
  21. })
  22. },
  23. async withdrawalFun() {
  24. let money = this.data.money
  25. if (isNaN(money)) {
  26. this.setData({
  27. errMsg: '金额不合法'
  28. })
  29. return
  30. }
  31. // 判断金额是否超过两位小数
  32. var decimalCount = (money.split('.')[1] || '').length;
  33. if (decimalCount > 2) {
  34. this.setData({
  35. errMsg: '最多两位小数'
  36. })
  37. return
  38. }
  39. if (money <= 0) {
  40. this.setData({
  41. errMsg: '请输入要提现的金额'
  42. })
  43. return
  44. }
  45. if (money > this.data.allIncome.withdraw / 100) {
  46. this.setData({
  47. errMsg: '可提现金额不足'
  48. })
  49. return
  50. }
  51. if (money > 500 || money < 50) {
  52. this.setData({
  53. errMsg: '提现金额需≥50元,单笔最高可提500元'
  54. })
  55. return
  56. }
  57. let res = await cashOut({
  58. amount: money * 100
  59. })
  60. this.setData({
  61. activationModal: true,
  62. })
  63. this.getIncome()
  64. },
  65. clearMoney() {
  66. this.setData({
  67. money: "",
  68. errMsg: ""
  69. });
  70. },
  71. setMoney({
  72. detail
  73. }) {
  74. this.setData({
  75. money: detail.value
  76. });
  77. },
  78. jump({
  79. currentTarget
  80. }) {
  81. wx.navigateTo({
  82. url: `/salesperson/pages/${currentTarget.dataset.url}/index`,
  83. })
  84. },
  85. closeModal() {
  86. this.setData({
  87. activationModal: false
  88. })
  89. },
  90. })