index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // pages/cash-withdrawal/index.js
  2. import {
  3. extractCash,
  4. extractBank,
  5. extractBankFee,
  6. getUserInfo
  7. } from '../../api/user.js';
  8. const app = getApp();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. parameter: {
  15. 'navbar': '1',
  16. 'return': '1',
  17. 'title': '提现',
  18. 'color': true,
  19. 'class': '0'
  20. },
  21. navList: [{
  22. 'name': '银行卡',
  23. 'icon': 'icon-yinhangqia'
  24. },
  25. {
  26. 'name': '微信',
  27. 'icon': 'icon-weixin2'
  28. },
  29. {
  30. 'name': '支付宝',
  31. 'icon': 'icon-icon34'
  32. }
  33. ],
  34. currentTab: 1,
  35. index: 0,
  36. array: [], //提现银行
  37. commissionCount: 0.00, //可提现金额
  38. minPrice: 0.0, // 最低提现金额
  39. wxName: '', // 微信实名
  40. bankCardNo: '', // 银行卡号
  41. bankUser: '', // 银行户名
  42. bankName: '', // 银行名称
  43. userInfo: [],
  44. isClone: false
  45. },
  46. onLoadFun: function () {
  47. this.getUserInfo();
  48. this.getUserExtractBank();
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. },
  55. getUserExtractBank: function () {
  56. var that = this;
  57. extractBank().then(res => {
  58. var array = res.data.extractBank;
  59. array.unshift("请选择银行");
  60. var idx = 0;
  61. for (var i = 0; i < array.length; i++) {
  62. if (array[i] == res.data.bankName) {
  63. idx = i
  64. }
  65. }
  66. that.setData({
  67. array: array,
  68. commissionCount: res.data.commissionCount,
  69. minPrice: res.data.minPrice,
  70. wxName: res.data.wxpayName,
  71. bankCardNo: res.data.bankCardNo,
  72. bankName: res.data.bankName,
  73. bankUser: res.data.bankUser,
  74. index: idx,
  75. });
  76. });
  77. },
  78. /**
  79. * 获取个人用户信息
  80. */
  81. getUserInfo: function () {
  82. var that = this;
  83. getUserInfo().then(res => {
  84. that.setData({
  85. userInfo: res.data
  86. });
  87. // app.globalData.unread = res.data.notice
  88. app.setUnread(res.data.notice)
  89. });
  90. },
  91. swichNav: function (e) {
  92. if (e.currentTarget.dataset.current > 1) {
  93. wx.showToast({
  94. title: '暂未开放',
  95. image: '',
  96. })
  97. return
  98. }
  99. this.setData({
  100. currentTab: e.currentTarget.dataset.current
  101. });
  102. },
  103. bindPickerChange: function (e) {
  104. this.setData({
  105. index: e.detail.value
  106. });
  107. },
  108. subCash: function (e) {
  109. let value = e.detail.value;
  110. if (value.money.length == 0) {
  111. return app.Tips({
  112. title: '请填写提现金额'
  113. });
  114. }
  115. if (Number(value.money) > Number(this.data.commissionCount)) {
  116. return app.Tips({
  117. title: '提现金额不能大于' + this.data.commissionCount
  118. });
  119. } else if (Number(value.money) < Number(this.data.minPrice)) {
  120. return app.Tips({
  121. title: '提现金额不能小于' + this.data.minPrice
  122. })
  123. }
  124. if (this.data.currentTab == 0) { //银行卡
  125. if (value.name.length == 0) return app.Tips({
  126. title: '请填写持卡人姓名'
  127. });
  128. if (value.cardnum.length == 0) return app.Tips({
  129. title: '请填写卡号'
  130. });
  131. if (this.data.index == 0) return app.Tips({
  132. title: "请选择银行"
  133. });
  134. value.extract_type = 'bank';
  135. value.bankname = this.data.array[this.data.index];
  136. var that = this
  137. extractBankFee(value).then(res => {
  138. wx.showModal({
  139. title: '银行卡提现手续费',
  140. content: '您提现' + value.money + '元,手续费为' + res.data.fee + '元,实际到帐' + res.data.valid + '元(手续费为通道费用,非美天旺收取,手续费费率为' + res.data.rate * 100 + '%,最少' + res.data.min + '元,最多' + res.data.max + '元)',
  141. showCancel: true,
  142. showConfirm: true,
  143. confirmText: '继续提现',
  144. success: (model) => {
  145. if (model.confirm) {
  146. extractCash(value).then(rs => {
  147. that.getUserInfo();
  148. return app.Tips({
  149. title: rs.msg,
  150. icon: 'success'
  151. });
  152. }).catch(err => {
  153. return app.Tips({
  154. title: err
  155. });
  156. });
  157. }
  158. },
  159. })
  160. }).catch(err => {
  161. return app.Tips({
  162. title: err
  163. });
  164. });
  165. } else {
  166. if (this.data.currentTab == 1) { //微信
  167. value.extract_type = 'weixin';
  168. if (value.name.length == 0) return app.Tips({
  169. title: '请填写微信实名'
  170. });
  171. value.weixin = value.name;
  172. } else if (this.data.currentTab == 2) { //支付宝
  173. value.extract_type = 'alipay';
  174. if (value.name.length == 0) return app.Tips({
  175. title: '请填写账号'
  176. });
  177. value.alipay_code = value.name;
  178. }
  179. var that = this
  180. extractCash(value).then(res => {
  181. that.getUserInfo();
  182. return app.Tips({
  183. title: res.msg,
  184. icon: 'success'
  185. });
  186. }).catch(err => {
  187. return app.Tips({
  188. title: err
  189. });
  190. });
  191. }
  192. },
  193. /**
  194. * 生命周期函数--监听页面初次渲染完成
  195. */
  196. onReady: function () {
  197. },
  198. /**
  199. * 生命周期函数--监听页面显示
  200. */
  201. onShow: function () {
  202. if (app.globalData.isLog && this.data.isClone) {
  203. this.getUserInfo();
  204. this.getUserExtractBank();
  205. }
  206. },
  207. /**
  208. * 生命周期函数--监听页面隐藏
  209. */
  210. onHide: function () {
  211. this.setData({
  212. isClone: true
  213. });
  214. },
  215. /**
  216. * 生命周期函数--监听页面卸载
  217. */
  218. onUnload: function () {
  219. },
  220. /**
  221. * 页面相关事件处理函数--监听用户下拉动作
  222. */
  223. onPullDownRefresh: function () {
  224. },
  225. /**
  226. * 页面上拉触底事件的处理函数
  227. */
  228. onReachBottom: function () {
  229. },
  230. /**
  231. * 用户点击右上角分享
  232. */
  233. onShareAppMessage: function () {
  234. }
  235. })