dialog.editItem.vue 3.9 KB

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