editInfo.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. tixian_money: '',
  8. final_money: 0,
  9. sxfee: 0,
  10. type: 1,
  11. items: [
  12. { name: '1', value: '系统余额', show: true, checked: false },
  13. { name: '2', value: '微信零钱', show: true, checked: false },
  14. { name: '3', value: '支付宝', show: true, checked: false },
  15. { name: '4', value: '银行卡', show: true, checked: false }
  16. ]
  17. },
  18. canTixian: true,
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function(options) {
  23. var token = wx.getStorageSync('token');
  24. var that = this;
  25. app.util.request({
  26. url: 'entry/wxapp/user',
  27. data: {
  28. controller: 'community.get_community_info',
  29. token: token
  30. },
  31. dataType: 'json',
  32. success: function(res) {
  33. if (res.data.code == 0) {
  34. let rdata = res.data;
  35. let items = that.data.items;
  36. let community_info = rdata.community_info;
  37. if (community_info.head_commiss_tixianway_yuer == 0) items[0].show = false;
  38. if (community_info.head_commiss_tixianway_weixin == 0) items[1].show = false;
  39. if (community_info.head_commiss_tixianway_alipay == 0) items[2].show = false;
  40. if (community_info.head_commiss_tixianway_bank == 0) items[3].show = false;
  41. let type = that.data.type;
  42. for (let i = 0; i < items.length; i++){
  43. if(items[i].show){
  44. items[i].checked = true;
  45. type = items[i].name;
  46. break
  47. }
  48. }
  49. let head_commiss_tixian_publish = rdata.head_commiss_tixian_publish;
  50. let hasTixianPublish = head_commiss_tixian_publish!='';
  51. let { is_need_subscript, need_subscript_template } = res.data;
  52. that.setData({
  53. head_commiss_tixian_publish,
  54. member_info: rdata.member_info,
  55. community_info: rdata.community_info,
  56. commission_info: rdata.commission_info,
  57. community_tixian_fee: rdata.community_tixian_fee,
  58. community_min_money: rdata.community_min_money,
  59. items,
  60. type,
  61. hasTixianPublish,
  62. is_need_subscript,
  63. need_subscript_template
  64. });
  65. } else {
  66. //is_login
  67. wx.reLaunch({
  68. url: '/lionfish_comshop/pages/user/me',
  69. })
  70. }
  71. }
  72. })
  73. },
  74. bindTixianMoneyInput: function(t) {
  75. let max_val = this.data.commission_info.money;
  76. var value = t.detail.value;
  77. if (value > max_val) {
  78. wx.showToast({
  79. title: '本次最大可提现' + max_val + '元',
  80. icon: "none",
  81. })
  82. }
  83. let fee = this.data.community_tixian_fee;
  84. let final_money = (value * (100 - fee) / 100).toFixed(2);
  85. let sxfee = (value - final_money).toFixed(2);
  86. this.setData({
  87. tixian_money: value,
  88. final_money: final_money,
  89. sxfee
  90. })
  91. },
  92. getAll: function() {
  93. var max_tixian_money = this.data.commission_info.money;
  94. let fee = this.data.community_tixian_fee;
  95. let final_money = (max_tixian_money * (100 - fee) / 100).toFixed(2);
  96. let sxfee = (max_tixian_money - final_money).toFixed(2);
  97. this.setData({
  98. tixian_money: max_tixian_money,
  99. final_money: final_money,
  100. sxfee
  101. })
  102. },
  103. /**
  104. * 提交
  105. */
  106. resSubmit: function(e) {
  107. const params = e.detail.value;
  108. let isNull = 0;
  109. let type = this.data.type;
  110. let errortip = [{}, {}, {
  111. bankusername: '微信真实姓名'
  112. }, {
  113. bankusername: '支付宝真实姓名',
  114. bankaccount: '支付宝账户'
  115. }, {
  116. bankname: '银行卡名称',
  117. bankusername: '持卡人姓名',
  118. bankaccount: '银行卡账户'
  119. }];
  120. for (let item in params) {
  121. params[item] = params[item].replace(/(^\s*)|(\s*$)/g, "");
  122. if (!params[item]) {
  123. const itemTip = errortip[type][item];
  124. wx.showToast({
  125. title: '请输入' + (itemTip || '正确的表单内容'),
  126. icon: 'none'
  127. })
  128. isNull = 1;
  129. break;
  130. }
  131. if (item == 'money' && params[item] * 1 <= 0) {
  132. wx.showToast({
  133. title: '请输入正确的金额',
  134. icon: 'none'
  135. })
  136. return;
  137. }
  138. }
  139. console.log(isNull)
  140. if (isNull == 1) return;
  141. params.type = type;
  142. console.log(params);
  143. let tdata = this.data;
  144. let tixian_money = parseFloat(tdata.tixian_money);
  145. let max_tixian_money = tdata.commission_info.money;
  146. let community_min_money = parseFloat(tdata.community_min_money);
  147. if (tixian_money == '' || community_min_money > tixian_money) {
  148. wx.showToast({
  149. title: '最小提现' + community_min_money + '元',
  150. icon: "none",
  151. })
  152. return false;
  153. }
  154. if (tixian_money > max_tixian_money) {
  155. wx.showToast({
  156. title: '本次最大可提现' + max_tixian_money + '元',
  157. icon: "none",
  158. })
  159. let fee = tdata.community_tixian_fee;
  160. let final_money = (max_tixian_money * (100 - fee) / 100).toFixed(2);
  161. let sxfee = (max_tixian_money - final_money).toFixed(2);
  162. this.setData({
  163. tixian_money: max_tixian_money,
  164. final_money: final_money,
  165. sxfee
  166. })
  167. return false;
  168. }
  169. if (!this.canTixian) return;
  170. this.canTixian = false;
  171. var token = wx.getStorageSync('token');
  172. var that = this;
  173. wx.showLoading();
  174. app.util.request({
  175. url: 'entry/wxapp/user',
  176. data: {
  177. controller: 'community.tixian_community_info',
  178. token: token,
  179. ...params
  180. },
  181. dataType: 'json',
  182. success: function (res) {
  183. if (res.data.code == 0) {
  184. wx.showToast({
  185. title: "提现成功,等待审核",
  186. icon: "none",
  187. duration: 2000,
  188. mask: true,
  189. success: function () {
  190. wx.redirectTo({
  191. url: '/lionfish_comshop/moduleA/groupCenter/cashList',
  192. })
  193. }
  194. });
  195. } else {
  196. wx.showToast({
  197. title: "提现失败",
  198. icon: "none",
  199. duration: 2000,
  200. mask: true
  201. });
  202. }
  203. setTimeout(()=>{
  204. that.canTixian = true;
  205. }, 500);
  206. }
  207. })
  208. },
  209. formSubmit: function(event) {
  210. let that = this;
  211. let is_need_subscript = this.data.is_need_subscript;
  212. if(is_need_subscript==1) {
  213. //弹出订阅消息
  214. this.subscriptionNotice().then(()=>{
  215. that.resSubmit(event);
  216. }).catch(()=>{
  217. that.resSubmit(event);
  218. });
  219. } else {
  220. that.resSubmit(event);
  221. }
  222. },
  223. /**
  224. * 订阅消息
  225. */
  226. subscriptionNotice: function() {
  227. let that = this;
  228. return new Promise((resolve, reject)=>{
  229. let obj = that.data.need_subscript_template;
  230. let tmplIds = Object.keys(obj).map(key => obj[key]); // 订阅消息模版id
  231. if (wx.requestSubscribeMessage) {
  232. tmplIds.length && wx.requestSubscribeMessage({
  233. tmplIds: tmplIds,
  234. success(res) {
  235. let is_need_subscript = 1;
  236. let acceptId = [];
  237. Object.keys(obj).forEach(item=>{
  238. if (res[obj[item]] == 'accept') {
  239. //用户同意了订阅,添加进数据库
  240. acceptId.push(item);
  241. } else {
  242. //用户拒绝了订阅或当前游戏被禁用订阅消息
  243. is_need_subscript = 0;
  244. }
  245. })
  246. if(acceptId.length) {
  247. that.addAccept(acceptId);
  248. }
  249. that.setData({ is_need_subscript })
  250. resolve();
  251. },
  252. fail(err) {
  253. console.log(err)
  254. reject();
  255. }
  256. })
  257. } else {
  258. // 兼容处理
  259. reject();
  260. }
  261. })
  262. },
  263. // 用户点击订阅添加到数据库
  264. addAccept: function (acceptId) {
  265. let token = wx.getStorageSync('token');
  266. let type = acceptId.join(',');
  267. app.util.request({
  268. url: 'entry/wxapp/user',
  269. data: {
  270. controller: 'user.collect_subscriptmsg',
  271. token,
  272. type
  273. },
  274. dataType: 'json',
  275. method: 'POST',
  276. success: function () {}
  277. })
  278. },
  279. /**
  280. * 切换类型
  281. */
  282. radioChange(e) {
  283. this.setData({ type: e.detail.value })
  284. }
  285. })