GridEtyPromptDialog_mark.vue 4.43 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
<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.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      border
      @row-dblclick="selectEty"
    >
      <el-table-column
        v-for="(item, idx) in tableColumn"
        :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="tableData.length"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="currentChange"
    >
    </el-pagination>
  </el-dialog>
</template>

<script>
export default {
  props: {
    promptData: {
      required: true,
      type: Object,
      default: () => {
        return {
          title: "",
          columnStr: "",
          data: [],
          rulePath: "",
          modelUrl: "", //非机构处理需要回填的字段路劲信息,isPty为false时必输
          defaultColumn: "",
        };
      },
    },
    isPty: {
      //默认为机构处理
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      show: false,
      currentPage: 1,
      pageSizes: [5, 10, 20, 30, 40, 50, 100],
      pageSize: 5,
    };
  },
  computed: {
    tableColumn() {
      return this.dealExtKeyTableColumn();
    },
    tableData() {
      return this.dealExtKeyTableData();
    },
  },
  methods: {
    dealExtKeyTableColumn() {
      const columnArr = [];
      const lines = this.promptData.columnStr.split("\n");
      const etyReg = /\"([^\"]*)\"/;
      const obj = {};
      for (let i = 0; i < lines.length; i++) {
        let line = lines[i];
        if (etyReg.test(line)) {
          const gs = line.match(etyReg);
          const columnName = gs[1];
          const newLine = line.replace(gs[0], " _ ");
          const colPropArr = newLine.split(/\s+/);
          const positionArr = colPropArr[1].split(":");
          if (!obj[positionArr[0]]) {
            obj[positionArr[0]] = [];
          }
          obj[positionArr[0]].push({
            idx: colPropArr[0],
            prop: columnName,
            width: colPropArr[3],
          });
        }
      }
      for (const k in obj) {
        if (Object.hasOwnProperty.call(obj, k)) {
          const o = obj[k];
          const tableColumn = o.map((item) => item.prop).join("\n");
          columnArr.push({
            prop: tableColumn,
            label: tableColumn,
            // width: o[0].width,
            width: "auto",
            index: k,
            children: o,
          });
        }
      }
      return columnArr.sort((a, b) => {
        return parseInt(a.index) - parseInt(b.index);
      });
    },
    dealExtKeyTableData() {
      const arr = [];
      for (let i = 0; i < this.promptData.data.length; i++) {
        const d = this.promptData.data[i];
        const items = d.split("\t");
        const it = {};
        for (let j = 0; j < this.tableColumn.length; j++) {
          const column = this.tableColumn[j];
          it[column["prop"]] = column.children
            .map((c) => items[c["idx"]] || " ")
            .join("\n");
        }
        it["IDX"] = i;
        //隐藏列,便于取值
        if (typeof this.promptData.shadow === "object") {
          for (let k in this.promptData.shadow) {
            it[k] = items[this.promptData.shadow[k]];
          }
        }
        arr.push(it);
      }
      return arr;
    },
    currentChange(currentPage) {
      this.currentPage = currentPage;
    },
    selectEty(row, column, event) {
      // 默认第一列
      var idx = this.promptData.defaultColumn;
      if (this.isPty) {
        const v = row[this.tableColumn[idx].prop].split("\n")[0];
        this.$emit("select-ety", v, this.promptData.rulePath);
      } else {
        const { modelUrl, isCover, rulePath } = this.promptData;
        let v = {};
        for (let k in modelUrl) {
          row[k] && (v[k] = row[k]);
        }
        this.$emit("select-ety", v, modelUrl, isCover, rulePath);
      }
      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>