TableEdit.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogFormVisible" width="800px" @close="close">
  3. <el-form ref="form" :model="form" :rules="rules" label-width="150px">
  4. <!-- id
  5. projectId
  6. generatingCapacity
  7. outageHours
  8. year
  9. month
  10. windpowerstationId -->
  11. <el-row>
  12. <el-col :span="12">
  13. <el-form-item label="编码" prop="id">
  14. <el-input class="inputs" v-model="form.id" autocomplete="off" :disabled="!idAdd?true:false"></el-input>
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="12">
  18. <el-form-item label="工程编号" prop="projectId">
  19. <el-input class="inputs" v-model="form.projectId" autocomplete="off"></el-input>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="12">
  23. <el-form-item label="计划发电量" prop="generatingCapacity">
  24. <el-input class="inputs" v-model="form.generatingCapacity" autocomplete="off"></el-input>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="12">
  28. <el-form-item label="计划停运小时" prop="outageHours">
  29. <el-input class="inputs" v-model="form.outageHours" autocomplete="off"></el-input>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="12">
  33. <el-form-item label="日期" prop="dateVal">
  34. <el-date-picker key="100" style="width:200px" @input="changeDate" v-model="form.dateVal" type="month" placeholder="选择月"></el-date-picker>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="12">
  38. <el-form-item label="场站编号冗余" prop="windpowerstationId">
  39. <el-input class="inputs" v-model="form.windpowerstationId" autocomplete="off"></el-input>
  40. </el-form-item>
  41. </el-col>
  42. </el-row>
  43. </el-form>
  44. <div slot="footer" class="dialog-footer">
  45. <el-button @click="close">取 消</el-button>
  46. <el-button type="primary" @click="save">确 定</el-button>
  47. </div>
  48. </el-dialog>
  49. </template>
  50. <script>
  51. import api from '@/api/realtimeDatabaseConfiguration'
  52. import dayjs from "dayjs";
  53. export default {
  54. name: 'TableEdit',
  55. props: {
  56. options: {
  57. type: Array,
  58. default: []
  59. },
  60. stationList: {
  61. type: Array,
  62. default: []
  63. },
  64. },
  65. data() {
  66. return {
  67. form: {
  68. id: "",
  69. projectId: "",
  70. generatingCapacity: "",
  71. outageHours: "",
  72. year: "",
  73. month: "",
  74. windpowerstationId: "",
  75. dateVal: ""
  76. },
  77. rules: {
  78. id: [{ required: true, trigger: 'blur', message: '请输入' }],
  79. projectId: [{ required: true, trigger: 'blur', message: '请输入' }],
  80. generatingCapacity: [{ required: true, trigger: 'blur', message: '请输入' }],
  81. outageHours: [{ required: true, trigger: 'blur', message: '请输入' }],
  82. dateVal: [{ required: true, trigger: 'blur', message: '请输入' }],
  83. windpowerstationId: [{ required: true, trigger: 'blur', message: '请输入' }],
  84. },
  85. title: '',
  86. dialogFormVisible: false,
  87. idAdd: true,
  88. }
  89. },
  90. created() { },
  91. methods: {
  92. changeDate() {
  93. this.$forceUpdate()
  94. },
  95. showEdit(row) {
  96. if (!row) {
  97. this.title = '添加'
  98. this.idAdd = true
  99. } else {
  100. this.title = '编辑'
  101. this.idAdd = false
  102. this.form = Object.assign({}, row)
  103. this.form.dateVal = this.form.year && this.form.month ? new Date(`${this.form.year}-${this.form.month}-01`).getTime() : ''
  104. }
  105. this.dialogFormVisible = true
  106. },
  107. close() {
  108. this.$refs['form'].resetFields()
  109. this.form = this.$options.data().form
  110. this.dialogFormVisible = false
  111. this.$emit('fetch-data')
  112. },
  113. save() {
  114. this.$refs['form'].validate(async (valid) => {
  115. if (valid) {
  116. this.form.year = new Date(this.form.dateVal).getFullYear()
  117. this.form.month = new Date(this.form.dateVal).getMonth() + 1
  118. api.addProjectstudy(this.form).then(res => {
  119. if (res.data) {
  120. this.$message({
  121. type: 'success',
  122. message: '添加成功!'
  123. });
  124. this.$emit('save-success');
  125. this.dialogFormVisible = false
  126. }
  127. })
  128. } else {
  129. return false
  130. }
  131. })
  132. },
  133. handleChange() {
  134. },
  135. onBlur(val, param) {
  136. if (typeof (this.form[param]) !== 'number') {
  137. this.form[param] = val.replace(/[^0-9]/ig, "")
  138. }
  139. },
  140. },
  141. }
  142. </script>
  143. <style lang="less" scoped>
  144. .inputs {
  145. width: 200px;
  146. }
  147. .lists {
  148. display: flex;
  149. flex-direction: row;
  150. align-items: center;
  151. justify-content: space-between;
  152. }
  153. </style>