合同台账

master
xy 2 years ago
parent f644cc58c1
commit 244081069d

@ -1,7 +1,19 @@
<template>
<div>
<avue-map v-model="map" placeholder="请选择地图"></avue-map>
<p style="zoom: .85;">{{ value }}</p>
<template v-if="typeof resultFormat === 'string'">
<el-input size="small" :prop="value" @input="e => $emit('input',e)"></el-input>
</template>
<template v-else-if="resultFormat instanceof Array">
<div class="loc-editor">
<el-input :placeholder="item" v-for="(item, index) in resultFormat" size="small" :value="map[item]" @input="e => inputHandle(e,item)">
</el-input>
</div>
</template>
<template v-else>
<el-input :placeholder="key" v-for="(value, key) of resultFormat" size="small" :value="map[key]" @input="e => inputHandle(e,key)">
</el-input>
</template>
</div>
</template>
@ -17,10 +29,14 @@ export default {
data() {
return {
map: {},
}
},
methods: {},
methods: {
inputHandle (e, key) {
this.map[key] = e;
this.map = Object.assign({}, this.map)
}
},
computed: {},
watch: {
map(newVal) {
@ -47,27 +63,43 @@ export default {
console.log(res)
this.$emit('input', res)
},
value(newVal) {
if(typeof this.resultFormat === 'string') {
this.map[this.resultFormat] = Number(newVal)
}
if(this.resultFormat instanceof Array && newVal) {
let valArr = newVal.split(',')
this.resultFormat.forEach((i,index) => {
this.map[i] = Number(valArr[index])
})
}
if(typeof this.resultFormat === 'object' && (!this.resultFormat instanceof Array)) {
for(let key in this.resultFormat) {
this.map[key] = Number(newVal[key])
}
}
value: {
handler: function(newVal) {
if (newVal) {
if(typeof this.resultFormat === 'string') {
this.map[this.resultFormat] = newVal
}
if(this.resultFormat instanceof Array && newVal) {
let valArr = newVal.split(',')
this.resultFormat.forEach((i,index) => {
this.map[i] = Number(valArr[index])
})
}
if(typeof this.resultFormat === 'object' && (!this.resultFormat instanceof Array)) {
for(let key in this.resultFormat) {
this.map[key] = newVal[key]
}
}
console.log(this.map)
console.log(this.map)
}
},
immediate: true
}
}
}
</script>
<style scoped lang="scss">
.loc-editor {
display: flex;
margin-top: 4px;
& > ::v-deep.el-input {
margin-left: 4px;
}
& > ::v-deep.el-input:first-child {
margin-left: 0;
}
}
</style>

@ -366,9 +366,9 @@ export default {
clearSelection() {
this.$refs.table.clearSelection();
},
toggleRowSelection(row) {
toggleRowSelection(row, selected) {
this.$nextTick(() => {
this.$refs.table.toggleRowSelection(row);
this.$refs.table.toggleRowSelection(row, selected);
});
},
toggleAllSelection() {

@ -309,7 +309,7 @@ export class CreateDialog {
let info = that.formInfo.find((i) => i.field === replace.key);
if (!info) {
if (replace.label) {
dom.push(
dom.splice(replace.sort??dom.length,0,
h(
"el-form-item",
{
@ -325,9 +325,9 @@ export class CreateDialog {
},
[replace.render]
)
);
)
} else {
dom.push(replace.render);
dom.splice(replace.sort??dom.length,0,replace.render)
}
}
});

@ -646,33 +646,33 @@ export default {
"wuyedanwei",
];
switch (i.field) {
case "shiyongzhuangtai":
this.table.push({
label: i.name,
width: i.width,
customFn:row => {
return (
<span>{
(() => {
let res = '无';
for (let i = 0;i < row.id_leases_house_id_relation.length;i++) {
let nowDate = this.$moment(new Date())
let startDate = this.$moment(new Date(row.id_leases_house_id_relation[i]?.zulinkaishiqixian))
let endDate = this.$moment(new Date(row.id_leases_house_id_relation[i]?.zulinjieshuqixian))
if (nowDate.isBetween(startDate,endDate)) {
res = "租赁给"+row.id_leases_house_id_relation[i]?.chengzufang
break;
}
}
return res;
})()
}</span>
)
}
})
break;
// case "shiyongzhuangtai":
// this.table.push({
// label: i.name,
// width: i.width,
// customFn:row => {
// return (
// <span>{
// (() => {
// let res = '';
// for (let i = 0;i < row.id_leases_house_id_relation.length;i++) {
// let nowDate = this.$moment(new Date())
// let startDate = this.$moment(new Date(row.id_leases_house_id_relation[i]?.zulinkaishiqixian))
// let endDate = this.$moment(new Date(row.id_leases_house_id_relation[i]?.zulinjieshuqixian))
//
// if (nowDate.isBetween(startDate,endDate)) {
// res = ""+row.id_leases_house_id_relation[i]?.chengzufang
// break;
// }
//
// }
// return res;
// })()
// }</span>
// )
// }
// })
// break;
case "bufuqingkuang":
this.table.push({
label: i.name,

@ -622,33 +622,33 @@ export default {
let alignLeft = ['dikuaimingcheng','chengjiandanwei','jianshedanwei','wuyedanwei']
switch (i.field) {
case "shiyongzhuangtai":
this.table.push({
label: i.name,
width: i.width,
customFn:row => {
return (
<span>{
(() => {
let res = '无';
for (let i = 0;i < row.id_leases_land_id_relation.length;i++) {
let nowDate = this.$moment(new Date())
let startDate = this.$moment(new Date(row.id_leases_land_id_relation[i]?.zulinkaishiqixian))
let endDate = this.$moment(new Date(row.id_leases_land_id_relation[i]?.zulinjieshuqixian))
if (nowDate.isBetween(startDate,endDate)) {
res = "租赁给"+row.id_leases_land_id_relation[i]?.chengzufang
break;
}
}
return res;
})()
}</span>
)
}
})
break;
// case "shiyongzhuangtai":
// this.table.push({
// label: i.name,
// width: i.width,
// customFn:row => {
// return (
// <span>{
// (() => {
// let res = '';
// for (let i = 0;i < row.id_leases_land_id_relation.length;i++) {
// let nowDate = this.$moment(new Date())
// let startDate = this.$moment(new Date(row.id_leases_land_id_relation[i]?.zulinkaishiqixian))
// let endDate = this.$moment(new Date(row.id_leases_land_id_relation[i]?.zulinjieshuqixian))
//
// if (nowDate.isBetween(startDate,endDate)) {
// res = ""+row.id_leases_land_id_relation[i]?.chengzufang
// break;
// }
//
// }
// return res;
// })()
// }</span>
// )
// }
// })
// break;
case "fangchanzhuangtai":
this.table.push({
label: i.name,
@ -745,6 +745,7 @@ export default {
width: 60,
label: "序号",
});
},
toHistory (row) {

@ -3,7 +3,7 @@
<el-card class="statics">
<div class="statics-item">
<p class="statics-item__title">面积总量</p>
<p class="statics-item__num">{{ areaTotal }} 平方</p>
<p class="statics-item__num">{{ areaTotal.toFixed(2) }} 平方</p>
</div>
<div class="statics-item">
<p class="statics-item__title">资产总量</p>
@ -11,11 +11,11 @@
</div>
<div class="statics-item">
<p class="statics-item__title">闲置面积</p>
<p class="statics-item__num">{{ idleArea }} 平方</p>
<p class="statics-item__num">{{ idleArea.toFixed(2) }} 平方</p>
</div>
<div class="statics-item">
<p class="statics-item__title">租赁面积</p>
<p class="statics-item__num">{{ leaseAreaTotal }} 平方</p>
<p class="statics-item__num">{{ leaseAreaTotal.toFixed(2) }} 平方</p>
</div>
<!-- <div class="statics-item">-->
<!-- <p class="statics-item__title">公益产业</p>-->
@ -478,10 +478,10 @@ export default {
let markerSpan = document.createElement("span");
markerSpan.setAttribute("class", "map-marker__text");
markerSpan.innerText =
item.name.length > 4
? item.name.slice(0, 2) +
item.name?.length > 4
? item.name?.slice(0, 2) +
".." +
item.name.slice(item.name.length - 2)
item.name?.slice(item.name.length - 2)
: item.name;
markerContent.appendChild(markerImg);
markerContent.appendChild(markerSpan);

@ -583,7 +583,6 @@ export default {
}
}
//let alignLeft = ['dikuaimingcheng','chengjiandanwei','jianshedanwei','wuyedanwei']
this.table.push(
Object.assign(
{
@ -607,25 +606,29 @@ export default {
adjustAlignment () {
if (this.firstAdjustTable) {
const data = this.$refs['xyTable'].getListData();
if (data.length === 0) return;
this.form.filter(i => i.list_show).forEach((i) => {
let lengthTemp;
let temp = 0;
while (!lengthTemp || temp < data.length) {
lengthTemp = data[temp][i.field]?.length??0;
temp++;
}
for (let j = 0;j < data.length;j++) {
if (/^-?\d+\.\d+/.test(data[j][i.field])) {
this.table.find(a => a.prop === i.field).align = 'right';
return
if (data.length < 2) return;
try {
this.form.filter(i => i.list_show).forEach((i) => {
let lengthTemp;
let temp = 0;
while (!lengthTemp || temp < data.length) {
lengthTemp = data[temp][i.field]?.length??0;
temp++;
}
if (Math.abs(lengthTemp - (data[j][i.field]?.length)??0) > 4) {
this.table.find(a => a.prop === i.field).align = 'left';
return
for (let j = 0;j < data.length;j++) {
if (/^-?\d+\.\d+/.test(data[j][i.field])) {
this.table.find(a => a.prop === i.field).align = 'right';
return
}
if (Math.abs(lengthTemp - (data[j][i.field]?.length)??0) > 4) {
this.table.find(a => a.prop === i.field).align = 'left';
return
}
}
}
})
})
} catch (e) {
}
this.$nextTick(() => {
this.$refs['xyTable'].doLayout();
this.firstAdjustTable = false;

@ -0,0 +1,620 @@
<script>
import { save, show, index, destroy } from "@/api/system/baseForm";
import { CreateDialog } from "@/utils/createDialog"
import { deepCopy } from "@/utils";
import { resolveFormInfo } from '@/utils/createTable'
export default {
props: {
tableName: String,
},
render(h) {
const _this = this;
let dialog = new CreateDialog(this,[
{
sort: 0,
key: "land_list",
label: "土地选择",
render: h('div',[
h('Button', {
props: {
type: "primary"
},
on: {
["click"]() {
_this.landDialog = true;
}
},
},"选择土地"),
h('div', _this.selectedLands?.map(item => h('Tag',{ props: { color: "primary" } }, item.name)))
])
},
{
sort: 1,
key: "house_list",
label: "房产选择",
render: h('div',[
h('Button', {
props: {
type: "primary"
},
on: {
["click"]() {
_this.houseDialog = true;
}
},
},"选择房产"),
h('div', _this.selectedHouses?.map(item => h('Tag',{ props: { color: "primary" } }, item.name)))
])
}
],{
width: "1000px"
})
return (
<div>
{
dialog.render()
}
<el-drawer title="土地列表"
visible={this.landDialog}
size="64%"
on={{
['update:visible']: (val) => this.landDialog = val,
}}>
<div style="padding: 0 10px;">
<xy-table
ref="landLinkTable"
table-item={
[
{
type: "selection",
width: 56,
align: "center",
reserveSelection: true,
fixed: "left",
},
{
"prop": "id",
"width": 60,
"label": "序号"
},
{
"prop": "tudiquanshuren",
"label": "土地权属人",
"width": 0,
"align": "left"
},
{
"prop": "area",
"label": "区域",
"width": 0,
"align": "center"
},
{
"prop": "name",
"label": "地块名称",
"width": 0,
"align": "left",
"fixed": "left"
},
{
"prop": "tudizhenghao",
"label": "土地证号",
"width": 0,
"align": "left"
},
{
"prop": "zuoluo",
"label": "坐落",
"width": 0,
"align": "left"
},
{
"prop": "zichanweizhi",
"label": "资产位置",
"width": 0,
"align": "center"
},
{
"prop": "quanliren",
"label": "证载“权利人”",
"width": 0,
"align": "left"
},
{
"prop": "gongyouqingkuang",
"label": "共有情况",
"width": 0,
"align": "center"
},
{
"prop": "shiyongnianxian",
"label": "使用年限(年)",
"width": 0,
"align": "center"
},
{
"prop": "xianzhuang",
"label": "现状",
"width": 0,
"align": "center"
},
{
"prop": "yongtu",
"label": "用途",
"width": 0,
"align": "left"
},
{
"prop": "shiyongquanleixing",
"label": "使用权类型",
"width": 0,
"align": "center"
},
{
"prop": "lingzhengriqi",
"label": "领证日期",
"width": 0,
"align": "center"
},
{
"prop": "zhongzhiriqi",
"label": "终止日期",
"width": 0,
"align": "center"
},
{
"prop": "dengjimianji",
"label": "登记面积",
"width": 0,
"align": "center"
},
{
"prop": "shijimianji",
"label": "实际面积",
"width": 0,
"align": "center"
},
{
"label": "不符情况",
"width": 0
},
{
"prop": "bufuyuanyin",
"label": "不符原因",
"width": 0,
"align": "center"
},
{
"prop": "ruzhangshijian",
"label": "入账时间",
"width": 0,
"align": "center"
},
{
"prop": "zhangmianyuanzhi",
"label": "账面原值",
"width": 0,
"align": "center"
},
{
"prop": "tudidengji",
"label": "土地等级",
"width": 0,
"align": "center"
},
{
"prop": "tudishuidanjia",
"label": "土地税单价",
"width": 0,
"align": "center"
},
{
"prop": "tudishui",
"label": "土地税",
"width": 0,
"align": "center"
},
{
"prop": "tudishuijiaonazhuti",
"label": "土地税缴纳主体",
"width": 0,
"align": "center"
},
{
"prop": "jiaoshuijine",
"label": "缴税金额",
"width": 0,
"align": "center"
}
]
}
action={this.index}
req-opt={{
table_name: "lands"
}}
on={{
['loaded']: _ => {
this.$nextTick(() => {
this.$refs['landLinkTable'].getListData()?.filter(item => this.originalForm.id_leases_to_assets_lease_id_relation.find(j => j.land_id === item.id))?.forEach(item => {
this.$refs['landLinkTable'].toggleRowSelection(item, true)
})
++this.landSelectTemp;
})
},
['select']: _ => ++this.landSelectTemp
}}
></xy-table>
</div>
</el-drawer>
<el-drawer title="房产列表"
visible={this.houseDialog}
size="64%"
on={{
['update:visible']: (val) => this.houseDialog = val,
}}>
<div style="padding: 0 10px;">
<xy-table
ref="houseLinkTable"
table-item={
[
{
type: "selection",
width: 56,
align: "center",
reserveSelection: true,
fixed: "left"
},
{
"prop": "id",
"width": 60,
"label": "序号"
},
{
"prop": "quanshuren",
"label": "权属人",
"width": 0,
"align": "center"
},
{
"prop": "area",
"label": "区域",
"width": 0,
"align": "center"
},
{
"prop": "name",
"label": "地块名称",
"width": 0,
"fixed": "left",
"align": "left"
},
{
"prop": "quanzhenghao",
"label": "权证号",
"width": 0,
"align": "center"
},
{
"prop": "zuoluo",
"label": "坐落",
"width": 0,
"align": "left"
},
{
"prop": "zichanweizhi",
"label": "房产位置",
"width": 0,
"align": "center"
},
{
"prop": "quanliren",
"label": "证载“权利人”",
"width": 0,
"align": "center"
},
{
"prop": "yongtu",
"label": "用途",
"width": 0,
"align": "left"
},
{
"prop": "zhuangtai",
"label": "现状",
"width": 0,
"align": "left"
},
{
"prop": "dengjishijian",
"label": "登记时间",
"width": 0,
"align": "center"
},
{
"prop": "dengjimianji",
"label": "登记面积",
"width": 0,
"align": "center"
},
{
"prop": "shijimianji",
"label": "实际面积",
"width": 0,
"align": "center"
},
{
"prop": "bufuyuanyin",
"label": "不符情况",
"width": 0,
"align": "center"
},
{
"prop": "ruzhangshijian",
"label": "入账时间",
"width": 0,
"align": "center"
},
{
"prop": "zhangmianyuanzhi",
"label": "账面原值",
"width": 0,
"align": "center"
},
{
"prop": "guanliantudizhengquanzheng",
"label": "关联土地证权证",
"width": 0,
"align": "center"
},
{
"prop": "shiyongzhuangtai",
"label": "使用状态",
"width": 0,
"align": "center"
}
]
}
action={this.index}
req-opt={{
table_name: "houses"
}}
on={{
['loaded']: _ => {
this.$nextTick(() => {
this.$refs['houseLinkTable'].getListData()?.filter(item => this.originalForm.id_leases_to_assets_lease_id_relation.find(j => j.house_id === item.id))?.forEach(item => {
this.$refs['houseLinkTable'].toggleRowSelection(item, true)
})
++this.houseSelectTemp;
})
},
['select']: _ => ++this.houseSelectTemp
}}
></xy-table>
</div>
</el-drawer>
</div>
)
},
data() {
return {
houseDialog: false,
houseSelectTemp: 0,
landDialog: false,
landSelectTemp: 0,
columns: 1,
row: {},
formInfo: [],
id: "",
type: "add",
dialogVisible: false,
form: {},
originalForm: {},
rules: {},
file: {},
};
},
methods: {
index,
setRow (row) {
this.row = row
},
init() {
for (let key in this.form) {
if (this.form[key] instanceof Array) {
this.form[key] = [];
} else {
this.form[key] = "";
}
}
this.$refs["elForm"].clearValidate();
},
show() {
this.dialogVisible = true;
},
hidden() {
this.dialogVisible = false;
},
setType(type = "add") {
let types = ["add", "editor", "show"];
if (types.includes(type)) {
this.type = type;
} else {
console.warn("Unknown type: " + type);
}
},
setId(id) {
if (typeof id == "number") {
this.id = id;
} else {
console.error("error typeof id: " + typeof id);
}
},
async getDetail() {
const res = await show({ id: this.id, table_name: 'leases' });
this.$integrateData(this.form, res);
this.formInfo.forEach((i) => {
if (i.edit_input === "file") {
}
if (i.edit_input === "files") {
this.file[i.field] = res[`${i.field}_upload_details`]
}
});
this.form = Object.assign({}, this.form);
this.originalForm = deepCopy(res);
},
submit() {
if (/\/house/g.test(this.$route.path)) {
this.form['house_id'] = this.row.id
}
if (/\/land/g.test(this.$route.path)) {
this.form['land_id'] = this.row.id
}
if (this.type === "add") {
if (this.form.hasOwnProperty("id")) {
delete this.form.id;
}
}
if (this.type === "editor") {
Object.defineProperty(this.form, "id", {
value: this.id,
enumerable: true,
configurable: true,
writable: true,
});
}
this.form.id_leases_to_assets_lease_id_relation = []
this.$refs['houseLinkTable'].getSelection()?.forEach(i => {
this.form.id_leases_to_assets_lease_id_relation.push({
house_id: i.id,
lease_id: this.id
})
})
this.$refs['landLinkTable'].getSelection()?.forEach(i => {
this.form.id_leases_to_assets_lease_id_relation.push({
land_id: i.id,
lease_id: this.id
})
})
save(Object.assign(this.form, { table_name: 'leases' })).then(res => {
this.$Message.success({
content: `${this.type === "add" ? "新增" : "编辑"}成功`,
});
this.$emit("refresh");
this.hidden();
})
},
},
computed: {
title () {
if (this.type === 'add') return '新增'
if (this.type === 'editor') return '编辑'
if (this.type === 'show') return '查看'
},
selectedLands () {
let temp = this.landSelectTemp;
return this.$refs['landLinkTable']?.getSelection() || [];
},
selectedHouses () {
let temp = this.houseSelectTemp;
return this.$refs['houseLinkTable']?.getSelection() || [];
},
},
watch: {
formInfo: {
handler: function (newVal) {
this.form = {};
this.rules = {};
this.file = {};
newVal.forEach((i) => {
if (i.field) {
this.form[i.field] = "";
if (
i.validation instanceof Array &&
i.validation.length > 0 &&
!!i.validation.find((i) => i === "required")
) {
this.rules[i.field] = [
{ required: true, message: `请填写${i.name}` },
];
}
if (i.edit_input === "files") {
this.form[i.field] = [];
}
if (i.edit_input === "files" || i.edit_input === "file") {
this.file[i.field] = [];
}
if (i.edit_input === "checkbox") {
this.form[i.field] = [];
}
if (i._relations) {
this.form[i._relations?.link_with_name] = [];
}
}
});
this.columns = newVal.length > 11 ? '2' : '1'
},
//immediate: true,
},
dialogVisible(val) {
if (val) {
document.documentElement.style.setProperty(
"--column-num",
this.columns
);
if (this.type === "editor" || this.type === "show") {
this.$nextTick(() => this.getDetail());
}
} else {
this.id = "";
this.type = "";
this.init();
this.$refs["elForm"].clearValidate();
delete this.form.id;
for (let key in this.file) {
this.file[key] = [];
}
this.$refs['landLinkTable'].clearSelection();
this.$refs['houseLinkTable'].clearSelection();
}
},
},
created() {
resolveFormInfo(15).then(res => this.formInfo = res)
}
};
</script>
<style>
:root {
--column-num: 2;
}
</style>
<style scoped lang="scss">
.uploaded-a {
color: red;
text-decoration: none;
transition: all 0.2s;
}
.uploaded-a:hover {
color: red;
text-decoration: underline;
}
.form-body {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(var(--column-num), 1fr);
}
</style>

@ -0,0 +1,681 @@
<template>
<div>
<!-- 查询配置 -->
<div>
<div ref="lxHeader">
<LxHeader
:icon="$route.meta.icon"
:text="$route.meta.title"
style="margin-bottom: 10px; border: 0px; margin-top: 15px"
>
<div slot="content"></div>
<slot>
<header-content :auths="auths_auth_mixin">
<template #search>
<div style="display: flex">
<Select
v-model="select.filter[0].key"
style="width: 100px"
placeholder="搜索条目"
>
<Option
v-for="item in form"
:key="item.id"
:value="item.field"
>{{ item.name }}</Option
>
</Select>
<Select
v-model="select.filter[0].op"
style="width: 100px; margin-left: 10px"
placeholder="搜索条件"
>
<Option
v-for="item in op"
:key="item.value"
:value="item.value"
>{{ item.label }}</Option
>
</Select>
<template
v-if="
select.filter[0].op !== 'range' &&
!columnArrTest(select.filter[0].key)
"
>
<Input
v-model="select.filter[0].value"
style="width: 150px; margin-left: 10px"
placeholder="请填写关键词"
/>
</template>
<template
v-else-if="
select.filter[0].op !== 'range' &&
columnArrTest(select.filter[0].key)
"
>
<Select
v-model="select.filter[0].value"
style="width: 150px; margin-left: 10px"
placeholder="请选择关键词"
>
<Option
v-for="item in getColumnParams(select.filter[0].key)"
:key="item.id"
:value="getColumnField(select.filter[0].key)._relations ? item[getColumnField(select.filter[0].key)._relations.foreign_key] : item.value"
>{{
item.key || item.value || item.name || item.no || item.mingcheng || item.id
}}</Option
>
</Select>
</template>
<template v-else>
<Input
:value="select.filter[0].value.split(',')[0]"
style="width: 150px; margin-left: 10px"
placeholder="范围开始关键词"
@input="(e) => inputStartHandler(e, select.filter[0])"
/>
<span
style="
margin-left: 10px;
display: flex;
align-items: center;
"
></span
>
<Input
:value="select.filter[0].value.split(',')[1]"
style="width: 150px; margin-left: 10px"
placeholder="范围结束关键词"
@input="(e) => inputEndHandler(e, select.filter[0])"
/>
</template>
<Button
style="margin-left: 10px"
type="primary"
@click="$refs['xyTable'].getTableData(true)"
>查询</Button
>
<xy-selectors
style="margin-left: 10px"
@reset="reset"
@search="$refs['xyTable'].getTableData(true)"
>
<template>
<div class="select">
<div
class="select__item"
v-for="(item, index) in select.filter"
:key="`${item.value}-${index}`"
>
<p>条件{{ index + 1 }}</p>
<Select
v-model="item.key"
style="width: 100px"
placeholder="搜索条目"
>
<Option
v-for="item in form"
:key="item.id"
:value="item.field"
>{{ item.name }}</Option
>
</Select>
<Select
v-model="item.op"
style="width: 100px; margin-left: 10px"
placeholder="搜索条件"
>
<Option
v-for="item in op"
:key="item.value"
:value="item.value"
>{{ item.label }}</Option
>
</Select>
<template
v-if="
item.op !== 'range' && !columnArrTest(item.key)
"
>
<Input
v-model="item.value"
style="width: 150px; margin-left: 10px"
placeholder="请填写关键词"
/>
</template>
<template
v-else-if="
item.op !== 'range' && columnArrTest(item.key)
"
>
<Select
v-model="item.value"
style="width: 150px; margin-left: 10px"
placeholder="请选择关键词"
>
<Option
v-for="item in getColumnParams(item.key)"
:key="item.id"
:value="getColumnField(item.key)._relations ? item[getColumnField(item.key)._relations.foreign_key] : item.value"
>{{
item.key || item.value || item.name || item.no || item.mingcheng || item.id
}}</Option
>
</Select>
</template>
<template v-else>
<Input
:value="item.value.split(',')[0]"
style="width: 150px; margin-left: 10px"
placeholder="范围开始关键词"
@input="(e) => inputStartHandler(e, item)"
/>
<span style="margin-left: 10px"></span>
<Input
:value="item.value.split(',')[1]"
style="width: 150px; margin-left: 10px"
placeholder="范围结束关键词"
@input="(e) => inputEndHandler(e, item)"
/>
</template>
<el-button
v-if="index !== 0"
size="small"
type="danger"
icon="el-icon-delete"
circle
style="margin-left: 10px"
@click="select.filter.splice(index, 1)"
></el-button>
</div>
</div>
<div class="add-btn">
<el-button
size="small"
type="primary"
icon="el-icon-plus"
circle
@click="
select.filter.push({ key: '', op: '', value: '' })
"
></el-button>
<span>新增一条</span>
</div>
</template>
</xy-selectors>
</div>
</template>
<template #create>
<Button
type="primary"
@click="
$refs['dialog'].setType('add'), $refs['dialog'].show()
"
>新增</Button
>
</template>
<template #import>
<Button type="primary" @click="$refs['imports'].show()"
>导入</Button
>
</template>
<template #export>
<Button
type="primary"
@click="exportExcel(new Date().getTime().toString())"
>导出</Button
>
</template>
</header-content>
</slot>
</LxHeader>
</div>
</div>
<xy-table
:btn-width="300"
:auths="auths_auth_mixin"
:delay-req="true"
:destroy-action="destroy"
ref="xyTable"
:border="true"
:action="index"
:req-opt="select"
:destroy-req-opt="select"
:table-item="table"
@detail="
(row) => {
$router.push({
path: $route.path + '/detail/' + row.id
})
}
"
@editor="
(row) => {
$refs['dialog'].setId(row.id);
$refs['dialog'].setType('editor');
$refs['dialog'].show();
}
"
@loaded="adjustAlignment"
>
</xy-table>
<add
:table-name="customForm.tableName"
ref="dialog"
@refresh="$refs['xyTable'].getTableData()"
>
</add>
<drawer
:table-name="customForm.tableName"
:form-info="form"
ref="drawer"
></drawer>
<imports
:table-name="customForm.tableName"
:form-info="form"
ref="imports"
@refresh="$refs['xyTable'].getTableData()"
></imports>
</div>
</template>
<script>
import { index as fieldIndex } from "@/api/system/customFormField";
import { authMixin } from "@/mixin/authMixin";
import { index, destroy } from "@/api/system/baseForm";
import { op } from "@/const/op";
import { download } from "@/utils/downloadRequest";
import { getparameter } from "@/api/system/dictionary";
import { show } from "@/api/system/customForm";
import * as XLSX from "xlsx";
import { saveAs } from "file-saver";
import { listdept } from "@/api/system/department"
import add from "./component/addLease.vue";
import LxHeader from "@/components/LxHeader/index.vue";
import headerContent from "@/components/LxHeader/XyContent.vue";
import drawer from "@/views/component/drawer.vue";
import imports from "@/views/component/imports.vue";
export default {
name: 'tableList',
components: {
LxHeader,
add,
headerContent,
drawer,
imports,
},
mixins: [authMixin],
provide: {
formStore: () => this.form,
},
data() {
return {
firstAdjustTable: true,
op,
select: {
table_name: "",
filter: [
{
key: "",
op: "",
value: "",
},
],
},
form: [],
table: [],
customForm: {
customFormId: "",
tableName: "",
},
};
},
methods: {
index,
destroy,
download,
reset() {
this.select.filter.splice(1);
this.select.filter[0] = {
key: "",
op: "",
value: "",
};
},
async exportExcel(sheetName) {
const res = await index(
Object.assign(this.select, { page: 1, page_size: 9999 })
);
if (res.data) {
let headers = this.form.map((i) => {
return {
key: i.field,
title: i.name,
};
});
const data = res.data.map((row) =>
headers.map((header) => row[header.key])
);
data.unshift(headers.map((header) => header.title));
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, sheetName);
const wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
`${sheetName}.xlsx`
);
}
},
//target
inputStartHandler(e, target) {
let temp = target?.value.split(",")[1];
target.value = `${e},${temp ? temp : ""}`;
},
inputEndHandler(e, target) {
let temp = target?.value.split(",")[0];
target.value = `${temp ? temp : ""},${e}`;
},
async getFormDetail() {
if (this.$route.meta.params?.custom_form) {
let decode = decodeURIComponent(this.$route.meta.params?.custom_form);
try {
let custom_form = JSON.parse(decode);
this.customForm.customFormId = custom_form.custom_form_id;
this.customForm.tableName = custom_form.table_name;
this.select.table_name = custom_form.table_name;
} catch (err) {
console.warn(err);
}
}
const res = await show({ id: this.customForm.customFormId }, false);
//
//
let baseTable = new Map([
['departments', async () => {
const res = await listdept()
return res
}],
['admins',[]]
])
let { fields, relation } = res;
let fieldRes = fields.sort((a,b) => a.sort - b.sort)
if (
!fields ||
!relation ||
!fields instanceof Array ||
!relation instanceof Array
) {
throw new Error("fields或relation格式错误");
}
console.log(fieldRes)
fieldRes?.forEach((i, index) => {
i._relations = relation.find(
(j) => j.link_table_name.split("_")[1] === i.field
) || relation.find(
(j) => j.local_key === i.field
);
if (i.select_item && typeof i.select_item === "object") {
let keys = Object.keys(i.select_item);
if (keys.length > 0) {
i._params = keys.map((key) => {
return {
key,
value: /^\d*$/.test(i.select_item[key])
? Number(i.select_item[key])
: i.select_item[key],
};
});
}
}
if (i.edit_input === 'file' || i.edit_input === 'files') {
return
}
if (i._relations) {
if (baseTable.get(i._relations.link_table_name)) {
baseTable
.get(i._relations.link_table_name)()
.then((res) => {
i._params = res.data;
});
} else {
i._params = i._relations.parameter_id
? getparameter({ id: i._relations.parameter_id }, false).then(
(res) => {
i._params = res.detail;
}
)
: this.index({
table_name: i._relations.link_table_name,
page: 1,
page_size: 9999,
}).then((res) => {
i._params = res.data;
});
}
}
});
this.form = fieldRes || [];
this.form
?.filter((i) => i.list_show)
.forEach((i) => {
let linkOb = {};
if (i.edit_input === "richtext") {
linkOb.customFn = (row) => {
return (
<div
style={{ "max-height": "55px","overflow": "scroll" }}
domPropsInnerHTML={row[i.field]}
></div>
);
};
}
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);
});
return <span>{ paramMap.get(row[i.field]) ? paramMap.get(row[i.field].toString()) : row[i.field] }</span>;
};
}
if (i._relations) {
let { link_relation, foreign_key, link_with_name } = i._relations;
if (link_relation === "newHasOne" || link_relation === "hasOne") {
linkOb.customFn = (row) => {
if (i.edit_input === "file") {
return (
<a
download={row[link_with_name]?.original_name}
href={row[link_with_name]?.url}
>
{row[link_with_name]?.original_name}
</a>
);
} else {
return (
<span>
{row[link_with_name]?.name ||
row[link_with_name]?.no ||
row[link_with_name]?.value}
</span>
);
}
};
}
if (link_relation === "hasMany" || link_relation === "newHasMany") {
linkOb.customFn = (row) => {
if (i.edit_input === "files") {
return (
<div style="display: flex;flex-direction: column;">
{row[link_with_name]?.map((o) => (
<a>
{ o?.original_name || o?.name }
</a>
))}
</div>
)
} else {
return (
<div>
{row[link_with_name]?.map((o) => (
<p>
{o?.name ||
o?.no ||
o?.value ||
o?.biaoti ||
o?.mingcheng}
</p>
))}
</div>
);
}
};
}
}
this.table.push(
Object.assign(
{
prop: i.field,
label: i.name,
width: i.width,
align: 'center',
fixed: i.is_fixed,
},
linkOb
)
);
});
this.table.unshift({
prop: "id",
width: 60,
label: "序号",
});
},
adjustAlignment () {
if (this.firstAdjustTable) {
const data = this.$refs['xyTable'].getListData();
if (data.length < 2) return;
try {
this.form.filter(i => i.list_show).forEach((i) => {
let lengthTemp;
let temp = 0;
while (!lengthTemp || temp < data.length) {
lengthTemp = data[temp][i.field]?.length??0;
temp++;
}
for (let j = 0;j < data.length;j++) {
if (!data[j] || !data[j][i.field]) return;
if (/^-?\d+\.\d+|^-?\d+/.test(data[j][i.field])) {
console.log(data[j][i.field])
this.table.find(a => a.prop === i.field).align = 'right';
return
}
if (Math.abs(lengthTemp - (data[j][i.field]?.length)??0) > 4) {
this.table.find(a => a.prop === i.field).align = 'left';
return
}
}
})
} catch (err) {
console.error(err);
}
this.$nextTick(() => {
this.$refs['xyTable'].doLayout();
this.firstAdjustTable = false;
})
}
}
},
computed: {
columnArrTest() {
return function (field) {
return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field).search_input === "checkbox" || this.form.find((i) => i.field === field).search_input === "radio"
: false;
};
},
getColumnField() {
return function (field) {
return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field)
: {};
};
},
getColumnParams() {
return function (field) {
return this.form.find((i) => i.field === field)
? this.form.find((i) => i.field === field)._params
: [];
};
}
},
created() {
this.getFormDetail();
},
};
</script>
<style scoped lang="scss">
.select {
&__item {
& > p {
display: inline-block;
width: 80px;
text-align: center;
}
& + div {
margin-top: 6px;
}
}
}
.add-btn {
display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;
& > span {
padding: 0 10px;
}
}
a {
color: red;
text-decoration: none;
transition: all 0.2s;
}
a:hover {
color: red;
text-decoration: underline;
}
</style>
Loading…
Cancel
Save