TableEdit.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogFormVisible"
  5. width="800px"
  6. @close="close"
  7. >
  8. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  9. <el-form-item label="场站" prop="windpowerstationId">
  10. <el-select
  11. v-model="form.windpowerstationId"
  12. style="width: 200px"
  13. placeholder="请选择"
  14. clearable
  15. :disabled="!idAdd ? true : false"
  16. >
  17. <el-option
  18. v-for="item in wplist"
  19. :key="item.nemCode"
  20. :label="item.name"
  21. :value="item.nemCode"
  22. ></el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="填报日期" prop="recordDate">
  26. <el-date-picker
  27. v-model="form.recordDate"
  28. :disabled="!idAdd ? true : false"
  29. style="width: 200px"
  30. type="date"
  31. placeholder="选择日期时间"
  32. ></el-date-picker>
  33. </el-form-item>
  34. <el-form-item label="日发电量" prop="generationDay">
  35. <el-input
  36. v-model="form.generationDay"
  37. style="width: 200px"
  38. class="inputs"
  39. placeholder="请输入"
  40. ></el-input>
  41. </el-form-item>
  42. <el-form-item label="月发电量" prop="generationMonth">
  43. <el-input
  44. v-model="form.generationMonth"
  45. style="width: 200px"
  46. class="inputs"
  47. placeholder="请输入"
  48. ></el-input>
  49. </el-form-item>
  50. <el-form-item label="年发电量" prop="generationYear">
  51. <el-input
  52. v-model="form.generationYear"
  53. style="width: 200px"
  54. class="inputs"
  55. placeholder="请输入"
  56. ></el-input>
  57. </el-form-item>
  58. <el-form-item label="功率负荷" prop="power">
  59. <el-input
  60. v-model="form.power"
  61. style="width: 200px"
  62. class="inputs"
  63. placeholder="请输入"
  64. ></el-input>
  65. </el-form-item>
  66. <el-form-item label="风速/光照" prop="speedOrBeam">
  67. <el-input
  68. v-model="form.speedOrBeam"
  69. style="width: 200px"
  70. class="inputs"
  71. placeholder="请输入"
  72. ></el-input>
  73. </el-form-item>
  74. </el-form>
  75. <div slot="footer" class="dialog-footer">
  76. <el-button @click="close">取 消</el-button>
  77. <el-button type="primary" @click="handleSave()">确 定</el-button>
  78. </div>
  79. </el-dialog>
  80. </template>
  81. <script>
  82. import { doEdit, doPut } from '@/api/zhibiao.js'
  83. import dayjs from 'dayjs'
  84. export default {
  85. name: 'TableEdit',
  86. props: {
  87. wplist: {
  88. type: Array,
  89. default: () => [],
  90. },
  91. // options: {
  92. // type: Array,
  93. // default: [],
  94. // },
  95. // standardList: {
  96. // type: Array,
  97. // default: [],
  98. // },
  99. },
  100. data() {
  101. return {
  102. form: {
  103. windpowerstationId: '',
  104. windpowerstationName: '',
  105. recordDate: '',
  106. generationDay: '',
  107. generationMonth: '',
  108. generationYear: '',
  109. power: '',
  110. speedOrBeam: '',
  111. },
  112. rules: {
  113. windpowerstationId: [
  114. { required: true, trigger: 'blur', message: '请选择' },
  115. ],
  116. generationDay: [
  117. { required: true, trigger: 'blur', message: '请选择' },
  118. ],
  119. generationMonth: [
  120. { required: true, trigger: 'blur', message: '请输入' },
  121. ],
  122. generationYear: [
  123. { required: true, trigger: 'blur', message: '请输入' },
  124. ],
  125. power: [{ required: true, trigger: 'blur', message: '请输入' }],
  126. recordDate: [{ required: true, trigger: 'blur', message: '请选择' }],
  127. speedOrBeam: [{ required: true, trigger: 'blur', message: '请选择' }],
  128. },
  129. title: '',
  130. dialogFormVisible: false,
  131. idAdd: true,
  132. }
  133. },
  134. created() {},
  135. methods: {
  136. setFormItem(wpid, recordDate) {
  137. this.form.windpowerstationId = wpid
  138. this.form.recordDate = recordDate
  139. },
  140. openDialog(row) {
  141. if (!row) {
  142. this.title = '添加'
  143. this.idAdd = true
  144. } else {
  145. this.title = '编辑'
  146. this.idAdd = false
  147. this.form = Object.assign({}, row)
  148. this.form.windpowerstationId = row.windpowerstationId
  149. }
  150. this.dialogFormVisible = true
  151. },
  152. close() {
  153. this.$refs['form'].resetFields()
  154. this.form = this.$options.data().form
  155. this.dialogFormVisible = false
  156. this.$emit('fetch-data')
  157. },
  158. handleSave() {
  159. this.$refs['form'].validate(async (valid) => {
  160. if (valid) {
  161. if (this.idAdd) {
  162. let wpinfo = this.wplist.find(
  163. (item) => item.nemCode == this.form.windpowerstationId
  164. )
  165. this.form.windpowerstationName = wpinfo.name
  166. this.form.recordDate = dayjs(this.form.recordDate).format(
  167. 'YYYY-MM-DD'
  168. )
  169. doEdit(this.form).then(({ data: res }) => {
  170. if (res.code == 200) {
  171. this.$message({
  172. type: 'success',
  173. message: '添加成功!',
  174. })
  175. this.$emit('handleSuccess')
  176. this.dialogFormVisible = false
  177. }
  178. })
  179. } else {
  180. console.log(this.form)
  181. doPut(this.form).then(({ data: res }) => {
  182. console.log(res)
  183. if (res.code == 200) {
  184. this.$message({
  185. type: 'success',
  186. message: '修改成功!',
  187. })
  188. this.$emit('handleSuccess')
  189. this.dialogFormVisible = false
  190. }
  191. })
  192. }
  193. } else {
  194. return false
  195. }
  196. })
  197. },
  198. },
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .inputs {
  203. width: 200px;
  204. }
  205. </style>