ReportForm.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <!-- 添加或修改巡检报告对话框 -->
  3. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  4. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  5. <el-form-item label="任务代码" prop="taskCode">
  6. <el-input v-model="form.taskCode" placeholder="请输入任务代码" />
  7. </el-form-item>
  8. <el-form-item label="结果状态" prop="resultStatus">
  9. <el-radio-group v-model="form.resultStatus">
  10. <el-radio
  11. v-for="dict in dict.type.inspection_result"
  12. :key="dict.value"
  13. :label="parseInt(dict.value)"
  14. >{{ dict.label }}
  15. </el-radio>
  16. </el-radio-group>
  17. </el-form-item>
  18. <el-form-item label="结果描述">
  19. <editor v-model="form.resultMsg" :min-height="192" />
  20. </el-form-item>
  21. <el-form-item label="完成时间" prop="finishTime">
  22. <el-date-picker clearable
  23. v-model="form.finishTime"
  24. type="datetime"
  25. format="yyyy-MM-dd HH:mm"
  26. value-format="yyyy-MM-dd HH:mm:00"
  27. :style="{width: '100%'}"
  28. placeholder="请选择开始时间">
  29. </el-date-picker>
  30. </el-form-item>
  31. </el-form>
  32. <div slot="footer" class="dialog-footer">
  33. <el-button type="primary" @click="submitForm">确 定</el-button>
  34. <el-button @click="cancel">取 消</el-button>
  35. </div>
  36. </el-dialog>
  37. </template>
  38. <script>
  39. import { addInspectionReport, getInspectionReport, updateInspectionReport } from '@/api/task/inspectionReport';
  40. import { Base64 } from 'js-base64';
  41. export default {
  42. name: 'ReportForm',
  43. dicts: ['inspection_result'],
  44. props: {
  45. taskInfo: {
  46. type: Object,
  47. default: null,
  48. },
  49. title: {
  50. type: String,
  51. default: '添加巡检报告',
  52. },
  53. reportId: {
  54. type: Number,
  55. default: null,
  56. },
  57. isAdd: {
  58. type: Boolean,
  59. default: true,
  60. },
  61. okCallback: {
  62. type: Function,
  63. default: () => {},
  64. },
  65. },
  66. watch: {
  67. taskInfo(val) {
  68. this.form.taskCode = val?.taskCode;
  69. },
  70. },
  71. data() {
  72. return {
  73. // 选中数组
  74. ids: [],
  75. // 是否显示弹出层
  76. open: false,
  77. // 表单参数
  78. form: {
  79. taskCode: this.taskInfo?.taskCode,
  80. },
  81. // 表单校验
  82. rules: {
  83. taskCode: [
  84. {
  85. required: true,
  86. message: '任务代码不能为空',
  87. trigger: 'blur',
  88. },
  89. ],
  90. resultStatus: [
  91. {
  92. required: true,
  93. message: '结果状态不能为空',
  94. trigger: 'change',
  95. },
  96. ],
  97. },
  98. };
  99. },
  100. created() {
  101. },
  102. methods: {
  103. // 取消按钮
  104. cancel() {
  105. this.open = false;
  106. this.reset();
  107. },
  108. // 表单重置
  109. reset() {
  110. this.form = {
  111. id: null,
  112. taskCode: null,
  113. resultStatus: null,
  114. resultMsg: null,
  115. finishTime: null,
  116. };
  117. this.resetForm('form');
  118. },
  119. /** 修改按钮操作 */
  120. handleUpdate() {
  121. this.reset();
  122. const id = this.reportId;
  123. getInspectionReport(id).then(response => {
  124. this.form = response.data;
  125. this.open = true;
  126. this.title = '修改巡检报告';
  127. });
  128. },
  129. /** 提交按钮 */
  130. submitForm() {
  131. this.$refs['form'].validate(valid => {
  132. if (valid) {
  133. if (this.form.resultMsg) {
  134. this.form.resultMsg = Base64.encode(this.form.resultMsg);
  135. }
  136. if (this.form.id != null) {
  137. updateInspectionReport(this.form).then(response => {
  138. this.$modal.msgSuccess('修改成功');
  139. this.open = false;
  140. this.okCallback();
  141. });
  142. } else {
  143. addInspectionReport(this.form).then(response => {
  144. this.$modal.msgSuccess('新增成功');
  145. this.open = false;
  146. this.okCallback();
  147. });
  148. }
  149. }
  150. });
  151. },
  152. show() {
  153. this.open = true;
  154. if (!this.isAdd) {
  155. this.handleUpdate();
  156. }
  157. },
  158. },
  159. };
  160. </script>