createVoyage.js 4.7 KB

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