addPayableDialog.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible="visible"
  6. :title="title"
  7. :append-to-body="true"
  8. :close-on-click-modal="false"
  9. :maxable="true"
  10. :resizable="true"
  11. width="85%"
  12. :before-close="cancel"
  13. >
  14. <div v-loading="loading">
  15. <headerTitle title="基本信息" style="margin-top: 30px"></headerTitle>
  16. <el-form ref="form" :model="dataForm" :rules="rules" label-width="120px">
  17. <el-row>
  18. <el-col :span="8">
  19. <el-form-item label="会计科目:" prop="accountingSubjectId">
  20. <ele-tree-select
  21. clearable
  22. :disabled="dialogType == 'view'"
  23. filterable
  24. ref="treeSelect"
  25. :data="accountingSubjectList"
  26. v-model="dataForm.accountingSubjectId"
  27. valueKey="id"
  28. labelKey="name"
  29. placeholder="请选择"
  30. @change="changeSubjectInfo"
  31. default-expand-all
  32. />
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="8">
  36. <el-form-item label="应付日期" prop="payableDate">
  37. <el-date-picker
  38. :disabled="dialogType == 'view'"
  39. v-model="dataForm.payableDate"
  40. value-format="yyyy-MM-dd"
  41. type="date"
  42. style="width: 100%"
  43. >
  44. </el-date-picker>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="8">
  48. <el-form-item prop="payableTotalPrice" label="应付金额">
  49. <!-- 无来源应付没有对账明细,应付金额 = 物品清单合计 -->
  50. <el-input :disabled="true" v-model="dataForm.payableTotalPrice"></el-input>
  51. </el-form-item>
  52. </el-col>
  53. </el-row>
  54. <el-row>
  55. <el-col :span="8">
  56. <el-form-item prop="invoiceCode" label="发票编码">
  57. <!-- 发票编码/发票号/发票种类、来源编码一律带出,新增和修改都不能改 -->
  58. <el-input disabled v-model="dataForm.invoiceCode"></el-input>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="8">
  62. <el-form-item prop="invoiceNos" label="发票号">
  63. <el-input disabled v-model="dataForm.invoiceNos"></el-input>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="8">
  67. <el-form-item prop="invoiceCategory" label="发票种类">
  68. <el-select
  69. disabled
  70. clearable
  71. class="ele-block"
  72. v-model="dataForm.invoiceCategory"
  73. placeholder="请选择"
  74. >
  75. <el-option label="增值税专用发票" :value="1"></el-option>
  76. <el-option label="增值税普通发票" :value="2"></el-option>
  77. </el-select>
  78. </el-form-item>
  79. </el-col>
  80. </el-row>
  81. <el-row>
  82. <el-col :span="8">
  83. <el-form-item prop="contactName" label="供应商名称">
  84. <!-- 无来源应付没有源单带出往来单位,需要手工选择 -->
  85. <el-input
  86. v-model="dataForm.contactName"
  87. placeholder="请选择"
  88. readonly
  89. @click.native="$refs.parentRef.open()"
  90. ></el-input>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="8">
  94. <el-form-item label="来源类型" prop="sourceType">
  95. <!-- 无来源应付的来源类型固定为「无来源」,不可改 -->
  96. <el-select
  97. :disabled="true"
  98. clearable
  99. class="ele-block"
  100. v-model="dataForm.sourceType"
  101. placeholder="请选择"
  102. >
  103. <el-option
  104. v-for="item in sourceTypeOptions"
  105. :key="item.value"
  106. :label="item.label"
  107. :value="item.value"
  108. />
  109. </el-select>
  110. </el-form-item>
  111. </el-col>
  112. <el-col :span="8">
  113. <el-form-item prop="sourceCode" label="来源编码">
  114. <el-input disabled v-model="dataForm.sourceCode"></el-input>
  115. </el-form-item>
  116. </el-col>
  117. <el-col :span="8">
  118. <el-form-item prop="billDirection" label="方向">
  119. <!-- 单据方向由后端按生成/金额符号确定,页面仅展示不可改 -->
  120. <el-select
  121. :disabled="true"
  122. clearable
  123. class="ele-block"
  124. v-model="dataForm.billDirection"
  125. placeholder="请选择"
  126. >
  127. <el-option
  128. v-for="item in finBillDirectionOp"
  129. :key="item.value"
  130. :label="item.label"
  131. :value="item.value"
  132. />
  133. </el-select>
  134. </el-form-item>
  135. </el-col>
  136. </el-row>
  137. <el-row>
  138. <el-col :span="8">
  139. <el-form-item prop="paymentType" label="款项类型">
  140. <el-select
  141. :disabled="dialogType == 'view'"
  142. clearable
  143. class="ele-block"
  144. v-model="dataForm.paymentType"
  145. placeholder="请选择"
  146. >
  147. <el-option
  148. v-for="item in paymentTypeOp"
  149. :key="item.value"
  150. :label="item.label"
  151. :value="item.value"
  152. />
  153. </el-select>
  154. </el-form-item>
  155. </el-col>
  156. <el-col :span="8">
  157. <el-form-item prop="remark" label="备注">
  158. <el-input :disabled="dialogType == 'view'" v-model="dataForm.remark"></el-input>
  159. </el-form-item>
  160. </el-col>
  161. <el-col :span="8">
  162. <el-form-item prop="files" label="附件">
  163. <fileMain v-model="dataForm.files" :type="dialogType == 'view' ? 'view' : 'add'"></fileMain>
  164. </el-form-item>
  165. </el-col>
  166. </el-row>
  167. </el-form>
  168. <!-- 物品清单:无来源应付没有对账单,明细手工录入(与发票「其他无订单无合同」同一张表) -->
  169. <headerTitle title="关联物品清单信息" style="margin-top: 30px"></headerTitle>
  170. <table-info
  171. ref="productTableRef"
  172. :dialogType="dialogType"
  173. @setPrice="setPayableTotalPrice"
  174. ></table-info>
  175. </div>
  176. <!-- 供应商选择(无来源应付) -->
  177. <parentList ref="parentRef" :classType="2" @changeParent="changeParent"></parentList>
  178. <div slot="footer" class="footer">
  179. <el-button
  180. v-if="dialogType !== 'view'"
  181. type="primary"
  182. @click="save"
  183. v-click-once
  184. >保存
  185. </el-button>
  186. <el-button
  187. v-if="dialogType !== 'view'"
  188. type="primary"
  189. @click="save('sub')"
  190. v-click-once
  191. >提交
  192. </el-button>
  193. <el-button @click="cancel">返回</el-button>
  194. </div>
  195. <process-submit-dialog
  196. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  197. v-if="processSubmitDialogFlag"
  198. ref="processSubmitDialogRef"
  199. @reload="reload"
  200. ></process-submit-dialog>
  201. </ele-modal>
  202. </template>
  203. <script>
  204. import tableInfo from '@/views/financialManage/invoiceManage/components/tableInfo.vue';
  205. import parentList from '@/views/purchasingManage/supplierManage/components/parentList.vue';
  206. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  207. import { getFinPayableInfoAPI, createPayableAPI, updatePayableAPI } from '@/api/financialManage/payableManage';
  208. import { getTreeByPid } from '@/api/classifyManage';
  209. import { paymentTypeOp, payAndReceiveEnum, manualPayableSourceType, finBillDirectionEnum } from '@/enum/dict';
  210. // 应付表单初始值
  211. const getDefaultDataForm = () => ({
  212. id: '',
  213. code: '',
  214. accountingSubjectId: '',
  215. accountingSubjectCode: '',
  216. accountingSubjectName: '',
  217. contactId: '',
  218. contactName: '',
  219. customerNo: '',
  220. payableDate: '',
  221. payableTotalPrice: '',
  222. paidTotalPrice: 0,
  223. unpaidTotalPrice: 0,
  224. invoiceCode: '',
  225. invoiceNos: '',
  226. invoiceCategory: '',
  227. invoiceId: '',
  228. invoiceStatus: 0,
  229. invoiceAmount: 0,
  230. unInvoiceAmount: 0,
  231. sourceType: manualPayableSourceType,
  232. sourceId: '',
  233. sourceCode: '',
  234. sourceName: '',
  235. paymentType: '',
  236. remark: '',
  237. files: [],
  238. // 付款状态 0未付款 1部分付款 2已付全款
  239. status: 0,
  240. // 审核状态 0未提交 1审核中 2审核通过 3审核不通过
  241. approvalStatus: 0
  242. });
  243. export default {
  244. name: 'addPayableDialog',
  245. components: {
  246. processSubmitDialog,
  247. parentList,
  248. tableInfo
  249. },
  250. props: {
  251. visible: {
  252. type: Boolean,
  253. default: false
  254. }
  255. },
  256. data() {
  257. return {
  258. paymentTypeOp,
  259. payAndReceiveEnum,
  260. finBillDirectionOp: finBillDirectionEnum,
  261. loading: false,
  262. saveLoading: false,
  263. datasource: [],
  264. accountingSubjectList: [],
  265. dataForm: getDefaultDataForm(),
  266. rules: {
  267. accountingSubjectId: { required: true, message: '请选择', trigger: 'change' },
  268. payableDate: { required: true, message: '请选择', trigger: 'change' },
  269. contactName: { required: true, message: '请选择供应商名称', trigger: 'change' },
  270. paymentType: { required: true, message: '请选择款项类型', trigger: 'change' }
  271. },
  272. title: '',
  273. processSubmitDialogFlag: false,
  274. dialogType: '',
  275. businessId: '',
  276. // 无来源应付已付/已开票金额(新增时为 0,修改时取接口返回值)
  277. savedAmount: {
  278. paidTotalPrice: 0,
  279. invoiceAmount: 0
  280. }
  281. };
  282. },
  283. computed: {
  284. // 来源类型:手工新增的应付只能是「无来源」
  285. sourceTypeOptions() {
  286. const options = payAndReceiveEnum.map((item) =>
  287. item.value === manualPayableSourceType
  288. ? { ...item, label: '无来源' }
  289. : item
  290. );
  291. return options.filter((item) => item.value === manualPayableSourceType);
  292. }
  293. },
  294. methods: {
  295. changeSubjectInfo(val) {
  296. // ele-tree-select 不会派发 el.form.change,表单不会自动重新校验,这里手动触发一次
  297. const node = this.$refs.treeSelect?.getNodeByValue?.(val) || {};
  298. this.dataForm.accountingSubjectCode = node.code || '';
  299. this.dataForm.accountingSubjectName = node.name || '';
  300. this.$refs.form && this.$refs.form.validateField('accountingSubjectId');
  301. },
  302. //获取分类管理中的数据
  303. async getClassifyList(id, listName) {
  304. let res = await getTreeByPid(id);
  305. this[listName] = res.data;
  306. },
  307. // 选择供应商(无来源应付)
  308. changeParent(obj = {}) {
  309. this.dataForm.contactName = obj.name || '';
  310. this.dataForm.contactId = obj.id || '';
  311. this.dataForm.customerNo = obj.code || '';
  312. // 组件是只读的,change 事件不会触发,手动校验一次去掉红字提示
  313. this.$refs.form && this.$refs.form.validateField('contactName');
  314. },
  315. // 物品清单合计 -> 应付金额
  316. setPayableTotalPrice(val) {
  317. this.dataForm.payableTotalPrice = val;
  318. },
  319. // 无来源应付的物品清单(提交用)
  320. getProductList() {
  321. const list = this.$refs.productTableRef?.getDetailList?.() || [];
  322. // 明细上带出往来单位(后端明细表里的客户/供应商字段)
  323. return list.map((item) => ({
  324. ...item,
  325. customerId: this.dataForm.contactId || undefined,
  326. customerNo: this.dataForm.customerNo || undefined,
  327. customerName: this.dataForm.contactName || undefined
  328. }));
  329. },
  330. // 按名称在会计科目树里找节点
  331. findSubjectNodes(list, name, result = []) {
  332. for (let item of list || []) {
  333. if (item.name === name) result.push(item);
  334. this.findSubjectNodes(item.children, name, result);
  335. }
  336. return result;
  337. },
  338. // 按科目编码在会计科目树里找节点
  339. findSubjectByCode(list, code) {
  340. for (let item of list || []) {
  341. if (item.code == code) return item;
  342. const child = this.findSubjectByCode(item.children, code);
  343. if (child) return child;
  344. }
  345. return null;
  346. },
  347. // 默认会计科目:应付账款
  348. setDefaultSubject() {
  349. const nodes = this.findSubjectNodes(
  350. this.accountingSubjectList,
  351. '应付账款'
  352. );
  353. // 同名优先取编码为 2202 的节点
  354. let subject = nodes.find((item) => item.code == '2202') || nodes[0];
  355. // 名称对不上时退而按科目编码 2202(应付账款)找
  356. if (!subject) {
  357. subject = this.findSubjectByCode(this.accountingSubjectList, '2202');
  358. }
  359. if (!subject) {
  360. console.warn('未找到会计科目「应付账款」,请手工选择');
  361. return;
  362. }
  363. this.dataForm.accountingSubjectId = subject.id;
  364. this.dataForm.accountingSubjectCode = subject.code;
  365. this.dataForm.accountingSubjectName = subject.name;
  366. },
  367. // open(dialogType, row)
  368. // 手工新增的应付(无来源):没有源单、没有对账明细,明细手工录入
  369. async open(dialogType, row = {}) {
  370. this.dialogType = dialogType;
  371. this.title =
  372. dialogType == 'add'
  373. ? '新增'
  374. : dialogType == 'update'
  375. ? '修改'
  376. : '详情';
  377. await this.getClassifyList(24, 'accountingSubjectList');
  378. this.dataForm = getDefaultDataForm();
  379. this.savedAmount = { paidTotalPrice: 0, invoiceAmount: 0 };
  380. this.datasource = [];
  381. if (dialogType == 'update' && row.id) {
  382. this.businessId = row.id;
  383. await this.getInfo(row);
  384. // 回填物品清单(静默:不改已保存的应付金额,用户改明细时才重算)
  385. this.$nextTick(() => {
  386. this.$refs.productTableRef?.setDetailList(this.datasource || [], true);
  387. });
  388. } else {
  389. this.businessId = '';
  390. // 会计科目默认应付账款
  391. this.setDefaultSubject();
  392. }
  393. // 打开时清掉上一次的校验提示
  394. this.$nextTick(() => {
  395. this.$refs.form && this.$refs.form.clearValidate();
  396. });
  397. },
  398. //获取应付详情
  399. async getInfo(row) {
  400. const data = await getFinPayableInfoAPI(row.id);
  401. this.dataForm = {
  402. ...this.dataForm,
  403. ...data,
  404. invoiceCategory: Number(data?.invoiceCategory) || '',
  405. // 无来源应付不带源单(来源类型固定「无来源」,来源编码为空)
  406. sourceId: '',
  407. sourceCode: '',
  408. sourceType: manualPayableSourceType
  409. };
  410. this.savedAmount = {
  411. paidTotalPrice: +data?.paidTotalPrice || 0,
  412. invoiceAmount: +data?.invoiceAmount || 0
  413. };
  414. this.datasource = data.productList || [];
  415. this.$forceUpdate();
  416. },
  417. //关闭弹窗
  418. cancel() {
  419. this.$emit('update:visible', false);
  420. },
  421. //保存
  422. async save(is) {
  423. // 基本信息必填项校验
  424. const valid = await this.$refs.form.validate().catch(() => false);
  425. if (!valid) return;
  426. // 物品清单:至少一行,且数量/折让比例等行内校验要过
  427. const tableRef = this.$refs.productTableRef;
  428. if (tableRef) {
  429. const detailValid = await new Promise((resolve) => tableRef.validateForm(resolve));
  430. if (!detailValid) return;
  431. if (!this.getProductList().length) {
  432. return this.$message.warning('请添加物品清单明细');
  433. }
  434. }
  435. const payableTotalPrice = +this.dataForm.payableTotalPrice || 0;
  436. if (payableTotalPrice <= 0) {
  437. return this.$message.warning('应付金额需大于 0,请填写物品清单明细');
  438. }
  439. try {
  440. // 已付/已开票:新增时是 0,修改时沿用接口返回值
  441. const paidTotalPrice = this.savedAmount.paidTotalPrice;
  442. const invoiceAmount = this.savedAmount.invoiceAmount;
  443. const params = {
  444. id: this.dataForm.id || undefined,
  445. // 应付编码:新增时留空由后端生成(同预收/预付),修改时回传原编码
  446. code: this.dataForm.code || '',
  447. accountingSubjectId: this.dataForm.accountingSubjectId,
  448. accountingSubjectCode: this.dataForm.accountingSubjectCode,
  449. accountingSubjectName: this.dataForm.accountingSubjectName,
  450. contactId: this.dataForm.contactId,
  451. contactName: this.dataForm.contactName,
  452. payableDate: this.dataForm.payableDate,
  453. payableTotalPrice,
  454. paidTotalPrice,
  455. // 未付金额 = 应付金额 - 已付金额
  456. unpaidTotalPrice: payableTotalPrice - paidTotalPrice,
  457. invoiceAmount,
  458. // 未开票金额 = 应付金额 - 已开票金额
  459. unInvoiceAmount: payableTotalPrice - invoiceAmount,
  460. invoiceCode: this.dataForm.invoiceCode || '',
  461. invoiceId: this.dataForm.invoiceId || null,
  462. invoiceStatus: this.dataForm.invoiceStatus ?? 0,
  463. // 来源类型固定「无来源」,不挂源单
  464. sourceType: manualPayableSourceType,
  465. sourceId: '',
  466. sourceCode: '',
  467. sourceName: '',
  468. paymentType: this.dataForm.paymentType,
  469. remark: this.dataForm.remark,
  470. files: this.dataForm.files || [],
  471. status: this.dataForm.status ?? 0,
  472. approvalStatus: this.dataForm.approvalStatus ?? 0,
  473. productList: this.getProductList()
  474. };
  475. const api =
  476. this.dialogType == 'add' ? createPayableAPI : updatePayableAPI;
  477. this.saveLoading = true;
  478. const data = await api(params);
  479. this.saveLoading = false;
  480. if (is == 'sub') {
  481. await this.submitApprove(data);
  482. return;
  483. }
  484. this.$message.success('操作成功');
  485. this.reload();
  486. } catch (error) {
  487. console.error('保存失败:', error);
  488. this.saveLoading = false;
  489. }
  490. },
  491. // 保存后提交审批
  492. async submitApprove(res) {
  493. // 新增(create)返回新单 id,修改(update)返回空对象,用 businessId 兜底
  494. const id = this.businessId || (res && typeof res === 'object' ? res.id : res);
  495. const data = await getFinPayableInfoAPI(id);
  496. this.processSubmitDialogFlag = true;
  497. this.$nextTick(() => {
  498. let params = {
  499. businessId: data.id,
  500. businessKey: 'fin_payable_approve',
  501. formCreateUserId: data.createUserId,
  502. variables: {
  503. businessCode: data.code,
  504. businessName: data.contactName,
  505. businessType: '应付'
  506. }
  507. };
  508. this.$refs.processSubmitDialogRef.init(params);
  509. });
  510. },
  511. reload() {
  512. this.cancel();
  513. //刷新主页面
  514. this.$emit('done');
  515. }
  516. }
  517. };
  518. </script>
  519. <style scoped lang="scss">
  520. ::v-deep.el-divider {
  521. margin: 10px;
  522. font-weight: bold;
  523. }
  524. </style>