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

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