addOrEditDialogNew.vue 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="addOrEditDialogFlag"
  6. :title="title"
  7. :append-to-body="true"
  8. :close-on-click-modal="false"
  9. width="70%"
  10. :before-close="cancel"
  11. :maxable="true"
  12. :resizable="true"
  13. >
  14. <el-form
  15. ref="form"
  16. :rules="rules"
  17. class="el-form-box-add"
  18. :model="form"
  19. label-width="160px"
  20. >
  21. <headerTitle title="基本信息"></headerTitle>
  22. <el-row :gutter="12">
  23. <el-col :span="8">
  24. <el-form-item label="发票类型" prop="type">
  25. <el-select
  26. v-model="form.type"
  27. @change="handleSelType('isType')"
  28. clearable
  29. :disabled="!isEditType"
  30. style="width: 100%"
  31. >
  32. <el-option label="开票" :value="1"></el-option>
  33. <el-option label="收票" :value="2"></el-option>
  34. </el-select>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="8" v-if="form.type">
  38. <el-form-item label="来源类型" prop="sourceType">
  39. <el-select
  40. v-model="form.sourceType"
  41. @change="handleSelType('sourceType')"
  42. :disabled="!isEditType || isDisabledType"
  43. clearable
  44. style="width: 100%"
  45. >
  46. <el-option v-for="item in sourceTypeOp" :label="item.label" :value="item.value" :key="item.value"></el-option>
  47. <!-- <el-option label="对账单" :value="1"></el-option>
  48. <el-option label="合同" :value="2"></el-option>
  49. <el-option label="订单" :value="3"></el-option> -->
  50. <!-- <el-option label="收款计划" :value="1"></el-option> -->
  51. <!-- <el-option
  52. label="已收"
  53. :value="5"
  54. v-if="form.type == 1"
  55. ></el-option>
  56. <el-option
  57. label="已付"
  58. :value="4"
  59. v-if="form.type == 2"
  60. ></el-option>
  61. <el-option label="其他无订单无合同" :value="99"></el-option> -->
  62. </el-select>
  63. </el-form-item>
  64. </el-col>
  65. <el-col :span="8" v-if="form.sourceType == 1">
  66. <el-form-item label="对账单" prop="sourceCode">
  67. <el-input
  68. v-model="form.sourceCode"
  69. readonly
  70. :disabled="dialogType === 'update'"
  71. @click.native="handleSelectAccount(1)"
  72. ></el-input>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="8" v-if="form.sourceType == 2">
  76. <el-form-item label="合同" prop="sourceCode">
  77. <el-input
  78. v-model="form.sourceCode"
  79. readonly
  80. @click.native="handleSelectAccount(2)"
  81. ></el-input>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="8" v-if="form.sourceType == 3">
  85. <el-form-item label="订单" prop="sourceCode">
  86. <el-input
  87. v-model="form.sourceCode"
  88. readonly
  89. @click.native="handleSelectAccount(3)"
  90. ></el-input>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="8" v-if="form.sourceType == 5">
  94. <el-form-item label="已收" prop="sourceCode">
  95. <el-input
  96. v-model="form.sourceCode"
  97. readonly
  98. @click.native="handleSelectAccount(5)"
  99. ></el-input>
  100. </el-form-item>
  101. </el-col>
  102. <el-col :span="8" v-if="form.sourceType == 4">
  103. <el-form-item label="已付" prop="sourceCode">
  104. <el-input
  105. v-model="form.sourceCode"
  106. readonly
  107. @click.native="handleSelectAccount(4)"
  108. ></el-input>
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="8">
  112. <el-form-item label="发票金额" prop="amount">
  113. <el-input
  114. type="number"
  115. v-model="form.amount"
  116. :precision="2"
  117. :controls="false"
  118. style="width: 100%"
  119. :disabled="Number(ifRedReversalInvoice) === 1"
  120. :min="0"
  121. >
  122. <template slot="append">
  123. <span>元</span>
  124. </template>
  125. </el-input>
  126. </el-form-item>
  127. </el-col>
  128. <el-col :span="8">
  129. <el-form-item label="发票号" prop="invoiceNos">
  130. <el-input
  131. v-model="form.invoiceNos"
  132. ></el-input>
  133. </el-form-item>
  134. </el-col>
  135. <el-col :span="8">
  136. <el-form-item label="开票日期">
  137. <el-date-picker
  138. style="width: 100%"
  139. v-model="form.expectInvoiceDate"
  140. type="date"
  141. value-format="yyyy-MM-dd"
  142. placeholder="选择日期"
  143. >
  144. </el-date-picker>
  145. </el-form-item>
  146. </el-col>
  147. <el-col :span="8">
  148. <el-form-item label="申请部门" prop="applyDeptId">
  149. <ele-tree-select
  150. clearable
  151. :data="deptTreeList"
  152. v-model="form.applyDeptId"
  153. valueKey="id"
  154. labelKey="name"
  155. placeholder="请选择"
  156. @change="changeDeptInfo"
  157. default-expand-all
  158. />
  159. </el-form-item>
  160. </el-col>
  161. <el-col :span="8">
  162. <el-form-item label="申请人" prop="applyUserId">
  163. <personSelect
  164. ref="directorRef"
  165. v-model="form.applyUserId"
  166. @selfChange="changeUserInfo"
  167. />
  168. </el-form-item>
  169. </el-col>
  170. <el-col :span="8">
  171. <el-form-item label="发票种类" prop="category">
  172. <el-select
  173. v-model="form.category"
  174. clearable
  175. style="width: 100%"
  176. >
  177. <el-option label="增值税专用发票" :value="1"></el-option>
  178. <el-option label="增值税普通发票" :value="2"></el-option>
  179. </el-select>
  180. </el-form-item>
  181. </el-col>
  182. <el-col :span="8">
  183. <el-form-item prop="files" label="发票附件">
  184. <fileMain v-model="form.files"></fileMain>
  185. </el-form-item>
  186. </el-col>
  187. </el-row>
  188. <headerTitle title="发票信息"></headerTitle>
  189. <el-row :gutter="12">
  190. <el-col :span="12">
  191. <el-form-item label="购买方名称" prop="companyName">
  192. <el-input
  193. v-model="form.companyName"
  194. placeholder="请输入"
  195. v-if="enterprisePage.length <= 1 || form.type == 1"
  196. />
  197. <el-select
  198. v-if="enterprisePage.length > 1 && form.type == 2"
  199. style="width: 100%"
  200. v-model="form.companyName"
  201. placeholder="请选择"
  202. @change="enterpriseChange"
  203. >
  204. <el-option
  205. v-for="item in enterprisePage"
  206. :key="item.id"
  207. :label="item.name"
  208. :value="item.name"
  209. >
  210. </el-option>
  211. </el-select>
  212. </el-form-item>
  213. <el-form-item
  214. label="统一社会信用代码"
  215. prop="companyUsc"
  216. class="form_item_label"
  217. >
  218. <el-input v-model="form.companyUsc"></el-input>
  219. </el-form-item>
  220. <el-form-item label="联系人" prop="companyContactName">
  221. <el-input v-model="form.companyContactName"></el-input>
  222. </el-form-item>
  223. <el-form-item label="电话" prop="companyTel">
  224. <el-input v-model="form.companyTel"></el-input>
  225. </el-form-item>
  226. <el-form-item label="银行账号" prop="companyBankAccount">
  227. <el-input v-model="form.companyBankAccount"></el-input>
  228. </el-form-item>
  229. <el-form-item label="开户行" prop="companyBankBranchNo">
  230. <el-input v-model="form.companyBankBranchNo"></el-input>
  231. </el-form-item>
  232. <el-form-item label="地址" prop="companyAddress">
  233. <el-input v-model="form.companyAddress"></el-input>
  234. </el-form-item>
  235. </el-col>
  236. <el-col :span="12">
  237. <el-form-item label="销售方名称" prop="receiverName">
  238. <el-input
  239. v-model="form.receiverName"
  240. placeholder="请输入"
  241. v-if="enterprisePage.length <= 1 || form.type == 2"
  242. />
  243. <el-select
  244. v-if="enterprisePage.length > 1 && form.type == 1"
  245. style="width: 100%"
  246. v-model="form.receiverName"
  247. placeholder="请选择"
  248. @change="enterpriseChange"
  249. >
  250. <el-option
  251. v-for="item in enterprisePage"
  252. :key="item.id"
  253. :label="item.name"
  254. :value="item.name"
  255. >
  256. </el-option>
  257. </el-select>
  258. </el-form-item>
  259. <el-form-item
  260. label="统一社会信用代码"
  261. prop="salesCompanyUsc"
  262. class="form_item_label"
  263. >
  264. <el-input v-model="form.salesCompanyUsc"></el-input>
  265. </el-form-item>
  266. <el-form-item label="联系人" prop="receiverContactName">
  267. <el-input v-model="form.receiverContactName"></el-input>
  268. </el-form-item>
  269. <el-form-item label="电话" prop="receiverTel">
  270. <el-input v-model="form.receiverTel"></el-input>
  271. </el-form-item>
  272. <el-form-item label="银行账号" prop="salesCompanyBankAccount">
  273. <el-input v-model="form.salesCompanyBankAccount"></el-input>
  274. </el-form-item>
  275. <el-form-item label="开户行" prop="salesCompanyBankBranchNo">
  276. <el-input v-model="form.salesCompanyBankBranchNo"></el-input>
  277. </el-form-item>
  278. <el-form-item label="地址" prop="receiverAddress">
  279. <el-input v-model="form.receiverAddress"></el-input>
  280. </el-form-item>
  281. <!-- <el-form-item prop="files" label="发票附件">
  282. <fileMain v-model="form.files"></fileMain>
  283. </el-form-item> -->
  284. </el-col>
  285. </el-row>
  286. <div v-if="form.sourceType != 99" class="payinfo" style="margin-top: 20px;">
  287. <headerTitle title="来源清单"></headerTitle>
  288. <!-- <el-form ref="form" :model="tableForm"> -->
  289. <ele-pro-table
  290. ref="table"
  291. :needPage="false"
  292. :columns="columns"
  293. :datasource="form.relatedList"
  294. row-key="id"
  295. class="time-form"
  296. >
  297. <template v-slot:toolbar>
  298. <!-- <span>已开票金额:{{ totalInvoiceAmount }}</span> -->
  299. </template>
  300. <template v-slot:planPaymentAmount="scope">
  301. <el-form-item
  302. style="width: 100%;"
  303. label-width="0"
  304. :prop="'relatedList.' + scope.$index + '.planPaymentAmount'"
  305. :rules="[
  306. {
  307. required: false,
  308. message: '请输入计划金额',
  309. trigger: 'blur'
  310. }
  311. ]"
  312. >
  313. <span v-if="dialogType === 'view'">{{ scope.row.planPaymentAmount }}</span>
  314. <el-input v-else v-model="scope.row.planPaymentAmount" type="number" @input="updatePlanPaymentAmount(scope.row)"></el-input>
  315. </el-form-item>
  316. </template>
  317. <template v-slot:invoiceAmount="scope">
  318. <el-form-item
  319. style="width: 100%;"
  320. label-width="0"
  321. :prop="'relatedList.' + scope.$index + '.invoiceAmount'"
  322. :rules="[
  323. {
  324. required: false,
  325. message: '请输入开票金额',
  326. trigger: 'blur'
  327. },
  328. {
  329. required: false,
  330. validator: (rule, value, callback) => {
  331. if (value === undefined || value === null || value === '') {
  332. callback('请输入开票金额');
  333. } else if (parseFloat(value) <= 0 || parseFloat(value) > parseFloat(scope.row.unInvoiceAmount)) {
  334. callback('开票金额必须大于0且不超过未开票金额');
  335. } else {
  336. callback();
  337. }
  338. },
  339. trigger: 'blur'
  340. }
  341. ]"
  342. >
  343. <span v-if="dialogType === 'view'">{{ scope.row.invoiceAmount }}</span>
  344. <el-input v-else v-model="scope.row.invoiceAmount" type="number" @input="updateInvoiceAmount(scope.row)"></el-input>
  345. </el-form-item>
  346. </template>
  347. </ele-pro-table>
  348. <!-- </el-form> -->
  349. </div>
  350. </el-form>
  351. <div style="margin-top: 20px;">
  352. <headerTitle title="关联物品清单信息"></headerTitle>
  353. <table-info-new
  354. v-if="form.sourceType != 99"
  355. :dialogType="dialogType"
  356. :contactData="contactData"
  357. ref="tableInfoRef"
  358. :invoiceAmount="form.invoiceAmount"
  359. :ifRedReversalInvoice="ifRedReversalInvoice"
  360. @invoiceAmountChange="invoiceAmountChange"
  361. ></table-info-new>
  362. <table-info
  363. v-else
  364. :dialogType="dialogType"
  365. :contactData="contactData"
  366. ref="tableInfoNoOrderRef"
  367. @setPrice="setPrice"
  368. ></table-info>
  369. </div>
  370. <div slot="footer">
  371. <el-button type="primary" v-click-once @click="handleSave(0)">保存</el-button>
  372. <el-button
  373. type="primary"
  374. v-if="isNeed_process_is_close"
  375. v-click-once
  376. @click="handleSave(1)"
  377. >提交</el-button
  378. >
  379. <el-button v-click-once @click="cancel">返回</el-button>
  380. </div>
  381. <process-submit-dialog
  382. api-fun-name="fininvoiceapplyStatusAPI"
  383. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  384. v-if="processSubmitDialogFlag"
  385. ref="processSubmitDialogRef"
  386. @reload="reload"
  387. ></process-submit-dialog>
  388. <!--对账单-->
  389. <account-statement-dialog
  390. ref="accountStatementDialogRef"
  391. :form="form"
  392. v-if="accountStatementDialogFlag"
  393. :accountstatement-dialog-flag.sync="accountStatementDialogFlag"
  394. @getAccountData="getAccountData"
  395. :contactData="contactData"
  396. :type="form.type"
  397. :multiple="true"
  398. >
  399. </account-statement-dialog>
  400. <!--采购订单-->
  401. <purchasinOrderListDialog
  402. ref="orderListDialogRef"
  403. @changeParent="changeOrder"
  404. ></purchasinOrderListDialog>
  405. <!--销售订单-->
  406. <saleOrderListDialog
  407. :isAll="true"
  408. ref="saleOrderListDialogref"
  409. @changeParent="changeOrder"
  410. ></saleOrderListDialog>
  411. <contractListDialog
  412. ref="selectContractRef"
  413. @changeParent="changeContract"
  414. :type="form.type"
  415. :multiple="true"
  416. ></contractListDialog>
  417. <!-- 应收 -->
  418. <receivableDialog
  419. ref="receivableRef"
  420. @receivableDone="receivableDone"
  421. v-if="receivableDialogFlag"
  422. :receivableDialogFlag.sync="receivableDialogFlag"
  423. :multiple="true"
  424. ></receivableDialog>
  425. <!-- 应付 -->
  426. <paymentListDialog
  427. ref="receivableRef1"
  428. @receivableDone="receivableDone"
  429. v-if="paymentListDialogFlag"
  430. :paymentListDialogFlag.sync="paymentListDialogFlag"
  431. ></paymentListDialog>
  432. <!-- 收款计划列表 -->
  433. <collectionPlanDialog
  434. ref="collectionPlanDialogRef"
  435. v-if="collectionPlanDialogFlag"
  436. :collectionPlanDialogFlag.sync="collectionPlanDialogFlag"
  437. @getPlanData="getPlanData"
  438. :type="form.type"
  439. ></collectionPlanDialog>
  440. </ele-modal>
  441. </template>
  442. <script>
  443. import personSelect from '@/components/CommomSelect/person-select.vue';
  444. import { listOrganizations } from '@/api/system/organization';
  445. import { mapGetters } from 'vuex';
  446. import fileUpload from '@/components/upload/fileUpload.vue';
  447. import tableInfoNew from './tableInfoNew.vue';
  448. import tableInfo from './tableInfo.vue';
  449. import { getTreeByPid } from '@/api/classifyManage';
  450. import {
  451. invoiceApplyInfoV2API,
  452. invoiceApplyCreateAPI,
  453. invoiceApplyUpdateV2API,
  454. initInvoiceByStatementId,
  455. splitInitAPI
  456. } from '@/api/financialManage/invoiceManage';
  457. import { getpurchaseorderDetail } from '@/api/purchasingManage/purchaseOrder';
  458. import { getSaleOrderDetail } from '@/api/saleManage/saleorder';
  459. import { getDetail } from '@/api/contractManage/contractBook';
  460. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  461. import accountStatementDialog from './accountstatementDialog.vue';
  462. import contractListDialog from '@/views/saleManage/saleOrder/components/contractListDialog.vue';
  463. import purchasinOrderListDialog from '@/views/purchasingManage/purchaseOrder/invoice/components/orderListDialog.vue'; //采购订单
  464. import saleOrderListDialog from '@/views/saleManage/saleOrder/invoice/components/orderListDialog.vue'; //销售订单
  465. import { enterprisePage } from '@/api/contractManage/contractBook';
  466. import { contactDetail } from '@/api/saleManage/contact';
  467. // import fileMain from '@/components/addDoc/index.vue';
  468. import receivableDialog from '@/views/financialManage/receivableManage/components/receivableDialog.vue'; //应收
  469. import paymentListDialog from '@/views/financialManage/payableManage/components/paymentListDialog.vue'; //应付
  470. import collectionPlanDialog from './collectionPlanDialog.vue' // 收款计划列表
  471. import { updateContractStatus } from '@/api/contractManage/contractBook';
  472. import { getMergeInvoiceInfoAPI } from '@/api/financialManage/payAndCollectPlan';
  473. import { paymentTypeOp } from '@/enum/dict';
  474. import inventoryTable from '@/BIZComponents/inventoryTable.vue';
  475. const defForm = {
  476. accountingSubjectCode: '',
  477. accountingSubjectId: '',
  478. accountingSubjectName: '',
  479. amount: undefined,
  480. contactId: '',
  481. companyAddress: '',
  482. companyBankAccount: '',
  483. companyUsc: '',
  484. expectInvoiceDate: '',
  485. companyBankBranchNo: '',
  486. companyName: '',
  487. receiverAddress: '',
  488. receiverName: '',
  489. receiverTel: '',
  490. receiverContactName: '',
  491. companyTel: '',
  492. companyContactName: '',
  493. detailList: [],
  494. drawerId: '',
  495. drawerName: '',
  496. files: [],
  497. invoiceStatus: '',
  498. link: [],
  499. remark: '',
  500. settlementAccountId: '',
  501. settlementAccountName: '',
  502. invoiceAmount: 0,
  503. getAccountData: '',
  504. sourceId: '',
  505. sourceCode: '',
  506. salesCompanyUsc: '',
  507. salesCompanyBankBranchNo: '',
  508. salesCompanyBankAccount: '',
  509. category: 1,
  510. relatedList: [],
  511. productMap: {}
  512. };
  513. export default {
  514. name: 'add-or-edit-dialog',
  515. components: {
  516. processSubmitDialog,
  517. fileUpload,
  518. personSelect,
  519. tableInfoNew,
  520. accountStatementDialog,
  521. contractListDialog,
  522. purchasinOrderListDialog,
  523. saleOrderListDialog,
  524. // fileMain,
  525. receivableDialog,
  526. paymentListDialog,
  527. collectionPlanDialog,
  528. tableInfo,
  529. inventoryTable
  530. },
  531. props: {
  532. isEditType: {
  533. type: Boolean,
  534. default: true
  535. },
  536. addOrEditDialogFlag: {
  537. type: Boolean,
  538. default: false
  539. },
  540. contactData: {
  541. type: Object,
  542. default: () => {
  543. return {};
  544. }
  545. }
  546. },
  547. provide() {
  548. return {
  549. invoiceType: () => this.form.type
  550. };
  551. },
  552. computed: {
  553. ...mapGetters(['user']),
  554. isAccountstatement() {
  555. return Array.isArray(this.form?.relatedList) && this.form?.relatedList?.[0]?.sourceType == 1;
  556. },
  557. sourceTypeOp() {
  558. if(this.$route.path.includes('invoiceManage') && !this.isAccountstatement) {
  559. return [{
  560. label: '其他无订单无合同',
  561. value: 99
  562. }];
  563. }
  564. return this.form.type == 1 ? [
  565. {
  566. label: '对账单',
  567. value: 1
  568. },
  569. {
  570. label: '合同',
  571. value: 2
  572. },
  573. {
  574. label: '订单',
  575. value: 3
  576. },
  577. {
  578. label: '已收',
  579. value: 5
  580. },
  581. {
  582. label: '其他无订单无合同',
  583. value: 99
  584. }
  585. ] : [
  586. {
  587. label: '对账单',
  588. value: 1
  589. },
  590. {
  591. label: '合同',
  592. value: 2
  593. },
  594. {
  595. label: '订单',
  596. value: 3
  597. },
  598. {
  599. label: '已付',
  600. value: 4
  601. },
  602. {
  603. label: '其他无订单无合同',
  604. value: 99
  605. }
  606. ]
  607. },
  608. isDisabledType() {
  609. return this.isAccountstatement;
  610. },
  611. columns() {
  612. return [
  613. {
  614. width: 45,
  615. type: 'index',
  616. columnKey: 'index',
  617. align: 'center',
  618. fixed: 'left'
  619. },
  620. {
  621. minWidth: 150,
  622. prop: 'sourceCode',
  623. label: '来源编码',
  624. align: 'center'
  625. },
  626. // {
  627. // width: 150,
  628. // prop: 'relatedOrderNo',
  629. // label: '来源编号',
  630. // align: 'center'
  631. // },
  632. {
  633. minWidth: 120,
  634. prop: 'sourceType',
  635. label: '来源类型',
  636. align: 'center',
  637. formatter: (row) => {
  638. return this.sourceTypeList.find(item => item.value == row.sourceType)?.label || ''
  639. }
  640. },
  641. // {
  642. // width: 170,
  643. // prop: 'planPaymentAmount',
  644. // label: this.form.type == 1 ? '计划收款金额' : '计划付款金额',
  645. // align: 'center',
  646. // slot: 'planPaymentAmount'
  647. // },
  648. {
  649. minWidth: 150,
  650. prop: 'unInvoiceAmount',
  651. label: '未开票金额',
  652. align: 'center'
  653. },
  654. {
  655. minWidth: 150,
  656. prop: 'invoicedAmount',
  657. label: '已开票金额',
  658. align: 'center'
  659. },
  660. {
  661. minWidth: 160,
  662. prop: 'invoiceAmount',
  663. label: '本次开票金额',
  664. align: 'center',
  665. // slot: 'invoiceAmount',
  666. fixed: 'right'
  667. }
  668. ];
  669. },
  670. },
  671. data() {
  672. return {
  673. cacheKeyUrl: 'eom-202608251804-inventoryTable',
  674. // 1-对账单,2-合同,3-订单,4-应付,5-应收,99-其他无订单无合同
  675. sourceTypeList: [
  676. {
  677. label: '对账单',
  678. value: 1
  679. },
  680. {
  681. label: '合同',
  682. value: 2
  683. },
  684. {
  685. label: '订单',
  686. value: 3
  687. },
  688. {
  689. label: '已付',
  690. value: 4
  691. },
  692. {
  693. label: '已收',
  694. value: 5
  695. },
  696. {
  697. label: '其他无订单无合同',
  698. value: 99
  699. }
  700. ],
  701. businessId: '',
  702. paymentTypeOp,
  703. fullscreen: false,
  704. receivableDialogFlag: false,
  705. dialogType: '',
  706. title: '',
  707. isOtherSourceFlag: false,
  708. processSubmitDialogFlag: false,
  709. collectionPlanDialogFlag: false,
  710. paymentListDialogFlag: false,
  711. accountStatementDialogFlag: false,
  712. enterprisePage: [],
  713. totalInvoiceAmount: 0,
  714. // 是否冲红发票:1-是(不允许编辑金额),0-否(允许编辑金额)
  715. ifRedReversalInvoice: 0,
  716. form: {
  717. applyDeptId: '',
  718. applyDeptName: '',
  719. applyUserId: '',
  720. applyUserName: '',
  721. type: 1,
  722. id: '',
  723. ...defForm
  724. },
  725. feeTypeList: [],
  726. accountingSubjectList: [],
  727. deptList: [],
  728. deptTreeList: [],
  729. rules: {
  730. applyDeptId: { required: true, message: '请选择', trigger: 'change' },
  731. applyUserId: { required: true, message: '请选择', trigger: 'change' },
  732. accountingSubjectId: {
  733. required: true,
  734. message: '请选择',
  735. trigger: 'change'
  736. },
  737. feeTypeId: { required: true, message: '请选择', trigger: 'change' },
  738. // amount: { required: true, message: '请输入', trigger: 'blur' },
  739. companyName: { required: true, message: '请输入', trigger: 'blur' },
  740. type: { required: true, message: '请选择', trigger: 'change' },
  741. sourceType: { required: true, message: '请选择', trigger: 'change' }
  742. },
  743. };
  744. },
  745. created() {
  746. this.getClassifyList(24, 'accountingSubjectList');
  747. this.getDeptList();
  748. },
  749. methods: {
  750. //从发票管理新增发票初始化
  751. async init(row = {}, type, splitData = null) {
  752. // 重置冲红标记,避免上次编辑状态污染本次
  753. this.ifRedReversalInvoice = 0;
  754. this.businessId = type == 'reissue' ? '' : row.id || '';
  755. this.title =
  756. type == 'add'
  757. ? '新增'
  758. : type == 'reissue'
  759. ? '开发票'
  760. : '修改';
  761. console.log('row', row, type);
  762. this.dialogType = type;
  763. // 修改时,先用列表行带过来的 ifRedReversalInvoice 占位(详情接口目前未返回该字段),
  764. // 后续 getInfo() 若接口补上该字段,会被详情返回值覆盖
  765. if (type === 'update') {
  766. this.ifRedReversalInvoice = Number(row?.ifRedReversalInvoice) || 0;
  767. }
  768. if (type == 'add' || type == 'reissue') {
  769. this.form.applyDeptId = this.user.info.groupId;
  770. this.form.applyDeptName = this.user.info.groupName;
  771. this.form.applyUserId = this.user.info.userId;
  772. this.form.applyUserName = this.user.info.name;
  773. enterprisePage({
  774. pageNum: 1,
  775. size: 200
  776. }).then((res) => {
  777. this.enterprisePage = [];
  778. this.enterprisePage.push(...res.list);
  779. this.enterpriseChange(this.enterprisePage[0]?.name);
  780. });
  781. // 开发票:根据总单ID拉取拆分初始化数据,预填到表单上
  782. if (type == 'reissue' && row.id) {
  783. try {
  784. // 优先使用调用方传入的 splitData(handleReissue 已检查过接口),避免重复调用
  785. const data = splitData ?? (await splitInitAPI(row.id));
  786. data.type = Number(data.type);
  787. Object.keys(data || {}).forEach((k) => {
  788. this.$set(this.form, k, data[k]);
  789. });
  790. this.$nextTick(() => {
  791. if (this.form.sourceType == 99) {
  792. this.$refs.tableInfoNoOrderRef?.setValue(this.form);
  793. } else {
  794. this.$refs.tableInfoRef?.putValue(this.form);
  795. }
  796. });
  797. } catch (e) {
  798. console.error('splitInit failed:', e);
  799. return false;
  800. }
  801. }
  802. } else {
  803. await this.getInfo(row.id);
  804. }
  805. this.$nextTick(async () => {
  806. // await this.getUser List(this.form.applyDeptId);
  807. });
  808. return true;
  809. },
  810. updateInvoiceAmount(row) {
  811. // row.invoiceAmount = Number(row.invoiceAmount).toFixed(2);
  812. this.form.amount = this.form.relatedList.reduce((pre, cur) => {
  813. return pre + Number(cur.invoiceAmount);
  814. }, 0);
  815. // this.$refs.tableInfoRef.setSinglePrice(row, this.form.relatedList);
  816. },
  817. //来源类型
  818. async handleSelectAccount(val) {
  819. if (val == 6 || val == 7) {
  820. this.collectionPlanDialogFlag = true;
  821. }
  822. if (val == 1) {
  823. this.accountStatementDialogFlag = true;
  824. }
  825. if (val == 2) {
  826. this.$refs.selectContractRef.open({}, 1, 1);
  827. }
  828. if (val == 3 && this.form.type == 2) {
  829. this.$refs.orderListDialogRef.open({}, 1, true);
  830. }
  831. if (val == 3 && this.form.type == 1) {
  832. this.$refs.saleOrderListDialogref.open({}, 1, true);
  833. }
  834. if (val == 5) {
  835. this.receivableDialogFlag = true;
  836. }
  837. if (val == 4) {
  838. this.paymentListDialogFlag = true;
  839. }
  840. },
  841. //合同回调
  842. async changeContract(data) {
  843. console.log('changeOrder~~~', data);
  844. // 子组件在单选/多选路径下 emit 的形态不一致,归一化为数组
  845. const list = Array.isArray(data) ? data : data ? [data] : [];
  846. if (!list.length) return;
  847. const tempIds = list.map((item) => item.id);
  848. const tempNames = list.map((item) => item.contractNo);
  849. this.getPlanData(tempIds, tempNames);
  850. // const res = await getDetail(data.id);
  851. // this.$set(this.form, 'sourceId', data.id);
  852. // this.$set(this.form, 'sourceCode', data.contractNo);
  853. // this.$set(
  854. // this.form,
  855. // 'amount',
  856. // res.contractVO?.discountTotalPrice - res.contractVO?.invoiceAmount
  857. // );
  858. // this.$set(this.form, 'invoiceAmount', res.contractVO?.invoiceAmount);
  859. // this.getContactDetail(
  860. // this.form.type == 2
  861. // ? res.contractVO?.partbId
  862. // : res.contractVO?.partaId,
  863. // res.contractVO
  864. // );
  865. // res.productList.forEach((item) => {
  866. // item.singlePrice =
  867. // (item.discountSinglePrice &&
  868. // Number(item.discountSinglePrice).toFixed(2)) ||
  869. // item.singlePrice;
  870. // item.totalPrice =
  871. // (item.discountTotalPrice &&
  872. // Number(item.discountTotalPrice).toFixed(2)) ||
  873. // item.totalPrice;
  874. // item.typeName = this.form.type == 1 ? '销售合同' : '采购合同';
  875. // item.type = this.form.type == 1 ? '101' : '102';
  876. // });
  877. // this.$nextTick(() => {
  878. // this.$refs.table.setValue(res.productList);
  879. // });
  880. this.$forceUpdate();
  881. },
  882. async getContactDetail(id, data) {
  883. let contactValue = {};
  884. if (id) {
  885. this.form.contactId = id;
  886. contactValue = await contactDetail(id);
  887. }
  888. const { base, other, bankList, linkList } = contactValue;
  889. if (this.form.type == 1) {
  890. this.form.companyName = base.name;
  891. this.form.companyUsc = base.unifiedSocialCreditCode;
  892. this.form.companyAddress = other?.addressName + other?.address;
  893. this.form.companyTel =
  894. data.partbTel ||
  895. linkList.find((item) => item.ifChief == 1)?.mobilePhone;
  896. this.form.companyBankAccount = bankList[0]?.accountNo;
  897. this.form.companyBankBranchNo = bankList[0]?.bankName;
  898. this.enterpriseChange(data.partbName);
  899. } else {
  900. this.form.receiverName = base.name;
  901. this.form.receiverAddress = base?.addressName + other?.address;
  902. this.form.receiverTel =
  903. data.partaTel ||
  904. linkList.find((item) => item.ifChief == 1)?.mobilePhone;
  905. this.form.salesCompanyUsc = base.unifiedSocialCreditCode;
  906. this.form.salesCompanyBankAccount = bankList[0]?.accountNo;
  907. this.form.salesCompanyBankBranchNo = bankList[0]?.bankName;
  908. this.enterpriseChange(data.partaName);
  909. }
  910. },
  911. setCompanyBankAccount(base) {
  912. console.log('base~~~', base);
  913. if (this.form.type == 1) {
  914. console.log('base~~~111', base.companyName);
  915. this.form.companyName = base.companyName;
  916. this.form.companyUsc = base.companyUsc;
  917. this.form.companyAddress = base.companyAddress;
  918. this.form.companyTel = base.companyTel;
  919. this.form.companyContactName = base.companyContactName;
  920. this.form.companyBankAccount = base.companyBankAccount;
  921. this.form.companyBankBranchNo = base.companyBankBranchNo;
  922. // this.enterpriseChange(base.companyName);
  923. } else {
  924. this.form.receiverName = base.receiverName;
  925. this.form.receiverAddress = base.receiverAddress;
  926. this.form.receiverTel = base.receiverTel;
  927. this.form.receiverContactName = base.receiverContactName;
  928. this.form.salesCompanyUsc = base.salesCompanyUsc;
  929. this.form.salesCompanyBankAccount = base.salesCompanyBankAccount;
  930. this.form.salesCompanyBankBranchNo = base.salesCompanyBankBranchNo;
  931. // this.enterpriseChange(base.receiverName);
  932. }
  933. },
  934. //订单回调
  935. async changeOrder(data) {
  936. console.log('changeOrder~~~', data);
  937. // 子组件在单选/多选路径下 emit 的形态不一致,归一化为数组
  938. const list = Array.isArray(data) ? data : data ? [data] : [];
  939. if (!list.length) return;
  940. const tempIds = list.map((item) => item.id);
  941. const tempNames = list.map((item) => item.orderNo);
  942. this.getPlanData(tempIds, tempNames);
  943. // this.$set(this.form, 'sourceId', data.id);
  944. // this.$set(this.form, 'sourceCode', data.orderNo);
  945. // let res = {};
  946. // if (this.form.type == 2) {
  947. // res = await getpurchaseorderDetail(data.id);
  948. // } else {
  949. // res = await getSaleOrderDetail(data.id);
  950. // }
  951. // this.$set(this.form, 'amount', res.payAmount - res.invoiceAmount);
  952. // this.$set(this.form, 'invoiceAmount', res.invoiceAmount);
  953. // this.getContactDetail(
  954. // this.form.type == 2 ? res.partbId : res.partaId,
  955. // res
  956. // );
  957. // res.productList.forEach((item) => {
  958. // item.singlePrice =
  959. // (item.discountSinglePrice &&
  960. // Number(item.discountSinglePrice).toFixed(2)) ||
  961. // item.singlePrice;
  962. // item.totalPrice =
  963. // (item.discountTotalPrice &&
  964. // Number(item.discountTotalPrice).toFixed(2)) ||
  965. // item.totalPrice;
  966. // item.typeName = this.form.type == 1 ? '销售订单' : '采购订单';
  967. // item.type = this.form.type == 1 ? '201' : '202';
  968. // });
  969. // this.$nextTick(() => {
  970. // this.$refs.table.setValue(res.productList);
  971. // });
  972. // this.$forceUpdate();
  973. // console.log(res);
  974. },
  975. //应收应付回调
  976. async payableManage(data) {
  977. const { row, form } = data;
  978. console.log(data);
  979. this.$set(this.form, 'sourceId', row.id);
  980. this.$set(this.form, 'sourceCode', row.code);
  981. // this.$set(
  982. // this.form,
  983. // 'amount',
  984. // row.receivedTotalPrice || row.paidTotalPrice
  985. // );
  986. // this.$set(this.form, 'invoiceAmount', row.invoiceAmount);
  987. // this.getContactDetail(form.contactId, {});
  988. },
  989. receivableDone(data) {
  990. // this.$set(this.form, 'type', Number(data.type));
  991. // this.$set(this.form, 'sourceType', data.sourceType);
  992. // this.payableManage(data.data);
  993. const tempIds = data.map((item) => item.detailId);
  994. const tempNames = data.map((item) => item.detailCode);
  995. console.log(data)
  996. this.getPlanData(tempIds, tempNames)
  997. },
  998. // 收/付款计划回调
  999. async getPlanData(tempIds, tempNames) {
  1000. console.log('getPlanDatadata~~~', tempIds, tempNames);
  1001. // let tempIds = [];
  1002. // let tempNames = [];
  1003. // if(this.form.sourceType == 4 || this.form.sourceType == 5) {
  1004. // tempIds = data.map((item) => item.receiptPlanOrderId);
  1005. // tempNames = data.map((item) => item.code);
  1006. // } else {
  1007. // tempIds = data.map((item) => item.id);
  1008. // tempNames = data.map((item) => item.statementNo);
  1009. // }
  1010. this.form.sourceCode = tempNames.join(',');
  1011. const res = await initInvoiceByStatementId(
  1012. {
  1013. sourceIds: tempIds,
  1014. sourceType: this.form.sourceType,
  1015. type: this.form.type
  1016. }
  1017. )
  1018. res.relatedList = [res.relatedVO];
  1019. res.relatedList = res.relatedList.map((item) => {
  1020. item.invoiceAmount = item.unInvoiceAmount;
  1021. return item
  1022. })
  1023. this.form.sourceId = res.sourceId;
  1024. this.form.relatedList = res.relatedList;
  1025. this.form.productMap = res.productMap;
  1026. const amount = this.form.relatedList.reduce((prev, cur) => prev +
  1027. +cur.invoiceAmount, 0) || 0;
  1028. this.form.amount = amount;
  1029. console.log('form~~~', this.form);
  1030. this.setCompanyBankAccount(res)
  1031. // this.form.detailList = res.detailList;
  1032. this.$nextTick(() => {
  1033. this.$refs.tableInfoRef.setValue(this.form);
  1034. })
  1035. console.log('getPlanData~~~', res);
  1036. // console.log('detailList~~~', res.detailList);
  1037. },
  1038. //对账单回调
  1039. async getAccountData(tableInfo) {
  1040. // let res = {};
  1041. // if (this.form.type == 2) {
  1042. // res = await getpurchaseorderDetail(tableInfo?.children?.orderId);
  1043. // } else {
  1044. // res = await getSaleOrderDetail(tableInfo?.children?.orderId);
  1045. // }
  1046. // this.getContactDetail(tableInfo.contactId, res);
  1047. // this.$nextTick(() => {
  1048. // this.$set(this.form, 'sourceId', tableInfo?.children?.id);
  1049. // this.$set(this.form, 'sourceCode', tableInfo?.statementNo);
  1050. // this.$set(
  1051. // this.form,
  1052. // 'invoiceAmount',
  1053. // tableInfo?.children?.invoiceAmount
  1054. // );
  1055. // this.$refs.table.getAccountData(tableInfo);
  1056. // });
  1057. const tempIds = tableInfo.map((item) => item.id);
  1058. const tempNames = tableInfo.map((item) => item.statementNo);
  1059. this.getPlanData(tempIds, tempNames);
  1060. console.log(tableInfo);
  1061. // this.getPlanData(tableInfo)
  1062. },
  1063. //订单、合同列表
  1064. async createInvoice1(data, type, sourceType) {
  1065. console.log('createInvoice1~~~', data);
  1066. this.$set(this.form, 'type', Number(type));
  1067. this.$set(this.form, 'sourceType', sourceType);
  1068. // this.$set(this.form, 'sourceCode', tempIds);
  1069. await this.init({}, 'add');
  1070. let tempIds = []
  1071. let tempNames = []
  1072. if(sourceType == 5) {
  1073. tempIds = data.map((item) => item.detailId);
  1074. tempNames = data.map((item) => item.detailCode);
  1075. } else {
  1076. tempIds = data.map((item) => item.id);
  1077. tempNames = data.map((item) => item.statementNo);
  1078. }
  1079. this.getPlanData(tempIds, tempNames);
  1080. // if (sourceType == 2) {
  1081. // this.changeContract(data);
  1082. // }
  1083. // if (sourceType == 3) {
  1084. // this.changeOrder(data);
  1085. // }
  1086. // if (sourceType == 4 || sourceType == 5) {
  1087. // this.payableManage(data);
  1088. // }
  1089. },
  1090. //对账单列表
  1091. createInvoice(
  1092. row = {},
  1093. invoiceType,
  1094. tableInfo = {},
  1095. isOtherSourceFlag = true,
  1096. dialogType = 'add'
  1097. ) {
  1098. this.dialogType = dialogType;
  1099. this.init(row, dialogType);
  1100. this.form.type = tableInfo.type;
  1101. this.$set(this.form, 'sourceType', invoiceType);
  1102. // this.form.sourceType=invoiceType
  1103. setTimeout(() => {
  1104. this.getAccountData(tableInfo);
  1105. }, 400);
  1106. },
  1107. //获取详情
  1108. async getInfo(id) {
  1109. this.form = (await invoiceApplyInfoV2API(id)) || {};
  1110. //来源清单没有数据时给空数组,避免表格因空行报错
  1111. this.form.relatedList = this.form.relatedVO ? [this.form.relatedVO] : [];
  1112. this.form.type = Number(this.form.type);
  1113. if(this.form.ifRedReversalInvoice){
  1114. // 冲红发票标记:1 是 / 0 否。仅在 1 时禁止编辑金额相关字段
  1115. this.ifRedReversalInvoice = Number(this.form.ifRedReversalInvoice);
  1116. }
  1117. this.$nextTick(() => {
  1118. // 根据来源类型设置数据源:99 用 tableInfo(setValue),非 99 用 tableInfoNew(putValue)
  1119. if (this.form.sourceType == 99) {
  1120. this.$refs.tableInfoNoOrderRef?.setValue(this.form);
  1121. } else {
  1122. this.$refs.tableInfoRef?.putValue(this.form);
  1123. }
  1124. })
  1125. },
  1126. //获取分类管理中的数据
  1127. async getClassifyList(id, listName) {
  1128. let res = await getTreeByPid(id);
  1129. this[listName] = res.data;
  1130. },
  1131. //获取费用类别选中数据
  1132. changeFeeTypeInfo(val) {
  1133. if (!val) {
  1134. this.form.feeTypeName = '';
  1135. this.form.feeTypeCode = '';
  1136. }
  1137. let data = this.$refs.feeTypeTree?.$refs?.tree?.getCurrentNode() || {};
  1138. this.form.feeTypeName = data.name;
  1139. this.form.feeTypeCode = data.code;
  1140. },
  1141. //获取会计科目选中数据
  1142. changeSubjectInfo(val) {
  1143. if (!val) return (this.form.accountingSubjectName = '');
  1144. let data = this.$refs.treeSelect?.$refs?.tree?.getCurrentNode() || {};
  1145. this.form.accountingSubjectName = data.name;
  1146. },
  1147. // 获取部门数据
  1148. getDeptList() {
  1149. listOrganizations().then((list) => {
  1150. this.deptList = list;
  1151. this.deptTreeList = this.$util.toTreeData({
  1152. data: list,
  1153. idField: 'id',
  1154. parentIdField: 'parentId'
  1155. });
  1156. });
  1157. },
  1158. // 选择负责人部门
  1159. changeDeptInfo(id) {
  1160. const info = this.deptList.find((e) => e.id == id) || {};
  1161. this.form.applyDeptName = info.name;
  1162. this.form.applyUserId = '';
  1163. this.form.applyUserName = '';
  1164. this.getUserList(id);
  1165. },
  1166. // 获取人员数据
  1167. getUserList(deptId) {
  1168. if (deptId) {
  1169. this.$refs.directorRef.getList({ deptId });
  1170. }
  1171. },
  1172. //选择人员数据
  1173. changeUserInfo(val, info) {
  1174. this.form.applyUserName = info.name;
  1175. },
  1176. //
  1177. handleSelType(val) {
  1178. console.log('val~~~', val);
  1179. this.form = Object.assign({}, this.form, defForm);
  1180. if (val == 'isType') {
  1181. this.$set(this.form, 'sourceType', '');
  1182. }
  1183. if(val == 'sourceType') {
  1184. this.$nextTick(() => {
  1185. this.$refs.tableInfoNoOrderRef?.setValue(this.form);
  1186. })
  1187. }
  1188. this.form.relatedList = [];
  1189. this.$refs.tableInfoRef?.clearTable();
  1190. this.$refs.tableInfoNoOrderRef?.clearTable();
  1191. this.enterpriseChange(this.enterprisePage[0]?.name);
  1192. },
  1193. setPrice(val) {
  1194. this.form.amount = val;
  1195. },
  1196. //系统公司信息
  1197. enterpriseChange(name) {
  1198. let data = this.enterprisePage.find((item) => item.name == name);
  1199. if (this.form.type == 2) {
  1200. this.form.companyName = data?.name;
  1201. this.form.companyUsc = data?.unifiedSocialCreditCode;
  1202. this.form.companyAddress = data?.address;
  1203. this.form.companyTel = data?.tel;
  1204. this.form.companyContactName = data?.contact;
  1205. } else {
  1206. this.form.receiverName = data?.name;
  1207. this.form.receiverAddress = data?.address;
  1208. this.form.salesCompanyUsc = data?.unifiedSocialCreditCode;
  1209. this.form.receiverTel = data?.tel;
  1210. this.form.receiverContactName = data?.contact;
  1211. }
  1212. this.$forceUpdate();
  1213. },
  1214. invoiceAmountChange(item, sum) {
  1215. console.log('item~~~', item, sum);
  1216. const sameKeyItems = this.form.relatedList.filter((d) => d.sourceCode === item.key);
  1217. console.log('sameKeyItems~~~', sameKeyItems);
  1218. let remainingTotal = sum;
  1219. const lastIndex = sameKeyItems.length - 1;
  1220. // 从上到下分配 sum 给相同订单号的数据,多余数量放在最后一个
  1221. // paymentItem.unInvoiceAmount 直接使用接口返回值,不再被关联物品清单覆盖
  1222. sameKeyItems.forEach((paymentItem, index) => {
  1223. if (remainingTotal <= 0) {
  1224. paymentItem.invoiceAmount = 0;
  1225. } else if (index === lastIndex) {
  1226. // 最后一个分配所有剩余
  1227. paymentItem.invoiceAmount = remainingTotal.toFixed(2);
  1228. } else {
  1229. const unInvoiceAmount = parseFloat(paymentItem.unInvoiceAmount) || 0;
  1230. const allocateAmount = Math.min(remainingTotal, unInvoiceAmount);
  1231. paymentItem.invoiceAmount = allocateAmount.toFixed(2);
  1232. remainingTotal -= allocateAmount;
  1233. }
  1234. });
  1235. this.updateInvoiceAmount();
  1236. console.log('分配完成后的 sameKeyItems:', sameKeyItems);
  1237. },
  1238. updatePlanPaymentAmount(item) {
  1239. console.log('item~~~', item);
  1240. // unInvoiceAmount 不再本地计算,直接使用接口返回的值
  1241. // 更新关联物品清单中的 defaultAmountTotalPrice
  1242. const tableInfoRef = this.$refs.tableInfoRef;
  1243. if (tableInfoRef && item.sourceCode) {
  1244. const key = item.sourceCode;
  1245. const newTotal = this.form.relatedList
  1246. .filter((d) => d.sourceCode === key)
  1247. .reduce((sum, d) => sum + (parseFloat(d.unInvoiceAmount) || 0), 0);
  1248. tableInfoRef.tableForm.detailList.forEach((detail) => {
  1249. if (detail.key === key) {
  1250. this.$set(detail, 'defaultAmountTotalPrice', newTotal.toFixed(2));
  1251. }
  1252. });
  1253. }
  1254. },
  1255. getValidate() {
  1256. console.log(this.form);
  1257. let arr = [
  1258. new Promise((resolve, reject) => {
  1259. this.$refs.form.validate((valid) => {
  1260. if (!valid) {
  1261. reject(false);
  1262. } else {
  1263. resolve(true);
  1264. }
  1265. });
  1266. })
  1267. ];
  1268. // this.$refs.tableInfoRef.tableForm.detailList.forEach((item, index) => {
  1269. // arr.push(
  1270. // new Promise((resolve, reject) => {
  1271. // this.$refs.tableInfoRef.$ref['form'+index].validateForm((valid) => {
  1272. // if (!valid) {
  1273. // reject(false);
  1274. // } else {
  1275. // resolve(true);
  1276. // }
  1277. // });
  1278. // })
  1279. // );
  1280. // })
  1281. return Promise.all(arr);
  1282. },
  1283. async handleSave(flag) {
  1284. // this.$refs.form.validate(async (valid) => {
  1285. try {
  1286. const valid = await this.getValidate();
  1287. console.log('valid~~~',valid);
  1288. // if (!valid) return this.$message.warning('有必填项未填,请检查');
  1289. // if (this.form.sourceType != 4 || this.form.sourceType != 5) {
  1290. // tableData = await this.$refs.table.getTableValidate();
  1291. // }
  1292. // // 校验表格数据
  1293. // const tableValid = await new Promise((resolve) => {
  1294. // this.$refs.table.validateForm((valid) => {
  1295. // resolve(valid);
  1296. // });
  1297. // });
  1298. // 根据来源类型选择对应表格:99 用 tableInfo(tableInfoNoOrderRef),非 99 用 tableInfoNew(tableInfoRef)
  1299. const tableRef =
  1300. this.form.sourceType == 99
  1301. ? this.$refs.tableInfoNoOrderRef
  1302. : this.$refs.tableInfoRef;
  1303. const tableValid = await tableRef.getTableValidate();
  1304. console.log('tableValid~~~',tableValid);
  1305. // if (!tableValid) {
  1306. // return;
  1307. // }
  1308. let tableData = tableRef.getTableData();
  1309. // this.form.link = tableData.link;
  1310. this.form.productMap = tableData;
  1311. console.log('commitData~~~',this.form);
  1312. const API =
  1313. (this.dialogType == 'add' || this.dialogType == 'reissue')
  1314. ? invoiceApplyCreateAPI
  1315. : invoiceApplyUpdateV2API;
  1316. const id = await API(this.form);
  1317. if (this.form.sourceType == 2) {
  1318. const idArr = this.form.sourceId?.split(',') || [];
  1319. updateContractStatus(idArr);
  1320. }
  1321. if (flag) {
  1322. await this.handleSub(id);
  1323. return;
  1324. }
  1325. this.$message.success('操作成功');
  1326. this.done();
  1327. this.cancel();
  1328. // });
  1329. } catch (error) {
  1330. // this.$message.warning('有必填项未填,请检查');
  1331. }
  1332. },
  1333. //
  1334. handleSave1(flag) {
  1335. this.$refs.form.validate(async (valid) => {
  1336. if (!valid) return this.$message.warning('有必填项未填,请检查');
  1337. let tableData = {};
  1338. if (this.form.sourceType != 4 || this.form.sourceType != 5) {
  1339. tableData = await this.$refs.table.getTableValidate();
  1340. }
  1341. // 校验表格数据
  1342. const tableValid = await new Promise((resolve) => {
  1343. this.$refs.table.validateForm((valid) => {
  1344. resolve(valid);
  1345. });
  1346. });
  1347. if (!tableValid) {
  1348. return;
  1349. }
  1350. this.form.link = tableData.link;
  1351. this.form.detailList = tableData.detailList;
  1352. const API =
  1353. this.dialogType == 'add'
  1354. ? invoiceApplySaveAPI
  1355. : invoiceApplyUpdateV2API;
  1356. const id = await API(this.form);
  1357. if (this.form.sourceType == 2) {
  1358. const idArr = this.form.sourceId?.split(',') || [];
  1359. updateContractStatus(idArr);
  1360. }
  1361. if (flag) {
  1362. await this.handleSub(id);
  1363. return;
  1364. }
  1365. this.$message.success('操作成功');
  1366. this.done();
  1367. this.cancel();
  1368. });
  1369. },
  1370. //提交-开启流程
  1371. async handleSub(id = '') {
  1372. let data = await invoiceApplyInfoV2API(this.businessId || id);
  1373. this.processSubmitDialogFlag = true;
  1374. let key =
  1375. data.type == 1 ? 'fin_invoice_apply' : 'fin_invoice_receive_apply';
  1376. this.$nextTick(() => {
  1377. let params = {
  1378. businessId: data.id,
  1379. businessKey: key,
  1380. formCreateUserId: data.createUserId,
  1381. variables: {
  1382. type: data.type,
  1383. businessCode: data.orderNo,
  1384. businessName: data.companyName,
  1385. businessType: data.type == 1 ? '开票' : '收票'
  1386. }
  1387. // callBackMethodType : '1',
  1388. // callBackMethod : 'proTargetPlanApproveApiImpl.updatePlanApprovalStatus',
  1389. // pcHandle : '/bpm/handleTask/components/project-manage/plan-manage/submit.vue',
  1390. // pcView : '/bpm/handleTask/components/project-manage/plan-manage/detailDialog.vue',
  1391. // miniHandle : '',
  1392. // miniView : '',
  1393. };
  1394. this.$refs.processSubmitDialogRef.init(params);
  1395. });
  1396. // try {
  1397. // await invoiceApplySubmit({
  1398. // businessId: id || this.form.id,
  1399. // type: this.form.type
  1400. // });
  1401. // } catch (e) {
  1402. // this.$message.error(e.message);
  1403. // }
  1404. },
  1405. reload() {
  1406. this.done();
  1407. this.cancel();
  1408. },
  1409. //刷新主列表数据
  1410. done() {
  1411. this.$emit('reload');
  1412. },
  1413. //关闭弹窗
  1414. cancel() {
  1415. this.$emit('update:addOrEditDialogFlag', false);
  1416. }
  1417. }
  1418. };
  1419. </script>
  1420. <style scoped lang="scss">
  1421. .el-form-box .el-table .el-table__row .el-table__cell {
  1422. padding: 10px 0;
  1423. }
  1424. .payinfo .el-form-item {
  1425. margin-bottom: 0!important;
  1426. }
  1427. </style>