index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // pages/cash-withdrawal/index.js
  2. import { extractCash, extractBank, extractBankFee, getUserInfo } from '../../api/user.js'
  3. const app = getApp()
  4. const CASH_CHANNELS = {
  5. weixin: '微信',
  6. bank: '银行卡',
  7. alipay: '支付宝'
  8. }
  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. {
  23. name: '银行卡',
  24. icon: 'icon-yinhangqia'
  25. },
  26. {
  27. name: '微信',
  28. icon: 'icon-weixin2'
  29. },
  30. {
  31. name: '支付宝',
  32. icon: 'icon-icon34'
  33. }
  34. ],
  35. currentTab: 1,
  36. index: 0,
  37. array: [], //提现银行
  38. commissionCount: 0.0, //可提现金额
  39. minPrice: 0.0, // 最低提现金额
  40. wxName: '', // 微信实名
  41. bankCardNo: '', // 银行卡号
  42. bankUser: '', // 银行户名
  43. bankName: '', // 银行名称
  44. userInfo: [],
  45. isClone: false
  46. },
  47. onLoadFun: function () {
  48. this.getUserInfo()
  49. this.getUserExtractBank()
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) {},
  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. //银行卡
  126. if (value.name.length == 0)
  127. return app.Tips({
  128. title: '请填写持卡人姓名'
  129. })
  130. if (value.cardnum.length == 0)
  131. return app.Tips({
  132. title: '请填写卡号'
  133. })
  134. if (this.data.index == 0)
  135. return app.Tips({
  136. title: '请选择银行'
  137. })
  138. value.extract_type = 'bank'
  139. value.bankname = this.data.array[this.data.index]
  140. var that = this
  141. extractBankFee(value)
  142. .then(res => {
  143. wx.showModal({
  144. title: '提现确认(含手续费)',
  145. content:
  146. '银行卡提现:' +
  147. value.money +
  148. ' 元\n' +
  149. '收款人: ' +
  150. value.name +
  151. '\n' +
  152. '手续费: ' +
  153. res.data.fee +
  154. ' 元\n' +
  155. '实际到帐: ' +
  156. res.data.valid +
  157. ' 元\n' +
  158. '说明:手续费为通道费用,非美天旺收取,手续费费率为 ' +
  159. res.data.rate * 100 +
  160. '%,最少 ' +
  161. res.data.min +
  162. ' 元,最多 ' +
  163. res.data.max +
  164. ' 元。',
  165. showCancel: true,
  166. showConfirm: true,
  167. confirmText: '继续提现',
  168. success: model => {
  169. if (model.confirm) {
  170. extractCash(value)
  171. .then(rs => {
  172. that.getUserInfo()
  173. return wx.showModal({
  174. title: '成功',
  175. content: rs.msg,
  176. showCancel: false,
  177. confirmText: '确定',
  178. complete: () => {
  179. wx.navigateBack({
  180. delta: 1
  181. })
  182. }
  183. })
  184. })
  185. .catch(err => {
  186. return wx.showModal({
  187. title: '失败',
  188. content: err,
  189. showCancel: false,
  190. confirmText: '确定',
  191. complete: () => {
  192. wx.navigateBack({
  193. delta: 1
  194. })
  195. }
  196. })
  197. })
  198. }
  199. }
  200. })
  201. })
  202. .catch(err => {
  203. return app.Tips({
  204. title: err
  205. })
  206. })
  207. } else {
  208. if (this.data.currentTab == 1) {
  209. //微信
  210. value.extract_type = 'weixin'
  211. if (value.name.length == 0)
  212. return app.Tips({
  213. title: '请填写微信实名'
  214. })
  215. value.weixin = value.name
  216. } else if (this.data.currentTab == 2) {
  217. //支付宝
  218. value.extract_type = 'alipay'
  219. if (value.name.length == 0)
  220. return app.Tips({
  221. title: '请填写账号'
  222. })
  223. value.alipay_code = value.name
  224. }
  225. var that = this
  226. wx.showModal({
  227. title: '提现确认',
  228. content:
  229. CASH_CHANNELS[value.extract_type] +
  230. '提现: ' +
  231. value.money +
  232. ' 元\n' +
  233. '收款人: 微信登录账号\n' +
  234. '手续费: 0 元\n' +
  235. '实际到帐: ' +
  236. value.money +
  237. ' 元\n',
  238. confirmText: '继续提现',
  239. success: model => {
  240. if (model.confirm) {
  241. extractCash(value)
  242. .then(res => {
  243. that.getUserInfo()
  244. return wx.showModal({
  245. title: '成功',
  246. content: res.msg,
  247. showCancel: false,
  248. confirmText: '确定',
  249. complete: () => {
  250. wx.navigateBack({
  251. delta: 1
  252. })
  253. }
  254. })
  255. })
  256. .catch(err => {
  257. return wx.showModal({
  258. title: '失败',
  259. content: err,
  260. showCancel: false,
  261. confirmText: '确定',
  262. complete: () => {
  263. wx.navigateBack({
  264. delta: 1
  265. })
  266. }
  267. })
  268. })
  269. }
  270. }
  271. })
  272. }
  273. },
  274. /**
  275. * 生命周期函数--监听页面初次渲染完成
  276. */
  277. onReady: function () {},
  278. /**
  279. * 生命周期函数--监听页面显示
  280. */
  281. onShow: function () {
  282. if (app.globalData.isLog && this.data.isClone) {
  283. this.getUserInfo()
  284. this.getUserExtractBank()
  285. }
  286. },
  287. /**
  288. * 生命周期函数--监听页面隐藏
  289. */
  290. onHide: function () {
  291. this.setData({
  292. isClone: true
  293. })
  294. },
  295. /**
  296. * 生命周期函数--监听页面卸载
  297. */
  298. onUnload: function () {},
  299. /**
  300. * 页面相关事件处理函数--监听用户下拉动作
  301. */
  302. onPullDownRefresh: function () {},
  303. /**
  304. * 页面上拉触底事件的处理函数
  305. */
  306. onReachBottom: function () {},
  307. /**
  308. * 用户点击右上角分享
  309. */
  310. onShareAppMessage: function () {}
  311. })