index.js 9.5 KB

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