You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.1 KiB

2 years ago
<template>
<div>
<el-dialog :visible.sync="dialogVisible">
<template>
2 years ago
<xy-table
:is-first-req="false"
ref="table"
:row-key="(row) => row.id"
:height="380"
:action="index"
:delay-req="true"
:req-opt="select"
:table-item="columns"
@row-click="rowPick"
@loaded="selectRows"
@select="selectBk"
></xy-table>
2 years ago
</template>
<template #footer>
<span>
2 years ago
<el-button size="mini" @click="dialogVisible = false"
> </el-button
>
<el-button size="mini" type="primary" @click="confirm"
> </el-button
>
2 years ago
</span>
</template>
</el-dialog>
</div>
</template>
<script>
import { index } from "@/api/system/baseForm";
2 years ago
import { index as customFormIndex, show } from "@/api/system/customForm";
2 years ago
export default {
props: {
linkType: String,
2 years ago
linkTableName: String,
2 years ago
field: String,
originalRows: {
default: () => [],
type: Array,
},
2 years ago
},
data() {
return {
2 years ago
tempRow: {},
2 years ago
dialogVisible: false,
select: {
2 years ago
table_name: "",
table_id: "",
2 years ago
},
2 years ago
columns: [],
originalRowIds: [],
2 years ago
};
},
methods: {
index,
show() {
this.dialogVisible = true;
},
hide() {
this.dialogVisible = false;
},
2 years ago
async getDataTableName() {
if (this.linkType === "hasMany" || this.linkType === "newHasMany") {
const tables = (
await customFormIndex({
page: 1,
page_size: 999,
})
)?.data;
const id = tables?.find((i) => i.table_name === this.linkTableName)?.id;
const res = (
await show(
{
id,
},
false
)
)?.relation[0]?.link_table_name;
2 years ago
2 years ago
this.select.table_name = res;
this.select.table_id = tables.find(
(i) => i.table_name === this.select.table_name
)?.id;
}
if (this.linkType === "hasOne" || this.linkType === "newHasOne") {
const tables = (
await customFormIndex({
page: 1,
page_size: 999,
})
)?.data;
2 years ago
2 years ago
const table = tables?.find((i) => i.table_name === this.linkTableName);
this.select.table_name = table.table_name;
this.select.table_id = table.id;
}
2 years ago
},
2 years ago
async getColumns() {
const res = await show(
{
id: this.select.table_id,
},
false
);
2 years ago
2 years ago
console.log(res);
this.columns = res.fields
?.filter((i) => i.list_show)
.map((i) => {
let linkOb = {};
2 years ago
2 years ago
if (
i.select_item &&
typeof i.select_item === "object" &&
!(i.select_item instanceof Array)
) {
let keys = Object.keys(i.select_item);
linkOb.customFn = (row) => {
let paramMap = new Map();
keys.forEach((key) => {
paramMap.set(i.select_item[key], key);
});
2 years ago
2 years ago
return <span>{paramMap.get(row[i.field]?.toString())}</span>;
};
2 years ago
}
2 years ago
return Object.assign(
{
prop: i.field,
label: i.name,
width: i.width,
fixed: i.is_fixed,
},
linkOb
);
});
2 years ago
this.columns.unshift({
2 years ago
type: "index",
width: 50,
});
2 years ago
2 years ago
if (this.linkType === "hasMany" || this.linkType === "newHasMany") {
2 years ago
this.columns.unshift({
2 years ago
type: "selection",
2 years ago
width: 50,
2 years ago
reserveSelection: true,
});
2 years ago
}
},
2 years ago
selectRows() {
this.originalRowIds.forEach((id) => {
let data = this.$refs["table"].getListData();
let row = data.find((i) => i.id === id);
if (row) {
this.$refs["table"].toggleRowSelection(row);
}
});
},
rowPick({ row }) {
this.tempRow = row;
2 years ago
},
2 years ago
selectBk (selections, row) {
if (!selections.find(i => i.id === row.id)) {
this.originalRowIds.splice(this.originalRowIds.indexOf(row.id),1)
}
},
confirm() {
this.linkType === "hasMany" || this.linkType === "newHasMany"
? this.$emit("confirm", {
field: this.field,
value: Array.from(new Set([...this.$refs["table"].getSelection()?.map(i => i.id),...this.originalRowIds])),
})
: this.$emit("confirm", {
field: this.field,
value: this.tempRow.id,
});
2 years ago
this.dialogVisible = false;
2 years ago
},
2 years ago
},
computed: {},
watch: {
2 years ago
async linkTableName(newVal) {
2 years ago
await this.getDataTableName();
await this.getColumns();
2 years ago
await this.$refs["table"].getTableData();
2 years ago
},
2 years ago
dialogVisible(newVal) {
2 years ago
if (newVal) {
} else {
2 years ago
this.tempRow = {};
this.$refs['table'].clearSelection();
2 years ago
}
2 years ago
},
originalRows (newVal) {
this.originalRowIds = newVal.map(i => i[this.field])
this.selectRows();
2 years ago
}
2 years ago
},
2 years ago
};
</script>
<style scoped lang="scss"></style>