GridEtyPromptDialog.vue 4.43 KB
Newer Older
1
<template>
zhengxiaokui committed
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
  <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>
36 37 38 39
</template>

<script>
export default {
zhengxiaokui committed
40 41 42 43 44
  props: {
    promptData: {
      required: true,
      type: Object,
      default: () => {
45
        return {
zhengxiaokui committed
46 47 48 49 50
          title: "",
          columnStr: "",
          data: [],
          rulePath: "",
          modelUrl: "", //非机构处理需要回填的字段路劲信息,isPty为false时必输
51
          defaultColumn: "",
zhengxiaokui committed
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
        };
      },
    },
    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 = [];
fukai committed
80
      const lines = this.promptData.columnStr.split("\n");
zhengxiaokui committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
      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],
          });
99
        }
zhengxiaokui committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
      }
      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);
      });
118
    },
zhengxiaokui committed
119 120 121 122 123 124 125 126 127 128 129
    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");
130
        }
zhengxiaokui committed
131
        it["IDX"] = i;
zhengxiaokui committed
132 133 134 135 136 137
        //隐藏列,便于取值
        if (typeof this.promptData.shadow === "object") {
          for (let k in this.promptData.shadow) {
            it[k] = items[this.promptData.shadow[k]];
          }
        }
zhengxiaokui committed
138 139 140 141 142 143
        arr.push(it);
      }
      return arr;
    },
    currentChange(currentPage) {
      this.currentPage = currentPage;
144
    },
zhengxiaokui committed
145 146
    selectEty(row, column, event) {
      // 默认第一列
147
      var idx = this.promptData.defaultColumn;
zhengxiaokui committed
148
      if (this.isPty) {
149
        const v = row[this.tableColumn[idx].prop].split("\n")[0];
zhengxiaokui committed
150 151
        this.$emit("select-ety", v, this.promptData.rulePath);
      } else {
zhengxiaokui committed
152
        const { modelUrl, isCover, rulePath } = this.promptData;
zhengxiaokui committed
153 154
        let v = {};
        for (let k in modelUrl) {
zhengxiaokui committed
155
          row[k] && (v[k] = row[k]);
156
        }
zhengxiaokui committed
157
        this.$emit("select-ety", v, modelUrl, isCover, rulePath);
zhengxiaokui committed
158 159 160 161 162 163 164 165 166 167 168
      }
      this.show = false;
      this.currentPage = 1;
    },
    beforeClose(done) {
      this.show = false;
      this.currentPage = 1;
      done();
    },
  },
};
169 170 171
</script>

<style>
zhengxiaokui committed
172 173
.grid-ety .el-table .cell {
  white-space: pre-wrap;
174 175
}
</style>