excharge.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. //Todo
  77. app.util.request({
  78. url: 'entry/wxapp/user',
  79. data: {
  80. controller: 'distribution.get_commission_info',
  81. token: token
  82. },
  83. dataType: 'json',
  84. success: function(res) {
  85. wx.hideLoading();
  86. if (res.data.code == 0) {
  87. let commiss_tixian_publish = res.data.data.commiss_tixian_publish;
  88. let items = that.data.items;
  89. let rdata = res.data.data;
  90. if (rdata.commiss_tixianway_yuer == 0) items[0].show = false;
  91. if (rdata.commiss_tixianway_weixin == 0) items[1].show = false;
  92. if (rdata.commiss_tixianway_alipay == 0) items[2].show = false;
  93. if (rdata.commiss_tixianway_bank == 0) items[3].show = false;
  94. let type = that.data.type;
  95. for (let i = 0; i < items.length; i++) {
  96. if (items[i].show) {
  97. items[i].checked = true;
  98. type = items[i].name;
  99. break
  100. }
  101. }
  102. let { is_need_subscript, need_subscript_template } = res.data;
  103. that.setData({
  104. info: res.data.data,
  105. items,
  106. type,
  107. is_need_subscript,
  108. need_subscript_template,
  109. commiss_tixian_publish
  110. })
  111. } else {
  112. wx.showModal({
  113. title: '提示',
  114. content: res.data.msg,
  115. showCancel: false,
  116. success(res) {
  117. if (res.confirm) {
  118. console.log('用户点击确定')
  119. wx.reLaunch({
  120. url: '/lionfish_comshop/pages/user/me',
  121. })
  122. }
  123. }
  124. })
  125. }
  126. }
  127. })
  128. },
  129. formSubmit: function(event) {
  130. let that = this;
  131. let is_need_subscript = this.data.is_need_subscript;
  132. if(is_need_subscript==1) {
  133. //弹出订阅消息
  134. this.subscriptionNotice().then(()=>{
  135. that.resSubmit(event);
  136. }).catch(()=>{
  137. that.resSubmit(event);
  138. });
  139. } else {
  140. that.resSubmit(event);
  141. }
  142. },
  143. resSubmit: function(e) {
  144. const params = e.detail.value;
  145. let isNull = 0;
  146. let type = this.data.type;
  147. let errortip = [{}, {}, {
  148. bankusername: '微信真实姓名'
  149. }, {
  150. bankusername: '支付宝真实姓名',
  151. bankaccount: '支付宝账户'
  152. }, {
  153. bankname: '银行卡名称',
  154. bankusername: '持卡人姓名',
  155. bankaccount: '银行卡账户'
  156. }];
  157. for (let item in params) {
  158. params[item] = params[item].replace(/(^\s*)|(\s*$)/g, "");
  159. if (!params[item]) {
  160. const itemTip = errortip[type][item];
  161. wx.showToast({
  162. title: '请输入' + (itemTip || '正确的表单内容'),
  163. icon: 'none'
  164. })
  165. isNull = 1;
  166. break;
  167. }
  168. if (item == 'money' && params[item] * 1 <= 0) {
  169. wx.showToast({
  170. title: '请输入正确的金额',
  171. icon: 'none'
  172. })
  173. return;
  174. }
  175. }
  176. if (isNull == 1) return;
  177. params.type = type;
  178. let tdata = this.data;
  179. let tixian_money = parseFloat(tdata.tixian_money);
  180. let max_tixian_money = tdata.info.money;
  181. let community_min_money = parseFloat(tdata.info.commiss_min_tixian_money);
  182. if (tixian_money == '' || community_min_money > tixian_money) {
  183. wx.showToast({
  184. title: '最小提现' + community_min_money + '元',
  185. icon: "none",
  186. })
  187. return false;
  188. }
  189. if (tixian_money > max_tixian_money) {
  190. wx.showToast({
  191. title: '本次最大可提现' + max_tixian_money + '元',
  192. icon: "none",
  193. })
  194. let fee = tdata.info.commiss_tixian_bili;
  195. let final_money = (max_tixian_money * (100 - fee) / 100).toFixed(2);
  196. this.setData({
  197. tixian_money: max_tixian_money,
  198. final_money: final_money
  199. })
  200. return false;
  201. }
  202. if (!this.canTixian) return;
  203. this.canTixian = false;
  204. wx.showLoading();
  205. var token = wx.getStorageSync('token');
  206. let that = this;
  207. app.util.request({
  208. url: 'entry/wxapp/user',
  209. data: {
  210. controller: 'distribution.tixian_sub',
  211. token: token,
  212. ...params
  213. },
  214. dataType: 'json',
  215. success: function(res) {
  216. wx.hideLoading();
  217. if (res.data.code == 0) {
  218. wx.showToast({
  219. title: '已提交申请',
  220. icon: 'none',
  221. duration: 2000,
  222. success: function(){
  223. that.setData({
  224. canPay: false,
  225. tixian_money: '',
  226. final_money: 0
  227. })
  228. that.getData();
  229. }
  230. })
  231. } else {
  232. wx.showToast({
  233. title: res.data.msg ? res.data.msg : '提交失败,请重试',
  234. icon: 'none'
  235. })
  236. }
  237. that.canTixian = true;
  238. }
  239. })
  240. },
  241. /**
  242. * 订阅消息
  243. */
  244. subscriptionNotice: function() {
  245. let that = this;
  246. return new Promise((resolve, reject)=>{
  247. let obj = that.data.need_subscript_template;
  248. let tmplIds = Object.keys(obj).map(key => obj[key]); // 订阅消息模版id
  249. if (wx.requestSubscribeMessage) {
  250. tmplIds.length && wx.requestSubscribeMessage({
  251. tmplIds: tmplIds,
  252. success(res) {
  253. let is_need_subscript = 1;
  254. let acceptId = [];
  255. Object.keys(obj).forEach(item=>{
  256. if (res[obj[item]] == 'accept') {
  257. //用户同意了订阅,添加进数据库
  258. acceptId.push(item);
  259. } else {
  260. //用户拒绝了订阅或当前游戏被禁用订阅消息
  261. is_need_subscript = 0;
  262. }
  263. })
  264. if(acceptId.length) {
  265. that.addAccept(acceptId);
  266. }
  267. that.setData({ is_need_subscript })
  268. resolve();
  269. },
  270. fail(err) {
  271. console.log(err)
  272. reject();
  273. }
  274. })
  275. } else {
  276. // 兼容处理
  277. reject();
  278. }
  279. })
  280. },
  281. // 用户点击订阅添加到数据库
  282. addAccept: function (acceptId) {
  283. let token = wx.getStorageSync('token');
  284. let type = acceptId.join(',');
  285. app.util.request({
  286. url: 'entry/wxapp/user',
  287. data: {
  288. controller: 'user.collect_subscriptmsg',
  289. token,
  290. type
  291. },
  292. dataType: 'json',
  293. method: 'POST',
  294. success: function () {}
  295. })
  296. },
  297. /**
  298. * 获得焦点
  299. */
  300. bindIptFocus: function() {
  301. this.setData({
  302. onFocus: true
  303. })
  304. },
  305. /**
  306. * 失去焦点
  307. */
  308. bindIptBlur: function() {
  309. this.setData({
  310. onFocus: false
  311. })
  312. },
  313. radioChange(e) {
  314. this.setData({
  315. type: e.detail.value
  316. })
  317. },
  318. bindTixianMoneyInput: function(t) {
  319. let max_val = this.data.info.money;
  320. var value = t.detail.value;
  321. if (!(/^(\d?)+(\.\d{0,2})?$/.test(value))) {
  322. value = value.substring(0, value.length - 1);
  323. value = parseFloat(value);
  324. }
  325. if (value > max_val) {
  326. wx.showToast({
  327. title: '本次最大可提现' + max_val + '元',
  328. icon: "none",
  329. })
  330. }
  331. let fee = this.data.info.commiss_tixian_bili;
  332. let val = parseFloat(value) > 0 ? parseFloat(value) : 0;
  333. let final_money = (val * (100 - fee) / 100).toFixed(2);
  334. let canPay = false;
  335. value ? canPay = true : canPay = false;
  336. this.setData({
  337. tixian_money: value,
  338. final_money: final_money,
  339. canPay
  340. })
  341. return value;
  342. },
  343. getAll: function() {
  344. const tdata = this.data;
  345. var max_tixian_money = tdata.info.money * 1;
  346. let fee = tdata.info.commiss_tixian_bili;
  347. let final_money = (max_tixian_money * (100 - fee) / 100).toFixed(2);
  348. let canPay = false;
  349. max_tixian_money ? canPay = true : canPay = false;
  350. this.setData({
  351. tixian_money: max_tixian_money,
  352. final_money: final_money,
  353. canPay
  354. })
  355. }
  356. })