createVoyage.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. const {
  2. postApi
  3. } = require("../../../apis/api")
  4. const app = getApp()
  5. // pages/voyageManage/createVoyage/createVoyage.js
  6. Page({
  7. data: {
  8. defaultParams: {
  9. },
  10. dischargePorts: [{}],
  11. voyage: {},
  12. startTime: '',
  13. currentCargoOwnerId: 0
  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. this.setData({
  22. currentCargoOwnerId: this.data.voyage
  23. })
  24. let cargoCmp = this.selectComponent('#cargoCmp');
  25. cargoCmp._getList({
  26. cargoOwnerId: e.detail.value
  27. })
  28. },
  29. selectCargo(e) {
  30. console.log(e)
  31. this.data.voyage.cargoId = e.detail.value
  32. this.data.voyage.cargo = e.detail.label
  33. },
  34. selectLoadPort(e) {
  35. this.data.voyage.loadPortId = e.detail.value
  36. this.data.voyage.loadPort = e.detail.label
  37. },
  38. selectDiscPort(e) {
  39. console.log(e)
  40. let {
  41. label: dischargePort,
  42. value: id
  43. } = e.detail
  44. this.data.dischargePorts[e.currentTarget.dataset.index] = {
  45. dischargePort,
  46. id,
  47. reasonableUnloadingDays: 0
  48. }
  49. this.setData({
  50. dischargePorts: this.data.dischargePorts,
  51. })
  52. },
  53. addDischargePort() {
  54. let dischargePorts = this.data.dischargePorts
  55. dischargePorts.push({})
  56. this.setData({
  57. dischargePorts
  58. })
  59. },
  60. deleteDischargePort(e) {
  61. let dischargePorts = this.data.dischargePorts
  62. if (dischargePorts.length == 1) {
  63. dischargePorts = [{}]
  64. } else {
  65. dischargePorts.splice(e.currentTarget.dataset.index, 1)
  66. }
  67. this.setData({
  68. dischargePorts
  69. })
  70. },
  71. checkData() {
  72. if (!this.data.voyage.shipId) {
  73. wx.showToast({
  74. title: '请选择船舶',
  75. icon: "error"
  76. })
  77. return
  78. }
  79. if (!this.data.voyage.cargoOwnerId) {
  80. wx.showToast({
  81. title: '请选择货主',
  82. icon: "error"
  83. })
  84. return
  85. }
  86. if (!this.data.voyage.cargo) {
  87. wx.showToast({
  88. title: '请选择货种',
  89. icon: "error"
  90. })
  91. return
  92. }
  93. if (!this.data.voyage.loadPort || !this.data.voyage.loadPortId) {
  94. wx.showToast({
  95. title: '请选择装货港',
  96. icon: "error"
  97. })
  98. return
  99. }
  100. if (!this.data.dischargePorts.length) {
  101. wx.showToast({
  102. title: '请添加卸货港',
  103. icon: "error"
  104. })
  105. return
  106. }
  107. if (!this.data.tons) {
  108. wx.showToast({
  109. title: '请输入吨位',
  110. icon: "error"
  111. })
  112. return
  113. }
  114. if (!this.data.reasonableUnloadingDays) {
  115. wx.showToast({
  116. title: '请输入合理卸货天数',
  117. icon: "none"
  118. })
  119. return
  120. }
  121. // if(!this.data.pieces){
  122. // wx.showToast({
  123. // title: '请输入件数',
  124. // icon:"error"
  125. // })
  126. // return
  127. // }
  128. // if (!this.data.startTime) {
  129. // wx.showToast({
  130. // title: '请选择开始时间',
  131. // icon: "error"
  132. // })
  133. // return
  134. // }
  135. return true
  136. },
  137. async createVoyage() {
  138. if (!this.checkData()) return
  139. wx.showLoading({
  140. title: '正在提交...',
  141. mask: true,
  142. success: (res) => {},
  143. fail: (res) => {},
  144. complete: (res) => {},
  145. })
  146. let startTime = this.data.startTime.replaceAll('-', '/')
  147. let postData = {
  148. ...this.data.voyage,
  149. loginAccountId: wx.getStorageSync('loginAccountId'),
  150. dischargePorts: this.data.dischargePorts,
  151. startTime,
  152. tons: this.data.tons,
  153. pieces: this.data.pieces,
  154. reasonableUnloadingDays: this.data.reasonableUnloadingDays
  155. }
  156. let res = await postApi('/voyage/add', postData)
  157. wx.hideLoading({
  158. success: (res) => {},
  159. })
  160. if (res.data.status == 0) {
  161. wx.showToast({
  162. title: res.data.msg,
  163. })
  164. app.globalData.maintab = 1
  165. wx.switchTab({
  166. url: '/pages/voyageManage/voyageManage',
  167. })
  168. } else {
  169. wx.showToast({
  170. title: res.data.msg,
  171. icon: "error"
  172. })
  173. }
  174. },
  175. onShow() {
  176. this.setData({
  177. defaultParams: {
  178. loginAccountId: wx.getStorageSync('loginAccountId')
  179. }
  180. })
  181. },
  182. onLoad(options) {
  183. if (options) {
  184. let {
  185. shipName,
  186. shipId
  187. } = options
  188. this.setData({
  189. voyage: {
  190. shipName,
  191. shipId
  192. }
  193. })
  194. }
  195. }
  196. })