123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946 |
- <template>
- <div class="data-table" :style="{ marginTop: marginTop,width: tableWidth ? tableWidth : '100%',height:tableHeight ? tableHeight : '100%',padding:isAuto ? '':'24px' }">
- <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" class="data-table-content">
- <div class="flex">
- <div class="manageTitle">{{ pageTitle }}</div>
- <div>
- <auth-button :auth="btnAddObj" />
- <auth-button :auth="btnQueryObj" />
- </div>
- </div>
- <template v-if="tableData.length || tableCols.length">
- <div style="height: calc(100% - 40px);">
- <el-table v-el-table-infinite-scroll="load" :data="filteredTableData" :summary-method="getSummaries" :span-method="tableSpanMethod" stripe :show-summary="showSummary" border @cell-click="cellClick" :cell-class-name="cellClass" ref="table" :height="tableHeight ? tableHeight : minHeight - 8 + 'vh'" class="table infinite-list" style=" overflow: auto" :style="{width: tableWidth ? tableWidth : '100%'}" @select="selectHandler">
- <el-table-column v-for="(item, index) in tableColsCopy" :sortable="item.needSort ? true : false" :key="index" :prop="item.columnName" :label="item.columnLabel" :show-overflow-tooltip="showOverflowTooltip" :formatter="formatter">
- <template #header>
- <span class="colTips">
- <el-tooltip :content="item.columnDescribe" placement="top">
- <span>{{ item.columnLabel }}</span>
- </el-tooltip>
- </span>
- <span v-if="item.needFilters">
- <el-popover placement="bottom" trigger="click" @show="popoverShowHandler(item.columnName)" @hide="popoverHideHandler">
- <i slot="reference" :class="[
- 'filter-arrow',
- 'el-icon-arrow-down',
- arrowClass(item.columnName),
- ]" />
- <el-form>
- <el-form-item :label="item.columnLabel">
- <el-select v-model="filterValues[item.columnName]" size="small" placeholder="筛选" default-first-option filterable clearable>
- <el-option v-for="(option, optionIndex) in tableDataFilters[
- item.columnName
- ]" :key="option.value + optionIndex" :value="option.value" :label="option.text" />
- </el-select>
- </el-form-item>
- </el-form>
- </el-popover>
- </span>
- </template>
- </el-table-column>
- <el-table-column v-if="authBtns.length" fixed="right" label="操作" :width="fixedWidth">
- <template slot-scope="scope">
- <div class="hd-td">
- <auth-button v-for="(item,index) in authBtns" :key="index" :auth="item" :row="scope.row" />
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </template>
- <template v-else>
- <NoData image-width="auto" image-height="100%" />
- </template>
- </div>
- <div class="data-table-dialog">
- <!--新增/编辑-->
- <Dialog :width="width" :isBody="isBody" :flag="flag">
- <div class="dialog-content">
- <div class="title">{{ tableTitle }}</div>
- <div style="max-height:580px;overflow-y: scroll;" class="contents">
- <el-form ref="ruleForm" :model="tableForm" :label-width="labelWidth">
- <el-row :gutter="20">
- <el-col v-for="(item, index) in tableColsCopy" :key="index" :span="rows">
- <el-form-item :label="item.columnLabel">
- <template v-if="
- item.listqueryTemplateID ||
- item.listqueryTemplateID == 0
- ">
- <el-select class="input-shadow" size="small" filterable default-first-option style="width: 100%" v-model="tableForm[item.columnName]" @change="changeSelect(item.columnName, item)" placeholder="请选择" clearable @clear="tableForm[item.columnName] = ''">
- <el-option v-for="item in tableOptions[item.columnName]" :key="item.v ? item.v : item.planDepartureApt" :label="item.k ? item.k : item.planDepartureApt" :value="
- item.setlabel === 'positionDescribe'
- ? item.v
- : item.v != undefined
- ? item.v
- : item.planDepartureApt
- ">
- </el-option>
- </el-select>
- </template>
- <template v-else-if="fromDataType(item.dataType) == 'text'">
- <el-input size="small" :rows="1" type="textarea" @change="inputChangeHandler(item.columnName)" v-model="tableForm[item.columnName]"></el-input>
- </template>
- <template v-else-if="fromDataType(item.dataType) == 'date'">
- <el-date-picker class="datetimes" value-format="yyyy-MM-dd" v-model="tableForm[item.columnName]" type="date" placeholder="选择日期" @change="inputChangeHandler(item.columnName)">
- </el-date-picker>
- </template>
- <template v-else-if="fromDataType(item.dataType) == 'datetime'">
- <el-date-picker class="datetimes" value-format="yyyy-MM-dd HH:mm:ss" v-model="tableForm[item.columnName]" type="datetime" placeholder="选择日期时间" @change="inputChangeHandler(item.columnName)">
- </el-date-picker>
- </template>
- <template v-else-if="fromDataType(item.dataType) == 'int' || fromDataType(item.dataType) == 'tinyint'">
- <el-input size="small" v-model.number="tableForm[item.columnName]" onkeyup="value=value.replace(/[^1-9]/g,'')" @change="inputChangeHandler(item.columnName)"></el-input>
- </template>
- <template v-else>
- <el-input size="small" v-model="tableForm[item.columnName]" @change="inputChangeHandler(item.columnName)"></el-input>
- </template>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- </div>
- <div class="foot right">
- <el-button size="medium" @click="handleOk" class="r24" type="primary">确定</el-button>
- <el-button @click="eledite" size="medium">取消</el-button>
- </div>
- </div>
- </Dialog>
- <!--删除-->
- <Dialog :isBody="isBody" :flag="rmFlag">
- <div class="airportInfoDialog">
- <div class="title del-title">删除</div>
- <div class="content del-content">
- <span class="el-icon-error error r10"></span>您是否确认删除<span class="error l10">{{ rmTitle }}</span>
- ?
- </div>
- <div class="foot right Delfoot">
- <el-button size="medium" class="r24" @click="tableRemove" type="danger">删除</el-button>
- <el-button size="medium" @click="rmFlag = false">取消</el-button>
- </div>
- </div>
- </Dialog>
- <!--高级查询-->
- <Dialog :flag="dialogFlag" width="852px">
- <AdvanceQuery :tableColMunt="tableCols" @getColData="getColData" @dialogHide="dialogHide" />
- </Dialog>
- </div>
- </div>
- </template>
- <script>
- import { setTableFilters } from "@/utils/table";
- import Dialog from "@/layout/components/Dialog/index.vue";
- import NoData from "@/components/nodata";
- import AdvanceQuery from './components/advanceQuery.vue';
- import AuthButton from './components/authButton.vue';
- import { translateDataToTreeAllTreeMsg, getAuthData } from "@/utils/validate";
- import { Query, newData, modifyData, moveData, abnormalDataRecovery } from "@/api/webApi";
- import { getToken } from '@/utils/auth';
- export default {
- name: "DataTable",
- props: {
- dataContent: {
- type: Object,
- default: () => ({}),
- },
- //弹框宽度
- width: {
- type: String,
- default: "630px",
- },
- //弹框是否显示在body上
- isBody: {
- type: Boolean,
- default: false,
- },
- //弹框表单-行数
- rows: {
- type: Number,
- default: 24,
- },
- //弹框-表单文字宽度
- labelWidth: {
- type: String,
- default: "120px",
- },
- minHeight: {
- type: Number,
- default: 89,
- },
- // 是否显示合计行
- showSummary: {
- type: Boolean,
- default: false,
- },
- marginTop: {
- type: String,
- default: "0px",
- },
- // 不换行,溢出隐藏
- showOverflowTooltip: {
- type: Boolean,
- default: true,
- },
- //操作列宽度
- fixedWidth: {
- type: String,
- default: "180px",
- },
- },
- components: { Dialog, NoData, AdvanceQuery, AuthButton },
- data () {
- return {
- pageTitle: '',
- asShow: true,
- loading: false,
- flag: false,
- serviceId: null,
- rmFlag: false,
- rowTitle: "",
- page: 0,
- pageSize: 20,
- noMore: false,
- tableCols: [], //表头数据
- tableData: [], //表格数据
- tableColsCopy: [], //表头数据缓存
- tableDataFilters: {}, //表头-下拉数据
- filterValues: {}, //表头-下拉-选中数据
- tableDataCopy: [], //缓存table数据
- tableGroups: [], //表格分组数据
- colShowFilter: "", //表头-下拉-箭头
- spanArr: [], //表格分组数据缓存
- pos: 0, //表格分组计数
- tableTitle: "新增", //弹框标题
- tableType: "add", //弹框类型=新增/编辑
- tableForm: {}, //弹框表单
- rmTitle: "", //弹框-删除-标题
- tableObj: {}, //增/删/改数据缓存
- tableOptions: {}, //弹框-下来数据缓存
- tableArrs: [], //重组table-表头下拉
- proAll: false, //重组时-所有请求是否都完成
- roles: JSON.parse(sessionStorage.getItem("userAuthList")) ?? [],
- tableOptionscp: {},
- tabledatacopy: {},
- queryId: '',
- tableOther: {},
- tableHeight: '',
- tableWidth: '',
- btnQueryObj: {},
- btnAddObj: {},
- btnEditObj: {},
- btnDelObj: {},
- btnRecordObj: {},
- isAuto: false,
- dialogFlag: false,
- authBtns: [],
- authBtnCol: [],
- authBtnColName: [],
- urlParams: {},
- authId: ''
- };
- },
- computed: {
- dataTableContentStyle () {
- const style = {};
- if (this.minHeight) {
- style["min-height"] = this.minHeight;
- }
- if (this.tableHeight) {
- style["height"] = this.tableHeight;
- }
- return style;
- },
- //设置表头-下拉-箭头样式
- arrowClass () {
- return function (prop) {
- let classString = "";
- if (this.colShowFilter === prop) {
- return "arrow-active";
- }
- if (
- Object.entries(this.tableDataFilters).find(
- ([key, arr]) => this.filterValues[prop]
- )
- ) {
- classString += "arrow-blue";
- }
- return classString;
- };
- },
- //设置新增修改表单类型
- fromDataType () {
- return function (type) {
- if (type) {
- return type.replace(/\([^\)]*\)/g, "");
- }
- }
- },
- //设置表头-下拉-选中数据
- filteredTableData () {
- if (this.isTree) {
- this.tableData = translateDataToTreeAllTreeMsg(
- this.tableData,
- "parentID",
- "companyID"
- );
- }
- return this.tableData.filter((item) => {
- let flag = true;
- Object.entries(this.filterValues).forEach(([key, value]) => {
- if (value !== "" && item[key] !== value) {
- flag = false;
- }
- });
- return flag;
- });
- },
- },
- mounted () {
- const { query } = this.$route
- const { title, auth_id } = this.$route.meta
- const { arrs } = getAuthData(auth_id)
- const table = arrs.filter(item => item.auth_type == 4)
- this.urlParams = query
- if (table && table.length) {
- const obj = table[0]
- const { arrs } = getAuthData(obj.auth_id)
- this.isAuto = true
- this.tableOther = obj
- this.pageTitle = obj.auth_name;
- this.authId = obj.auth_id
- this.queryId = obj.queryTemplateID;
- this.authBtns = arrs.filter(item => Number(item.service_type) > 2 && Number(item.service_type) < 6)
- this.authBtnCol = arrs.filter(item => Number(item.service_type) == 6)
- if (this.authBtnCol.length) {
- this.authBtnCol.forEach(item => {
- this.authBtnColName.push(item.relation_data)
- })
- }
- if (arrs && arrs.length) {
- arrs.forEach(item => {
- this.autoBtnObj(item)
- })
- }
- this.getColumnData(obj.auth_id);
- } else {
- this.pageTitle = title;
- if (auth_id) {
- this.queryId = auth_id;
- this.authId = auth_id
- this.getColumnData(auth_id);
- }
- }
- },
- updated () {
- if (Object.keys(this.tableOther).length) {
- this.tableHeight = this.tableOther.table_height
- this.tableWidth = `${this.tableOther.table_width}`.includes('%') ? this.tableOther.table_width + 'px' : this.tableOther.table_width + 'px'
- }
- this.$refs["table"]?.doLayout();
- // this.$refs['table'].style.width = this.tableOther.table_width
- },
- methods: {
- //获取表头数据
- async getColumnData (id) {
- try {
- const { code, returnData } = await Query({
- serviceId: SERVICE_ID.sysUserAuthId,
- dataContent: [
- {
- user_id: getToken('userid'),
- auth_id: id
- }
- ],
- });
- if (code == 0) {
- if (returnData && returnData.length) {
- const titleColumn = returnData.find(
- (item) => item.needShow === 1
- );
- if (titleColumn) {
- this.rowTitle = titleColumn.columnName;
- }
- this.$store.dispatch('auth/changeAuthMsg', returnData)
- this.tableCols = returnData;
- if (Object.keys(this.urlParams).length) {
- this.getQuery(this.queryId, this.urlParams);
- } else {
- this.getQuery(this.queryId);
- }
- }
- } else {
- this.$message.error("获取表头数据失败");
- }
- } catch (error) {
- console.log(error)
- }
- },
- autoBtnObj (item) {
- switch (item.service_type) {
- case '1':
- this.btnQueryObj = item
- break;
- case '2':
- this.btnAddObj = item
- break;
- case '3':
- if (item.open_method != "1") {
- this.btnEditObj = item
- }
- else {
- this.btnRecordObj = item
- }
- break;
- case '4':
- this.btnDelObj = item
- break;
- default:
- break;
- }
- },
- autoBtnClick (id, url) {
- switch (id) {
- case '1':
- this.$message.warning('平铺功能开发中')
- break;
- case '2':
- this.$router.push(url)
- break;
- default:
- break;
- }
- },
- handleQuery () {
- const { open_method, route_info } = this.btnQueryObj
- if (open_method) {
- if (open_method != 3) {
- this.autoBtnClick(open_method, route_info)
- } else {
- this.dialogFlag = true
- }
- }
- },
- eledite () {
- this.flag = false;
- const arrbegin = _.cloneDeep(this.tableOptionscp);
- this.tableOptions = arrbegin;
- },
- load () {
- //
- if (!this.isTree) {
- if (this.noMore || this.loading) {
- return;
- }
- if (Object.keys(this.urlParams).length) {
- this.getQuery(this.queryId, this.urlParams);
- } else {
- this.getQuery(this.queryId);
- }
- }
- },
- resetTable () {
- this.page = 0;
- this.noMore = false;
- this.tableData = [];
- },
- changeSelect (data, name) {
- if (this.tableForm[data] === "") {
- this.tableForm[data] = null;
- }
- this.tableForm[this.tableOptions[data][0].setvalue] =
- this.tableForm[data];
- const arrbegin = _.cloneDeep(this.tabledatacopy);
- if (this.tableForm.beginNode) {
- this.tableOptions.beginPosition = arrbegin.beginPosition.filter(
- (i) => i.nodeCode === this.tableForm.beginNode
- );
- arrbegin.beginPosition.forEach((element) => {
- if (element.v === this.tableForm.beginPosition) {
- if (element.nodeCode !== this.tableForm.beginNode) {
- this.tableForm.beginPosition = "";
- }
- }
- });
- // let arr = [];
- // this.tableOptions.beginPosition.forEach((element) => {
- // arr.push(element.nodeCode);
- // });
- // if (
- // !arr.includes(this.tableForm.beginPosition) &&
- // this.tableForm.beginNode
- // ) {
- // this.tableForm.beginPosition = null;
- // }
- this.asShow = false;
- this.asShow = true;
- }
- if (this.tableForm.beginPosition && !this.tableForm.beginNode) {
- arrbegin.beginPosition.forEach((element) => {
- if (this.tableForm.beginPosition === element.v) {
- this.tableForm.beginNode = element.nodeCode;
- }
- });
- }
- if (this.tableForm.endNode) {
- this.tableOptions.endPosition = arrbegin.endPosition.filter(
- (i) => i.nodeCode === this.tableForm.endNode
- );
- arrbegin.endPosition.forEach((element) => {
- if (element.v === this.tableForm.endPosition) {
- if (element.nodeCode !== this.tableForm.endNode) {
- this.tableForm.endPosition = "";
- }
- }
- });
- this.asShow = false;
- this.asShow = true;
- }
- if (this.tableForm.endPosition && !this.tableForm.endNode) {
- arrbegin.endPosition.forEach((element) => {
- if (this.tableForm.endPosition === element.v) {
- this.tableForm.endNode = element.nodeCode;
- }
- });
- }
- },
- inputChangeHandler (data) {
- if (this.tableForm[data] === "") {
- this.tableForm[data] = null;
- }
- },
- //获取高级查询条件
- getColData (val) {
- const arr = [...val]
- if (arr && arr.length) {
- arr.forEach(item => {
- item.value = item.value.replace(/\s*/g, "")
- })
- }
- this.resetTable()
- this.getQuery(this.queryId, arr);
- },
- //获取表格数据
- async getQuery (id, dataContent = this.dataContent) {
- try {
- this.loading = true;
- const { code, returnData } = await Query({
- serviceId: id,
- page: ++this.page,
- pageSize: this.pageSize,
- dataContent,
- authId: this.authId
- });
- if (code == 0) {
- if (returnData.length === 0) {
- this.page--;
- this.noMore = true;
- this.loading = false;
- }
- this.tableData.push(...returnData);
- // this.tableCols = columnset;
- this.serviceId = id;
- setTimeout(() => {
- this.initTableData();
- this.loading = false;
- }, 100);
- } else {
- this.page--;
- this.loading = false;
- this.$message.error("获取表格数据失败");
- }
- } catch (error) {
- this.page--;
- this.loading = false;
- }
- },
- //表格-增/删/改
- async generalDataReception (event, data) {
- try {
- const params = {
- serviceId: this.serviceId,
- dataContent: data,
- event: `${event}`,
- };
- const { code } =
- event == 1
- ? await newData(params)
- : event == 2
- ? await modifyData(params)
- : await moveData(params);
- if (code == 0) {
- this.$message.success("操作成功");
- this.resetTable();
- this.getQuery(this.queryId);
- this.flag = false;
- this.rmFlag = false;
- this.tableObj = {};
- this.tableForm = {};
- // this.$router.go(0);
- } else {
- this.$message.error("操作失败");
- this.flag = false;
- this.rmFlag = false;
- this.tableObj = {};
- this.tableForm = {};
- }
- } catch (error) {
- this.flag = false;
- this.rmFlag = false;
- this.tableObj = {};
- this.tableForm = {};
- }
- },
- // 表格勾选
- toggleRowSelection (row, isSelected) {
- this.$refs["table"].toggleRowSelection(row, isSelected);
- },
- // 表格初始勾选
- selectTableRows (tableData, selectFlagName) {
- tableData.forEach((row) => {
- this.$refs["table"].toggleRowSelection(row, !!row[selectFlagName]);
- });
- this.$emit("selectionAll", this.$refs.table.selection);
- },
- //初始化表格
- initTableData () {
- this.tableColsCopy = this.tableCols.filter((item) => item.needShow);
- this.tableColsCopy = _.orderBy(this.tableColsCopy, ['orderNumber'], ['asc']);
- this.tableDataCopy = _.cloneDeep(this.tableData);
- const datas = _.cloneDeep(this.tableColsCopy);
- // const reqUts = [];
- datas.forEach(async (item) => {
- this.tableDataFilters[item.columnName] = [];
- if (item.needGroup) {
- this.tableGroups.push(item.columnName);
- }
- if (item.listqueryTemplateID || item.listqueryTemplateID == 0) {
- this.tableArrs.push(item.columnName);
- // const reqUt = this.getSelectData(item.listqueryTemplateID)
- // reqUts.push(reqUt)
- if (!this.tableOptions[item.columnName]) {
- //开始位置beginPosition 结束位置endPosition (区分开始结束位置必须传null)
- if (
- item.columnName !== "beginPosition" &&
- item.columnName !== "endPosition"
- ) {
- this.tableOptions[item.columnName] = await this.getSelectData(
- item.listqueryTemplateID
- );
- } else {
- this.tableOptions[item.columnName] = await this.getSelectData(
- item.listqueryTemplateID,
- null
- );
- this.tabledatacopy[item.columnName] = _.cloneDeep(
- this.tableOptions[item.columnName]
- );
- }
- } else {
- if (
- item.columnName === "beginPosition" ||
- item.columnName === "endPosition"
- ) {
- this.tableOptions[item.columnName] = await this.getSelectData(
- item.listqueryTemplateID,
- null
- );
- }
- }
- //
- }
- // this.filterValues[item.columnName] = ''
- });
- setTableFilters(this.tableData, this.tableDataFilters);
- this.tableGroup(this.tableData);
- // this.selectTableRows(this.tableData, "DeployID");
- this.tableOptionscp = _.cloneDeep(this.tableOptions);
- const arrbegin = _.cloneDeep(this.tableOptions);
- if (arrbegin) {
- setTimeout(() => {
- this.tableData.forEach((element) => {
- if (this.tableOptions.beginNode) {
- arrbegin.beginNode.forEach((res) => {
- if (res.v === element.beginNode) {
- element.beginNode = res.k;
- }
- });
- arrbegin.endNode.forEach((res) => {
- if (res.v == element.endNode) {
- element.endNode = res.k;
- }
- });
- arrbegin.calculationBasis.forEach((res) => {
- if (res.v == element.calculationBasis) {
- element.calculationBasis = res.k;
- }
- });
- //位置
- this.tabledatacopy.beginPosition.forEach((res) => {
- if (res.v == element.beginPosition) {
- element.beginPosition = res.k;
- }
- });
- this.tabledatacopy.endPosition.forEach((res) => {
- if (res.v == element.endPosition) {
- element.endPosition = res.k;
- }
- });
- }
- });
- }, 100);
- }
- // this.getSelectDataAll(reqUts)
- },
- //获取所有获取弹框-下拉数据-请求状态
- getSelectDataAll (reqUts) {
- Promise.all(reqUts)
- .then((res) => {
- this.proAll = true;
- })
- .catch((err) => {
- this.proAll = false;
- });
- },
- //获取弹框-下拉数据
- async getSelectData (id, name) {
- // name ? [name] : name === null ? [null]: [],
- const { code, returnData } = await Query({
- id,
- dataContent: name ? [name] : name === null ? [null] : [],
- });
- if (code == 0) {
- return returnData.listValues;
- } else {
- return [];
- }
- },
- //重组table-显示名称
- setTable () {
- this.tableArrs.forEach((item) => {
- this.tableOptions[item].forEach((p) => {
- this.tableDataCopy.forEach((msg) => {
- if (msg[item] == p.v) {
- msg[item] = p.k;
- }
- });
- this.tableDataFilters[item].forEach((cap) => {
- if (cap.value == p.v) {
- cap.text = p.k;
- cap.value = p.k;
- }
- });
- });
- });
- this.tableData = this.tableDataCopy;
- },
- //分组
- tableGroup (tableData) {
- const spanArr = [];
- let pos = 0;
- let ifYj = this.tableGroups[0];
- for (let i = 0; i < tableData.length; i++) {
- if (i === 0) {
- spanArr.push(1);
- } else {
- if (tableData[i][ifYj] === tableData[i - 1][ifYj]) {
- spanArr[pos] += 1;
- spanArr.push(0);
- } else {
- spanArr.push(1);
- pos = i;
- }
- }
- }
- this.spanArr = spanArr;
- this.pos = pos;
- },
- popoverShowHandler (prop) {
- this.colShowFilter = prop;
- },
- popoverHideHandler () {
- this.colShowFilter = "";
- },
- //分组
- tableSpanMethod ({ row, column, rowIndex, columnIndex }) {
- if (this.tableGroups.includes(column["property"])) {
- const _row = this.spanArr[rowIndex];
- const _col = _row > 0 ? 1 : 0;
- return {
- rowspan: _row,
- colspan: _col,
- };
- }
- },
- //合计
- getSummaries (param) {
- const { columns, data } = param;
- const sums = [];
- columns.forEach((column, index) => {
- this.tableColsCopy.forEach((p) => {
- if (column.property == p.columnName && p.needCount) {
- const values = data.map((item) => Number(item[column.property]));
- if (!values.every((value) => isNaN(value))) {
- sums[index] = values.reduce((prev, curr) => {
- const value = Number(curr);
- if (!isNaN(value)) {
- return prev + curr;
- } else {
- return prev;
- }
- }, 0);
- sums[index] += "";
- }
- }
- });
- });
- return sums;
- },
- //弹框-确定
- handleOk () {
- this.submitClickHandler();
- },
- //滚动
- tableLoad () { },
- //表格-新增
- handleAdd () {
- const { open_method, route_info } = this.btnAddObj
- if (open_method) {
- if (open_method != 3) {
- this.autoBtnClick(open_method, route_info)
- } else {
- this.flag = true;
- this.tableType = "add";
- this.tableTitle = "新增";
- this.tableForm = {};
- }
- }
- },
- //表格-编辑
- async handleEdit (row) {
- const { open_method, route_info } = this.btnEditObj
- if (open_method) {
- if (open_method != 3) {
- this.autoBtnClick(open_method, route_info)
- } else {
- this.flag = true;
- this.tableType = "edit";
- this.tableTitle = "编辑";
- this.tableForm = _.cloneDeep(row);
- }
- }
- },
- //表格-其他类型按钮操作
- handleOther (row, auth) {
- const { open_method, route_info } = auth
- if (open_method) {
- if (open_method != 3) {
- this.autoBtnClick(open_method, route_info)
- } else {
- console.log(row)
- }
- }
- },
- //表格-数据恢复
- async handleRecord (row) {
- const { open_method, route_info } = this.btnRecordObj
- console.log(code)
- const params = {
- "serviceId": row.serviceId,
- "dataObjectId": row.dataObjectId
- }
- const { code } = await abnormalDataRecovery(params)
- console.log(code)
- },
- // 新增/编辑-确认
- submitClickHandler () {
- this.$refs["ruleForm"].validate((valid) => {
- if (valid) {
- if (this.tableType == "add") {
- this.tableForm.event = 1;
- } else {
- this.tableForm.event = 2;
- }
- this.generalDataReception(this.tableForm.event, this.tableForm);
- } else {
- return false;
- }
- });
- },
- //表格-删除
- handleRemove (row) {
- const { open_method, route_info } = this.btnDelObj
- if (open_method) {
- if (open_method != 3) {
- this.autoBtnClick(open_method, route_info)
- } else {
- this.rmFlag = true;
- this.rmTitle = row[this.rowTitle];
- this.tableObj = row;
- }
- }
- },
- //表格-删除-确认
- tableRemove () {
- this.generalDataReception(3, this.tableObj);
- },
- // 表格-选中行
- selectHandler (selection, row) {
- this.$emit("selection-change", selection, row);
- },
- // 表格-查询模板预览
- handlePreview (row) {
- this.$emit("preview", row);
- },
- //高级查询关闭
- dialogHide () {
- this.dialogFlag = false
- },
- //表格-单元格点击
- cellClick (row, column) {
- const dataBtns = this.authBtnCol
- if (dataBtns && dataBtns.length) {
- const clickBtn = dataBtns.filter(item => item.relation_data == column.property)[0]
- if (clickBtn) {
- const { open_method, route_info, pass_parameters } = clickBtn
- if (open_method == 2) {
- if (pass_parameters) {
- const query = pass_parameters.split(',')
- const obj = {}
- query.forEach(item => {
- obj[item] = row[item]
- })
- this.$router.push({
- path: route_info,
- query: obj
- })
- } else {
- this.autoBtnClick(open_method, route_info)
- }
- }
- }
- }
- },
- //表格-设置单元格样式
- cellClass ({ row, column, rowIndex, columnIndex }) {
- if (this.authBtnColName.includes(column.property)) {
- return 'is-click-btn'
- }
- },
- formatter(row, column, cellValue, index) {
- const sameColumn = this.tableCols.find(col => col.columnName === column.property)
- if (sameColumn && this.fromDataType(sameColumn.dataType) === 'datetime') {
- return (cellValue ?? '').replace('T', ' ')
- }
- return cellValue
- }
- },
- };
- </script>
- <style lang="scss" scoped>
- @import "./css/index.scss";
- </style>
|