PurchaseOrderFormForm.vue 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. <template>
  2. <a-spin :spinning="loading">
  3. <JFormContainer :disabled="disabled">
  4. <template #detail>
  5. <a-form v-bind="formItemLayout" name="PurchaseOrderFormModal" ref="formRef">
  6. <a-row>
  7. <a-col :span="12">
  8. <a-form-item label="组织(organize)" v-bind="validateInfos.organize" id="PurchaseOrderFormModal-organize" name="organize">
  9. <a-select v-model:value="formData.organize" :disabled="formData.id !== '' && formData.submit == '1'">
  10. <a-select-option value="上海">上海</a-select-option>
  11. <a-select-option value="香港">香港</a-select-option>
  12. </a-select>
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="12">
  16. <a-form-item label="订单编号(bill code)" v-bind="validateInfos.billCode" id="PurchaseOrderFormModal-billCode" name="billCode">
  17. <a-input v-model:value="formData.billCode" placeholder="自动生成" disabled />
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="12">
  21. <a-form-item label="单据日期(bill date)" v-bind="validateInfos.billDate" id="PurchaseOrderFormModal-billDate" name="billDate">
  22. <a-date-picker
  23. placeholder="请选择单据日期(bill date)"
  24. v-model:value="formData.billDate"
  25. value-format="YYYY-MM-DD"
  26. style="width: 100%"
  27. allow-clear
  28. />
  29. </a-form-item>
  30. </a-col>
  31. <a-col :span="12">
  32. <a-form-item label="项目(project)" v-bind="validateInfos.projectName" id="PurchaseOrderFormModal-projectName" name="projectName">
  33. <a-input-search
  34. v-model:value="formData.projectName"
  35. placeholder="请输入项目(project)"
  36. readonly
  37. :disabled="notAllowEdit"
  38. allow-clear
  39. enter-button="Search"
  40. AutoComplete="off"
  41. @search="onSearchProject"
  42. />
  43. </a-form-item>
  44. </a-col>
  45. <a-col :span="12">
  46. <a-form-item label="供应商(supplier)" v-bind="validateInfos.supplier" id="PurchaseOrderFormModal-supplier" name="supplier">
  47. <ApiSelect
  48. :api="supplierOption"
  49. showSearch
  50. v-model:value="formData.supplier"
  51. optionFilterProp="label"
  52. resultField="records"
  53. labelField="name"
  54. valueField="id"
  55. disabled
  56. :params="{ pageSize: -1, status: 1 }"
  57. />
  58. </a-form-item>
  59. </a-col>
  60. <a-col :span="12">
  61. <a-form-item label="优先级(priority)" v-bind="validateInfos.priority" id="PurchaseOrderFormModal-priority" name="priority">
  62. <JDictSelectTag v-model:value="formData.priority" placeholder="请选择" dictCode="priority" disabled />
  63. </a-form-item>
  64. </a-col>
  65. <a-col :span="12">
  66. <a-form-item
  67. label="产品分类(production class)"
  68. v-bind="validateInfos.productionClass"
  69. id="PurchaseOrderFormModal-productionClass"
  70. name="productionClass"
  71. >
  72. <ApiSelect
  73. :api="ClassList"
  74. showSearch
  75. v-model:value="formData.productionClass"
  76. optionFilterProp="label"
  77. resultField="records"
  78. labelField="name"
  79. valueField="id"
  80. disabled
  81. :params="{ pageSize: -1 }"
  82. />
  83. </a-form-item>
  84. </a-col>
  85. <a-col :span="12">
  86. <a-form-item label="机型(model)" v-bind="validateInfos.model" id="PurchaseOrderFormModal-model" name="model">
  87. <JDictSelectTag v-model:value="formData.model" placeholder="请选择" dictCode="model_typer" disabled />
  88. </a-form-item>
  89. </a-col>
  90. <a-col :span="12">
  91. <a-form-item label="厂家(maker)" v-bind="validateInfos.maker" id="PurchaseOrderFormModal-maker" name="maker">
  92. <a-input v-model:value="formData.maker" placeholder="请输入厂家(maker)" allow-clear disabled />
  93. </a-form-item>
  94. </a-col>
  95. <a-col :span="12">
  96. <a-form-item label="贸易条款(trade term)" v-bind="validateInfos.tradeTerms" id="PurchaseOrderFormModal-tradeTerms" name="tradeTerms">
  97. <JDictSelectTag v-model:value="formData.tradeTerms" placeholder="请选择" dictCode="delivery_terms" />
  98. </a-form-item>
  99. </a-col>
  100. <a-col :span="12">
  101. <a-form-item label="是否出口(export)" v-bind="validateInfos.isExport" id="PurchaseOrderFormModal-isExport" name="isExport">
  102. <JDictSelectTag v-model:value="formData.isExport" placeholder="请选择" dictCode="yes_or_no" />
  103. </a-form-item>
  104. </a-col>
  105. <a-col :span="12">
  106. <a-form-item
  107. label="包装要求(package requirement)"
  108. v-bind="validateInfos.packagebRequirement"
  109. id="PurchaseOrderFormModal-packagebRequirement"
  110. name="packagebRequirement"
  111. >
  112. <a-input
  113. v-model:value="formData.packagebRequirement"
  114. placeholder="请输入包装要求(package requirement)"
  115. allow-clear
  116. AutoComplete="off"
  117. />
  118. </a-form-item>
  119. </a-col>
  120. <!-- <a-col :span="12">
  121. <a-form-item label="收件人(recipient)" v-bind="validateInfos.recipient" id="PurchaseOrderFormModal-recipient" name="recipient">
  122. <a-input v-model:value="formData.recipient" placeholder="请输入" AutoComplete="off" />
  123. </a-form-item>
  124. </a-col> -->
  125. <a-col :span="12">
  126. <a-form-item label="运输方式(transport)" v-bind="validateInfos.transport" id="PurchaseOrderFormModal-transport" name="transport">
  127. <JDictSelectTag v-model:value="formData.transport" placeholder="请选择" dictCode="delivery_methods" />
  128. </a-form-item>
  129. </a-col>
  130. <!-- <a-col :span="12">
  131. <a-form-item
  132. label="收件人地址(recipient address)"
  133. v-bind="validateInfos.recipientAddress"
  134. id="PurchaseOrderFormModal-recipientAddress"
  135. name="recipientAddress"
  136. >
  137. <a-input v-model:value="formData.recipientAddress" placeholder="请输入" AutoComplete="off" />
  138. </a-form-item>
  139. </a-col> -->
  140. <a-col :span="12">
  141. <a-form-item
  142. label="付款条件(payment terms)"
  143. v-bind="validateInfos.paymentTerms"
  144. id="PurchaseOrderFormModal-paymentTerms"
  145. name="paymentTerms"
  146. >
  147. <JDictSelectTag v-model:value="formData.paymentTerms" placeholder="请选择" dictCode="payment_terms" />
  148. </a-form-item>
  149. </a-col>
  150. <!-- <a-col :span="12">
  151. <a-form-item label="收件人电话(recipient tel)" v-bind="validateInfos.recipientTel" id="PurchaseOrderFormModal-recipientTel" name="recipientTel">
  152. <a-input v-model:value="formData.recipientTel" placeholder="请输入" AutoComplete="off" />
  153. </a-form-item>
  154. </a-col> -->
  155. <a-col :span="12">
  156. <a-form-item label="发货方式(delivery)" v-bind="validateInfos.delivery" id="PurchaseOrderFormModal-delivery" name="delivery">
  157. <JDictSelectTag v-model:value="formData.delivery" placeholder="请选择" dictCode="delivery_sale_order" />
  158. </a-form-item>
  159. </a-col>
  160. <a-col :span="12">
  161. <a-form-item
  162. label="质保期(warranty period)"
  163. v-bind="validateInfos.warrantyPeriod"
  164. id="PurchaseOrderFormModal-warrantyPeriod"
  165. name="warrantyPeriod"
  166. >
  167. <a-input
  168. v-model:value="formData.warrantyPeriod"
  169. placeholder="请输入"
  170. style="width: 85%; margin-right: 1%"
  171. AutoComplete="off"
  172. />月(month)
  173. </a-form-item>
  174. </a-col>
  175. <a-col :span="12">
  176. <a-form-item
  177. label="质保条款(warranty terms)"
  178. v-bind="validateInfos.warrantyTerms"
  179. id="PurchaseOrderFormModal-warrantyTerms"
  180. name="warrantyTerms"
  181. >
  182. <a-input v-model:value="formData.warrantyTerms" placeholder="请输入质保条款(warranty terms)" allow-clear AutoComplete="off" />
  183. </a-form-item>
  184. </a-col>
  185. <a-col :span="12">
  186. <a-form-item
  187. label="汇率(exchange rate)"
  188. v-bind="validateInfos.exchangeRate"
  189. id="PurchaseOrderFormModal-exchangeRate"
  190. name="exchangeRate"
  191. >
  192. <a-input v-model:value="formData.exchangeRate" placeholder="请输入" allow-clear AutoComplete="off" disabled />
  193. </a-form-item>
  194. </a-col>
  195. <a-col :span="12">
  196. <a-form-item label="币种(currency)" v-bind="validateInfos.currency" id="PurchaseOrderFormModal-currency" name="currency">
  197. <JDictSelectTag :disabled="!hasPermission('purCode:pur_order:editBZ')" v-model:value="formData.currency" placeholder="请选择" dictCode="currency" @change="handleChangeCurrency" />
  198. </a-form-item>
  199. </a-col>
  200. <a-col :span="12">
  201. <a-form-item
  202. label="采购部门(purchase department)"
  203. v-bind="validateInfos.purchaseDepartment"
  204. id="PurchaseOrderFormModal-purchaseDepartment"
  205. name="purchaseDepartment"
  206. >
  207. <a-input v-model:value="formData.purchaseDepartmentName" placeholder="请输入" allow-clear disabled />
  208. </a-form-item>
  209. </a-col>
  210. <a-col :span="12">
  211. <a-form-item label="采购员(purchasesman)" v-bind="validateInfos.purchaseman" id="PurchaseOrderFormModal-purchaseman" name="purchaseman">
  212. <a-input v-model:value="formData.purchasemanName" placeholder="请输入采购员(salesman)" allow-clear disabled />
  213. </a-form-item>
  214. </a-col>
  215. <a-col :span="12">
  216. <a-form-item
  217. label="折扣(discountHead)"
  218. v-bind="validateInfos.discountHead"
  219. id="PurchaseOrderFormModal-discountHead"
  220. name="discountHead"
  221. >
  222. <a-input-number
  223. v-model:value="formData.discountHead"
  224. placeholder="请输入折扣(discountHead)"
  225. :min="0"
  226. :max="100"
  227. @blur="discountHeadChange"
  228. />
  229. </a-form-item>
  230. </a-col>
  231. <a-col :span="12">
  232. <a-form-item
  233. label="折后金额(discounted amount)"
  234. v-bind="validateInfos.discountAmount"
  235. id="PurchaseOrderFormModal-discountAmount"
  236. name="discountAmount"
  237. >
  238. <a-input v-model:value="formData.discountAmount" allow-clear disabled />
  239. </a-form-item>
  240. </a-col>
  241. <a-col :span="12">
  242. <a-form-item label="备注(notes)" v-bind="validateInfos.notes" id="PurchaseOrderFormModal-notes" name="notes">
  243. <a-input v-model:value="formData.notes" AutoComplete="off" />
  244. </a-form-item>
  245. </a-col>
  246. <a-col :span="12">
  247. <a-form-item
  248. label="协议条款(agreement terms)"
  249. v-bind="validateInfos.agreementTerms"
  250. id="PurchaseOrderFormModal-agreementTerms"
  251. name="agreementTerms"
  252. >
  253. <JSelectMultiple
  254. v-model:value="formData.agreementTerms"
  255. placeholder=""
  256. dictCode="base_agreement_terms,name,name"
  257. page="false"
  258. showSearch
  259. />
  260. </a-form-item>
  261. </a-col>
  262. <a-col :span="12">
  263. <a-form-item
  264. label="收件人地址(recipient address)"
  265. v-bind="validateInfos.recipientAddress"
  266. id="SaleOrderForm-recipientAddress"
  267. name="recipientAddress"
  268. >
  269. <a-textarea v-model:value="formData.recipientAddress" AutoComplete="off" :rows="2" />
  270. </a-form-item>
  271. </a-col>
  272. <a-col :span="12">
  273. <a-form-item label="附件(attachs)" v-bind="validateInfos.attachs" id="PurchaseOrderFormModal-attachs" name="attachs">
  274. <JUpload v-model:value="formData.attachs" />
  275. </a-form-item>
  276. </a-col>
  277. </a-row>
  278. </a-form>
  279. </template>
  280. </JFormContainer>
  281. <!-- 子表单区域 -->
  282. <a-tabs v-model:activeKey="activeKey" animated style="padding: 24px; padding-top: 0px">
  283. <a-tab-pane tab="采购订单 - 产品明细(product details)" key="purOrderFormShipFormProduct" :forceRender="true">
  284. <a-button
  285. type="primary"
  286. style="margin-right: 1%; margin-bottom: 1%"
  287. @click="selectSaleOrderList"
  288. :disabled="disabled || formData.sourceCode !== ''"
  289. >
  290. 选择销售订单(select saleorder)</a-button
  291. >
  292. <a-button type="primary" style="margin-right: 1%; margin-bottom: 1%" @click="selectVirtualProducts" :disabled="disabled">
  293. 选择虚拟产品(select virtual products)</a-button
  294. >
  295. <a-button
  296. type="primary"
  297. style="margin-right: 1%; margin-bottom: 1%"
  298. @click="SelectSupplierQuotationList"
  299. v-auth="'purCode:pur_order:selection'"
  300. :disabled="disabled || formData.sourceCode2 !== ''"
  301. >选择供应商报价选定(select supplier quotation selection)</a-button
  302. >
  303. <j-vxe-table
  304. :keep-source="true"
  305. resizable
  306. ref="purOrderFormShipFormProductTableRef"
  307. :loading="purOrderFormShipFormProductTable.loading"
  308. :columns="purOrderFormShipFormProductTable.columns"
  309. :dataSource="purOrderFormShipFormProductTable.dataSource"
  310. :disabled="disabled"
  311. :rowNumber="true"
  312. :rowSelection="true"
  313. asyncRemove
  314. @value-change="changeValues"
  315. >
  316. <template #action="props">
  317. <a-popconfirm title="确定删除吗?" @confirm="handleDelete(props)" v-if="!(formData.id !== '' && formData.submit == '1') && !disabled">
  318. <a>删除(delete)</a>
  319. </a-popconfirm>
  320. </template>
  321. </j-vxe-table>
  322. </a-tab-pane>
  323. <a-tab-pane tab="采购订单 - 船明细(ship details)" key="PurOrderFormShipFormShip" :forceRender="true">
  324. <j-vxe-table
  325. :keep-source="true"
  326. resizable
  327. ref="PurOrderFormShipFormShipTableRef"
  328. :loading="PurOrderFormShipFormShipTable.loading"
  329. :columns="PurOrderFormShipFormShipTable.columns"
  330. :dataSource="PurOrderFormShipFormShipTable.dataSource"
  331. :disabled="disabled"
  332. :rowNumber="true"
  333. :rowSelection="true"
  334. >
  335. <template #action="props">
  336. <a @click="viewAccessory(props)">查看配件信息(view accessory information)</a>
  337. </template>
  338. </j-vxe-table>
  339. </a-tab-pane>
  340. </a-tabs>
  341. <SelectPrpductModal ref="SelectPrpductModalRef" @select-product="addProduct" />
  342. <SelectProjectModal ref="SelectProjectModalRef" @select-project="addProject" />
  343. <BaseShipArchiveAccessoriesModal ref="BaseShipArchiveAccessoriesModalRef" />
  344. <SelectSaleOrderModal ref="SelectSaleOrderModalRef" @select-sale-order="addFormSaleOrder" />
  345. <SelectSupplierQuotation ref="SelectSupplierQuotationRef" @select-supplier-quatation-confirm="addFromQuotation" />
  346. </a-spin>
  347. </template>
  348. <script lang="ts">
  349. import { defineComponent, ref, reactive, computed, toRaw, watch } from 'vue';
  350. import { defHttp } from '/@/utils/http/axios';
  351. import { useValidateAntFormAndTable } from '/@/hooks/system/useJvxeMethods';
  352. import {
  353. queryPurOrderFormShipFormShippTable,
  354. queryPurOrderFormProductListByMainId,
  355. ClassList,
  356. queryDataById,
  357. supplierOption,
  358. saveOrUpdate,
  359. queryVersonHistoryById,
  360. queryPurVersonFormShipListByMainId,
  361. queryPurVersonProductListByMainId,
  362. getExchangeRate
  363. } from '../PurchaseOrderyForm.api';
  364. import { JVxeTable } from '/@/components/jeecg/JVxeTable';
  365. import { purchaseOrderShipColumns, purchaseOrderProductColumns } from '../PurchaseOrderForm.data';
  366. import SelectPrpductModal from '../../../publicComponents/SelectPrpductModal.vue';
  367. import SelectProjectModal from '../../../publicComponents/SelectProjectModal.vue';
  368. import SelectSaleOrderModal from '../../../publicComponents/SelectSaleOrderModal.vue';
  369. import BaseShipArchiveAccessoriesModal from '../../../publicComponents/BaseShipArchiveAccessoriesModal.vue';
  370. import SelectSupplierQuotation from '../../../publicComponents/SelectSupplierQuotation.vue';
  371. import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  372. import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  373. import { JDictSelectTag, ApiSelect } from '/@/components/Form';
  374. import JSelectInput from '/@/components/Form/src/jeecg/components/JSelectInput.vue';
  375. import JSelectMultiple from '/@/components/Form/src/jeecg/components/JSelectMultiple.vue';
  376. import { Form, message } from 'ant-design-vue';
  377. import { useUserStore } from '/@/store/modules/user';
  378. import { usePermission } from '/@/hooks/web/usePermission';
  379. import moment from 'moment';
  380. const useForm = Form.useForm;
  381. export default defineComponent({
  382. name: 'PurchaseOrderFormModal',
  383. components: {
  384. JVxeTable,
  385. JFormContainer,
  386. SelectPrpductModal,
  387. JUpload,
  388. JDictSelectTag,
  389. JSelectInput,
  390. SelectProjectModal,
  391. BaseShipArchiveAccessoriesModal,
  392. SelectSaleOrderModal,
  393. ApiSelect,
  394. JSelectMultiple,
  395. SelectSupplierQuotation,
  396. },
  397. props: {
  398. formDisabled: {
  399. type: Boolean,
  400. default: false,
  401. },
  402. formData: { type: Object, default: () => {} },
  403. formBpm: { type: Boolean, default: true },
  404. },
  405. emits: ['success'],
  406. setup(props, { emit }) {
  407. const { hasPermission } = usePermission();
  408. const userStore = useUserStore();
  409. const loading = ref(false);
  410. const formRef = ref();
  411. const PurOrderFormShipFormShipTableRef = ref();
  412. const SelectPrpductModalRef = ref();
  413. const SelectProjectModalRef = ref();
  414. const SelectSupplierQuotationRef = ref();
  415. const BaseShipArchiveAccessoriesModalRef = ref();
  416. const SelectSaleOrderModalRef = ref();
  417. const PurOrderFormShipFormShipTable = reactive<Record<string, any>>({
  418. loading: false,
  419. columns: purchaseOrderShipColumns,
  420. dataSource: [],
  421. });
  422. const purOrderFormShipFormProductTableRef = ref();
  423. const purOrderFormShipFormProductTable = reactive<Record<string, any>>({
  424. loading: false,
  425. columns: purchaseOrderProductColumns,
  426. dataSource: [],
  427. });
  428. const activeKey = ref('purOrderFormShipFormProduct');
  429. var notAllowEdit = ref(false);
  430. const formData = reactive<Record<string, any>>({
  431. id: '',
  432. status: undefined,
  433. delFlag: undefined,
  434. sourceCode: '',
  435. sourceCode2: '',
  436. submit: undefined,
  437. organize: '',
  438. billCode: '',
  439. billDate: moment(new Date()).format('YYYY-MM-DD'),
  440. project: '',
  441. projectName: '',
  442. supplier: '',
  443. supplierName: '',
  444. priority: '',
  445. productionClass: '',
  446. model: '',
  447. maker: '',
  448. tradeTerms: '',
  449. isExport: '',
  450. packagebRequirement: '',
  451. recipient: '',
  452. recipientTel: '',
  453. recipientAddress: '',
  454. paymentTerms: '',
  455. delivery: '',
  456. transport: '',
  457. warrantyPeriod: '',
  458. warrantyTerms: '',
  459. exchangeRate: '',
  460. purchaseDepartment: '',
  461. purchaseDepartmentName: '',
  462. purchaseman: '',
  463. purchasemanName: '',
  464. currency: '',
  465. notes: '',
  466. agreementTerms: '',
  467. discountHead: 0,
  468. discountAmount: '',
  469. totalAmount: '',
  470. attachs: '',
  471. });
  472. //表单验证
  473. const validatorRules = reactive({
  474. projectName: [{ required: true, message: '请选择报价项目(select project)' }],
  475. organize: [{ required: true, message: '请选择组织(select organize)' }],
  476. // currency:[
  477. // { required: true, message: '请选择币种(currency)' }
  478. // ],
  479. });
  480. const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: false });
  481. const dbData = {};
  482. const formItemLayout = {
  483. labelCol: { xs: { span: 24 }, sm: { span: 7 } },
  484. wrapperCol: { xs: { span: 24 }, sm: { span: 15 } },
  485. labelCol1: { xs: { span: 24 }, sm: { span: 7 } },
  486. wrapperCol1: { xs: { span: 24 }, sm: { span: 15 } },
  487. };
  488. // 表单禁用
  489. const disabled = computed(() => {
  490. if (props.formBpm === true) {
  491. if (props.formData.disabled === false) {
  492. return false;
  493. } else {
  494. return true;
  495. }
  496. }
  497. return props.formDisabled;
  498. });
  499. function add() {
  500. resetFields();
  501. PurOrderFormShipFormShipTable.dataSource = [];
  502. purOrderFormShipFormProductTable.dataSource = [];
  503. activeKey.value = 'purOrderFormShipFormProduct';
  504. formData.purchaseman = userStore.getUserInfo.username;
  505. formData.purchasemanName = userStore.getUserInfo.realname;
  506. formData.purchaseDepartment = userStore.getUserInfo.orgCode;
  507. formData.purchaseDepartmentName = userStore.getUserInfo.orgName;
  508. formData.discountHead = 0;
  509. }
  510. async function copy(data, id) {
  511. //主表数据
  512. await queryMainData(id);
  513. formData.id = '';
  514. formData.billCode = '';
  515. formData.submit = undefined;
  516. formData.sourceCode = '';
  517. formData.sourceCode2 = '';
  518. formData.project = '';
  519. formData.projectName = '';
  520. //子表数据
  521. const PurOrderFormShipFormShipDataList = await queryPurOrderFormShipFormShippTable(id);
  522. PurOrderFormShipFormShipTable.dataSource = [...PurOrderFormShipFormShipDataList];
  523. data.map((item) => {
  524. item.sourceId = '';
  525. item.sourceType = '';
  526. });
  527. purOrderFormShipFormProductTable.dataSource = [...data];
  528. notAllowEdit.value = false;
  529. }
  530. // 判断有没有参照的子表
  531. // function isSelect() {
  532. // var arrQuo = [],
  533. // arrCon = [];
  534. // purOrderFormShipFormProductTable.dataSource.map((item) => {
  535. // var sign = '';
  536. // sign = item.sourceId ? item.sourceId.substring(0, 3) : '';
  537. // if (item.sourceId && sign == 'Quo') {
  538. // arrQuo.push(item.sourceId);
  539. // } else if (item.sourceId && sign == 'Sale') {
  540. // arrCon.push(item.sourceId);
  541. // }
  542. // });
  543. // if (arrQuo.length == 0 && arrCon.length == 0) {
  544. // formData.sourceCode2 = '';
  545. // formData.sourceCode = '';
  546. // notAllowEdit.value = false;
  547. // } else if (arrQuo.length == 0) {
  548. // formData.sourceCode = '';
  549. // notAllowEdit.value = true;
  550. // } else if (arrCon.length == 0) {
  551. // formData.sourceCode2 = '';
  552. // notAllowEdit.value = true;
  553. // }
  554. // }
  555. async function edit(row) {
  556. //主表数据
  557. await queryMainData(row.id);
  558. //子表数据
  559. const PurOrderFormShipFormShipDataList = await queryPurOrderFormShipFormShippTable(row['id']);
  560. PurOrderFormShipFormShipTable.dataSource = [...PurOrderFormShipFormShipDataList];
  561. const purOrderFormShipFormProductDataList = await queryPurOrderFormProductListByMainId(row['id']);
  562. purOrderFormShipFormProductTable.dataSource = [...purOrderFormShipFormProductDataList];
  563. notAllowEdit.value = true;
  564. }
  565. async function queryMainData(id) {
  566. const row = await queryDataById(id);
  567. resetFields();
  568. const tmpData = {};
  569. Object.keys(formData).forEach((key) => {
  570. if (row.hasOwnProperty(key)) {
  571. tmpData[key] = row[key];
  572. }
  573. });
  574. //赋值
  575. Object.assign(formData, tmpData);
  576. }
  577. //查看版本详情
  578. async function VersionDetail(record) {
  579. //主表数据
  580. await queryVersonHistoryData(record.id);
  581. //子表数据
  582. const PurchaseOrderFormModalShipFormShipDataList = await queryPurVersonFormShipListByMainId(record.id);
  583. PurOrderFormShipFormShipTable.dataSource = [...PurchaseOrderFormModalShipFormShipDataList];
  584. const purOrderFormShipFormProductDataList = await queryPurVersonProductListByMainId(record.id);
  585. purOrderFormShipFormProductTable.dataSource = [...purOrderFormShipFormProductDataList];
  586. }
  587. async function queryVersonHistoryData(id) {
  588. const row = await queryVersonHistoryById(id);
  589. resetFields();
  590. const tmpData = {};
  591. Object.keys(formData).forEach((key) => {
  592. if (row.hasOwnProperty(key)) {
  593. tmpData[key] = row[key];
  594. }
  595. });
  596. //赋值
  597. Object.assign(formData, tmpData);
  598. }
  599. const { getSubFormAndTableData, transformData } = useValidateAntFormAndTable(activeKey, {
  600. purOrderShip: PurOrderFormShipFormShipTableRef,
  601. purOrderProduct: purOrderFormShipFormProductTableRef,
  602. });
  603. async function getFormData() {
  604. try {
  605. // 触发表单验证
  606. await validate();
  607. } catch ({ errorFields }) {
  608. if (errorFields) {
  609. const firstField = errorFields[0];
  610. if (firstField) {
  611. formRef.value.scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
  612. }
  613. }
  614. return Promise.reject(errorFields);
  615. }
  616. return transformData(toRaw(formData));
  617. }
  618. async function submitForm() {
  619. var xTable = purOrderFormShipFormProductTableRef.value!.getXTable();
  620. if (xTable.data.length == 0) {
  621. message.warning('请添加产品明细');
  622. } else {
  623. purOrderFormShipFormProductTableRef.value!.validateTable().then(async (errMap) => {
  624. if (errMap) {
  625. console.log('表单验证未通过:', { errMap });
  626. } else {
  627. const mainData = await getFormData();
  628. const subData = await getSubFormAndTableData();
  629. const values = Object.assign({}, dbData, mainData, subData);
  630. console.log('表单提交数据', values);
  631. const isUpdate = values.id ? true : false;
  632. const isRevise = values.submit == '1' ? true : false;
  633. await saveOrUpdate(values, isUpdate, isRevise);
  634. //关闭弹窗
  635. emit('success');
  636. }
  637. });
  638. }
  639. }
  640. function setFieldsValue(values) {
  641. if (values) {
  642. Object.keys(values).map((k) => {
  643. formData[k] = values[k];
  644. });
  645. }
  646. }
  647. function onSearchProject() {
  648. SelectProjectModalRef.value.getTable();
  649. }
  650. function addProduct(data) {
  651. data.map((item) => {
  652. item.productClass = item.classId_dictText;
  653. item.productCode = item.code;
  654. item.productId = item.id;
  655. item.id = undefined;
  656. item.notes = '';
  657. });
  658. var xTable = purOrderFormShipFormProductTableRef.value!.getXTable();
  659. var arrProduct = xTable.data.concat(data);
  660. purOrderFormShipFormProductTable.dataSource = arrProduct;
  661. }
  662. function getShipList(id, status) {
  663. let params = { id: id };
  664. let url =
  665. status == 'quotation'
  666. ? '/purCode/purQuotationSelection/queryPurQuotationSelectionShipByMainId'
  667. : '/saleCode/saleOrder/querySaleOrderShipByMainId';
  668. defHttp.get({ url: url, params }, { isTransformResponse: false }).then((res) => {
  669. if (res) {
  670. PurOrderFormShipFormShipTable.dataSource = res.result;
  671. }
  672. });
  673. }
  674. function addFormSaleOrder(data) {
  675. data.map((item) => {
  676. item.model = item.childModel;
  677. item.sourceId = item.childId;
  678. item.sourceType = 'Sale' + item.childId;
  679. item.sourceCode = item.billCode;
  680. item.taxPrice = item.taxPriceGys;
  681. item.taxAmount = (item.taxPrice * item.quantity).toFixed(2);
  682. formData.notes = data[0].notes;
  683. item.notes = '';
  684. // item.productClass =data[0].productClass
  685. });
  686. var xTable = purOrderFormShipFormProductTableRef.value!.getXTable();
  687. var arrProduct = xTable.data.concat(data);
  688. purOrderFormShipFormProductTable.dataSource = arrProduct;
  689. notAllowEdit.value = true;
  690. if (formData.sourceCode2.includes(data[0].billCode)) {
  691. formData.sourceCode2 = formData.sourceCode2;
  692. } else {
  693. formData.sourceCode2 = formData.sourceCode2 == '' ? data[0].billCode : formData.sourceCode2 + ',' + data[0].billCode;
  694. }
  695. if (formData.sourceCode == '') {
  696. formData.project = data[0].project;
  697. formData.projectName = data[0].projectName;
  698. formData.supplierName = data[0].supplierName;
  699. formData.supplier = data[0].supplierId;
  700. formData.priority = data[0].priority;
  701. formData.productionClass = data[0].productionClass;
  702. formData.model = data[0].headModel;
  703. formData.maker = data[0].maker;
  704. formData.packagebRequirement = data[0].packagebRequirement;
  705. formData.delivery = data[0].delivery;
  706. formData.paymentTerms = data[0].paymentTerms;
  707. formData.warrantyPeriod = data[0].warrantyPeriod;
  708. formData.warrantyTerms = data[0].warrantyTerms;
  709. formData.isExport = data[0].isExport;
  710. formData.exchangeRate = data[0].exchangeRateGys;
  711. formData.currency = data[0].currencyGys;
  712. formData.tradeTerms = data[0].deliveryTerms;
  713. formData.attachs = data[0].attachs;
  714. getShipList(data[0].headId, 'contract');
  715. }
  716. }
  717. function addFromQuotation(data) {
  718. data.map((item) => {
  719. item.fatherModel = item.model;
  720. item.model = item.childModel;
  721. item.sourceId = item.childId;
  722. item.sourceType = 'Quo' + item.childId;
  723. item.sourceCode = item.billCode;
  724. });
  725. var arrProduct = data.concat(purOrderFormShipFormProductTable.dataSource);
  726. purOrderFormShipFormProductTable.dataSource = arrProduct;
  727. notAllowEdit.value = true;
  728. formData.sourceCode = data[0].billCode;
  729. formData.paymentTerms = data[0].paymentTerm;
  730. if (formData.sourceCode2 == '') {
  731. formData.project = data[0].inquiryProject;
  732. formData.projectName = data[0].projectName;
  733. formData.supplier = data[0].selectionSupplier;
  734. formData.supplierName = data[0].selectionSupplier_dictText;
  735. formData.priority = data[0].priority;
  736. formData.productionClass = data[0].productionClass;
  737. formData.model = data[0].fatherModel;
  738. formData.maker = data[0].maker;
  739. formData.exchangeRate = data[0].exchangeRateUsd;
  740. formData.currency = data[0].currency;
  741. getShipList(data[0].headId, 'quotation');
  742. }
  743. }
  744. //选择供应商报价单选定
  745. function SelectSupplierQuotationList() {
  746. SelectSupplierQuotationRef.value.getTable(formData, 'purOrder');
  747. }
  748. function addProject(data) {
  749. if (data.lenght == 0) {
  750. formData.projectName = '';
  751. formData.projectName = '';
  752. } else {
  753. formData.project = data[0].id;
  754. formData.projectName = data[0].code;
  755. }
  756. }
  757. //查看配件信息
  758. function viewAccessory(prop) {
  759. BaseShipArchiveAccessoriesModalRef.value.getTable(prop.row);
  760. }
  761. //产品明细-删除行
  762. function handleDelete(prop) {
  763. var xTable = purOrderFormShipFormProductTableRef.value!.getXTable();
  764. var newArray = [...xTable.data];
  765. newArray.splice(prop.rowIndex, 1);
  766. purOrderFormShipFormProductTable.dataSource = newArray;
  767. if (purOrderFormShipFormProductTable.dataSource.length !== 0) {
  768. var arrQuo = [],
  769. arrCon = [];
  770. purOrderFormShipFormProductTable.dataSource.map((item) => {
  771. var sign = '';
  772. sign = item.sourceType ? item.sourceType.substring(0, 3) : '';
  773. if (item.sourceType && sign == 'Quo') {
  774. arrQuo.push(item.sourceType);
  775. } else if (item.sourceType && sign == 'Sale') {
  776. arrCon.push(item.sourceType);
  777. }
  778. });
  779. if (arrQuo.length == 0 && arrCon.length == 0) {
  780. formData.sourceCode2 = '';
  781. formData.sourceCode = '';
  782. notAllowEdit.value = false;
  783. } else if (arrQuo.length == 0) {
  784. formData.sourceCode = '';
  785. } else if (arrCon.length == 0) {
  786. formData.sourceCode2 = '';
  787. }
  788. } else {
  789. notAllowEdit.value = false;
  790. formData.sourceCode2 = '';
  791. formData.sourceCode = '';
  792. }
  793. }
  794. // 选择销售订单
  795. function selectSaleOrderList() {
  796. SelectSaleOrderModalRef.value.getTable(formData, 'purOrder');
  797. }
  798. function selectVirtualProducts() {
  799. SelectPrpductModalRef.value.getTableVirtual();
  800. }
  801. function changeValues(prop) {
  802. if (prop.col.key == 'quantity') {
  803. if (prop.row.quantity == 0 || prop.row.quantity) {
  804. var num = prop.row.quantity * Number(prop.row.taxPrice);
  805. prop.row.taxAmount = isNaN(num) ? '' : num.toFixed(2);
  806. purOrderFormShipFormProductTable.dataSource[prop.rowIndex].taxAmount = Number(prop.row.taxAmount);
  807. }
  808. }
  809. if (prop.col.key == 'taxPrice') {
  810. if (prop.row.taxPrice) {
  811. var num = prop.row.quantity * Number(prop.row.taxPrice);
  812. prop.row.taxAmount = isNaN(num) ? '' : num.toFixed(2);
  813. var nowTaxPriceOriginal = prop.row.taxPrice / (1 - Number(prop.row.discount) / 100);
  814. prop.row.taxPriceOriginal = isNaN(nowTaxPriceOriginal) ? '' : nowTaxPriceOriginal.toFixed(2);
  815. purOrderFormShipFormProductTable.dataSource[prop.rowIndex].taxAmount = Number(prop.row.taxAmount);
  816. }
  817. }
  818. if (prop.col.key == 'taxPriceOriginal') {
  819. if (prop.row.taxPriceOriginal) {
  820. let price = 0;
  821. if (prop.row.discount) {
  822. price = Number(prop.row.taxPriceOriginal) * (1 - Number(prop.row.discount) / 100);
  823. } else {
  824. price = Number(prop.row.taxPriceOriginal);
  825. }
  826. prop.row.taxPrice = isNaN(price) ? '' : Number(price.toFixed(2));
  827. let num = prop.row.quantity * Number(prop.row.taxPrice);
  828. prop.row.taxAmount = isNaN(num) ? '' : num.toFixed(2);
  829. purOrderFormShipFormProductTable.dataSource[prop.rowIndex].taxAmount = Number(prop.row.taxAmount);
  830. }
  831. }
  832. }
  833. /**
  834. * 值改变事件触发-树控件回调
  835. * @param key
  836. * @param value
  837. */
  838. function handleFormChange(key, value) {
  839. formData[key] = value;
  840. }
  841. // 折扣改变
  842. const discountHeadChange = (event) => {
  843. if (formData.totalAmount) {
  844. getDiscountAmount();
  845. formData.discountAmount = parseFloat(formData.discountAmount) + parseFloat(formData.virtualAmount);
  846. }
  847. };
  848. // 计算折扣金额
  849. const getDiscountAmount = () => {
  850. formData.discountAmount = (Number(formData.totalAmount) * (1 - Number(formData.discountHead) / 100)).toFixed(2);
  851. };
  852. // 监听 count 的变化
  853. watch(
  854. purOrderFormShipFormProductTable,
  855. (newValue, oldValue) => {
  856. let data = newValue.dataSource;
  857. let total = 0;
  858. let other = 0;
  859. data.map((item) => {
  860. if (item.sourceType) {
  861. total += Number(item.taxAmount) || 0;
  862. } else {
  863. other += Number(item.taxAmount) || 0;
  864. }
  865. });
  866. formData.totalAmount = total;
  867. formData.virtualAmount = other;
  868. getDiscountAmount();
  869. formData.discountAmount = parseFloat(formData.discountAmount) + parseFloat(formData.virtualAmount);
  870. if (data.length < 1) {
  871. formData.discountHead = 0;
  872. formData.discountAmount = '';
  873. }
  874. },
  875. { deep: true }
  876. );
  877. // 监听币种变化,获取汇率
  878. watch(() => formData.currency,
  879. async (newVal, oldVal) => {
  880. if (newVal && newVal !== oldVal) {
  881. // setExchangeRate();
  882. await handleChangeCurrency(newVal, oldVal);
  883. }
  884. },
  885. { immediate: true }
  886. );
  887. // 监听日期变化,获取汇率
  888. watch(() => formData.billDate,
  889. async (newDate, oldDate) => {
  890. const currentCurrency = formData.currency;
  891. if (currentCurrency && newDate !== oldDate) {
  892. // 保留当前币种不变,但重新获取汇率并刷新子表
  893. await handleChangeCurrency(currentCurrency, currentCurrency);
  894. }
  895. },
  896. { immediate: false }
  897. );
  898. async function handleChangeCurrency (newCurrency?: string, oldCurrency?: string) {
  899. if (!newCurrency || !oldCurrency) return;
  900. const date = moment(formData.billDate);
  901. const year = date.format('YYYY');
  902. const month = date.format('MM');
  903. try {
  904. // 获取旧币种汇率(原币种)与 新币种汇率(新币种),并展示新币种汇率
  905. const oldRateRes = await getExchangeRate({ year, month, currency: oldCurrency });
  906. const oldExchangeRate = parseFloat(oldRateRes || '1');
  907. const newRateRes = await getExchangeRate({ year, month, currency: newCurrency });
  908. const newExchangeRate = parseFloat(newRateRes || '1');
  909. formData.exchangeRate = isNaN(newExchangeRate) ? '' : newExchangeRate;
  910. purOrderFormShipFormProductTable.dataSource = purOrderFormShipFormProductTable.dataSource.map(item => {
  911. const originalTaxPriceOriginal = item.taxPriceOriginal;
  912. if (!originalTaxPriceOriginal) return item;
  913. // 换算逻辑:原币种金额 × 原汇率 ÷ 新汇率
  914. const convertedTaxPriceOriginal = originalTaxPriceOriginal * oldExchangeRate / newExchangeRate;
  915. return {
  916. ...item,
  917. taxPriceOriginal: convertedTaxPriceOriginal.toFixed(6) || '',
  918. _needUpdate: true // 标记需要更新的行
  919. };
  920. });
  921. // 手动触发 changeValues 计算其他字段
  922. const updatedDataSource = purOrderFormShipFormProductTable.dataSource;
  923. updatedDataSource.forEach((row,index) => {
  924. if (row._needUpdate) {
  925. changeValues({
  926. col: { key: 'taxPriceOriginal' },
  927. row: row,
  928. rowIndex: index
  929. });
  930. }
  931. });
  932. } catch (err) {
  933. console.error('汇率换算失败:', err);
  934. formData.exchangeRate = '';
  935. }
  936. }
  937. return {
  938. hasPermission,
  939. discountHeadChange,
  940. PurOrderFormShipFormShipTableRef,
  941. PurOrderFormShipFormShipTable,
  942. purOrderFormShipFormProductTableRef,
  943. purOrderFormShipFormProductTable,
  944. SelectSaleOrderModalRef,
  945. SelectSupplierQuotationRef,
  946. validatorRules,
  947. validateInfos,
  948. activeKey,
  949. loading,
  950. formData,
  951. setFieldsValue,
  952. handleFormChange,
  953. formItemLayout,
  954. disabled,
  955. getFormData,
  956. submitForm,
  957. add,
  958. edit,
  959. copy,
  960. formRef,
  961. SelectPrpductModalRef,
  962. addProduct,
  963. onSearchProject,
  964. SelectProjectModalRef,
  965. addProject,
  966. handleDelete,
  967. BaseShipArchiveAccessoriesModalRef,
  968. viewAccessory,
  969. VersionDetail,
  970. notAllowEdit,
  971. selectSaleOrderList,
  972. addFormSaleOrder,
  973. ClassList,
  974. supplierOption,
  975. selectVirtualProducts,
  976. changeValues,
  977. SelectSupplierQuotationList,
  978. addFromQuotation,
  979. handleChangeCurrency,
  980. };
  981. },
  982. });
  983. </script>
  984. <style lang="less" scoped>
  985. /** 时间和数字输入框样式 */
  986. :deep(.ant-input-number) {
  987. width: 100%;
  988. }
  989. :deep(.ant-calendar-picker) {
  990. width: 100%;
  991. }
  992. // /deep/.vxe-table--body-wrapper{
  993. // height: 100% !important;
  994. // }
  995. /deep/.ant-modal-body {
  996. padding: 24px !important;
  997. }
  998. /deep/.ant-form-item {
  999. margin-bottom: 8px !important;
  1000. }
  1001. /deep/.vxe-cell--valid-error-msg {
  1002. color: white !important;
  1003. background-color: white !important;
  1004. }
  1005. </style>