addDialog.vue 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. v-if="visible"
  6. :visible.sync="visible"
  7. :title="title"
  8. :close-on-click-modal="false"
  9. width="80%"
  10. @close="cancel"
  11. >
  12. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  13. <headerTitle title="合同信息"></headerTitle>
  14. <el-row>
  15. <el-col :span="12">
  16. <el-form-item
  17. label="合同类型"
  18. prop="type"
  19. style="margin-bottom: 22px"
  20. >
  21. <DictSelection
  22. dictName="合同类型"
  23. clearable
  24. v-model="form.type"
  25. @itemChange="dictChange"
  26. :disabled="create"
  27. >
  28. </DictSelection>
  29. </el-form-item>
  30. <el-form-item
  31. label="合同名称"
  32. prop="contractName"
  33. style="margin-bottom: 22px"
  34. >
  35. <el-input
  36. clearable
  37. v-model="form.contractName"
  38. placeholder="请输入"
  39. />
  40. </el-form-item>
  41. <el-form-item
  42. label="合同编号"
  43. prop="contractNumber"
  44. style="margin-bottom: 22px"
  45. >
  46. <el-input
  47. clearable
  48. v-model="form.contractNumber"
  49. placeholder="请输入"
  50. />
  51. </el-form-item>
  52. <el-form-item prop="contractFile" label="合同附件">
  53. <fileUpload
  54. v-model="form.contractFile"
  55. module="main"
  56. :showLib="false"
  57. :limit="10"
  58. />
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="12">
  62. <el-form-item
  63. label="合同分类"
  64. prop="categoryId"
  65. style="margin-bottom: 22px; width: 340px"
  66. >
  67. <ele-tree-select
  68. :data="categoryTreeList"
  69. v-model="form.categoryId"
  70. valueKey="id"
  71. labelKey="name"
  72. @change="treeChange"
  73. placeholder="请选择"
  74. default-expand-all
  75. />
  76. </el-form-item>
  77. <el-form-item
  78. label="签订日期"
  79. prop="contractStartDate"
  80. style="margin-bottom: 22px"
  81. >
  82. <el-date-picker
  83. v-model="form.contractStartDate"
  84. @change="setDeliveryDays"
  85. type="date"
  86. placeholder="选择日期"
  87. >
  88. </el-date-picker>
  89. </el-form-item>
  90. <el-form-item
  91. label="结束日期"
  92. prop="contractEndDate"
  93. style="margin-bottom: 22px"
  94. >
  95. <el-date-picker
  96. v-model="form.contractEndDate"
  97. type="date"
  98. placeholder="选择日期"
  99. >
  100. </el-date-picker>
  101. </el-form-item>
  102. <el-form-item
  103. :label="form.type == '2' ? '付款类型' : '收款类型'"
  104. prop="receiptPaymentType"
  105. style="margin-bottom: 22px"
  106. >
  107. <el-select v-model="form.receiptPaymentType" placeholder="请选择">
  108. <el-option
  109. v-for="item in paymentTypeOptions"
  110. :key="item.id"
  111. :label="item.name"
  112. :value="item.id"
  113. >
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. <headerTitle title="基本信息"></headerTitle>
  120. <el-row>
  121. <el-col :span="12">
  122. <el-form-item
  123. label="甲方名称"
  124. prop="partaName"
  125. style="margin-bottom: 22px"
  126. >
  127. <template v-if="form.type == '2'">
  128. <el-input
  129. clearable
  130. v-model="form.partaName"
  131. placeholder="请输入"
  132. v-if="enterprisePage.length <= 1"
  133. />
  134. <el-select
  135. v-if="enterprisePage.length > 1"
  136. style="width: 100%"
  137. v-model="form.partaName"
  138. placeholder="请选择"
  139. @change="getEnterprise(1)"
  140. >
  141. <el-option
  142. v-for="item in enterprisePage"
  143. :key="item.id"
  144. :label="item.name"
  145. :value="item.name"
  146. >
  147. </el-option>
  148. </el-select>
  149. </template>
  150. <template v-else>
  151. <el-input
  152. clearable
  153. v-model="form.partaName"
  154. @click.native="handParent"
  155. placeholder="请选择"
  156. />
  157. </template>
  158. </el-form-item>
  159. <el-form-item
  160. label="甲方统一社会信用代码"
  161. prop="partaUnifiedSocialCreditCode"
  162. label-width="160px"
  163. style="margin-bottom: 22px"
  164. >
  165. <el-input
  166. clearable
  167. v-model="form.partaUnifiedSocialCreditCode"
  168. placeholder="请输入"
  169. />
  170. </el-form-item>
  171. <el-form-item
  172. label="甲方联系人"
  173. prop="partaLinkName"
  174. style="margin-bottom: 22px"
  175. >
  176. <template v-if="form.type == '2'">
  177. <el-input
  178. clearable
  179. v-model="form.partaLinkName"
  180. @click.native="handHead"
  181. placeholder="请选择"
  182. />
  183. </template>
  184. <template v-else>
  185. <el-select
  186. v-model="form.partaLinkName"
  187. placeholder="请选择"
  188. @change="onchangeLink"
  189. @focus="selectFocus"
  190. >
  191. <el-option
  192. v-for="item in linkNameOptions"
  193. :key="item.id"
  194. :label="item.linkName"
  195. :value="item.id"
  196. >
  197. </el-option>
  198. </el-select>
  199. </template>
  200. </el-form-item>
  201. <el-form-item
  202. label="甲方电话"
  203. prop="partaTel"
  204. style="margin-bottom: 22px"
  205. >
  206. <el-input
  207. clearable
  208. :maxlength="20"
  209. v-model="form.partaTel"
  210. placeholder="请输入"
  211. />
  212. </el-form-item>
  213. <el-form-item
  214. label="甲方传真"
  215. prop="partaFax"
  216. style="margin-bottom: 22px"
  217. >
  218. <el-input clearable v-model="form.partaFax" placeholder="请输入" />
  219. </el-form-item>
  220. <el-form-item
  221. label=" 甲方Email"
  222. prop="partaEmail"
  223. style="margin-bottom: 22px"
  224. >
  225. <el-input
  226. clearable
  227. v-model="form.partaEmail"
  228. placeholder="请输入"
  229. />
  230. </el-form-item>
  231. <el-form-item
  232. label="甲方地址"
  233. prop="partaAddress"
  234. style="margin-bottom: 22px"
  235. >
  236. <el-input
  237. clearable
  238. v-model="form.partaAddress"
  239. placeholder="请输入"
  240. />
  241. </el-form-item>
  242. </el-col>
  243. <el-col :span="12">
  244. <template v-if="form.type == '2'">
  245. <el-form-item
  246. label="乙方名称"
  247. prop="partbName"
  248. style="margin-bottom: 22px"
  249. >
  250. <el-input
  251. clearable
  252. v-model="form.partbName"
  253. @click.native="handSupplier"
  254. placeholder="请输入"
  255. />
  256. </el-form-item>
  257. </template>
  258. <template v-else>
  259. <el-form-item
  260. label="乙方名称"
  261. prop="partbName"
  262. style="margin-bottom: 22px"
  263. >
  264. <el-input
  265. clearable
  266. v-model="form.partbName"
  267. placeholder="请输入"
  268. v-if="enterprisePage.length <= 1"
  269. />
  270. <el-select
  271. v-if="enterprisePage.length > 1"
  272. style="width: 100%"
  273. v-model="form.partbName"
  274. placeholder="请选择"
  275. @change="getEnterprise(1)"
  276. >
  277. <el-option
  278. v-for="item in enterprisePage"
  279. :key="item.id"
  280. :label="item.name"
  281. :value="item.name"
  282. >
  283. </el-option>
  284. </el-select>
  285. </el-form-item>
  286. </template>
  287. <el-form-item
  288. label="乙方统一社会信用代码"
  289. prop="partbUnifiedSocialCreditCode"
  290. label-width="160px"
  291. style="margin-bottom: 22px"
  292. >
  293. <el-input
  294. clearable
  295. v-model="form.partbUnifiedSocialCreditCode"
  296. placeholder="请输入"
  297. />
  298. </el-form-item>
  299. <el-form-item
  300. label="乙方联系人"
  301. prop="partbLinkName"
  302. style="margin-bottom: 22px"
  303. >
  304. <template v-if="form.type == '2'">
  305. <el-select
  306. v-model="form.partbLinkName"
  307. placeholder="请选择"
  308. @change="onchangeLink"
  309. @focus="selectFocus"
  310. >
  311. <el-option
  312. v-for="item in linkNameOptions"
  313. :key="item.id"
  314. :label="item.linkName"
  315. :value="item.id"
  316. >
  317. </el-option>
  318. </el-select>
  319. </template>
  320. <template v-else>
  321. <el-input
  322. clearable
  323. v-model="form.partbLinkName"
  324. @click.native="handHead"
  325. placeholder="请输入"
  326. />
  327. </template>
  328. </el-form-item>
  329. <el-form-item prop="partbTel" label="乙方联系电话">
  330. <el-input clearable v-model="form.partbTel" placeholder="请输入" />
  331. </el-form-item>
  332. <el-form-item prop="partbFax" label="乙方传真">
  333. <el-input clearable v-model="form.partbFax" placeholder="请输入" />
  334. </el-form-item>
  335. <el-form-item
  336. label="乙方Email"
  337. prop="partbEmail"
  338. style="margin-bottom: 22px"
  339. >
  340. <el-input
  341. clearable
  342. v-model="form.partbEmail"
  343. placeholder="请输入"
  344. />
  345. </el-form-item>
  346. <el-form-item
  347. label="乙方地址"
  348. prop="partbAddress"
  349. style="margin-bottom: 22px"
  350. >
  351. <el-input
  352. clearable
  353. v-model="form.partbAddress"
  354. placeholder="请输入"
  355. />
  356. </el-form-item>
  357. </el-col>
  358. </el-row>
  359. <headerTitle title="产品清单" style="margin-top: 30px"></headerTitle>
  360. <inventoryTable
  361. ref="inventoryTable"
  362. :contractStartDate="this.form.contractStartDate"
  363. ></inventoryTable>
  364. <headerTitle
  365. :title="form.type == '2' ? '付款清单' : '收款清单'"
  366. style="margin-top: 30px"
  367. ></headerTitle>
  368. <paymentList ref="paymentListTable" />
  369. </el-form>
  370. <div slot="footer" class="footer">
  371. <el-button type="primary" @click="save">保存</el-button>
  372. <el-button type="primary" @click="save('sub')">提交</el-button>
  373. <el-button @click="cancel">返回</el-button>
  374. </div>
  375. <parentList ref="parentRef" @changeParent="changeParent"></parentList>
  376. <supplierList
  377. ref="supplierListRef"
  378. :classType="2"
  379. @changeParent="changeSupplier"
  380. ></supplierList>
  381. <head-list ref="headRef" @changeParent="changePersonel"></head-list>
  382. </ele-modal>
  383. </template>
  384. <script>
  385. import { emailReg, phoneReg, numberReg } from 'ele-admin';
  386. import { acceptUnpackoptions } from '@/enum/dict';
  387. import inventoryTable from './inventoryTable.vue';
  388. import { categoryData } from 'element-china-category-data';
  389. import fileUpload from '@/components/upload/fileUpload';
  390. import { cityData } from 'ele-admin/packages/utils/regions';
  391. import dictMixins from '@/mixins/dictMixins';
  392. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  393. import personSelect from '@/components/CommomSelect/person-select.vue';
  394. import parentList from '@/views/saleManage/contact/components/parentList.vue';
  395. import {
  396. getDetail,
  397. UpdateInformation,
  398. addInformation,
  399. submit
  400. } from '@/api/contractManage/contractBook';
  401. import { getcontactlink } from '@/api/saleManage/businessFollow';
  402. import headList from '@/views/saleManage/businessOpportunity/components/headList.vue';
  403. import supplierList from '@/views/purchasingManage/supplierManage/components/parentList.vue';
  404. import paymentList from './paymentList.vue';
  405. import { copyObj } from '@/utils/util';
  406. import { enterprisePage } from '@/api/contractManage/contractBook';
  407. export default {
  408. props: {
  409. categoryTreeList: Array
  410. },
  411. mixins: [dictMixins],
  412. components: {
  413. fileUpload,
  414. headList,
  415. paymentList,
  416. inventoryTable,
  417. supplierList,
  418. deptSelect,
  419. parentList,
  420. personSelect
  421. },
  422. data() {
  423. let formDef = {
  424. id: '',
  425. contractEndDate: '',
  426. contractFile: [],
  427. contractName: '',
  428. contractNumber: '',
  429. contractStartDate: '',
  430. opportunityId: '',
  431. categoryName: '',
  432. categoryId: '',
  433. partaUnifiedSocialCreditCode: '',
  434. partbUnifiedSocialCreditCode: '',
  435. partaAddress: '',
  436. partaEmail: '',
  437. partaFax: '',
  438. partaId: '',
  439. partaLinkId: '',
  440. partaLinkName: '',
  441. partaName: '',
  442. partaTel: '',
  443. partbAddress: '',
  444. partbEmail: '',
  445. partbFax: '',
  446. partbId: '',
  447. partbLinkId: '',
  448. partbLinkName: '',
  449. partbName: '',
  450. partbTel: '',
  451. receiptPaymentType: '',
  452. sourceId: '',
  453. sourceType: '',
  454. totalPrice: null,
  455. type: '', //1=销售合同 2=采购合同
  456. typeName: ''
  457. };
  458. return {
  459. payWayOptions: [],
  460. delDetailIds: [],
  461. paymentTypeOptions: [
  462. { id: 1, name: '固定' },
  463. { id: 2, name: '分期' }
  464. ],
  465. linkNameOptions: [],
  466. acceptUnpackoptions,
  467. visible: false,
  468. title: '',
  469. row: {},
  470. activeName: 'base',
  471. formDef,
  472. form: copyObj(formDef),
  473. // removeBankList: [],
  474. // removeLinkList: [],
  475. tableBankData: [],
  476. tableLinkData: [],
  477. rules: {
  478. type: [
  479. { required: true, message: '请选择合同类型', trigger: 'change' }
  480. ],
  481. receiptPaymentType: [
  482. { required: true, message: '请选择收付款类型', trigger: 'change' }
  483. ],
  484. categoryId: [
  485. { required: true, message: '请选择合同分类', trigger: 'change' }
  486. ],
  487. contractNumber: [
  488. { required: true, message: '请输入自带编号', trigger: 'change' }
  489. ],
  490. contractName: [
  491. { required: true, message: '请输入合同名称', trigger: 'blur' }
  492. ],
  493. partaName: [
  494. { required: true, message: '请选择甲方名称', trigger: 'change' }
  495. ],
  496. partaLinkName: [
  497. { required: true, message: '请选择甲方联系人', trigger: 'change' }
  498. ],
  499. acceptUnpack: [
  500. { required: true, message: '请选择是否接受', trigger: 'change' }
  501. ],
  502. partaTel: [
  503. {
  504. required: true,
  505. pattern: numberReg,
  506. message: '请输入甲方联系电话',
  507. trigger: 'blur'
  508. }
  509. ],
  510. deliveryDate: [
  511. { required: true, message: '请选择交货日期', trigger: 'change' }
  512. ],
  513. partbName: [
  514. { required: true, message: '请输入乙方名称', trigger: 'change' }
  515. ],
  516. partbLinkName: [
  517. { required: true, message: '请输入乙方联系人', trigger: 'change' }
  518. ],
  519. partbTel: [
  520. {
  521. required: true,
  522. pattern: numberReg,
  523. message: '请输入乙方联系电话',
  524. trigger: 'blur'
  525. }
  526. ],
  527. partaEmail: [
  528. { pattern: emailReg, message: '邮箱格式不正确', trigger: 'blur' }
  529. ],
  530. contractStartDate: [
  531. {
  532. required: true,
  533. validator: this.validateStartDate,
  534. trigger: 'blur'
  535. }
  536. ],
  537. contractEndDate: [
  538. { validator: this.validateEndDate, trigger: 'blur' }
  539. ]
  540. },
  541. enterprise: {
  542. address: '',
  543. unifiedSocialCreditCode: '',
  544. tel: '',
  545. name: ''
  546. },
  547. options: {
  548. cityData,
  549. categoryData
  550. },
  551. // 提交状态
  552. loading: false,
  553. // 是否是修改
  554. isUpdate: false,
  555. // 组织机构树形结构数据
  556. groupTreeData: [],
  557. // 组织机构平铺数据
  558. groupData: [],
  559. enterprisePage: [],
  560. create: false,
  561. businessId:''
  562. };
  563. },
  564. created() {
  565. enterprisePage({
  566. pageNum: 1,
  567. size: 200
  568. }).then((res) => {
  569. this.enterprisePage = [];
  570. this.enterprisePage.push(...res.list);
  571. this.getEnterprise();
  572. });
  573. },
  574. methods: {
  575. //开始日期验证
  576. validateStartDate(rule, value, callback) {
  577. if (this.form.contractEndDate && value > this.form.contractEndDate) {
  578. callback(new Error('开始日期不能大于结束日期'));
  579. } else {
  580. callback();
  581. }
  582. },
  583. //结束日期验证
  584. validateEndDate(rule, value, callback) {
  585. if (
  586. this.form.contractEndDate &&
  587. this.form.contractStartDate &&
  588. value < this.form.contractStartDate
  589. ) {
  590. callback(new Error('结束日期不能小于开始日期'));
  591. } else {
  592. callback();
  593. }
  594. },
  595. //选择供应商
  596. changeSupplier(obj) {
  597. this.form = Object.assign({}, this.form, {
  598. partbId: obj.id,
  599. partbName: obj.name,
  600. partbAddress: obj.addressName + obj.address,
  601. partbLinkId: '',
  602. partbLinkName: '',
  603. partbEmail: '',
  604. partbTel: ''
  605. });
  606. this.getLinkInfo(obj.id);
  607. },
  608. //获取详情
  609. async getDetailData(id) {
  610. this.businessId = id;
  611. this.loading = true;
  612. const data = await getDetail(id);
  613. this.loading = false;
  614. if (data) {
  615. this.$nextTick(() => {
  616. let { contractVO } = data;
  617. this.form = contractVO;
  618. this.$refs.inventoryTable &&
  619. this.$refs.inventoryTable.putTableValue(data);
  620. this.$refs.paymentListTable &&
  621. this.$refs.paymentListTable.putTableValue(
  622. data.receiptPaymentList
  623. );
  624. this.getLinkInfo(
  625. data.type == '2' ? contractVO.partbId : contractVO.partaId
  626. );
  627. });
  628. }
  629. },
  630. //签订日期 更新
  631. setDeliveryDays() {
  632. this.$refs.inventoryTable.setDeliveryDays('', '', '', true);
  633. },
  634. //更新联系人数据
  635. async getLinkInfo(contactId) {
  636. const data = await getcontactlink({ contactId });
  637. if (data && data?.length) {
  638. this.linkNameOptions = data;
  639. }
  640. },
  641. selectFocus() {
  642. if (this.linkNameOptions.length === 0) {
  643. return this.$message.error('请先选择名称');
  644. }
  645. },
  646. //选择合同类型
  647. dictChange(val) {
  648. this.form = Object.assign({}, this.form, {
  649. typeName: val.dictValue,
  650. partaAddress: '',
  651. partaEmail: '',
  652. partaFax: '',
  653. partaId: '',
  654. partaLinkId: '',
  655. partaLinkName: '',
  656. partaName: '',
  657. partaTel: '',
  658. partbAddress: '',
  659. partbEmail: '',
  660. partbFax: '',
  661. partbId: '',
  662. partbLinkId: '',
  663. partbLinkName: '',
  664. partbName: '',
  665. partbTel: '',
  666. partaUnifiedSocialCreditCode: '',
  667. partbUnifiedSocialCreditCode: '',
  668. categoryName: '',
  669. categoryId: ''
  670. });
  671. this.getEnterprise();
  672. },
  673. getEnterprise(type) {
  674. let key = this.form.type == '1' || !this.form.type ? 'partb' : 'parta';
  675. let keyArr = [
  676. key + 'Name',
  677. key + 'UnifiedSocialCreditCode',
  678. key + 'Fax',
  679. key + 'Address'
  680. ];
  681. if (type === 1) {
  682. let data = this.enterprisePage.find(
  683. (item) => item.name == this.form[keyArr[0]]
  684. );
  685. this.form[keyArr[0]] = data.name;
  686. this.form[keyArr[1]] = data.unifiedSocialCreditCode;
  687. this.form[keyArr[2]] = data.fax;
  688. this.form[keyArr[3]] = data.address;
  689. return;
  690. }
  691. if (this.enterprisePage.length > 0) {
  692. console.log('dsds');
  693. this.form[keyArr[0]] =
  694. this.form[keyArr[0]] || this.enterprisePage[0].name;
  695. this.form[keyArr[1]] =
  696. this.form[keyArr[1]] ||
  697. this.enterprisePage[0].unifiedSocialCreditCode;
  698. this.form[keyArr[2]] =
  699. this.form[keyArr[2]] || this.enterprisePage[0].fax;
  700. this.form[keyArr[3]] =
  701. this.form[keyArr[3]] || this.enterprisePage[0].address;
  702. }
  703. },
  704. //选择合同分类
  705. treeChange(val) {
  706. //这里eladmin组件有bug,要手动验证下
  707. this.$set(this.form, 'categoryId', val);
  708. this.$refs.form.validateField('categoryId');
  709. },
  710. //选择下拉框
  711. onchangeLink(selectedOptions) {
  712. if (this.form.type == '2') {
  713. const option = this.linkNameOptions.find(
  714. (opt) => opt.id === selectedOptions
  715. );
  716. this.form = Object.assign({}, this.form, {
  717. partbEmail: option?.email,
  718. partbLinkName: option?.linkName || '',
  719. partbTel: option?.mobilePhone || option?.phone || '',
  720. partbLinkId: option?.id
  721. });
  722. } else {
  723. const option = this.linkNameOptions.find(
  724. (opt) => opt.id === selectedOptions
  725. );
  726. this.form = Object.assign({}, this.form, {
  727. partaEmail: option?.email,
  728. partaLinkName: option?.linkName || '',
  729. partaTel: option?.mobilePhone || option?.phone || '',
  730. partaLinkId: option?.id
  731. });
  732. }
  733. },
  734. handHead(title) {
  735. if (this.form.type == '2') {
  736. let item = {
  737. id: this.form.partaLinkId
  738. };
  739. this.$refs.headRef.open(item,0,title);
  740. } else {
  741. let item = {
  742. id: this.form.partbLinkId
  743. };
  744. this.$refs.headRef.open(item,0,title);
  745. }
  746. },
  747. //选择乙方人和采购合同下的甲方人回调
  748. changePersonel(obj,index, title) {
  749. if (this.form.type == '2') {
  750. this.$set(this.form, 'partaLinkId', obj.id);
  751. this.$set(this.form, 'partaLinkName', obj.name);
  752. this.$set(this.form, 'partaTel', obj.phone);
  753. this.$set(this.form, 'partaEmail', obj.email);
  754. } else {
  755. this.$set(this.form, 'partbLinkId', obj.id);
  756. this.$set(this.form, 'partbLinkName', obj.name);
  757. this.$set(this.form, 'partbTel', obj.phone);
  758. this.$set(this.form, 'partbEmail', obj.email);
  759. }
  760. },
  761. //选择客户回调
  762. changeParent(obj) {
  763. this.form = Object.assign({}, this.form, {
  764. partaId: obj.id,
  765. partaName: obj.name,
  766. partaAddress: obj.addressName + obj.address,
  767. partaLinkId: '',
  768. partaLinkName: '',
  769. partaEmail: '',
  770. partaTel: ''
  771. });
  772. this.getLinkInfo(obj.id);
  773. },
  774. //选择采购合同的乙方
  775. handSupplier() {
  776. let item = {
  777. id: this.form.partbId
  778. };
  779. this.$refs.supplierListRef.open(item);
  780. },
  781. handParent() {
  782. let item = {
  783. id: this.form.contactId
  784. };
  785. this.$refs.parentRef.open(item);
  786. },
  787. async open(type, row, create = false) {
  788. this.title = type === 'add' ? '新增' : '修改';
  789. this.row = row;
  790. this.visible = true;
  791. this.create = create;
  792. if (type == 'add') {
  793. this.isUpdate = false;
  794. if (create) {
  795. this.create = create;
  796. //核价单生成的合同
  797. this.$nextTick(() => {
  798. let { contractVO } = row;
  799. console.log(row, 'row');
  800. this.form = contractVO;
  801. this.$refs.inventoryTable &&
  802. this.$refs.inventoryTable.putTableValue(row);
  803. this.$refs.paymentListTable &&
  804. this.$refs.paymentListTable.putTableValue(
  805. row.receiptPaymentList
  806. );
  807. this.getEnterprise();
  808. this.getLinkInfo(
  809. contractVO.type == '2' ? contractVO.partbId : contractVO.partaId
  810. );
  811. });
  812. }
  813. } else {
  814. this.isUpdate = true;
  815. this.getDetailData(row.id);
  816. }
  817. },
  818. salesmanChange(val, info) {
  819. this.otherForm.salesmanName = info.name;
  820. },
  821. settlementModeChange(info) {
  822. this.otherForm.settlementModeName = info.dictValue;
  823. },
  824. ifChiefChange(value, idx) {
  825. if (value === 1) {
  826. this.tableLinkData.forEach((e) => (e.ifChief = 0));
  827. this.tableLinkData[idx].ifChief = 1;
  828. }
  829. },
  830. getValidate() {
  831. return new Promise((resolve, reject) => {
  832. this.$refs.form.validate((valid) => {
  833. if (!valid) {
  834. reject(false);
  835. } else {
  836. resolve(true);
  837. }
  838. });
  839. });
  840. },
  841. getValidate() {
  842. return Promise.all([
  843. new Promise((resolve, reject) => {
  844. this.$refs.form.validate((valid) => {
  845. if (!valid) {
  846. reject(false);
  847. } else {
  848. resolve(true);
  849. }
  850. });
  851. }),
  852. new Promise((resolve, reject) => {
  853. this.$refs.inventoryTable.validateForm((valid) => {
  854. if (!valid) {
  855. reject(false);
  856. } else {
  857. resolve(true);
  858. }
  859. });
  860. }),
  861. new Promise((resolve, reject) => {
  862. this.$refs.paymentListTable.validateForm((valid) => {
  863. if (!valid) {
  864. reject(false);
  865. } else {
  866. resolve(true);
  867. }
  868. });
  869. })
  870. ]);
  871. },
  872. async save(type) {
  873. try {
  874. await this.getValidate();
  875. // 表单验证通过,执行保存操作
  876. this.loading = true;
  877. if (!this.isUpdate) {
  878. delete this.form.id;
  879. }
  880. let [totalPrice, discountTotalPrice] =
  881. this.$refs.inventoryTable.getPrice();
  882. this.form.totalPrice = totalPrice;
  883. this.form.discountTotalPrice = discountTotalPrice;
  884. if (this.form.categoryId) {
  885. this.form.categoryName = this.findNameById(
  886. this.categoryTreeList,
  887. this.form.categoryId
  888. );
  889. }
  890. let commitData = Object.assign(
  891. {},
  892. {
  893. contract: this.form,
  894. productList: this.$refs.inventoryTable.getTableValue(),
  895. receiptPaymentList: this.$refs.paymentListTable.getTableValue()
  896. }
  897. );
  898. if (this.isUpdate) {
  899. UpdateInformation(commitData)
  900. .then((res) => {
  901. this.loading = false;
  902. this.$message.success('修改成功');
  903. if (type === 'sub') {
  904. this.contractBookSubmit(res);
  905. return;
  906. }
  907. this.cancel();
  908. this.$emit('done');
  909. })
  910. .catch((e) => {
  911. //this.loading = false;
  912. });
  913. } else {
  914. addInformation(commitData)
  915. .then((res) => {
  916. this.loading = false;
  917. this.$message.success('新增成功');
  918. if (type === 'sub') {
  919. this.contractBookSubmit(res);
  920. return;
  921. }
  922. this.cancel();
  923. this.$emit('done');
  924. })
  925. .catch((e) => {
  926. //this.loading = false;
  927. });
  928. }
  929. } catch (error) {
  930. console.log(error);
  931. // 表单验证未通过,不执行保存操作
  932. }
  933. },
  934. contractBookSubmit(res) {
  935. submit({
  936. businessId: this.businessId || res,
  937. // productionSupervisorId
  938. }).then((res) => {
  939. this.cancel();
  940. this.$emit('done');
  941. });
  942. },
  943. cancel() {
  944. this.$nextTick(() => {
  945. this.activeName = 'base';
  946. // 关闭后,销毁所有的表单数据
  947. this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  948. this.$refs['formRef'] && this.$refs['formRef'].resetFields();
  949. this.form = copyObj(this.formDef);
  950. this.$store.commit('concact/setDiscountAmount', 0);
  951. this.visible = false;
  952. });
  953. },
  954. //查找合同分类对应name
  955. findNameById(tree, targetId) {
  956. for (let i = 0; i < tree.length; i++) {
  957. const node = tree[i];
  958. if (node.id === targetId) {
  959. return node.name;
  960. }
  961. if (node.children && node.children.length > 0) {
  962. const name = this.findNameById(node.children, targetId);
  963. if (name) {
  964. return name;
  965. }
  966. }
  967. }
  968. return null;
  969. }
  970. }
  971. };
  972. </script>
  973. <style scoped lang="scss">
  974. .TotalAmount {
  975. font-size: 16px;
  976. padding-right: 30px;
  977. }
  978. </style>