index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // pages/temp/cash/index.js
  2. const app = getApp()
  3. const util = require("../../../utils/jmsUtil.js");
  4. const util2 = require("../../../utils/util.js");
  5. const api = require('../../../api/jms.js');
  6. const user = require('../../../utils/user.js');
  7. const check = require('../../../utils/check.js');
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. workerFee: {},
  14. worker: '',
  15. workerFeeList: [],
  16. pageIndex: 1,
  17. showAuth: false,
  18. code: '',
  19. checked: false
  20. },
  21. userProtocol() {
  22. wx.navigateTo({
  23. url: '/pages/temp/cash/protocol'
  24. });
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. this.getBlance();
  31. this.getWorkerFeeList();
  32. this.getLoginCode();
  33. },
  34. getBlance(){
  35. util.request(api.getWorkerFee, {}, 'GET').then(res => {
  36. this.setData({
  37. workerFee: res.data.fee,
  38. worker: res.data.worker
  39. })
  40. });
  41. },
  42. goCancel() {
  43. this.setData({
  44. showAuth: false
  45. })
  46. },
  47. goCashout() { //去提现
  48. let that = this
  49. //是否认证过
  50. if (!this.data.worker.signStatus || this.data.worker.signStatus == false) {
  51. this.setData({
  52. showAuth: true
  53. })
  54. return;
  55. }
  56. if(that.data.workerFee.blance<=0){
  57. util.showErrorToast("无可提现金额");
  58. return;
  59. }
  60. wx.showModal({
  61. title: '提示',
  62. confirmText:'提现',
  63. content: '提现金额为' + that.data.workerFee.blance + ',平台通过授权第三方(“云账户”)向您的微信钱包打款',
  64. success: function (sm) {
  65. if (sm.confirm) {
  66. util.request(api.Cashout, {
  67. amount: that.data.workerFee.blance
  68. }).then(function (res) {
  69. if (res.errno === 0) {
  70. wx.showToast({
  71. title: '提现申请成功,请查看【微信支付】',
  72. icon: 'none',
  73. duration: 2000
  74. });
  75. that.setData({
  76. showAuth: false
  77. })
  78. that.getBlance();
  79. }else{
  80. util.showErrorToast(res.errmsg);
  81. }
  82. });
  83. } else if (sm.cancel) {
  84. console.log('用户点击取消')
  85. }
  86. }
  87. })
  88. },
  89. goDeductDetail() {
  90. wx.navigateTo({
  91. url: '/pages/temp/cash/cashList',
  92. })
  93. },
  94. getWorkerFeeList(e) { //扣款明细
  95. let that = this;
  96. util.request(api.getWorkerFeeList, {
  97. pageIndex: that.data.pageIndex,
  98. pageSize: 10
  99. }, 'GET').then(res => {
  100. if (res.data.list.length == 0) {
  101. util2.showErrorToast("没有更多数据");
  102. } else {
  103. let list = that.data.workerFeeList;
  104. list = list.concat(res.data.list);
  105. that.setData({
  106. workerFeeList: list,
  107. pageIndex: that.data.pageIndex + 1
  108. })
  109. console.info(that.data.workerFeeList)
  110. }
  111. });
  112. },
  113. bindinputName(e) {
  114. let val = e.detail.value;
  115. this.setData({
  116. ['worker.name']: val
  117. });
  118. },
  119. bindinputNid(e) {
  120. let val = e.detail.value;
  121. this.setData({
  122. ['worker.idCard']: val
  123. })
  124. },
  125. onChange(e) {
  126. console.log(e);
  127. this.setData({
  128. checked: e.detail,
  129. });
  130. },
  131. cashoutAuth() {
  132. if (this.data.worker.name == '') {
  133. wx.showToast({
  134. title: '请输入真实姓名',
  135. icon: 'none',
  136. duration: 2000
  137. });
  138. return false;
  139. } else if (!check.isCardCheck(this.data.worker.idCard)) {
  140. wx.showToast({
  141. title: '请输入正确的身份证号',
  142. icon: 'none',
  143. duration: 2000
  144. });
  145. return false;
  146. } else if (!this.data.checked) {
  147. wx.showToast({
  148. title: '请阅读《用户条款》并勾选',
  149. icon: 'none',
  150. duration: 2000
  151. });
  152. return false;
  153. }
  154. let that = this;
  155. util.request(api.getSign, {
  156. tempWorkerId: this.data.worker.id,
  157. name: this.data.worker.name,
  158. idCard: this.data.worker.idCard,
  159. phone: this.data.worker.tel,
  160. code: this.data.code
  161. }, "POST").then(res => {
  162. if (res.errno == 0) {
  163. that.setData({
  164. showAuth: false,
  165. 'worker.signStatus':true
  166. })
  167. that.goCashout();
  168. } else {
  169. that.getLoginCode();
  170. util.showErrorToast(res.errmsg);
  171. }
  172. });
  173. },
  174. getLoginCode() {
  175. let that = this;
  176. user.login().then(res => {
  177. console.info(res)
  178. that.setData({
  179. code: res.code
  180. })
  181. })
  182. },
  183. /**
  184. * 生命周期函数--监听页面初次渲染完成
  185. */
  186. onReady: function () {
  187. },
  188. /**
  189. * 生命周期函数--监听页面显示
  190. */
  191. onShow: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面隐藏
  195. */
  196. onHide: function () {
  197. },
  198. /**
  199. * 生命周期函数--监听页面卸载
  200. */
  201. onUnload: function () {
  202. },
  203. /**
  204. * 页面相关事件处理函数--监听用户下拉动作
  205. */
  206. onPullDownRefresh: function () {
  207. },
  208. /**
  209. * 页面上拉触底事件的处理函数
  210. */
  211. onReachBottom: function () {
  212. this.getWorkerFeeList();
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage: function () {
  218. }
  219. })