createVoyage.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. this.selectComponent('#disc0')._clear()
  54. } else {
  55. dischargePorts.splice(e.currentTarget.dataset.index, 1)
  56. dischargePortIds.splice(e.currentTarget.dataset.index, 1)
  57. }
  58. this.setData({
  59. dischargePortIds,
  60. dischargePorts
  61. })
  62. },
  63. checkData() {
  64. if (!this.data.shipId) {
  65. wx.showToast({
  66. title: '请选择船舶',
  67. icon: "error"
  68. })
  69. return
  70. }
  71. if (!this.data.cargoOwnerId) {
  72. wx.showToast({
  73. title: '请选择货主',
  74. icon: "error"
  75. })
  76. return
  77. }
  78. if (!this.data.cargo) {
  79. wx.showToast({
  80. title: '请选择货种',
  81. icon: "error"
  82. })
  83. return
  84. }
  85. if (!this.data.loadPort || !this.data.loadPortId) {
  86. wx.showToast({
  87. title: '请选择装货港',
  88. icon: "error"
  89. })
  90. return
  91. }
  92. if (!this.data.dischargePortIds.length || !this.data.dischargePorts.length) {
  93. wx.showToast({
  94. title: '请添加卸货港',
  95. icon: "error"
  96. })
  97. return
  98. }
  99. if (!this.data.tons) {
  100. wx.showToast({
  101. title: '请输入吨位',
  102. icon: "error"
  103. })
  104. return
  105. }
  106. // if(!this.data.pieces){
  107. // wx.showToast({
  108. // title: '请输入件数',
  109. // icon:"error"
  110. // })
  111. // return
  112. // }
  113. if (!this.data.startTime) {
  114. wx.showToast({
  115. title: '请选择开始时间',
  116. icon: "error"
  117. })
  118. return
  119. }
  120. return true
  121. },
  122. async createVoyage() {
  123. if (!this.checkData()) return
  124. wx.showLoading({
  125. title: '正在提交...',
  126. mask: true,
  127. success: (res) => {},
  128. fail: (res) => {},
  129. complete: (res) => {},
  130. })
  131. let dischargePortIds = this.data.dischargePortIds.filter(item => {
  132. return item
  133. })
  134. let dischargePorts = this.data.dischargePorts.filter(item => {
  135. return item
  136. })
  137. let startTime = this.data.startTime.replaceAll('-', '/')
  138. let postData = {
  139. ...this.data.voyage,
  140. loginAccountId: wx.getStorageSync('loginAccountId'),
  141. dischargePortIds: dischargePortIds.join(','),
  142. dischargePorts: dischargePorts.join(','),
  143. startTime,
  144. tons: this.data.tons,
  145. pieces: this.data.pieces,
  146. }
  147. let res = await postApi('/voyage/backstage/add', postData)
  148. wx.hideLoading({
  149. success: (res) => {},
  150. })
  151. if (res.data.status == 0) {
  152. wx.showToast({
  153. title: res.data.msg,
  154. })
  155. wx.switchTab({
  156. url: '/pages/voyageManage/voyageManage',
  157. })
  158. } else {
  159. wx.showToast({
  160. title: res.data.msg,
  161. icon: "error"
  162. })
  163. }
  164. }
  165. })