excharge.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. mixins: [require('../../mixin/commonMixin.js')],
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. type: 1,
  10. items: [{
  11. name: '1',
  12. value: '系统余额',
  13. show: true,
  14. checked: false
  15. },
  16. {
  17. name: '2',
  18. value: '微信零钱',
  19. show: true,
  20. checked: false
  21. },
  22. {
  23. name: '3',
  24. value: '支付宝',
  25. show: true,
  26. checked: false
  27. },
  28. {
  29. name: '4',
  30. value: '银行卡',
  31. show: true,
  32. checked: false
  33. }
  34. ],
  35. info: [],
  36. tixian_money: '',
  37. final_money: 0
  38. },
  39. canTixian: true,
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function(options) {
  44. wx.showLoading();
  45. this.getData();
  46. },
  47. onShow: function() {
  48. let that = this;
  49. util.check_login_new().then((res) => {
  50. if (res) {
  51. that.setData({
  52. needAuth: false
  53. })
  54. } else {
  55. that.setData({
  56. needAuth: true
  57. })
  58. }
  59. })
  60. },
  61. /**
  62. * 授权成功回调
  63. */
  64. authSuccess: function() {
  65. let that = this;
  66. this.setData({
  67. needAuth: false
  68. }, () => {
  69. wx.showLoading();
  70. that.getData();
  71. })
  72. },
  73. getData: function() {
  74. var token = wx.getStorageSync('token');
  75. let that = this;
  76. app.util.request({
  77. url: 'entry/wxapp/user',
  78. data: {
  79. controller: 'localtown.get_distribution_commission_info',
  80. token: token
  81. },
  82. dataType: 'json',
  83. success: function(res) {
  84. wx.hideLoading();
  85. if (res.data.code == 0) {
  86. let commiss_tixian_publish = res.data.data.commiss_tixian_publish;
  87. let items = that.data.items;
  88. let rdata = res.data.data;
  89. if (rdata.commiss_tixianway_yuer == 0) items[0].show = false;
  90. if (rdata.commiss_tixianway_weixin == 0) items[1].show = false;
  91. if (rdata.commiss_tixianway_alipay == 0) items[2].show = false;
  92. if (rdata.commiss_tixianway_bank == 0) items[3].show = false;
  93. let type = that.data.type;
  94. for (let i = 0; i < items.length; i++) {
  95. if (items[i].show) {
  96. items[i].checked = true;
  97. type = items[i].name;
  98. break
  99. }
  100. }
  101. that.setData({
  102. info: res.data.data,
  103. items,
  104. type,
  105. commiss_tixian_publish
  106. })
  107. } else {
  108. wx.showModal({
  109. title: '提示',
  110. content: res.data.msg,
  111. showCancel: false,
  112. success(res) {
  113. if (res.confirm) {
  114. console.log('用户点击确定')
  115. wx.reLaunch({
  116. url: '/lionfish_comshop/pages/user/me',
  117. })
  118. }
  119. }
  120. })
  121. }
  122. }
  123. })
  124. },
  125. formSubmit: function(e) {
  126. const params = e.detail.value;
  127. let isNull = 0;
  128. let type = this.data.type;
  129. let errortip = [{}, {}, {
  130. bankusername: '微信真实姓名'
  131. }, {
  132. bankusername: '支付宝真实姓名',
  133. bankaccount: '支付宝账户'
  134. }, {
  135. bankname: '银行卡名称',
  136. bankusername: '持卡人姓名',
  137. bankaccount: '银行卡账户'
  138. }];
  139. for (let item in params) {
  140. params[item] = params[item].replace(/(^\s*)|(\s*$)/g, "");
  141. if (!params[item]) {
  142. const itemTip = errortip[type][item];
  143. wx.showToast({
  144. title: '请输入' + (itemTip || '正确的表单内容'),
  145. icon: 'none'
  146. })
  147. isNull = 1;
  148. break;
  149. }
  150. if (item == 'money' && params[item] * 1 <= 0) {
  151. wx.showToast({
  152. title: '请输入正确的金额',
  153. icon: 'none'
  154. })
  155. return;
  156. }
  157. }
  158. if (isNull == 1) return;
  159. params.type = this.data.type;
  160. console.log(params);
  161. let tdata = this.data;
  162. let tixian_money = parseFloat(tdata.tixian_money);
  163. let max_tixian_money = tdata.info.money;
  164. let community_min_money = parseFloat(tdata.info.commiss_min_tixian_money);
  165. if (tixian_money == '' || community_min_money > tixian_money) {
  166. wx.showToast({
  167. title: '最小提现' + community_min_money + '元',
  168. icon: "none",
  169. })
  170. return false;
  171. }
  172. if (tixian_money > max_tixian_money) {
  173. wx.showToast({
  174. title: '本次最大可提现' + max_tixian_money + '元',
  175. icon: "none",
  176. })
  177. let fee = tdata.info.commiss_tixian_bili;
  178. let final_money = (max_tixian_money * (100 - fee) / 100).toFixed(2);
  179. this.setData({
  180. tixian_money: max_tixian_money,
  181. final_money: final_money
  182. })
  183. return false;
  184. }
  185. if (!this.canTixian) return;
  186. this.canTixian = false;
  187. wx.showLoading();
  188. var token = wx.getStorageSync('token');
  189. let that = this;
  190. app.util.request({
  191. url: 'entry/wxapp/user',
  192. data: {
  193. controller: 'localtown.tixian_sub',
  194. token: token,
  195. ...params
  196. },
  197. dataType: 'json',
  198. success: function(res) {
  199. wx.hideLoading();
  200. if (res.data.code == 0) {
  201. wx.showToast({
  202. title: '已提交申请',
  203. icon: 'none',
  204. duration: 2000,
  205. success: function () {
  206. that.setData({
  207. canPay: false,
  208. tixian_money: '',
  209. final_money: 0
  210. })
  211. that.getData();
  212. }
  213. })
  214. } else {
  215. wx.showToast({
  216. title: res.data.msg ? res.data.msg : '提交失败,请重试',
  217. icon: 'none'
  218. })
  219. }
  220. that.canTixian = true;
  221. }
  222. })
  223. },
  224. /**
  225. * 获得焦点
  226. */
  227. bindIptFocus: function() {
  228. this.setData({
  229. onFocus: true
  230. })
  231. },
  232. /**
  233. * 失去焦点
  234. */
  235. bindIptBlur: function() {
  236. this.setData({
  237. onFocus: false
  238. })
  239. },
  240. radioChange(e) {
  241. this.setData({
  242. type: e.detail.value
  243. })
  244. },
  245. bindTixianMoneyInput: function(t) {
  246. let max_val = this.data.info.money;
  247. var value = t.detail.value;
  248. if (!(/^(\d?)+(\.\d{0,2})?$/.test(value))) {
  249. value = value.substring(0, value.length - 1);
  250. value = parseFloat(value);
  251. }
  252. if (value > max_val) {
  253. wx.showToast({
  254. title: '本次最大可提现' + max_val + '元',
  255. icon: "none",
  256. })
  257. }
  258. let fee = this.data.info.commiss_tixian_bili;
  259. let final_money = (value * (100 - fee) / 100).toFixed(2);
  260. let canPay = false;
  261. value ? canPay = true : canPay = false;
  262. this.setData({
  263. tixian_money: value,
  264. final_money: final_money,
  265. canPay
  266. })
  267. return value;
  268. },
  269. getAll: function() {
  270. const tdata = this.data;
  271. var max_tixian_money = tdata.info.money * 1;
  272. let fee = tdata.info.commiss_tixian_bili;
  273. let final_money = (max_tixian_money * (100 - fee) / 100).toFixed(2);
  274. let canPay = false;
  275. max_tixian_money ? canPay = true : canPay = false;
  276. this.setData({
  277. tixian_money: max_tixian_money,
  278. final_money: final_money,
  279. canPay
  280. })
  281. }
  282. })