fund.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. var _request = require('../../../../utils/request.js')
  2. var TAKE_CASH_SUBSCRIBE_TEMPLATE_ID = "L073dR84XibBZNxfvTkvTIemd7JAbj5o2Og7-VBAiX8"
  3. Page({
  4. data: {
  5. page: 1,
  6. per_page: 10,
  7. cashTotal: '',
  8. cashList: [],
  9. cashList_more: true,
  10. cashList_change: false,
  11. identityDialog: false,
  12. confirmDialog: false,
  13. bannerList: [],
  14. isCertificate: 0,
  15. lockWithdraw: false,
  16. has_bank:false,
  17. min_cash:0,
  18. max_cahs:0,
  19. sourceurl:false
  20. },
  21. onLoad: function (options) {
  22. console.log('source',options);
  23. if(options && options['source'] && options['source'] == 'canteen'){
  24. this.setData({
  25. sourceurl:'/pages/canteen/canteen'
  26. })
  27. }
  28. this.getCashTotal()
  29. this.getCashList()
  30. this.getBanners()
  31. },
  32. onPullDownRefresh: function () {
  33. this.setData({
  34. page: 1,
  35. cashList_more: true,
  36. cashList_change: true
  37. })
  38. this.getCashList()
  39. wx.stopPullDownRefresh()
  40. },
  41. onReachBottom: function () {
  42. if (this.data.cashList_more) {
  43. var page = this.data.page + 1
  44. this.setData({
  45. page: page
  46. })
  47. this.getCashList()
  48. }
  49. },
  50. onShow () {
  51. if (getApp().globalData.rechargeChanged) {
  52. getApp().globalData.rechargeChanged = false
  53. this.refreshCashPage()
  54. this.checkCertified()
  55. this.getWithDrawlimit()
  56. return
  57. }
  58. this.getCashTotal()
  59. this.checkCertified()
  60. this.getWithDrawlimit()
  61. },
  62. refreshCashPage () {
  63. this.setData({
  64. page: 1,
  65. cashList: [],
  66. cashList_more: true,
  67. cashList_change: false
  68. })
  69. this.getCashTotal()
  70. this.getCashList()
  71. },
  72. getCashTotal () {
  73. var that = this
  74. var url = 'v1/user/cash/balance/info'
  75. var params = {
  76. }
  77. var success = function (res) {
  78. console.log('res.data',res.data)
  79. that.setData({
  80. cashTotal: res.data
  81. })
  82. }
  83. _request.$get(url, params, success)
  84. },
  85. getCashList () {
  86. var that = this
  87. var url = 'v1/user/cash/balances'
  88. var params = {
  89. page: that.data.page,
  90. per_page: that.data.per_page
  91. }
  92. var success = function (res) {
  93. if (that.data.cashList_change) {
  94. that.setData({
  95. cashList: [],
  96. cashList_change: false
  97. })
  98. }
  99. var result = that.data.cashList.concat(res.data.balance_list || [])
  100. var listMore = res.data.balance_count > result.length
  101. that.setData({
  102. cashList: result,
  103. cashList_more: listMore
  104. })
  105. }
  106. _request.$get(url, params, success)
  107. },
  108. getWithDrawlimit () {
  109. var that = this
  110. var url = 'v1/user/takecash/limit'
  111. var params = {}
  112. var success = function (res) {
  113. that.setData({
  114. min_cash: res.data.min_limit_cash,
  115. max_cash: res.data.max_limit_cash
  116. })
  117. }
  118. _request.$get(url, params, success)
  119. },
  120. tipClick () {
  121. var that = this
  122. // if (!that.data.isCertificate) {
  123. // }
  124. that.data.confirmDialog = !that.data.confirmDialog
  125. if (that.data.cashTotal.available >= that.data.min_cash && that.data.cashTotal.available <= that.data.max_cash) {
  126. that.setData({
  127. confirmDialog: that.data.confirmDialog
  128. })
  129. } else {
  130. wx.showToast({
  131. title: '单次提现金额范围,大于'+that.data.min_cash/100 +'元 小于'+that.data.max_cash/100 +'元',
  132. icon: 'none',
  133. duration: 2000
  134. })
  135. }
  136. },
  137. getBankInfoAndTip(){
  138. var that = this
  139. that.requestTakeCashSubscribe(function () {
  140. that.showWithdrawConfirm()
  141. })
  142. },
  143. showWithdrawConfirm () {
  144. var that = this
  145. // var url = 'v1/user/get_bank_info'
  146. // var params = {
  147. // }
  148. // var success = function (res) {
  149. // that.setData({
  150. // has_bank:res.data.has_bank
  151. // })
  152. // if(that.data.has_bank){
  153. that.data.confirmDialog = !that.data.confirmDialog
  154. if (that.data.cashTotal.available >= that.data.min_cash && that.data.cashTotal.available <= that.data.max_cash) {
  155. that.setData({
  156. confirmDialog: that.data.confirmDialog
  157. })
  158. } else {
  159. wx.showToast({
  160. title: '单次提现金额范围,大于'+that.data.min_cash/100 +'元 小于'+that.data.max_cash/100 +'元',
  161. icon: 'none',
  162. duration: 2000
  163. })
  164. }
  165. // }
  166. // _request.$get(url, params, success)
  167. },
  168. toTransfer(){
  169. wx.navigateTo({
  170. url: '/packageUser/pages/user/transfer/transfer'
  171. })
  172. },
  173. goRechargeClick () {
  174. console.log('sourceurl',this.data.sourceurl);
  175. if(!this.data.sourceurl){
  176. wx.navigateTo({
  177. url: '/packageUser/pages/user/recharge/recharge'
  178. })
  179. }else{
  180. console.log('here');
  181. wx.navigateTo({
  182. url: '/packageUser/pages/user/recharge/recharge?source='+this.data.sourceurl
  183. })
  184. }
  185. },
  186. goIdentityClick () {
  187. var that = this
  188. that.setData({
  189. identityDialog: false
  190. })
  191. wx.navigateTo({
  192. url: '/packageUser/pages/user/identity/identity'
  193. })
  194. },
  195. goWithdrawClick () {
  196. wx.navigateTo({
  197. url: '/packageUser/pages/user/withdraw/withdraw'
  198. })
  199. },
  200. cancelIdentity () {
  201. var that = this
  202. that.setData({
  203. identityDialog: false
  204. })
  205. },
  206. buyClick () {
  207. var that = this
  208. wx.navigateTo({
  209. url: that.data.bannerList[0].url
  210. })
  211. },
  212. confrimClick () {
  213. var that = this
  214. console.log('that.data.has_bank',that.data.has_bank)
  215. // if (that.data.has_bank) {
  216. that.requestTakeCashSubscribe(function () {
  217. that.withdrawClick()
  218. })
  219. // } else {
  220. // that.setData({
  221. // confirmDialog: false,
  222. // identityDialog: true
  223. // })
  224. // }
  225. },
  226. requestTakeCashSubscribe (done) {
  227. if (!wx.requestSubscribeMessage) {
  228. done && done()
  229. return
  230. }
  231. wx.requestSubscribeMessage({
  232. tmplIds: [TAKE_CASH_SUBSCRIBE_TEMPLATE_ID],
  233. success: function (res) {
  234. console.log("take cash subscribe message", res)
  235. },
  236. fail: function (res) {
  237. console.log("take cash subscribe message fail", res)
  238. },
  239. complete: function () {
  240. done && done()
  241. }
  242. })
  243. },
  244. closedDialog () {
  245. var that = this
  246. that.setData({
  247. confirmDialog: false
  248. })
  249. },
  250. withdrawClick () {
  251. var that = this
  252. var url = 'v1/user/takecash'
  253. var params = {
  254. amount: that.data.cashTotal.available
  255. }
  256. var success = function (res) {
  257. if (res.data) {
  258. that.setData({
  259. confirmDialog: false
  260. })
  261. // that.data.lockWithdraw = false
  262. wx.showToast({
  263. title: '提现成功~',
  264. icon: 'none',
  265. duration: 2000
  266. })
  267. wx.navigateTo({
  268. url: '/packageUser/pages/user/withdraw/withdraw'
  269. })
  270. }
  271. }
  272. _request.$post(url, params, success)
  273. },
  274. getBanners: function () {
  275. var that = this
  276. var url = 'v1/ad/withdraw_ad/items'
  277. var params = {
  278. cache: false
  279. }
  280. var success = function (res) {
  281. that.setData({
  282. bannerList: res.data
  283. })
  284. console.log('ad',res)
  285. }
  286. _request.$get(url, params, success)
  287. },
  288. checkCertified () {
  289. var that = this
  290. var url = 'v1/user/certificate'
  291. var params = {
  292. }
  293. var success = function (res) {
  294. that.setData({
  295. isCertificate: res.data.is_certification
  296. })
  297. }
  298. _request.$get(url, params, success)
  299. },
  300. onShareAppMessage: function (val) {
  301. return _request.share({
  302. sc: 'xcx_user_cash'
  303. })
  304. }
  305. })