<template>
|
<div class="other-share-holder">
|
<el-row class="add-button" v-if="addorupdate === '01'">
|
<el-col :span="24">
|
<el-button
|
type="primary"
|
size="small"
|
icon="el-icon-circle-plus-outline"
|
@click="handleAddCus"
|
class="add_btn"
|
>新增</el-button>
|
</el-col>
|
</el-row>
|
|
<ProTable
|
:pageInfo="pageInfo"
|
@doAction="doAction"
|
@handleCurrentChange="handleCurrentChange"
|
@handleSizeChange="handleSizeChange"
|
:isAutoIndex="true"
|
:list="records"
|
:header="tableHeader"
|
:loading="loading"
|
/>
|
|
<el-dialog
|
:title="dialogTitle"
|
:visible.sync="dialogVisible"
|
:close-on-click-modal="false"
|
:close-on-press-escape="false"
|
:destroy-on-close="true"
|
:show-close="false"
|
custom-class="stock_dialog"
|
width="890px"
|
center
|
>
|
<CreateForms
|
ref="financeForms"
|
v-if="dialogVisible"
|
:isReset="true"
|
:isView="isView"
|
:isShowBorder="isShowBorder"
|
:screenWidth="1000"
|
:formItems="formItems"
|
:defValues="defValues"
|
:formRules="formRules"
|
@beforeFormAvatarUpload="beforeAvatarUpload"
|
@handleFormUpload="handleUpload"
|
@handleFormDelete="handleDelete"
|
/>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="handleDialogCancel">取消</el-button>
|
<el-button type="primary" v-if="!isView" @click="saveBoardInfo">
|
{{
|
addOrModify === "0" ? "新增" : "修改"
|
}}
|
</el-button>
|
</span>
|
</el-dialog>
|
|
<Dialog
|
v-model="isDelete"
|
title="财务信息删除确认"
|
:buttons="[{text: '取消'},{text: '确定', type: 'primary'}]"
|
@handleClick="clickDelete"
|
:contentText="`请确认是否需要删除${tempRecord.financialTypeCn}财务信息?`"
|
></Dialog>
|
</div>
|
</template>
|
|
<script>
|
// 财务信息
|
import ProTable from "@/views/components/ProTable";
|
import CreateForms from "@/views/components/CreateForms";
|
import Dialog from "../components/Dialog";
|
import OperateSuccessTip from "../components/OperateSuccessTip";
|
|
import {
|
qryFinancialDataList,
|
delFinancialData,
|
financialDataUpdate,
|
getDictionaryList
|
} from "@/http/api.js";
|
import { enterpriseCusFinanceInfo } from "../config/column.config";
|
import { financeInfoDefault } from "../config/defValues.config";
|
import { financeInfo } from "../config/formItem.config";
|
import { financeInfoRules } from "../config/rules.config";
|
export default {
|
components: {
|
ProTable,
|
Dialog,
|
OperateSuccessTip,
|
CreateForms
|
},
|
props: {
|
tableHeader: {
|
type: [Object, Array],
|
default: () => {
|
return [];
|
}
|
},
|
addorupdate: {
|
type: [String],
|
default: ""
|
}
|
},
|
created() {
|
this.init();
|
},
|
data() {
|
return {
|
operateBtns: [{ label: "删除", type: "DELETE", value: true }],
|
columnConfig: [...enterpriseCusFinanceInfo],
|
loading: false,
|
isShowBorder: true,
|
dialogTitle: "",
|
isView: false,
|
dialogVisible: false,
|
formItems: [...financeInfo],
|
formRules: { ...financeInfoRules },
|
defValues: { ...financeInfoDefault },
|
addOrModify: "", // 0-新增 1-修改
|
pageInfo: {
|
currentPage: 1,
|
pageSize: 10,
|
total: 0
|
},
|
records: [],
|
tempRecord: {},
|
isDelete: false,
|
passValidate: false, // 控制是否通过检验
|
objectNo: "" // 存放customerId
|
};
|
},
|
methods: {
|
async init() {
|
const { pageInfo, $route } = this;
|
const { query } = $route;
|
|
const { customerId, operation } = query;
|
this.objectNo = customerId;
|
const params = {
|
objectNo: customerId,
|
...pageInfo
|
};
|
const { result } = await qryFinancialDataList(params);
|
// 给每行数据添加操作按钮
|
this.records = result.records.map(item => {
|
const newItem = { ...item };
|
if (operation === "02") {
|
} else {
|
newItem.operationOption = [
|
{ key: "delete", label: "删除", value: true },
|
{ key: "edit", label: "修改", value: true }
|
];
|
}
|
return newItem;
|
});
|
this.$set(this.pageInfo, "total", result.total);
|
},
|
// 新增
|
handleAddCus() {
|
this.isView = false;
|
this.isShowBorder = true;
|
this.setSelectOptions();
|
this.dialogTitle = "新增财务信息";
|
this.dialogVisible = true;
|
this.addOrModify = "0";
|
const { defValues } = this;
|
for (let key in defValues) {
|
defValues[key] = "";
|
}
|
},
|
setSelectOptions() {
|
const { formItems } = this;
|
formItems.forEach(({ name }) => {
|
if (name === "financialType") {
|
this.getDictionaryList(name);
|
}
|
});
|
},
|
async getDictionaryList(name) {
|
const codeNo = name.substring(0, 1).toUpperCase() + name.substring(1);
|
const { result } = await getDictionaryList({ codeNo });
|
const list = result.map(item => {
|
return {
|
label: item.itemname,
|
value: item.itemno
|
};
|
});
|
this.updateValue(name, { options: list });
|
},
|
updateValue(index, info) {
|
const { formItems } = this;
|
const nameIndex = formItems.findIndex(({ name }) => name === index);
|
if (nameIndex > -1) {
|
const preInfo = formItems[nameIndex];
|
this.$set(formItems, nameIndex, { ...preInfo, ...info });
|
}
|
},
|
// 取消
|
handleDialogCancel() {
|
this.serialno = ''
|
this.dialogVisible = false;
|
},
|
|
// 保存/修改
|
async saveBoardInfo() {
|
const { objectNo, serialno } = this;
|
await this.vailateForm();
|
const { passValidate } = this;
|
if (!passValidate) {
|
return false;
|
}
|
const formRef = this.$refs.financeForms;
|
const { model } = formRef.$refs["createForm"];
|
let temp = serialno
|
? { ...model, objectNo, serialno }
|
: { ...model, objectNo };
|
await financialDataUpdate(temp);
|
this.dialogVisible = false;
|
this.$message.success(`${serialno ? "修改成功" : "新增成功"}`);
|
this.serialno = "";
|
this.init();
|
},
|
vailateForm() {
|
const formRef = this.$refs.financeForms;
|
formRef.$refs["createForm"].validate(async valid => {
|
if (valid) {
|
this.passValidate = true;
|
return true;
|
} else {
|
this.passValidate = false;
|
this.$message.error("请完善必填项!");
|
return false;
|
}
|
});
|
},
|
beforeAvatarUpload() {},
|
handleUpload() {},
|
handleDelete() {},
|
// 修改翻页条数
|
handleSizeChange(val) {
|
this.pageInfo.pageSize = val;
|
this.getBoardList();
|
},
|
// 修改翻页数
|
handleCurrentChange(val) {
|
this.pageInfo.currentPage = val;
|
this.getBoardList();
|
},
|
// 表单事件回调
|
doAction(name, item, { key }) {
|
this.tempRecord = item;
|
if (key === "delete") {
|
this.isDelete = true;
|
}
|
if (key === "edit") {
|
this.toEdit();
|
this.dialogVisible = true;
|
this.dialogTitle = "修改财务信息";
|
}
|
},
|
toEdit() {
|
const { tempRecord, defValues } = this;
|
this.setSelectOptions();
|
// defValues.financialType = '01'
|
for (let key in defValues) {
|
for (let tempKey in tempRecord) {
|
if (key === tempKey) {
|
defValues[key] = tempRecord[tempKey];
|
}
|
}
|
}
|
this.serialno = tempRecord.serialno;
|
},
|
// 删除按钮回调事件
|
clickDelete(index) {
|
if (index === 0) {
|
this.isDelete = false;
|
} else {
|
this.toDelete();
|
}
|
},
|
|
async toDelete() {
|
const { tempRecord } = this;
|
const { serialno } = tempRecord;
|
try {
|
await delFinancialData({ serialno });
|
this.$message.success("删除成功");
|
this.isDelete = false;
|
this.init();
|
} catch (error) {
|
this.isDelete = false;
|
}
|
}
|
}
|
};
|
</script>
|
|
<style lang="less" scoped>
|
.other-share-holder {
|
& .add-button {
|
margin-bottom: 20px;
|
}
|
& .stock_dialog {
|
& .el-dialog__footer {
|
& .dialog-footer {
|
& .el-button--default {
|
width: 120px;
|
height: 30px;
|
line-height: 7px;
|
border-radius: 4px;
|
border: 1px solid rgba(204, 204, 204, 1);
|
}
|
& .el-button--primary {
|
width: 120px;
|
height: 30px;
|
line-height: 7px;
|
background: #0081f0;
|
border-color: #0081f0;
|
border-radius: 4px;
|
margin-left: 40px;
|
}
|
}
|
}
|
}
|
}
|
</style>
|