SelectDutyDialog.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <el-dialog :modal="true" :close-on-click-modal="false" :close-on-press-escape="false" title="选择数据目录"
  3. :append-to-body="true" :visible.sync="visible" width="50%" :before-close="handleClose">
  4. <el-form :inline="true" label-width="auto" :model="searchForm" class="form-detail-inline-two">
  5. <el-form-item label="数据目录名称">
  6. <el-input placeholder="请输入数据目录名称" v-model="searchForm.searchName" />
  7. </el-form-item>
  8. <el-form-item class="no-label">
  9. <el-button type="primary" @click="handleSearch">查询</el-button>
  10. <el-button @click="reset">重置</el-button>
  11. </el-form-item>
  12. </el-form>
  13. <el-table ref="tableRef" :data="tableData" max-height="500" @select="selectionChange" row-key="id"
  14. class="table-new--dialog">
  15. <el-table-column type="selection" width="50" align="center" />
  16. <el-table-column prop="belongDepartmentName" label="内设机构名称" align="center" />
  17. <el-table-column prop="agenciesPrsponsibility" label="内设机构职责" align="center" />
  18. </el-table>
  19. <div slot="footer" class="dialog-footer">
  20. <el-button type="primary" @click="saveHandle">确定</el-button>
  21. <el-button @click="handleClose">取消</el-button>
  22. </div>
  23. </el-dialog>
  24. </template>
  25. <script>
  26. import { mapState, mapActions } from 'vuex';
  27. import { getResponsibilityList, } from '@/api/unified-resources/job-directory/index.js'
  28. export default {
  29. props: {
  30. value: {
  31. type: Boolean,
  32. default: false,
  33. },
  34. operationType: {
  35. type: String,
  36. default: ''
  37. },
  38. // selectDutyId: {
  39. // type: String,
  40. // default: ''
  41. // }
  42. },
  43. data() {
  44. return {
  45. visible: this.value,
  46. searchForm: { searchName: '' },
  47. selectArr: [],
  48. tableData: [],
  49. selectObj: {},
  50. currentPage: 1,
  51. pageSize: 10,
  52. tableRef: null
  53. };
  54. },
  55. computed: {
  56. ...mapState('projectManage', ['selectDutyId']), // 映射 Vuex 状态
  57. },
  58. watch: {
  59. value(newVal) {
  60. this.visible = newVal;
  61. },
  62. visible(newVal) {
  63. this.$emit("input", newVal);
  64. },
  65. selectDutyId(newVal) {
  66. if (newVal) {
  67. this.tableData.forEach(element => {
  68. if (element.id === newVal) {
  69. this.$nextTick(() => {
  70. this.$refs.tableRef.toggleRowSelection(element, true); // 自动选择行
  71. });
  72. }
  73. });
  74. }
  75. }
  76. },
  77. mounted() {
  78. this.getList(); // 获取数据
  79. },
  80. methods: {
  81. // ...mapActions('projectManage', ['setsSelectDutyId']), // 映射 Vuex actions
  82. getList() {
  83. getResponsibilityList({
  84. pageNumber: this.currentPage,
  85. pageSize: this.pageSize,
  86. agenciesName: this.searchForm.searchName
  87. }).then(res => {
  88. if (+res.code === 200) {
  89. this.tableData = res.data;
  90. if (this.selectDutyId) {
  91. this.tableData.forEach(element => {
  92. if (element.id === this.selectDutyId) {
  93. this.$nextTick(() => {
  94. this.$refs.tableRef.toggleRowSelection(element, true);
  95. });
  96. }
  97. });
  98. }
  99. }
  100. });
  101. },
  102. handleSearch() {
  103. this.currentPage = 1;
  104. this.pageSize = 10;
  105. this.getList();
  106. },
  107. reset() {
  108. this.searchForm.searchName = '';
  109. this.currentPage = 1;
  110. this.pageSize = 10;
  111. this.getList();
  112. },
  113. selectionChange(selection, row) {
  114. this.$refs.tableRef.clearSelection();
  115. if (this.selectArr.length === 0) {
  116. this.$refs.tableRef.toggleRowSelection(row, true);
  117. } else {
  118. if (this.selectArr[0].id === row.id) {
  119. this.$refs.tableRef.toggleRowSelection(row, false);
  120. } else {
  121. this.$refs.tableRef.toggleRowSelection(row, true);
  122. }
  123. }
  124. this.selectArr = this.$refs.tableRef.selection;
  125. this.selectObj = row;
  126. },
  127. saveHandle() {
  128. debugger
  129. this.$store.dispatch('projectManage/setsSelectDutyId', this.selectObj.id)
  130. // this.setsSelectDutyId(this.selectObj.id); // 更新 Vuex 状态
  131. this.$emit('saveHandle', this.selectObj); // 向父组件发送选择的对象
  132. this.handleClose();
  133. },
  134. handleClose() {
  135. this.visible = false;
  136. this.$emit("cancel");
  137. }
  138. }
  139. };
  140. </script>
  141. <style scoped lang="scss">
  142. .op-btn {
  143. margin-top: 30px;
  144. text-align: center;
  145. }
  146. .el-row {
  147. margin-top: 10px;
  148. }
  149. .el-select {
  150. width: 100%;
  151. }
  152. .el-divider--horizontal {
  153. margin: 13px 0;
  154. }
  155. .custom-tree-node {
  156. width: 200px;
  157. }
  158. </style>