SysReservationConfigForm.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import AntModal from '@/components/pt/dialog/AntModal'
  2. import { getSysReservationConfig, addSysReservationConfig, updateSysReservationConfig, batchAddSysReservationConfig } from '@/api/system/sysReservationConfig'
  3. export default {
  4. name: 'CreateForm',
  5. props: {
  6. statusOptions: {
  7. type: Array,
  8. required: true
  9. }
  10. },
  11. components: {
  12. AntModal
  13. },
  14. data () {
  15. return {
  16. open: false,
  17. closeDialog: true,
  18. spinning: false,
  19. delayTime: 100,
  20. labelCol: { span: 4 },
  21. wrapperCol: { span: 14 },
  22. loading: false,
  23. disabled: false,
  24. total: 0,
  25. id: undefined,
  26. formTitle: '预约配置',
  27. // 表单参数
  28. form: {},
  29. batchForm: {
  30. dateRange: []
  31. },
  32. rules: {
  33. reservationDate: [{ required: true, message: '预约日期不能为空', trigger: 'blur' }],
  34. reservationStartTime: [{ required: true, message: '预约开始时段不能为空', trigger: 'blur' }],
  35. reservationEndTime: [{ required: true, message: '预约结束时段不能为空', trigger: 'blur' }],
  36. enableNum: [{ required: true, message: '可预约人数不能为空', trigger: 'blur' }]
  37. },
  38. batchAddRules: {
  39. dateRange: [{ required: true, message: '预约日期不能为空', trigger: 'blur' }],
  40. duration: [{ required: true, message: '班次时长不能为空', trigger: 'blur' }],
  41. enableNum: [{ required: true, message: '可预约人数不能为空', trigger: 'blur' }]
  42. }
  43. }
  44. },
  45. filters: {},
  46. created () {},
  47. computed: {},
  48. watch: {},
  49. mounted () {},
  50. methods: {
  51. onClose () {
  52. this.open = false
  53. this.reset()
  54. this.$emit('close')
  55. },
  56. // 取消按钮
  57. cancel () {
  58. this.open = false
  59. this.reset()
  60. this.$emit('close')
  61. },
  62. // 表单重置
  63. reset () {
  64. this.form = {
  65. id: undefined,
  66. reservationDate: undefined,
  67. reservationStartTime: undefined,
  68. reservationEndTime: undefined,
  69. enableNum: undefined,
  70. status: '0'
  71. }
  72. },
  73. /** 新增按钮操作 */
  74. handleAdd () {
  75. this.reset()
  76. this.open = true
  77. this.formTitle = '预约配置'
  78. },
  79. /** 修改按钮操作 */
  80. handleUpdate (row) {
  81. this.reset()
  82. this.open = true
  83. this.spinning = !this.spinning
  84. const sysReservationConfigId = row.id
  85. getSysReservationConfig(sysReservationConfigId).then(response => {
  86. this.form = response.data
  87. this.formTitle = '修改预约配置'
  88. this.spinning = !this.spinning
  89. })
  90. },
  91. batchSave: function (closeDialog, status) {
  92. this.closeDialog = closeDialog
  93. this.disabled = true
  94. this.$refs.batchForm.validate(valid => {
  95. if (valid) {
  96. const saveForm = {
  97. startDate: this.batchForm.dateRange[0],
  98. endDate: this.batchForm.dateRange[1],
  99. duration: this.batchForm.duration,
  100. enableNum: this.batchForm.enableNum,
  101. status: status
  102. }
  103. batchAddSysReservationConfig(saveForm).then(response => {
  104. this.$message.success('配置成功', 3)
  105. this.open = false
  106. this.$emit('ok')
  107. this.$emit('close')
  108. this.disabled = false
  109. })
  110. } else {
  111. this.disabled = false
  112. return false
  113. }
  114. })
  115. },
  116. /** 提交按钮 */
  117. submitForm: function (closeDialog) {
  118. this.closeDialog = closeDialog
  119. this.disabled = true
  120. this.$refs.form.validate(valid => {
  121. if (valid) {
  122. const saveForm = JSON.parse(JSON.stringify(this.form))
  123. if (this.form.id !== undefined) {
  124. updateSysReservationConfig(saveForm).then(response => {
  125. this.$message.success('更新成功', 3)
  126. this.open = false
  127. this.$emit('ok')
  128. this.$emit('close')
  129. this.disabled = false
  130. })
  131. } else {
  132. addSysReservationConfig(saveForm).then(response => {
  133. this.$message.success('新增成功', 3)
  134. this.open = false
  135. this.$emit('ok')
  136. this.$emit('close')
  137. this.disabled = false
  138. })
  139. }
  140. } else {
  141. this.disabled = false
  142. return false
  143. }
  144. })
  145. },
  146. back () {
  147. const index = '/system/sysreservationconfig/index'
  148. this.$router.push(index)
  149. }
  150. }
  151. }