dialog.editItem.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="rule-type">
  3. <el-dialog
  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="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)">新增履职内容</el-button>
  33. </div>
  34. <el-table :data="formData.pointDtoList" border style="width: 100%">
  35. <el-table-column prop="name" label="履职内容"> </el-table-column>
  36. <el-table-column prop="areaName" label="履职区域">
  37. </el-table-column>
  38. <el-table-column label="操作" width="140">
  39. <template slot-scope="scope">
  40. <el-button
  41. type="text"
  42. size="small"
  43. @click="onEdit(scope.$index, scope.row)"
  44. >编辑</el-button
  45. >
  46. <el-button
  47. type="text"
  48. size="small"
  49. @click="delitem(scope.$index)"
  50. >删除</el-button
  51. >
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. </div>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button @click="dialogVisible = false">取 消</el-button>
  59. <el-button type="primary" @click="onSubmit()">保 存</el-button>
  60. </span>
  61. </el-dialog>
  62. <EditPoint
  63. ref="editDialog"
  64. @submit="onPointSubmit"
  65. :rule="rule"
  66. v-bind="$attrs"
  67. ></EditPoint>
  68. </div>
  69. </template>
  70. <script>
  71. import { mapState, mapMutations } from "vuex";
  72. import EditPoint from "./dialog.editPoint.vue";
  73. import { get, update } from "@/api/resumption/ruleManager.js";
  74. export default {
  75. data() {
  76. return {
  77. dialogVisible: false,
  78. formData: this.reset(),
  79. formDataRules: {
  80. name: [{ required: true, message: "请输入履职项" }],
  81. },
  82. };
  83. },
  84. props: {
  85. rule: {
  86. type: Object,
  87. },
  88. },
  89. watch: {},
  90. computed: {
  91. ...mapState([]),
  92. },
  93. methods: {
  94. ...mapMutations([]),
  95. reset() {
  96. return {
  97. id: null,
  98. name: null,
  99. ruleId: null,
  100. pointDtoList: [],
  101. };
  102. },
  103. async show(id) {
  104. const data = id ? (await get(id)).data : this.reset();
  105. this.formData = data;
  106. this.dialogVisible = true;
  107. },
  108. // 事件
  109. onHide() {
  110. this.formData = this.reset();
  111. },
  112. async onSubmit() {
  113. this.formData.ruleId = this.rule.id;
  114. await update(this.formData).then((v) => {
  115. console.log(v);
  116. this.formData = this.reset();
  117. this.dialogVisible = false;
  118. this.$emit("success");
  119. });
  120. },
  121. onclose() {
  122. this.dataVisible = false;
  123. },
  124. onEdit(index, row) {
  125. this.$refs.editDialog.show(index, { ...row });
  126. },
  127. onPointSubmit(index, point) {
  128. if (index >= 0) {
  129. this.$set(this.formData.pointDtoList, index, point);
  130. } else {
  131. this.formData.pointDtoList.push(point);
  132. }
  133. },
  134. delitem(val) {
  135. this.formData.pointDtoList.splice(val, 1);
  136. },
  137. },
  138. mounted() {},
  139. components: { EditPoint },
  140. };
  141. </script>
  142. <style lang="scss">
  143. .brand_info {
  144. .el-form {
  145. width: 600px;
  146. padding-top: 40px;
  147. }
  148. }
  149. </style>