GridSelectDialog.vue 2.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
<!-- 带分页请求的选择弹框 -->
<template>
  <el-dialog
    :title="promptData.title"
    :visible.sync="show"
    custom-class="grid-ety"
    :highlight-current-row="true"
    width="60%"
    :before-close="beforeClose"
  >
    <el-table
      :data="tableData"
      border
      @row-dblclick="selectEty"
    >
      <el-table-column
        v-for="(item, idx) in promptData.columns"
        :key="idx"
        :property="item.prop"
        :label="item.label"
        :width="item.width"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      layout="prev, pager, next, total, jumper"
      :total="pagination.total"
      :page-sizes="pagination.pageSizes"
      :page-size="pagination.pageSize"
      :current-page="pagination.currentPage"
      @current-change="currentChange"
      @size-change="handleSizeChange"
    >
    </el-pagination>
  </el-dialog>
</template>

<script>
import Api from "~/service/Api";
import commonApi from '~/mixin/commonApi';
export default {
  mixins: [commonApi],
  props: {
    promptData: {
      type: Object,
      required: true,
      default: () => {
        return {
          title: '',
          columns: [],
          apiUrl: '',
          apiArgs: {}
        }
      }
    }
  },
  data() {
    return {
      show: false,
      cod: '',
      tableData: [],
      pagination: {
        currentPage: 1,
        pageSizes: [10, 20, 50, 100, 500],
        pageSize: 10,
        total: 0,
      },
    };
  },
  methods: {
    async handleSearch() {
      let params = {
        ...this.promptData.apiArgs,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
      };
      const loading = this.loading();
      let res = await Api.post(this.promptData.apiUrl, params);
      if (res.respCode == SUCCESS) {
        this.tableData = res.data && res.data.atpList.list;
        this.pagination.total = Number((res.data && res.data.atpList.total) || 0);
      }
      loading.close();
    },
    currentChange(val) {
      this.pagination.currentPage = val;
      this.handleSearch()
    },
    handleSizeChange(val) {
      this.pagination.currentPage = 1;
      this.pagination.pageSize = val;
      this.handleSearch();
    },
    selectEty(row) {
      this.$emit("selectEty", {
        ...row,
        role: this.promptData.type
      });
      this.show = false;
      this.currentPage = 1;
    },
    beforeClose(done) {
      this.show = false;
      this.currentPage = 1;
      done();
    },
  },
};
</script>

<style>
.grid-ety .el-table .cell {
  white-space: pre-wrap;
}
</style>