index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. length: 0,
  9. earnings: 0,
  10. list: [
  11. { 'num': '提现到银行卡' },
  12. ],
  13. idx: null,
  14. id: null,
  15. name: null,
  16. price: null,
  17. checked: true,
  18. merchant: null,
  19. names: null,
  20. bankName: null,
  21. accountId: null,
  22. activeColor: getApp().globalData.activeColor,
  23. titleColor: getApp().globalData.titleColor,
  24. },
  25. async getUserAgentWithdraw() {
  26. let merchant = wx.getStorageSync("merchant");
  27. if (merchant == "") {
  28. wx.redirectTo({
  29. url: '/nova-bzzb/pages/my/login/index'
  30. });
  31. return;
  32. }
  33. if (this.data.length > 2) {
  34. wx.showToast({
  35. title: '您本月的提现次数已到上限',
  36. icon: 'none',
  37. });
  38. return;
  39. }
  40. if (!this.data.price) {
  41. wx.showToast({
  42. title: '请输入提现金额',
  43. icon: 'none',
  44. });
  45. return
  46. }
  47. console.log(this.data.price, this.data.earnings);
  48. console.log(this.data.price > this.data.earnings)
  49. if (Number(this.data.price) > Number(this.data.earnings)) {
  50. wx.showToast({
  51. title: '您输入的金额超过了您的可提现金额',
  52. icon: 'none',
  53. });
  54. return
  55. }
  56. if (this.data.price < 1000) {
  57. wx.showToast({
  58. title: '最低提现金额为1000元',
  59. icon: 'none',
  60. });
  61. return
  62. }
  63. if (!this.data.name) {
  64. wx.showToast({
  65. title: '请选择提现方式',
  66. icon: 'none',
  67. });
  68. return
  69. }
  70. if (!this.data.names || !this.data.bankName || !this.data.accountId) {
  71. wx.showToast({
  72. title: '请输入完整银行卡信息',
  73. icon: 'none',
  74. });
  75. return
  76. }
  77. let UserAgentWithdraw = Parse.Object.extend("UserAgentWithdraw")
  78. let userAgentWithdraw = new UserAgentWithdraw()
  79. userAgentWithdraw.set("count", Number(this.data.price))
  80. userAgentWithdraw.set("type", "bank")
  81. userAgentWithdraw.set("isVerified", false)
  82. userAgentWithdraw.set("company", {
  83. __type: 'Pointer',
  84. className: 'Company',
  85. objectId: company
  86. })
  87. userAgentWithdraw.set("user", {
  88. __type: 'Pointer',
  89. className: '_User',
  90. objectId: this.data.merchant
  91. })
  92. userAgentWithdraw.set("info", [{
  93. name: this.data.names,
  94. accountId: this.data.accountId,
  95. bankName: this.data.bankName,
  96. storeName: this.data.id,
  97. }]
  98. )
  99. userAgentWithdraw.save().then(res => {
  100. console.log(res)
  101. wx.showToast({
  102. title: '提现成功',
  103. icon: 'none',
  104. });
  105. wx.navigateBack({
  106. delta: 1
  107. })
  108. })
  109. },
  110. goIndex(e) {
  111. let index = e.currentTarget.dataset.index;
  112. let name = e.currentTarget.dataset.item.num
  113. if (index == this.data.idx) {
  114. this.setData({
  115. idx: null,
  116. name: null
  117. })
  118. } else {
  119. this.setData({
  120. idx: index,
  121. name: name
  122. })
  123. }
  124. },
  125. blur(e) {
  126. let name = e.currentTarget.dataset.name
  127. this.setData({
  128. [name]: e.detail.value
  129. })
  130. },
  131. async getTotal(startTime, endTime) {
  132. let UserAgentWithdraw = new Parse.Query('UserAgentWithdraw')
  133. UserAgentWithdraw.equalTo('user', this.data.merchant)
  134. UserAgentWithdraw.equalTo('type', 'bank')
  135. UserAgentWithdraw.greaterThan('createdAt', startTime)
  136. UserAgentWithdraw.lessThan('createdAt', endTime)
  137. let userAgentWithdraw = await UserAgentWithdraw.find()
  138. let length
  139. if (userAgentWithdraw) {
  140. console.log(userAgentWithdraw.length);
  141. length = userAgentWithdraw.length
  142. }
  143. this.setData({
  144. length: length
  145. })
  146. console.log(this.data.length);
  147. },
  148. /**
  149. * 生命周期函数--监听页面加载
  150. */
  151. onLoad: function (options) {
  152. console.log(Parse.User.current().id);
  153. let earnings = options.earnings
  154. let id = options.id
  155. let merchant = wx.getStorageSync('merchant'); //用户
  156. console.log(merchant);
  157. console.log(earnings);
  158. this.setData({
  159. earnings: earnings,
  160. merchant: merchant.objectId,
  161. id: id
  162. })
  163. let d = new Date();
  164. this.date = d
  165. let data = new Date(d.getFullYear(), d.getMonth() + 1, 0);
  166. let day = data.getDate();
  167. this.data.year = d.getFullYear()
  168. this.data.month = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1)
  169. let dayArr = []
  170. for (let i = 0; i < day; i++) {
  171. if (i < 9) {
  172. dayArr.push("0" + (i + 1))
  173. } else {
  174. dayArr.push((i + 1))
  175. }
  176. }
  177. let startTime = this.data.year + "-" + this.data.month + "-" + "01" + " 00:00:00"
  178. let endTime = this.data.year + "-" + this.data.month + "-" + dayArr.length + " 23:59:57"
  179. console.log(startTime, endTime);
  180. this.getTotal(startTime, endTime)
  181. },
  182. /**
  183. * 生命周期函数--监听页面初次渲染完成
  184. */
  185. onReady: function () {
  186. },
  187. /**
  188. * 生命周期函数--监听页面显示
  189. */
  190. onShow: function () {
  191. },
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload: function () {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh: function () {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom: function () {
  211. },
  212. /**
  213. * 用户点击右上角分享
  214. */
  215. onShareAppMessage: function () {
  216. }
  217. })