SysShipForm.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import AntModal from '@/components/pt/dialog/AntModal'
  2. import { getSysShip, addSysShip, updateSysShip } from '@/api/system/sysShip'
  3. import { getAllSysWharf } from '@/api/system/sysWharf'
  4. export default {
  5. name: 'CreateForm',
  6. props: {
  7. statusOptions: {
  8. type: Array,
  9. required: true
  10. }
  11. },
  12. components: {
  13. AntModal
  14. },
  15. data () {
  16. return {
  17. open: false,
  18. closeDialog: true,
  19. spinning: false,
  20. delayTime: 100,
  21. labelCol: { span: 4 },
  22. wrapperCol: { span: 14 },
  23. loading: false,
  24. disabled: false,
  25. total: 0,
  26. id: undefined,
  27. formTitle: '添加船只管理',
  28. // 表单参数
  29. wharfList: [],
  30. travelList: [
  31. {
  32. id: '1',
  33. name: '由西向东(正向)'
  34. },
  35. {
  36. id: '0',
  37. name: '由东向西(反向)'
  38. }
  39. ],
  40. form: {},
  41. rules: {
  42. shipNum: [{ required: true, message: '船只编号不能为空', trigger: 'blur' }],
  43. shipNanme: [{ required: true, message: '船只名称不能为空', trigger: 'blur' }]
  44. }
  45. }
  46. },
  47. filters: {},
  48. created () {
  49. this._getAllSysWharf()
  50. },
  51. computed: {},
  52. watch: {},
  53. mounted () {},
  54. methods: {
  55. _getAllSysWharf() {
  56. getAllSysWharf().then(res => {
  57. this.wharfList = res.data
  58. })
  59. },
  60. onClose () {
  61. this.open = false
  62. this.reset()
  63. this.$emit('close')
  64. },
  65. // 取消按钮
  66. cancel () {
  67. this.open = false
  68. this.reset()
  69. this.$emit('close')
  70. },
  71. // 表单重置
  72. reset () {
  73. this.form = {
  74. id: undefined,
  75. shipNum: undefined,
  76. shipNanme: undefined,
  77. gpsDeviceNum: undefined,
  78. nuclearLoadNum: undefined,
  79. lat: undefined,
  80. lng: undefined,
  81. status: '0',
  82. wharf: undefined,
  83. travel: undefined
  84. }
  85. },
  86. /** 新增按钮操作 */
  87. handleAdd () {
  88. this.reset()
  89. this.open = true
  90. this.formTitle = '添加船只管理'
  91. },
  92. /** 修改按钮操作 */
  93. handleUpdate (row) {
  94. this.reset()
  95. this.open = true
  96. this.spinning = !this.spinning
  97. const sysShipId = row.id
  98. getSysShip(sysShipId).then(response => {
  99. this.form = response.data
  100. this.formTitle = '修改船只管理'
  101. this.spinning = !this.spinning
  102. })
  103. },
  104. /** 提交按钮 */
  105. submitForm: function (closeDialog) {
  106. this.closeDialog = closeDialog
  107. this.disabled = true
  108. this.$refs.form.validate(valid => {
  109. if (valid) {
  110. const saveForm = JSON.parse(JSON.stringify(this.form))
  111. if (this.form.id !== undefined) {
  112. updateSysShip(saveForm).then(response => {
  113. this.$message.success('更新成功', 3)
  114. this.open = false
  115. this.$emit('ok')
  116. this.$emit('close')
  117. this.disabled = false
  118. })
  119. } else {
  120. addSysShip(saveForm).then(response => {
  121. this.$message.success('新增成功', 3)
  122. this.open = false
  123. this.$emit('ok')
  124. this.$emit('close')
  125. this.disabled = false
  126. })
  127. }
  128. } else {
  129. this.disabled = false
  130. return false
  131. }
  132. })
  133. },
  134. back () {
  135. const index = '/system/sysship/index'
  136. this.$router.push(index)
  137. }
  138. }
  139. }