createVoyage.js 5.1 KB

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