dialog.editItem.vue 4.7 KB

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