apply.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad(e) {
  13. // 读取分享链接中的邀请人编号
  14. if (e && e.inviter_id) {
  15. wx.setStorageSync('referrer', e.inviter_id)
  16. }
  17. // 静默式授权注册/登陆
  18. AUTH.authorize().then(res => {
  19. })
  20. },
  21. onShow() {
  22. },
  23. chooseInvoiceTitle(){
  24. wx.chooseInvoiceTitle({
  25. success: (res) => {
  26. this.setData({
  27. wxInvoiceInfo: res
  28. })
  29. },
  30. fail: err => {
  31. console.error(err);
  32. wx.showToast({
  33. title: '读取失败',
  34. icon: 'none'
  35. })
  36. }
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. },
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function () {
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage() {
  63. return {
  64. title: '申请开票',
  65. imageUrl: 'https://cdn.it120.cc/apifactory/2019/06/13/13f5f43c-4819-414d-88f5-968e32facd79.png',
  66. path: '/pages/invoice/apply?inviter_id=' + wx.getStorageSync('uid')
  67. }
  68. },
  69. async bindSave(e) {
  70. // 提交保存
  71. let comName = e.detail.value.comName;
  72. let tfn = e.detail.value.tfn;
  73. let mobile = e.detail.value.mobile;
  74. let amount = e.detail.value.amount;
  75. let consumption = e.detail.value.consumption;
  76. let remark = e.detail.value.remark;
  77. let address = e.detail.value.address;
  78. let bank = e.detail.value.bank;
  79. if (!mobile) {
  80. wx.showToast({
  81. title: '请填写您在工厂注册的手机号码',
  82. icon: 'none'
  83. })
  84. return
  85. }
  86. if (!comName) {
  87. wx.showToast({
  88. title: '公司名称不能为空',
  89. icon: 'none'
  90. })
  91. return
  92. }
  93. if (!tfn) {
  94. wx.showToast({
  95. title: '税号不能为空',
  96. icon: 'none'
  97. })
  98. return
  99. }
  100. if (!consumption) {
  101. wx.showToast({
  102. title: '发票内容不能为空',
  103. icon: 'none'
  104. })
  105. return
  106. }
  107. if (!amount || amount*1 < 100) {
  108. wx.showToast({
  109. title: '开票金额不能低于100',
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. const extJsonStr = {}
  115. extJsonStr['api工厂账号'] = mobile
  116. extJsonStr['地址与电话'] = address
  117. extJsonStr['开户行与账号'] = bank
  118. WXAPI.invoiceApply({
  119. token: wx.getStorageSync('token'),
  120. comName,
  121. tfn,
  122. amount,
  123. consumption,
  124. remark,
  125. extJsonStr: JSON.stringify(extJsonStr)
  126. }).then(res => {
  127. if (res.code == 0) {
  128. wx.showModal({
  129. title: '成功',
  130. content: '提交成功,请耐心等待我们处理!',
  131. showCancel: false,
  132. confirmText: '我知道了',
  133. success(res) {
  134. wx.navigateTo({
  135. url: "/pages/invoice/list"
  136. })
  137. }
  138. })
  139. } else {
  140. wx.showModal({
  141. title: '失败',
  142. content: res.msg,
  143. showCancel: false,
  144. confirmText: '我知道了'
  145. })
  146. }
  147. })
  148. },
  149. })