dialog.editItem.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="rule-type">
  3. <DialogCom
  4. :title="!formData.id ? '新增检查项' : '编辑检查项'"
  5. :visible.sync="dialogVisible"
  6. width="50%"
  7. :show-close="true"
  8. @close="onHide"
  9. >
  10. <div>
  11. <div class="box">
  12. <el-form
  13. ref="form"
  14. :model="formData"
  15. :rules="formDataRules"
  16. label-width="110px"
  17. >
  18. <el-form-item prop="name" label="检查项">
  19. <el-input
  20. v-model.trim="formData.name"
  21. :maxlength="50"
  22. name="name"
  23. placeholder="请输入检查项"
  24. clearable
  25. />
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. <div class="box">
  30. <p>检查内容</p>
  31. <div style="margin-bottom: 10px">
  32. <el-button type="primary" @click="onEdit(-1)"
  33. >新增检查内容</el-button
  34. >
  35. </div>
  36. <el-table :data="formData.pointDtoList" border style="width: 100%">
  37. <el-table-column prop="name" label="检查内容">
  38. <template slot-scope="scope">
  39. <pre>{{ scope.row.name }}</pre>
  40. </template>
  41. </el-table-column>
  42. <el-table-column prop="areaName" label="检查区域">
  43. </el-table-column>
  44. <el-table-column label="操作" width="140">
  45. <template slot-scope="scope">
  46. <el-button
  47. type="text"
  48. size="small"
  49. @click="onEdit(scope.$index, scope.row)"
  50. >编辑</el-button
  51. >
  52. <el-popconfirm title="是否删除检查内容" @confirm="delitem(scope.$index)" style="margin-left: 20px;">
  53. <el-button slot="reference" type="text" size="small">删除</el-button>
  54. </el-popconfirm>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. </div>
  59. </div>
  60. <div slot="footer" class="dialog-footer">
  61. <el-button @click="dialogVisible = false">取 消</el-button>
  62. <el-button type="primary" @click="onSubmit()">保 存</el-button>
  63. </div>
  64. </DialogCom>
  65. <EditPoint
  66. ref="editDialog"
  67. @submit="onPointSubmit"
  68. :rule="rule"
  69. v-bind="$attrs"
  70. ></EditPoint>
  71. </div>
  72. </template>
  73. <script>
  74. import { mapState, mapMutations } from "vuex";
  75. import EditPoint from "./dialog.editPoint.vue";
  76. import { get, update } from "@/api/safetycheck/ruleManager.js";
  77. import MessageEx from "@/components/message/messageex.js";
  78. export default {
  79. data() {
  80. return {
  81. dialogVisible: false,
  82. formData: this.reset(),
  83. formDataRules: {
  84. name: [{ required: true, message: "请输入检查项" }],
  85. },
  86. };
  87. },
  88. props: {
  89. rule: {
  90. type: Object,
  91. },
  92. },
  93. watch: {},
  94. computed: {
  95. ...mapState([]),
  96. },
  97. methods: {
  98. ...mapMutations([]),
  99. reset() {
  100. return {
  101. id: null,
  102. name: null,
  103. ruleId: null,
  104. pointDtoList: [],
  105. };
  106. },
  107. async show(id) {
  108. const data = id ? (await get(id)).data : this.reset();
  109. this.formData = data;
  110. this.dialogVisible = true;
  111. },
  112. // 事件
  113. onHide() {
  114. this.formData = this.reset();
  115. },
  116. async onSubmit() {
  117. this.formData.ruleId = this.rule.id;
  118. this.$refs.form.validate((isValidate) => {
  119. if (!isValidate) {
  120. return;
  121. }
  122. if(!this.formData.pointDtoList || this.formData.pointDtoList.length==0){
  123. MessageEx.info("检查内容不能为空!");
  124. return;
  125. }
  126. update(this.formData).then((v) => {
  127. this.formData = this.reset();
  128. this.dialogVisible = false;
  129. this.$emit("success");
  130. });
  131. });
  132. },
  133. onclose() {
  134. this.dataVisible = false;
  135. },
  136. onEdit(index, row) {
  137. this.$refs.editDialog.show(index, { ...row });
  138. },
  139. onPointSubmit(index, point) {
  140. if (index >= 0) {
  141. this.$set(this.formData.pointDtoList, index, point);
  142. } else {
  143. this.formData.pointDtoList.push(point);
  144. }
  145. },
  146. delitem(val) {
  147. this.formData.pointDtoList.splice(val, 1);
  148. },
  149. },
  150. mounted() {},
  151. components: { EditPoint },
  152. };
  153. </script>
  154. <style lang="scss">
  155. .box {
  156. margin-bottom: 20px;
  157. }
  158. </style>