fund.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. var _request = require('../../../../utils/request.js')
  2. Page({
  3. data: {
  4. page: 1,
  5. per_page: 10,
  6. cashTotal: '',
  7. cashList: [],
  8. cashList_more: true,
  9. cashList_change: false,
  10. identityDialog: false,
  11. confirmDialog: false,
  12. bannerList: [],
  13. isCertificate: 0,
  14. lockWithdraw: false,
  15. has_bank:false,
  16. min_cash:0,
  17. max_cahs:0,
  18. sourceurl:false,
  19. submittingTakeCash:false,
  20. transferConfirmDialog:false,
  21. pendingTakeCash:null,
  22. transferConfirming:false,
  23. transferCanceling:false
  24. },
  25. onLoad: function (options) {
  26. console.log('source',options);
  27. if(options && options['source'] && options['source'] == 'canteen'){
  28. this.setData({
  29. sourceurl:'/pages/canteen/canteen'
  30. })
  31. }
  32. this.getCashTotal()
  33. this.getCashList()
  34. this.getBanners()
  35. },
  36. onPullDownRefresh: function () {
  37. this.setData({
  38. page: 1,
  39. cashList_more: true,
  40. cashList_change: true
  41. })
  42. this.getCashList()
  43. wx.stopPullDownRefresh()
  44. },
  45. onReachBottom: function () {
  46. if (this.data.cashList_more) {
  47. var page = this.data.page + 1
  48. this.setData({
  49. page: page
  50. })
  51. this.getCashList()
  52. }
  53. },
  54. onShow () {
  55. if (getApp().globalData.rechargeChanged) {
  56. getApp().globalData.rechargeChanged = false
  57. this.refreshCashPage()
  58. this.checkCertified()
  59. this.getWithDrawlimit()
  60. return
  61. }
  62. this.getCashTotal()
  63. this.checkCertified()
  64. this.getWithDrawlimit()
  65. },
  66. refreshCashPage () {
  67. this.setData({
  68. page: 1,
  69. cashList: [],
  70. cashList_more: true,
  71. cashList_change: false
  72. })
  73. this.getCashTotal()
  74. this.getCashList()
  75. },
  76. getCashTotal () {
  77. var that = this
  78. var url = 'v1/user/cash/balance/info'
  79. var params = {
  80. }
  81. var success = function (res) {
  82. console.log('res.data',res.data)
  83. that.setData({
  84. cashTotal: res.data
  85. })
  86. }
  87. _request.$get(url, params, success)
  88. },
  89. getCashList () {
  90. var that = this
  91. var url = 'v1/user/cash/balances'
  92. var params = {
  93. page: that.data.page,
  94. per_page: that.data.per_page
  95. }
  96. var success = function (res) {
  97. if (that.data.cashList_change) {
  98. that.setData({
  99. cashList: [],
  100. cashList_change: false
  101. })
  102. }
  103. var result = that.data.cashList.concat(res.data.balance_list || [])
  104. var listMore = res.data.balance_count > result.length
  105. that.setData({
  106. cashList: result,
  107. cashList_more: listMore
  108. })
  109. }
  110. _request.$get(url, params, success)
  111. },
  112. getWithDrawlimit () {
  113. var that = this
  114. var url = 'v1/user/takecash/limit'
  115. var params = {}
  116. var success = function (res) {
  117. that.setData({
  118. min_cash: res.data.min_limit_cash,
  119. max_cash: res.data.max_limit_cash
  120. })
  121. }
  122. _request.$get(url, params, success)
  123. },
  124. tipClick () {
  125. var that = this
  126. // if (!that.data.isCertificate) {
  127. // }
  128. that.data.confirmDialog = !that.data.confirmDialog
  129. if (that.data.cashTotal.available >= that.data.min_cash && that.data.cashTotal.available <= that.data.max_cash) {
  130. that.setData({
  131. confirmDialog: that.data.confirmDialog
  132. })
  133. } else {
  134. wx.showToast({
  135. title: '单次提现金额范围,大于'+that.data.min_cash/100 +'元 小于'+that.data.max_cash/100 +'元',
  136. icon: 'none',
  137. duration: 2000
  138. })
  139. }
  140. },
  141. getBankInfoAndTip(){
  142. var that = this
  143. that.showWithdrawConfirm()
  144. },
  145. showWithdrawConfirm () {
  146. var that = this
  147. // var url = 'v1/user/get_bank_info'
  148. // var params = {
  149. // }
  150. // var success = function (res) {
  151. // that.setData({
  152. // has_bank:res.data.has_bank
  153. // })
  154. // if(that.data.has_bank){
  155. that.data.confirmDialog = !that.data.confirmDialog
  156. if (that.data.cashTotal.available >= that.data.min_cash && that.data.cashTotal.available <= that.data.max_cash) {
  157. that.setData({
  158. confirmDialog: that.data.confirmDialog
  159. })
  160. } else {
  161. wx.showToast({
  162. title: '单次提现金额范围,大于'+that.data.min_cash/100 +'元 小于'+that.data.max_cash/100 +'元',
  163. icon: 'none',
  164. duration: 2000
  165. })
  166. }
  167. // }
  168. // _request.$get(url, params, success)
  169. },
  170. toTransfer(){
  171. wx.navigateTo({
  172. url: '/packageUser/pages/user/transfer/transfer'
  173. })
  174. },
  175. goRechargeClick () {
  176. console.log('sourceurl',this.data.sourceurl);
  177. if(!this.data.sourceurl){
  178. wx.navigateTo({
  179. url: '/packageUser/pages/user/recharge/recharge'
  180. })
  181. }else{
  182. console.log('here');
  183. wx.navigateTo({
  184. url: '/packageUser/pages/user/recharge/recharge?source='+this.data.sourceurl
  185. })
  186. }
  187. },
  188. goIdentityClick () {
  189. var that = this
  190. that.setData({
  191. identityDialog: false
  192. })
  193. wx.navigateTo({
  194. url: '/packageUser/pages/user/identity/identity'
  195. })
  196. },
  197. goWithdrawClick () {
  198. wx.navigateTo({
  199. url: '/packageUser/pages/user/withdraw/withdraw'
  200. })
  201. },
  202. cancelIdentity () {
  203. var that = this
  204. that.setData({
  205. identityDialog: false
  206. })
  207. },
  208. buyClick () {
  209. var that = this
  210. wx.navigateTo({
  211. url: that.data.bannerList[0].url
  212. })
  213. },
  214. confrimClick () {
  215. var that = this
  216. console.log('that.data.has_bank',that.data.has_bank)
  217. // if (that.data.has_bank) {
  218. that.withdrawClick()
  219. // } else {
  220. // that.setData({
  221. // confirmDialog: false,
  222. // identityDialog: true
  223. // })
  224. // }
  225. },
  226. closedDialog () {
  227. var that = this
  228. that.setData({
  229. confirmDialog: false
  230. })
  231. },
  232. withdrawClick () {
  233. var that = this
  234. if (that.data.submittingTakeCash) {
  235. return
  236. }
  237. var url = 'v1/user/takecash'
  238. var params = {
  239. amount: that.data.cashTotal.available
  240. }
  241. that.setData({
  242. submittingTakeCash: true
  243. })
  244. var success = function (res) {
  245. that.setData({
  246. submittingTakeCash: false
  247. })
  248. if (res.data) {
  249. that.setData({
  250. confirmDialog: false
  251. })
  252. if (res.data.can_confirm_transfer && res.data.package_info) {
  253. that.showTakeCashTransferConfirm(res.data)
  254. } else {
  255. that.finishTakeCashTransfer('提现成功~')
  256. }
  257. }
  258. }
  259. var fail = function () {
  260. that.setData({
  261. submittingTakeCash: false
  262. })
  263. }
  264. _request.$post(url, params, success, fail)
  265. },
  266. showTakeCashTransferConfirm (order) {
  267. this.setData({
  268. pendingTakeCash: order,
  269. transferConfirmDialog: true,
  270. transferConfirming: false,
  271. transferCanceling: false
  272. })
  273. },
  274. confirmTakeCashTransfer () {
  275. var that = this
  276. var order = that.data.pendingTakeCash || {}
  277. if (that.data.transferConfirming) {
  278. return
  279. }
  280. if (!order.package_info) {
  281. wx.showToast({
  282. title: '提现确认信息缺失,请稍后重试',
  283. icon: 'none',
  284. duration: 2000
  285. })
  286. return
  287. }
  288. if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
  289. wx.showToast({
  290. title: '当前微信版本不支持确认收款,请升级微信',
  291. icon: 'none',
  292. duration: 2000
  293. })
  294. return
  295. }
  296. that.setData({
  297. transferConfirming: true
  298. })
  299. wx.requestMerchantTransfer({
  300. mchId: String(order.mch_id || ''),
  301. appId: String(order.app_id || ''),
  302. package: order.package_info,
  303. success: function () {
  304. that.setData({
  305. transferConfirmDialog: false,
  306. pendingTakeCash: null,
  307. transferConfirming: false
  308. })
  309. that.finishTakeCashTransfer('确认收款已提交')
  310. },
  311. fail: function (res) {
  312. that.setData({
  313. transferConfirming: false
  314. })
  315. var errMsg = (res && res.errMsg) ? res.errMsg : ''
  316. wx.showToast({
  317. title: errMsg.indexOf('cancel') >= 0 ? '用户取消确认,可继续确认或取消提现' : '确认收款失败,请稍后重试',
  318. icon: 'none',
  319. duration: 3000
  320. })
  321. }
  322. })
  323. },
  324. cancelTakeCashTransfer () {
  325. var that = this
  326. var order = that.data.pendingTakeCash || {}
  327. if (that.data.transferCanceling) {
  328. return
  329. }
  330. if (!order.order_id && !order.id) {
  331. that.setData({
  332. transferConfirmDialog: false,
  333. pendingTakeCash: null
  334. })
  335. return
  336. }
  337. that.setData({
  338. transferCanceling: true
  339. })
  340. var params = {
  341. order_id: order.order_id || '',
  342. id: order.id || ''
  343. }
  344. var success = function () {
  345. that.setData({
  346. transferConfirmDialog: false,
  347. pendingTakeCash: null,
  348. transferCanceling: false
  349. })
  350. wx.showToast({
  351. title: '已取消提现',
  352. icon: 'none',
  353. duration: 2000
  354. })
  355. getApp().globalData.withdrawChanged = true
  356. that.refreshCashPage()
  357. that.getCashTotal()
  358. }
  359. var fail = function () {
  360. that.setData({
  361. transferCanceling: false
  362. })
  363. }
  364. _request.$post('v1/user/takecash/cancel', params, success, fail)
  365. },
  366. finishTakeCashTransfer (title) {
  367. wx.showToast({
  368. title: title || '提现成功~',
  369. icon: 'none',
  370. duration: 2000
  371. })
  372. getApp().globalData.withdrawChanged = true
  373. this.refreshCashPage()
  374. this.getCashTotal()
  375. wx.navigateTo({
  376. url: '/packageUser/pages/user/withdraw/withdraw'
  377. })
  378. },
  379. getBanners: function () {
  380. var that = this
  381. var url = 'v1/ad/withdraw_ad/items'
  382. var params = {
  383. cache: false
  384. }
  385. var success = function (res) {
  386. that.setData({
  387. bannerList: res.data
  388. })
  389. console.log('ad',res)
  390. }
  391. _request.$get(url, params, success)
  392. },
  393. checkCertified () {
  394. var that = this
  395. var url = 'v1/user/certificate'
  396. var params = {
  397. }
  398. var success = function (res) {
  399. that.setData({
  400. isCertificate: res.data.is_certification
  401. })
  402. }
  403. _request.$get(url, params, success)
  404. },
  405. onShareAppMessage: function (val) {
  406. return _request.share({
  407. sc: 'xcx_user_cash'
  408. })
  409. }
  410. })