editPlan.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
  3. <el-form ref="form" label-position="top" :model="form" :rules="rules">
  4. <el-row :gutter="20">
  5. <el-col :span="24">
  6. <el-form-item label="计划标题" prop="planTitle">
  7. <el-input v-model="form.planTitle" placeholder="请输入计划标题" />
  8. </el-form-item>
  9. </el-col>
  10. </el-row>
  11. <el-row :gutter="20">
  12. <el-col :span="24">
  13. <el-form-item label="时间范围" prop="date">
  14. <el-date-picker
  15. v-model="form.date"
  16. end-placeholder="结束日期"
  17. range-separator="至"
  18. start-placeholder="开始日期"
  19. style="width: 100%"
  20. type="datetimerange"
  21. value-format="yyyy-MM-dd HH:mm:ss" />
  22. </el-form-item>
  23. </el-col>
  24. </el-row>
  25. </el-form>
  26. <template #footer>
  27. <el-button @click="close">取 消</el-button>
  28. <el-button type="primary" @click="save">确 定</el-button>
  29. </template>
  30. </el-dialog>
  31. </template>
  32. <script>
  33. import planApi from '@/api/work/deliverPlan'
  34. export default {
  35. name: 'WorkOrderFeedback',
  36. components: {},
  37. props: {
  38. // orderStatusOptions: {
  39. // type: Array,
  40. // default: () => [],
  41. // },
  42. },
  43. data() {
  44. return {
  45. form: {
  46. deliverOrderId: 0,
  47. planTitle: undefined,
  48. date: [],
  49. },
  50. rules: {
  51. planTitle: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }],
  52. date: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }],
  53. },
  54. dialogFormVisible: false,
  55. planId: 0,
  56. title: '',
  57. }
  58. },
  59. mounted() {},
  60. methods: {
  61. open(planId) {
  62. console.log('planId', planId)
  63. if (planId) {
  64. this.planId = planId
  65. this.title = '编辑'
  66. this.getPlanDetail()
  67. } else {
  68. this.title = '新建计划'
  69. this.planId = 0
  70. }
  71. this.form.deliverOrderId = parseInt(this.$route.query.id)
  72. this.dialogFormVisible = true
  73. },
  74. close() {
  75. this.$refs['form'].resetFields()
  76. this.form = this.$options.data().form
  77. this.dialogFormVisible = false
  78. },
  79. async getPlanDetail() {
  80. const { data, code } = await planApi.getPlan({ id: this.planId })
  81. if (code == 200) {
  82. this.form.date = [data.planStartDate, data.planEndDate]
  83. this.form.planTitle = data.planTitle
  84. }
  85. },
  86. save() {
  87. this.$refs['form'].validate(async (valid) => {
  88. if (valid) {
  89. console.log(this.form.date)
  90. const params = {
  91. deliverOrderId: this.form.deliverOrderId,
  92. planTitle: this.form.planTitle,
  93. planStartDate: this.form.date[0],
  94. planEndDate: this.form.date[1],
  95. }
  96. if (this.planId) {
  97. params.id = this.planId
  98. const { msg } = await planApi.updatePlan(params)
  99. this.$baseMessage(msg, 'success', 'vab-hey-message-success')
  100. } else {
  101. const { msg } = await planApi.addPlan(params)
  102. this.$baseMessage(msg, 'success', 'vab-hey-message-success')
  103. }
  104. this.$emit('fetch-data')
  105. this.close()
  106. }
  107. })
  108. },
  109. },
  110. }
  111. </script>