uploadDischarge.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // pages/voyages/uploadDischarge/uploadDischarge.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. import {
  6. uploadImage
  7. } from "../../../utils/uploadImage"
  8. Page({
  9. data: {
  10. dischargeTime: '',
  11. dischargeTons: 0,
  12. dischargePieces: 0,
  13. fileList: [],
  14. },
  15. async uploadBill(e) {
  16. let {
  17. type
  18. } = e.currentTarget.dataset
  19. let postData = {
  20. type,
  21. voyageId: this.data.voyageId
  22. }
  23. let res = await uploadImage("/voyage/uploadVoyageWayBill", postData)
  24. let {
  25. id,
  26. viewUrl
  27. } = res.result
  28. this.data.fileList.push({
  29. id,
  30. viewUrl
  31. })
  32. this.setData({
  33. fileList: this.data.fileList
  34. })
  35. },
  36. async submit() {
  37. let {
  38. dischargeTime,
  39. dischargeTons,
  40. dischargePieces,
  41. fileList,
  42. portId,
  43. voyageId
  44. } = this.data
  45. let arr = []
  46. for (let i of fileList) {
  47. arr.push(i.id)
  48. }
  49. let postData = {
  50. loginAccountId: wx.getStorageSync('loginAccountId'),
  51. voyageId,
  52. portId,
  53. dischargeTons,
  54. dischargePieces,
  55. dischargeTime: dischargeTime.replaceAll('-', '/') + " 00:00:00",
  56. voyageFileIds: arr.join(',')
  57. }
  58. let res = await postApi("/voyage/addDischarge", postData)
  59. wx.setStorageSync('addStatus', 'success')
  60. wx.navigateBack()
  61. },
  62. preview(e) {
  63. wx.previewImage({
  64. urls: [e.currentTarget.dataset.src],
  65. })
  66. },
  67. remove(e) {
  68. wx.showModal({
  69. content: "移除当前图片?",
  70. success: res => {
  71. if (res.confirm) {
  72. this.data.fileList.splice(e.currentTarget.dataset.index, 1)
  73. this.setData({
  74. fileList: this.data.fileList
  75. })
  76. }
  77. }
  78. })
  79. },
  80. onLoad(options) {
  81. this.setData({
  82. voyageId: options.voyageId,
  83. portId: options.portId
  84. })
  85. },
  86. })