You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.0 KiB

  1. var app = getApp();
  2. const config = require('../../../config/config.js')
  3. const util = require('../../../utils/util.js')
  4. const Http = require('../../../utils/HttpBasics.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. receiptUrl:null,
  11. id:"",
  12. newPrice:'',
  13. },
  14. goBack(){
  15. wx.navigateBack({
  16. delta: 1
  17. })
  18. },
  19. // setNewPrice(e){
  20. // this.setData({
  21. // newPrice: e.detail.value
  22. // })
  23. // },
  24. uploadImg() {
  25. let that = this;
  26. wx.chooseImage({
  27. success(res) {
  28. const tempFilePaths = res.tempFilePaths
  29. wx.showLoading({
  30. title: '上传中...',
  31. })
  32. wx.uploadFile({
  33. url: config.api.imgUpload, // 仅为示例,非真实的接口地址
  34. filePath: tempFilePaths[0],
  35. name: 'file',
  36. header: {
  37. 'token': app.globalData.token
  38. },
  39. success(res) {
  40. const data = res.data
  41. that.setData({
  42. receiptUrl: JSON.parse(res.data).data.url
  43. })
  44. wx.hideLoading()
  45. // do something
  46. },
  47. fail() {
  48. wx.hideLoading()
  49. }
  50. })
  51. },
  52. })
  53. },
  54. submit(){
  55. let this_ = this;
  56. if (!this.data.receiptUrl){
  57. wx.showToast({
  58. title: `请先上传凭证在提交!`,
  59. icon: "none",
  60. duration: 1000,
  61. })
  62. return true
  63. }else{
  64. Http.post({
  65. url: config.api.finishBill,
  66. data:{
  67. id:this.data.id,
  68. payImg:this.data.receiptUrl,
  69. billTypeValue: this.data.billTypeValue,
  70. newPrice: this.data.newPrice
  71. }
  72. }).then(res=>{
  73. wx.showToast({
  74. title: "上传成功!",
  75. icon: 'none',
  76. duration: 2000,
  77. mask: false,
  78. success(res){
  79. setTimeout(function () {
  80. this_.goBack()
  81. }, 2000);
  82. },
  83. });
  84. }).catch(err=>{
  85. wx.showToast({
  86. title: err.message,
  87. icon: 'none',
  88. duration: 2000,
  89. mask: false
  90. });
  91. })
  92. }
  93. },
  94. /**
  95. * 生命周期函数--监听页面加载
  96. */
  97. onLoad: function (options) {
  98. console.log(options.id)
  99. this.setData({
  100. id : options.id,
  101. billTypeValue: options.billTypeValue,
  102. newPrice: options.newPrice
  103. })
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })