index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // pages/order/invoicingApply/index.js
  2. const util = require('../../../utils/util');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. invoiceInfo: [], //开票信息展示包含password和金额的数组
  9. password: [], //保存password的数组
  10. sumPrice: 0,
  11. company: '',
  12. dutyNumber: '', //税号
  13. email: '',
  14. showconsumptionCode: false,
  15. type: 1, //消费码//1开票金额发生变更
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. this.data.invoiceInfo = JSON.parse(options.queryBean)
  22. let arr = this.data.invoiceInfo
  23. // console.log(arr);
  24. // 开票信息显示数组
  25. let invoiceInfoPassword = []
  26. arr.forEach(e => {
  27. invoiceInfoPassword.push({
  28. password: e.password,
  29. price: e.income,
  30. attendantNames: e.attendantNames
  31. })
  32. })
  33. console.log(invoiceInfoPassword);
  34. let sumPrice = []
  35. invoiceInfoPassword.forEach((v) => {
  36. sumPrice.push(v.price),
  37. this.data.password.push(v.password)
  38. })
  39. // console.log(sumPrice);
  40. let priceSum = sumPrice.reduce((acc, cur) => {
  41. return acc + cur
  42. }, 0)
  43. this.setData({
  44. invoiceInfo: invoiceInfoPassword,
  45. sumPrice: priceSum.toFixed(2),
  46. })
  47. this.invoicingApply()
  48. },
  49. //输入事件
  50. bindinput(e) {
  51. let type = e.currentTarget.dataset.type
  52. let value = e.detail.value
  53. console.log(value);
  54. if (type == 'company') {
  55. this.setData({
  56. company: value
  57. })
  58. }
  59. if (type == 'dutyNumber') {
  60. this.setData({
  61. dutyNumber: value
  62. })
  63. }
  64. if (type == 'email') {
  65. this.setData({
  66. email: value
  67. })
  68. }
  69. },
  70. closeTips() {
  71. let type = this.data.type
  72. console.log(type);
  73. this.setData({
  74. showconsumptionCode: false
  75. })
  76. wx.navigateBack({
  77. delta: 1
  78. })
  79. },
  80. preImg(e) {
  81. console.log(e)
  82. let url="https://img.bbztx.com/miniProgram/teamLeader/invoiceSample.png"
  83. wx.previewImage({
  84. current: url, // 当前显示图片的http链接
  85. urls: [url] // 需要预览的图片http链接列表
  86. })
  87. },
  88. // 提交
  89. submit() {
  90. let that = this
  91. if (util.isEmpty(that.data.company)) {
  92. util.showTips('公司名称不能为空')
  93. } else if (util.isEmpty(that.data.dutyNumber)) {
  94. util.showTips('税号不能为空')
  95. } else if (util.isEmpty(that.data.email)) {
  96. util.showTips('邮箱不能为空')
  97. } else {
  98. // console.log(this.data.showconsumptionCode);
  99. // console.log(that.data.company, that.data.dutyNumber, that.data.email);
  100. let data = {}
  101. data.passwords = that.data.password
  102. data.type = 0
  103. data.company = that.data.company
  104. data.dutyNumber = that.data.dutyNumber
  105. data.email = that.data.email
  106. data.isUpdate = false
  107. data.price = that.data.sumPrice
  108. util.ajax({
  109. func: "articleInvoice/save",
  110. data,
  111. method: 'POST',
  112. load:false,
  113. }, ({
  114. data,
  115. code,
  116. reason
  117. }) => {
  118. if (code == 0) {
  119. console.log(data);
  120. wx.redirectTo({
  121. url: '/pages/order/subSuccessful/index',
  122. })
  123. } else if (code == -12) {
  124. this.setData({
  125. type: 0,
  126. showconsumptionCode: true
  127. })
  128. } else if (code == -13) {
  129. this.setData({
  130. type: 1,
  131. showconsumptionCode: true
  132. })
  133. }
  134. })
  135. }
  136. },
  137. // 申请开票回显
  138. invoicingApply() {
  139. let that = this
  140. // let passwords = ['26719439']
  141. // console.log(that.data.password.toString().replace('[]', ''));
  142. util.ajax({
  143. func: "articleInvoice/getArticleInvoiceByPassword",
  144. data: {
  145. passwords: that.data.password.toString().replace('[]', ''),
  146. },
  147. load:false,
  148. }, function ({
  149. data,
  150. code
  151. }) {
  152. if (code == 0) {
  153. that.setData({
  154. company: data.company,
  155. dutyNumber: data.dutyNumber,
  156. email: data.email
  157. })
  158. } else {
  159. util.showTips(res.reason);
  160. }
  161. })
  162. },
  163. /**
  164. * 生命周期函数--监听页面初次渲染完成
  165. */
  166. onReady() {
  167. },
  168. /**
  169. * 生命周期函数--监听页面显示
  170. */
  171. onShow() {
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide() {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload() {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh() {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom() {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage() {
  197. }
  198. })