createVoyage.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. const {
  2. postApi
  3. } = require("../../../apis/api")
  4. // pages/voyageManage/createVoyage/createVoyage.js
  5. Page({
  6. data: {
  7. defaultParams: {
  8. loginAccountId: wx.getStorageSync('loginAccountId')
  9. },
  10. dischargePorts: [''],
  11. dischargePortIds: [''],
  12. voyage: {},
  13. startTime: ''
  14. },
  15. selectShip(e) {
  16. console.log(e)
  17. this.data.voyage.shipId = e.detail.value
  18. },
  19. selectCargoOwner(e) {
  20. this.data.voyage.cargoOwnerId = e.detail.value
  21. },
  22. selectCargo(e) {
  23. this.data.voyage.cargo = e.detail.value
  24. },
  25. selectLoadPort(e) {
  26. this.data.voyage.loadPortId = e.detail.value
  27. this.data.voyage.loadPort = e.detail.label
  28. },
  29. selectDiscPort(e) {
  30. this.data.dischargePortIds[e.currentTarget.dataset.index] = e.detail.value
  31. this.data.dischargePorts[e.currentTarget.dataset.index] = e.detail.label
  32. this.setData({
  33. dischargePorts: this.data.dischargePorts,
  34. dischargePortIds: this.data.dischargePortIds
  35. })
  36. },
  37. addDischargePort() {
  38. let dischargePorts = this.data.dischargePorts
  39. let dischargePortIds = this.data.dischargePortIds
  40. dischargePorts.push('')
  41. dischargePortIds.push('')
  42. this.setData({
  43. dischargePortIds,
  44. dischargePorts
  45. })
  46. },
  47. deleteDischargePort(e) {
  48. let dischargePorts = this.data.dischargePorts
  49. let dischargePortIds = this.data.dischargePortIds
  50. if (dischargePorts.length == 1) {
  51. dischargePortIds = ['']
  52. dischargePorts = ['']
  53. } else {
  54. dischargePorts.splice(e.currentTarget.dataset.index, 1)
  55. dischargePortIds.splice(e.currentTarget.dataset.index, 1)
  56. }
  57. this.setData({
  58. dischargePortIds,
  59. dischargePorts
  60. })
  61. },
  62. checkData() {
  63. if (!this.data.shipId) {
  64. wx.showToast({
  65. title: '请选择船舶',
  66. icon: "error"
  67. })
  68. return
  69. }
  70. if (!this.data.cargoOwnerId) {
  71. wx.showToast({
  72. title: '请选择货主',
  73. icon: "error"
  74. })
  75. return
  76. }
  77. if (!this.data.cargo) {
  78. wx.showToast({
  79. title: '请选择货种',
  80. icon: "error"
  81. })
  82. return
  83. }
  84. if (!this.data.loadPort || !this.data.loadPortId) {
  85. wx.showToast({
  86. title: '请选择装货港',
  87. icon: "error"
  88. })
  89. return
  90. }
  91. if (!this.data.dischargePortIds.length || !this.data.dischargePorts.length) {
  92. wx.showToast({
  93. title: '请添加卸货港',
  94. icon: "error"
  95. })
  96. return
  97. }
  98. if (!this.data.tons) {
  99. wx.showToast({
  100. title: '请输入吨位',
  101. icon: "error"
  102. })
  103. return
  104. }
  105. // if(!this.data.pieces){
  106. // wx.showToast({
  107. // title: '请输入件数',
  108. // icon:"error"
  109. // })
  110. // return
  111. // }
  112. if (!this.data.startTime) {
  113. wx.showToast({
  114. title: '请选择开始时间',
  115. icon: "error"
  116. })
  117. return
  118. }
  119. return true
  120. },
  121. async createVoyage() {
  122. if (!this.checkData()) return
  123. wx.showLoading({
  124. title: '正在提交...',
  125. mask: true,
  126. success: (res) => {},
  127. fail: (res) => {},
  128. complete: (res) => {},
  129. })
  130. let dischargePortIds = this.data.dischargePortIds.filter(item => {
  131. return item
  132. })
  133. let dischargePorts = this.data.dischargePorts.filter(item => {
  134. return item
  135. })
  136. let startTime = this.data.startTime.replaceAll('-', '/')
  137. let postData = {
  138. ...this.data.voyage,
  139. loginAccountId: wx.getStorageSync('loginAccountId'),
  140. dischargePortIds: dischargePortIds.join(','),
  141. dischargePorts: dischargePorts.join(','),
  142. startTime,
  143. tons: this.data.tons,
  144. pieces: this.data.pieces,
  145. }
  146. let res = await postApi('/voyage/backstage/add', postData)
  147. wx.hideLoading({
  148. success: (res) => {},
  149. })
  150. if (res.data.status == 0) {
  151. wx.showToast({
  152. title: res.data.msg,
  153. })
  154. wx.switchTab({
  155. url: '/pages/voyageManage/voyageManage',
  156. })
  157. } else {
  158. wx.showToast({
  159. title: res.data.msg,
  160. icon: "error"
  161. })
  162. }
  163. }
  164. })