createVoyage.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. dischargePortIds: [''],
  12. voyage: {},
  13. startTime: '',
  14. currentCargoOwnerId: 0
  15. },
  16. selectShip(e) {
  17. console.log(e)
  18. this.data.voyage.shipId = e.detail.value
  19. },
  20. selectCargoOwner(e) {
  21. this.data.voyage.cargoOwnerId = e.detail.value
  22. this.setData({
  23. currentCargoOwnerId: this.data.voyage
  24. })
  25. let cargoCmp = this.selectComponent('#cargoCmp');
  26. cargoCmp._getList({
  27. cargoOwnerId: e.detail.value
  28. })
  29. },
  30. selectCargo(e) {
  31. console.log(e)
  32. this.data.voyage.cargo = e.detail.value
  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. this.data.dischargePortIds[e.currentTarget.dataset.index] = e.detail.value
  40. this.data.dischargePorts[e.currentTarget.dataset.index] = e.detail.label
  41. this.setData({
  42. dischargePorts: this.data.dischargePorts,
  43. dischargePortIds: this.data.dischargePortIds
  44. })
  45. },
  46. addDischargePort() {
  47. let dischargePorts = this.data.dischargePorts
  48. let dischargePortIds = this.data.dischargePortIds
  49. dischargePorts.push('')
  50. dischargePortIds.push('')
  51. this.setData({
  52. dischargePortIds,
  53. dischargePorts
  54. })
  55. },
  56. deleteDischargePort(e) {
  57. let dischargePorts = this.data.dischargePorts
  58. let dischargePortIds = this.data.dischargePortIds
  59. if (dischargePorts.length == 1) {
  60. dischargePortIds = ['']
  61. dischargePorts = ['']
  62. } else {
  63. dischargePorts.splice(e.currentTarget.dataset.index, 1)
  64. dischargePortIds.splice(e.currentTarget.dataset.index, 1)
  65. }
  66. this.setData({
  67. dischargePortIds,
  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.dischargePortIds.length || !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.pieces){
  115. // wx.showToast({
  116. // title: '请输入件数',
  117. // icon:"error"
  118. // })
  119. // return
  120. // }
  121. // if (!this.data.startTime) {
  122. // wx.showToast({
  123. // title: '请选择开始时间',
  124. // icon: "error"
  125. // })
  126. // return
  127. // }
  128. return true
  129. },
  130. async createVoyage() {
  131. if (!this.checkData()) return
  132. wx.showLoading({
  133. title: '正在提交...',
  134. mask: true,
  135. success: (res) => {},
  136. fail: (res) => {},
  137. complete: (res) => {},
  138. })
  139. let dischargePortIds = this.data.dischargePortIds.filter(item => {
  140. return item
  141. })
  142. let dischargePorts = this.data.dischargePorts.filter(item => {
  143. return item
  144. })
  145. let startTime = this.data.startTime.replaceAll('-', '/')
  146. let postData = {
  147. ...this.data.voyage,
  148. loginAccountId: wx.getStorageSync('loginAccountId'),
  149. dischargePortIds: dischargePortIds.join(','),
  150. dischargePorts: dischargePorts.join(','),
  151. startTime,
  152. tons: this.data.tons,
  153. pieces: this.data.pieces,
  154. }
  155. let res = await postApi('/voyage/add', postData)
  156. wx.hideLoading({
  157. success: (res) => {},
  158. })
  159. if (res.data.status == 0) {
  160. wx.showToast({
  161. title: res.data.msg,
  162. })
  163. app.globalData.maintab = 1
  164. wx.switchTab({
  165. url: '/pages/voyageManage/voyageManage',
  166. })
  167. } else {
  168. wx.showToast({
  169. title: res.data.msg,
  170. icon: "error"
  171. })
  172. }
  173. },
  174. onShow() {
  175. this.setData({
  176. defaultParams: {
  177. loginAccountId: wx.getStorageSync('loginAccountId')
  178. }
  179. })
  180. },
  181. onLoad(options) {
  182. let {
  183. shipName,
  184. shipId
  185. } = options
  186. this.setData({
  187. voyage: {
  188. shipName,
  189. shipId
  190. }
  191. })
  192. }
  193. })