EditTable.vue 10.6 KB
Newer Older
fukai committed
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
<template>
	<div class="clearfix">
		<c-col :span="24" style="margin-bottom: 18px">
			<c-table :border="border" :highlight-current-row="highlight" :list="model" :paginationShow="paginationShow" :row-class-name="tableRowClassName" @row-click="handleClick" style="text-align: center">
				<el-table-column type="index" v-if="isIndex" width="50">
				</el-table-column>
				<template v-for="item in columns">
					<el-table-column :key="item.dataIndex" :label="item.title" :min-width="item.width">
						<template slot-scope="scope">
							<c-select
							  :isFixed="true"
								v-if="item.show === 'select'"
								:disabled="disabledAll"
								@change="handleChangeRole(scope.row, scope.$index, item.dataIndex)"
								v-model="scope.row[item.dataIndex]"
							>
								<el-option
									v-for="item in roleList"
									:key="item.value"
									:value="item.value"
									:label="item.label"
								></el-option>
							</c-select>
							<div style="display: flex;justify-content: flex-start;" v-else-if="item.show === 'input'">
								<c-input :disabled="disabledAll" :placeholder="`请输入${item.title}`" @keyup.enter.native="showPtapDialog(scope.row, scope.$index, item.dataIndex)" v-model="scope.row[item.dataIndex]"></c-input>
								<c-button @click="showPtapDialog(scope.row, scope.$index, item.dataIndex)" icon="el-icon-info" size="small" style="margin:0 0" type="primary"></c-button>
							</div>
							<c-checkbox :disabled="disabledAll" :placeholder="`请输入${item.title}`" checked v-else-if="item.show === 'checkbox'" v-model="scope.row[item.dataIndex]"></c-checkbox>
							<span v-else>{{ scope.row[item.dataIndex] }}</span>
						</template>
					</el-table-column>
				</template>
				<el-table-column :offset="1" :span="1" fixed="right" label="" prop="det" v-if="isShowOperation" width="150px">
					<template slot="header" slot-scope="scope">
						<c-button @click="handleAdd(scope)" circle class="el-icon-plus" size="mini" style="padding: 4px">
						</c-button>
						<c-button @click="handleDelete(scope)" circle class="el-icon-minus" size="mini" style="padding: 4px">
						</c-button>
					</template>
					<!-- 可以用自定义方式添加操作 -->
					<slot>
						<!-- 详情 -->
						<template slot-scope="scope">
							<el-button @click="handleDetails(scope.row)" icon="el-icon-info" size="mini" type="primary"></el-button>
						</template>
					</slot>
				</el-table-column>
			</c-table>
		</c-col>
		<!-- 弹窗 -->
		<el-dialog v-dialogDrag :title="dialogTitle" :visible.sync="dialogTableVisible" v-if="dialogTableVisible" width="80%">
			<div v-if="!loading && tableList.length === 0">暂无数据</div>
			<div style="width: 100%;height: 100%;" v-else>
				<el-table :before-close="beforeClose" :data="tableList" @row-dblclick="dbClickRow" height="calc(100% - 32px)" id='tableRef' style="width: 100%;" v-loading="loading">
					<el-table-column :key="key" :label="item.label" :prop="item.prop" :render-header="renderheader" v-for="(item,key) in tableColumn">
					</el-table-column>
				</el-table>
				<el-pagination :current-page="currentPage" :page-size="pageSize" :total="total" @current-change="currentChange" layout="prev, pager, next, jumper">
				</el-pagination>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import Table from "./Table.vue";
import { columnMap } from "./Ptap/ptapColumn.js";
import { getPtaTableDtat, getPtsptaByInr } from "~/service/business/common";
import Utils from "~/utils";

export default {
  components: { "c-table": Table },
  inject: ["root"],
  data() {
    return {
      rowIndex: null,
      dialogTitle: "", // 弹框标题
      dialogTableVisible: false, // 控制弹框的展示和隐藏
      loading: true,
      total: 0,
      currentPage: 1,
      pageSizes: [5, 10, 20, 30, 40, 50, 100],
      pageSize: 5,
      columns: [
        {
          title: "角色",
          width: "120px",
          dataIndex: "rol",
          show: "select"
        },
        {
          title: "当事人",
          width: "210px",
          dataIndex: "extkey",
          show: "input"
        },
        {
          title: "当事人名称",
          width: "250px",
          dataIndex: "nam"
        },
        {
          title: "地址编号",
          width: "250px",
          dataIndex: "ref"
        }
      ],
      tableList: [],
      inputValue: "",
      tableColumn: [],
      currentRowIndex: 0,
      currentRowData: {}
    };
  },
  props: {
    value: {
      type: Array,
      default: () => []
    },
    roleList: {
      type: Array,
      default: () => []
    },
    paginationShow: {
      type: Boolean,
      default: false
    },
    disabledAll: {
      //是否全部灰显
      type: Boolean,
      default: false
    },

    border: {
      //是否有边框
      type: Boolean,
      default: true
    },
    highlight: {
      type: Boolean,
      default: true
    },
    isIndex: {
      type: Boolean,
      default: false
    },
    // 是否显示操作列
    isShowOperation: {
      type: Boolean,
      default: true
    },
    // ptytyp: {
    //   //决定弹框的表头
    //   type: String,
    //   default: "C"
    // },
    bchinr: {
      type: String,
      default: "00000047"
    },
    keyCode: {
      type: String,
      default: "gidgrp"
    }
  },
  computed: {
    model: {
      get() {
        return this.value;
      },
      set(newVal) {
        console.log(newVal);
        this.$emit("input", newVal);
      }
    }
  },
  methods: {
    // 改变角色
    handleChangeRole(row, index, key) {
      if (key === "rol") {
        this.currentRowIndex = index;
        this.currentRowData = row;
        // 回填角色数据
        this.setRoleData();
      }
    },
    // 回填角色中的pts
    setRoleData() {
      if (this.currentRowData.rol && this.root) {
        let rol = this.currentRowData.rol.toLowerCase();
        let rootRolData = this.root.model[this.keyCode][rol];
        if (rootRolData) {
          if (Utils.typeOf(rootRolData.pts) === "Object") {
            this.root.model[this.keyCode][rol].pts = {
              ...rootRolData.pts,
              ...this.model[this.currentRowIndex]
            };
          }
        } else {
          this.$set(this.root.model[this.keyCode], rol, {
            pts: {
              ...this.model[this.currentRowIndex]
            }
          });
        }
      }
    },
    showPtapDialog(row, index, key) {
			// const selectPtytyp=row.rol
    	// if( selectPtytyp==="DRW"|| selectPtytyp==="BE2" || selectPtytyp==="OAP" ){
			// 	this.ptytyp="C"
		  // }else{
			// 	this.ptytyp="B"
			// }
      this.roleList.forEach(item=>{
        if(item.value===row.rol){
					this.ptytyp=item.ptytyp
				}
			})
      this.currentRowIndex = index;
      this.currentRowData = row;
      const value = this.model[index][key];
      // 设置弹框标题
      this.dialogTitle = `当事人详情`;
      this.dialogTableVisible = true;
      this.tableColumn = columnMap["C"];
      // 分层取值
      this.getTableData(value,this.ptytyp);
    },
    // 表头 头部换行,以 / 作为换行标志
    renderheader(h, { column, $index }) {
      return h("span", {}, [
        h("span", {}, column.label.split("/")[0]),
        h("br"),
        h("span", {}, column.label.split("/")[1])
      ]);
    },
    // 获取弹框内的table数据
    getTableData(value) {
      this.loading = true;
      this.tableList = [];
      this.currentPage = 1;
      this.pageSize = 10;
      this.total = 0;
      // 获取table的表格数据
      let params = {
        ptytyp: this.ptytyp,
        extkey: value || "",
        bchinr: this.bchinr,
        pageNum: this.currentPage,
        pageSize: this.pageSize
      };
      getPtaTableDtat(params, this.moduleRouter()).then(res => {
        if (res.respCode === SUCCESS) {
          if (res.data && res.data.list) {
            this.total = res.data.total;
            this.tableList = res.data.list.map(it => ({
              ...it,
              // 添加新key将Party Number和Address Number换行
              partyNumberAndAdressNumber: `${it.ptaptyextkey}\n${it.ptaobjkey}`,
              bchbranchAndBchbchname: `${it.bchbranch}\n${it.bchbchname}`,
              adrnam1AndPtanam1: `${it.adrnam1}\n${it.ptanam1}`,
              adradr1AndAdrstr1: `${it.adradr1}\n${it.adrstr1}`,
              adrstr2Andadrloccty: `${it.adrstr2}\n${it.adrloccty}`,
              adrloczipAndadrloctxt: `${it.adrloczip}\n${it.adrloctxt}`
            }));
            this.currentPage = res.data.offset;
            this.pageSize = res.data.limit;
          }
        }
        this.loading = false; //接口掉完变成false
      });
    },
    async dbClickRow(row, column, event) {
      let params = {
        inr: row.ptainr
      };
      const response = await getPtsptaByInr(params, this.moduleRouter());
      if (response.respCode === SUCCESS) {
        // 回填数据
        this.model[this.currentRowIndex].extkey = row.ptaobjkey;
        this.model[this.currentRowIndex].ptainr = response.data.ptaobjinr;
        this.model[this.currentRowIndex].ptyinr = response.data.ptyinr;
        this.model[this.currentRowIndex].nam = response.data.nam;
        this.model[this.currentRowIndex].adrblk = response.data.enadr;
        // 回填角色数据
        this.setRoleData();
        // 此处为了回填数据时回调
        this.$emit("handleChange");
      }
      this.dialogTableVisible = false;
    },
    currentChange(num) {
      this.currentPage = num;
      this.getTableData();
    },
    beforeClose(done) {
      this.dialogTableVisible = false;
      this.currentPage = 1;
      done();
    },
    //获取表格数据索引,方便删除
    tableRowClassName({ row, rowIndex }) {
      Object.defineProperty(row, "row_index", {
        value: rowIndex,
        configurable: true,
        writable: true,
        enumerable: false
      });
    },
    // 记录选中行索引
    handleClick(row, column, event) {
      console.log(row);
      this.rowIndex = row.row_index;
      console.log("选择:" + this.rowIndex);
    },

    handleAdd() {
      let temp = {};
      for (let it of this.columns) {
        temp[it.dataIndex] = "";
      }
      this.model.push(temp);
      this.$emit("handleChange");
    },
    handleDelete() {
      if (this.model.length === 0) return;
      if (this.rowIndex === null) {
        this.rowIndex = this.model[this.model.length - 1].row_index; //没有选中删除最后一行
      }
      this.model.splice(this.rowIndex, 1);
      this.rowIndex = null;
      this.$emit("handleChange");
    },
    handleDetails(row) {
      console.log(12, row);
    }
  }
};
</script>
<style lang="less" scoped>
.el-dialog__body {
  height: calc(100% - 55px);
}
</style>