| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- <template>
- <ele-modal
- custom-class="ele-dialog-form long-dialog-form"
- :centered="true"
- :visible="visible"
- :title="title"
- :append-to-body="true"
- :close-on-click-modal="false"
- :maxable="true"
- :resizable="true"
- width="85%"
- :before-close="cancel"
- >
- <div v-loading="loading">
- <headerTitle title="基本信息" style="margin-top: 30px"></headerTitle>
- <el-form ref="form" :model="dataForm" :rules="rules" label-width="120px">
- <el-row>
- <el-col :span="8">
- <el-form-item label="会计科目:" prop="accountingSubjectId">
- <ele-tree-select
- clearable
- :disabled="dialogType == 'view'"
- filterable
- ref="treeSelect"
- :data="accountingSubjectList"
- v-model="dataForm.accountingSubjectId"
- valueKey="id"
- labelKey="name"
- placeholder="请选择"
- @change="changeSubjectInfo"
- default-expand-all
- />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="应付日期" prop="payableDate">
- <el-date-picker
- :disabled="dialogType == 'view'"
- v-model="dataForm.payableDate"
- value-format="yyyy-MM-dd"
- type="date"
- style="width: 100%"
- >
- </el-date-picker>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="payableTotalPrice" label="应付金额">
- <!-- 无来源应付没有对账明细,应付金额 = 物品清单合计 -->
- <el-input :disabled="true" v-model="dataForm.payableTotalPrice"></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="8">
- <el-form-item prop="invoiceCode" label="发票编码">
- <!-- 发票编码/发票号/发票种类、来源编码一律带出,新增和修改都不能改 -->
- <el-input disabled v-model="dataForm.invoiceCode"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="invoiceNos" label="发票号">
- <el-input disabled v-model="dataForm.invoiceNos"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="invoiceCategory" label="发票种类">
- <el-select
- disabled
- clearable
- class="ele-block"
- v-model="dataForm.invoiceCategory"
- placeholder="请选择"
- >
- <el-option label="增值税专用发票" :value="1"></el-option>
- <el-option label="增值税普通发票" :value="2"></el-option>
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="8">
- <el-form-item prop="contactName" label="供应商名称">
- <!-- 无来源应付没有源单带出往来单位,需要手工选择 -->
- <el-input
- v-model="dataForm.contactName"
- placeholder="请选择"
- readonly
- @click.native="$refs.parentRef.open()"
- ></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="来源类型" prop="sourceType">
- <!-- 无来源应付的来源类型固定为「无来源」,不可改 -->
- <el-select
- :disabled="true"
- clearable
- class="ele-block"
- v-model="dataForm.sourceType"
- placeholder="请选择"
- >
- <el-option
- v-for="item in sourceTypeOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="sourceCode" label="来源编码">
- <el-input disabled v-model="dataForm.sourceCode"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="billDirection" label="方向">
- <!-- 单据方向由后端按生成/金额符号确定,页面仅展示不可改 -->
- <el-select
- :disabled="true"
- clearable
- class="ele-block"
- v-model="dataForm.billDirection"
- placeholder="请选择"
- >
- <el-option
- v-for="item in finBillDirectionOp"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="8">
- <el-form-item prop="paymentType" label="款项类型">
- <el-select
- :disabled="dialogType == 'view'"
- clearable
- class="ele-block"
- v-model="dataForm.paymentType"
- placeholder="请选择"
- >
- <el-option
- v-for="item in paymentTypeOp"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="remark" label="备注">
- <el-input :disabled="dialogType == 'view'" v-model="dataForm.remark"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="files" label="附件">
- <fileMain v-model="dataForm.files" :type="dialogType == 'view' ? 'view' : 'add'"></fileMain>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <!-- 物品清单:无来源应付没有对账单,明细手工录入(与发票「其他无订单无合同」同一张表) -->
- <headerTitle title="关联物品清单信息" style="margin-top: 30px"></headerTitle>
- <table-info
- ref="productTableRef"
- :dialogType="dialogType"
- @setPrice="setPayableTotalPrice"
- ></table-info>
- </div>
- <!-- 供应商选择(无来源应付) -->
- <parentList ref="parentRef" :classType="2" @changeParent="changeParent"></parentList>
- <div slot="footer" class="footer">
- <el-button
- v-if="dialogType !== 'view'"
- type="primary"
- @click="save"
- v-click-once
- >保存
- </el-button>
- <el-button
- v-if="dialogType !== 'view'"
- type="primary"
- @click="save('sub')"
- v-click-once
- >提交
- </el-button>
- <el-button @click="cancel">返回</el-button>
- </div>
- <process-submit-dialog
- :processSubmitDialogFlag.sync="processSubmitDialogFlag"
- v-if="processSubmitDialogFlag"
- ref="processSubmitDialogRef"
- @reload="reload"
- ></process-submit-dialog>
- </ele-modal>
- </template>
- <script>
- import tableInfo from '@/views/financialManage/invoiceManage/components/tableInfo.vue';
- import parentList from '@/views/purchasingManage/supplierManage/components/parentList.vue';
- import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
- import { getFinPayableInfoAPI, createPayableAPI, updatePayableAPI } from '@/api/financialManage/payableManage';
- import { getTreeByPid } from '@/api/classifyManage';
- import { paymentTypeOp, payAndReceiveEnum, manualPayableSourceType, finBillDirectionEnum } from '@/enum/dict';
- // 应付表单初始值
- const getDefaultDataForm = () => ({
- id: '',
- code: '',
- accountingSubjectId: '',
- accountingSubjectCode: '',
- accountingSubjectName: '',
- contactId: '',
- contactName: '',
- customerNo: '',
- payableDate: '',
- payableTotalPrice: '',
- paidTotalPrice: 0,
- unpaidTotalPrice: 0,
- invoiceCode: '',
- invoiceNos: '',
- invoiceCategory: '',
- invoiceId: '',
- invoiceStatus: 0,
- invoiceAmount: 0,
- unInvoiceAmount: 0,
- sourceType: manualPayableSourceType,
- sourceId: '',
- sourceCode: '',
- sourceName: '',
- paymentType: '',
- remark: '',
- files: [],
- // 付款状态 0未付款 1部分付款 2已付全款
- status: 0,
- // 审核状态 0未提交 1审核中 2审核通过 3审核不通过
- approvalStatus: 0
- });
- export default {
- name: 'addPayableDialog',
- components: {
- processSubmitDialog,
- parentList,
- tableInfo
- },
- props: {
- visible: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- paymentTypeOp,
- payAndReceiveEnum,
- finBillDirectionOp: finBillDirectionEnum,
- loading: false,
- saveLoading: false,
- datasource: [],
- accountingSubjectList: [],
- dataForm: getDefaultDataForm(),
- rules: {
- accountingSubjectId: { required: true, message: '请选择', trigger: 'change' },
- payableDate: { required: true, message: '请选择', trigger: 'change' },
- contactName: { required: true, message: '请选择供应商名称', trigger: 'change' },
- paymentType: { required: true, message: '请选择款项类型', trigger: 'change' }
- },
- title: '',
- processSubmitDialogFlag: false,
- dialogType: '',
- businessId: '',
- // 无来源应付已付/已开票金额(新增时为 0,修改时取接口返回值)
- savedAmount: {
- paidTotalPrice: 0,
- invoiceAmount: 0
- }
- };
- },
- computed: {
- // 来源类型:手工新增的应付只能是「无来源」
- sourceTypeOptions() {
- const options = payAndReceiveEnum.map((item) =>
- item.value === manualPayableSourceType
- ? { ...item, label: '无来源' }
- : item
- );
- return options.filter((item) => item.value === manualPayableSourceType);
- }
- },
- methods: {
- changeSubjectInfo(val) {
- // ele-tree-select 不会派发 el.form.change,表单不会自动重新校验,这里手动触发一次
- const node = this.$refs.treeSelect?.getNodeByValue?.(val) || {};
- this.dataForm.accountingSubjectCode = node.code || '';
- this.dataForm.accountingSubjectName = node.name || '';
- this.$refs.form && this.$refs.form.validateField('accountingSubjectId');
- },
- //获取分类管理中的数据
- async getClassifyList(id, listName) {
- let res = await getTreeByPid(id);
- this[listName] = res.data;
- },
- // 选择供应商(无来源应付)
- changeParent(obj = {}) {
- this.dataForm.contactName = obj.name || '';
- this.dataForm.contactId = obj.id || '';
- this.dataForm.customerNo = obj.code || '';
- // 组件是只读的,change 事件不会触发,手动校验一次去掉红字提示
- this.$refs.form && this.$refs.form.validateField('contactName');
- },
- // 物品清单合计 -> 应付金额
- setPayableTotalPrice(val) {
- this.dataForm.payableTotalPrice = val;
- },
- // 无来源应付的物品清单(提交用)
- getProductList() {
- const list = this.$refs.productTableRef?.getDetailList?.() || [];
- // 明细上带出往来单位(后端明细表里的客户/供应商字段)
- return list.map((item) => ({
- ...item,
- customerId: this.dataForm.contactId || undefined,
- customerNo: this.dataForm.customerNo || undefined,
- customerName: this.dataForm.contactName || undefined
- }));
- },
- // 按名称在会计科目树里找节点
- findSubjectNodes(list, name, result = []) {
- for (let item of list || []) {
- if (item.name === name) result.push(item);
- this.findSubjectNodes(item.children, name, result);
- }
- return result;
- },
- // 按科目编码在会计科目树里找节点
- findSubjectByCode(list, code) {
- for (let item of list || []) {
- if (item.code == code) return item;
- const child = this.findSubjectByCode(item.children, code);
- if (child) return child;
- }
- return null;
- },
- // 默认会计科目:应付账款
- setDefaultSubject() {
- const nodes = this.findSubjectNodes(
- this.accountingSubjectList,
- '应付账款'
- );
- // 同名优先取编码为 2202 的节点
- let subject = nodes.find((item) => item.code == '2202') || nodes[0];
- // 名称对不上时退而按科目编码 2202(应付账款)找
- if (!subject) {
- subject = this.findSubjectByCode(this.accountingSubjectList, '2202');
- }
- if (!subject) {
- console.warn('未找到会计科目「应付账款」,请手工选择');
- return;
- }
- this.dataForm.accountingSubjectId = subject.id;
- this.dataForm.accountingSubjectCode = subject.code;
- this.dataForm.accountingSubjectName = subject.name;
- },
- // open(dialogType, row)
- // 手工新增的应付(无来源):没有源单、没有对账明细,明细手工录入
- async open(dialogType, row = {}) {
- this.dialogType = dialogType;
- this.title =
- dialogType == 'add'
- ? '新增'
- : dialogType == 'update'
- ? '修改'
- : '详情';
- await this.getClassifyList(24, 'accountingSubjectList');
- this.dataForm = getDefaultDataForm();
- this.savedAmount = { paidTotalPrice: 0, invoiceAmount: 0 };
- this.datasource = [];
- if (dialogType == 'update' && row.id) {
- this.businessId = row.id;
- await this.getInfo(row);
- // 回填物品清单(静默:不改已保存的应付金额,用户改明细时才重算)
- this.$nextTick(() => {
- this.$refs.productTableRef?.setDetailList(this.datasource || [], true);
- });
- } else {
- this.businessId = '';
- // 会计科目默认应付账款
- this.setDefaultSubject();
- }
- // 打开时清掉上一次的校验提示
- this.$nextTick(() => {
- this.$refs.form && this.$refs.form.clearValidate();
- });
- },
- //获取应付详情
- async getInfo(row) {
- const data = await getFinPayableInfoAPI(row.id);
- this.dataForm = {
- ...this.dataForm,
- ...data,
- invoiceCategory: Number(data?.invoiceCategory) || '',
- // 无来源应付不带源单(来源类型固定「无来源」,来源编码为空)
- sourceId: '',
- sourceCode: '',
- sourceType: manualPayableSourceType
- };
- this.savedAmount = {
- paidTotalPrice: +data?.paidTotalPrice || 0,
- invoiceAmount: +data?.invoiceAmount || 0
- };
- this.datasource = data.productList || [];
- this.$forceUpdate();
- },
- //关闭弹窗
- cancel() {
- this.$emit('update:visible', false);
- },
- //保存
- async save(is) {
- // 基本信息必填项校验
- const valid = await this.$refs.form.validate().catch(() => false);
- if (!valid) return;
- // 物品清单:至少一行,且数量/折让比例等行内校验要过
- const tableRef = this.$refs.productTableRef;
- if (tableRef) {
- const detailValid = await new Promise((resolve) => tableRef.validateForm(resolve));
- if (!detailValid) return;
- if (!this.getProductList().length) {
- return this.$message.warning('请添加物品清单明细');
- }
- }
- const payableTotalPrice = +this.dataForm.payableTotalPrice || 0;
- if (payableTotalPrice <= 0) {
- return this.$message.warning('应付金额需大于 0,请填写物品清单明细');
- }
- try {
- // 已付/已开票:新增时是 0,修改时沿用接口返回值
- const paidTotalPrice = this.savedAmount.paidTotalPrice;
- const invoiceAmount = this.savedAmount.invoiceAmount;
- const params = {
- id: this.dataForm.id || undefined,
- // 应付编码:新增时留空由后端生成(同预收/预付),修改时回传原编码
- code: this.dataForm.code || '',
- accountingSubjectId: this.dataForm.accountingSubjectId,
- accountingSubjectCode: this.dataForm.accountingSubjectCode,
- accountingSubjectName: this.dataForm.accountingSubjectName,
- contactId: this.dataForm.contactId,
- contactName: this.dataForm.contactName,
- payableDate: this.dataForm.payableDate,
- payableTotalPrice,
- paidTotalPrice,
- // 未付金额 = 应付金额 - 已付金额
- unpaidTotalPrice: payableTotalPrice - paidTotalPrice,
- invoiceAmount,
- // 未开票金额 = 应付金额 - 已开票金额
- unInvoiceAmount: payableTotalPrice - invoiceAmount,
- invoiceCode: this.dataForm.invoiceCode || '',
- invoiceId: this.dataForm.invoiceId || null,
- invoiceStatus: this.dataForm.invoiceStatus ?? 0,
- // 来源类型固定「无来源」,不挂源单
- sourceType: manualPayableSourceType,
- sourceId: '',
- sourceCode: '',
- sourceName: '',
- paymentType: this.dataForm.paymentType,
- remark: this.dataForm.remark,
- files: this.dataForm.files || [],
- status: this.dataForm.status ?? 0,
- approvalStatus: this.dataForm.approvalStatus ?? 0,
- productList: this.getProductList()
- };
- const api =
- this.dialogType == 'add' ? createPayableAPI : updatePayableAPI;
- this.saveLoading = true;
- const data = await api(params);
- this.saveLoading = false;
- if (is == 'sub') {
- await this.submitApprove(data);
- return;
- }
- this.$message.success('操作成功');
- this.reload();
- } catch (error) {
- console.error('保存失败:', error);
- this.saveLoading = false;
- }
- },
- // 保存后提交审批
- async submitApprove(res) {
- // 新增(create)返回新单 id,修改(update)返回空对象,用 businessId 兜底
- const id = this.businessId || (res && typeof res === 'object' ? res.id : res);
- const data = await getFinPayableInfoAPI(id);
- this.processSubmitDialogFlag = true;
- this.$nextTick(() => {
- let params = {
- businessId: data.id,
- businessKey: 'fin_payable_approve',
- formCreateUserId: data.createUserId,
- variables: {
- businessCode: data.code,
- businessName: data.contactName,
- businessType: '应付'
- }
- };
- this.$refs.processSubmitDialogRef.init(params);
- });
- },
- reload() {
- this.cancel();
- //刷新主页面
- this.$emit('done');
- }
- }
- };
- </script>
- <style scoped lang="scss">
- ::v-deep.el-divider {
- margin: 10px;
- font-weight: bold;
- }
- </style>
|