SendPurchasePayment.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <div class="form">
  3. <testForm
  4. v-model="formData.data"
  5. :formOption="formOption"
  6. :formConfig="formConfig"
  7. :rules="rules"
  8. @onSubmit="onSubmit"
  9. ref="formDom"
  10. ></testForm>
  11. <testForm
  12. v-model="formData.data"
  13. :formOption="formOptionOne"
  14. :formConfig="formConfigOne"
  15. :rules="rules"
  16. @onSubmit="onSubmit"
  17. ref="formDomOne"
  18. ></testForm>
  19. </div>
  20. </template>
  21. <script setup>
  22. import { ref, reactive, getCurrentInstance, onMounted } from "vue";
  23. import { showSuccessToast, showFailToast } from "vant";
  24. import { useRoute } from "vue-router";
  25. import testForm from "@/components/testForm/index.vue";
  26. const proxy = getCurrentInstance().proxy;
  27. const route = useRoute();
  28. const formDom = ref(null);
  29. const formDomOne = ref(null);
  30. const formData = reactive({
  31. data: {},
  32. });
  33. const rules = {
  34. supplyId: [
  35. {
  36. required: true,
  37. message: proxy.t("purchasePayment.supplyNameCanNotBeEmpty"),
  38. },
  39. ],
  40. type: [
  41. {
  42. required: true,
  43. message: proxy.t("purchasePayment.paymentTypeCanNotBeEmpty"),
  44. },
  45. ],
  46. advanceCode: [
  47. {
  48. required: true,
  49. message: proxy.t("purchasePayment.prepaymentCodeCanNotBeEmpty"),
  50. },
  51. ],
  52. remark: [
  53. {
  54. required: true,
  55. message: proxy.t("purchasePayment.descriptionCanNotBeEmpty"),
  56. },
  57. ],
  58. invoiceType: [
  59. {
  60. required: true,
  61. message: proxy.t("purchasePayment.invoiceTypeCanNotBeEmpty"),
  62. },
  63. ],
  64. rate: [
  65. {
  66. required: true,
  67. message: proxy.t("purchasePayment.taxRateCanNotBeEmpty"),
  68. },
  69. ],
  70. purchaseId: [
  71. {
  72. required: true,
  73. message: proxy.t("purchasePayment.purchaseContractCanNotBeEmpty"),
  74. },
  75. ],
  76. money: [
  77. {
  78. required: true,
  79. message: proxy.t("purchasePayment.paymentAmountCanNotBeEmpty"),
  80. },
  81. ],
  82. payType: [
  83. {
  84. required: true,
  85. message: proxy.t("purchasePayment.paymentMethonCanNotBeEmpty"),
  86. },
  87. ],
  88. accountManagementId: [
  89. {
  90. required: true,
  91. message: proxy.t("purchasePayment.paymentAccountCanNotBeEmpty"),
  92. },
  93. ],
  94. name: [
  95. {
  96. required: true,
  97. message: proxy.t("purchasePayment.accountNameCanNotBeEmpty"),
  98. },
  99. ],
  100. };
  101. const formOption = reactive({
  102. readonly: false, //用于控制整个表单是否只读
  103. disabled: false,
  104. labelAlign: "top",
  105. scroll: true,
  106. labelWidth: "62pk",
  107. submitBtnText: proxy.t("common.submit"),
  108. hiddenSubmitBtn: true,
  109. btnConfig: {
  110. isNeed: true,
  111. label: proxy.t("purchasePayment.paymentDetails"),
  112. prop: "payDetailList",
  113. plain: true,
  114. listConfig: [
  115. {
  116. type: "picker",
  117. label: proxy.t("purchasePayment.purchaseContract"),
  118. prop: "purchaseId",
  119. itemType: "onePicker",
  120. showPicker: false,
  121. readonly: false,
  122. fieldNames: {
  123. text: "label",
  124. value: "value",
  125. },
  126. data: [],
  127. changeFn: function (option, item, index, currentSonIndex, prop) {
  128. proxy.formChangeTwo(
  129. option,
  130. item,
  131. index,
  132. currentSonIndex,
  133. prop,
  134. formData
  135. );
  136. formDom.value.btnConfigCopy.listConfig[
  137. currentSonIndex
  138. ].showPicker = false;
  139. changePurchaseId(option.selectedValues[0], index);
  140. },
  141. },
  142. {
  143. type: "input",
  144. itemType: "number",
  145. label: proxy.t("purchasePayment.contractAmount"),
  146. prop: "amount",
  147. readonly: true,
  148. },
  149. {
  150. type: "input",
  151. itemType: "number",
  152. label: proxy.t("purchasePayment.paidAmount"),
  153. prop: "sumPayMoney",
  154. readonly: true,
  155. },
  156. {
  157. type: "input",
  158. itemType: "textarea",
  159. label: proxy.t("purchasePayment.paymentDescription"),
  160. prop: "remark",
  161. readonly: false,
  162. },
  163. {
  164. type: "input",
  165. itemType: "number",
  166. label: proxy.t("purchasePayment.paymentAmount"),
  167. prop: "money",
  168. readonly: false,
  169. changeFn: (index, val) => {
  170. changeMoney();
  171. },
  172. },
  173. ],
  174. clickFn: () => {
  175. if (
  176. formData.data.payDetailList &&
  177. formData.data.payDetailList.length > 0
  178. ) {
  179. formData.data.payDetailList.push({
  180. purchaseId: "",
  181. money: "",
  182. remark: "",
  183. });
  184. } else {
  185. formData.data.payDetailList = [
  186. { purchaseId: "", money: "", remark: "" },
  187. ];
  188. }
  189. },
  190. },
  191. });
  192. const formConfig = reactive([
  193. {
  194. type: "picker",
  195. label: proxy.t("purchasePayment.supplyName"),
  196. prop: "supplyId",
  197. itemType: "onePicker",
  198. showPicker: false,
  199. readonly: false,
  200. fieldNames: {
  201. text: "label",
  202. value: "value",
  203. },
  204. data: [],
  205. changeFn: function (option, item, index) {
  206. formData.data[item.prop] = option.selectedOptions[0].value;
  207. formData.data[item.prop + "Name"] = option.selectedOptions[0].label;
  208. formConfig[index].showPicker = false;
  209. changeSupply(option.selectedOptions[0].value);
  210. },
  211. },
  212. {
  213. type: "picker",
  214. label: proxy.t("purchasePayment.paymentTerm"),
  215. prop: "deadline",
  216. itemType: "datePickerTime",
  217. showPicker: false,
  218. readonly: false,
  219. needDefault: false,
  220. },
  221. // 先去掉以下选择
  222. {
  223. type: "pickerOne",
  224. label: proxy.t("purchasePayment.paymentType"),
  225. prop: "type",
  226. itemType: "onePicker",
  227. showPicker: false,
  228. readonly: false,
  229. fieldNames: {
  230. text: "label",
  231. value: "value",
  232. },
  233. data: [
  234. { label: "未核销", value: "0" },
  235. { label: "发票核销", value: "1" },
  236. ],
  237. changeFn: function (option, item, index) {
  238. proxy.formChange(option, item, formData);
  239. formConfig[index].showPicker = false;
  240. changeType(formData.data[item.prop]);
  241. },
  242. },
  243. {
  244. type: "pickerOne",
  245. label: proxy.t("purchasePayment.prepaymentCode"),
  246. prop: "advanceCode",
  247. itemType: "onePicker",
  248. showPicker: false,
  249. readonly: false,
  250. fieldNames: {
  251. text: "label",
  252. value: "value",
  253. },
  254. data: [],
  255. changeFn: function (option, item, index) {
  256. formData.data[item.prop] = option.selectedOptions[0].value;
  257. formData.data[item.prop + "Name"] = option.selectedOptions[0].label;
  258. formConfig[index].showPicker = false;
  259. changeSupply(option.selectedOptions[0].value);
  260. },
  261. },
  262. {
  263. type: "input",
  264. label: proxy.t("purchasePayment.paymentDescription"),
  265. prop: "remark",
  266. itemType: "textarea",
  267. readonly: false,
  268. },
  269. {
  270. type: "input",
  271. label: proxy.t("purchasePayment.documentNumber"),
  272. prop: "receiptsNum",
  273. itemType: "number",
  274. readonly: false,
  275. },
  276. {
  277. type: "picker",
  278. label: proxy.t("purchasePayment.invoiceType"),
  279. prop: "invoiceType",
  280. itemType: "onePicker",
  281. showPicker: false,
  282. readonly: false,
  283. fieldNames: {
  284. text: "label",
  285. value: "value",
  286. },
  287. data: [],
  288. changeFn: function (option, item, index) {
  289. proxy.formChange(option, item, formData);
  290. formConfig[index].showPicker = false;
  291. changeInvoiceType(formData.data[item.prop]);
  292. },
  293. },
  294. {
  295. type: "input",
  296. label: proxy.t("purchasePayment.taxRate") + "(%)",
  297. prop: "rate",
  298. itemType: "number",
  299. readonly: false,
  300. },
  301. ]);
  302. const formOptionOne = reactive({
  303. readonly: false, //用于控制整个表单是否只读
  304. disabled: false,
  305. labelAlign: "top",
  306. scroll: true,
  307. labelWidth: "62pk",
  308. submitBtnText: proxy.t("common.submit"),
  309. hiddenSubmitBtn: true,
  310. });
  311. const formConfigOne = reactive([
  312. {
  313. type: "input",
  314. label: proxy.t("purchasePayment.totalPaymentAmount"),
  315. prop: "amount",
  316. itemType: "number",
  317. readonly: true,
  318. },
  319. {
  320. type: "picker",
  321. label: proxy.t("purchasePayment.paymentMethon"),
  322. prop: "payType",
  323. itemType: "onePicker",
  324. showPicker: false,
  325. readonly: false,
  326. fieldNames: {
  327. text: "label",
  328. value: "value",
  329. },
  330. data: [],
  331. changeFn: function (option, item, index) {
  332. proxy.formChange(option, item, formData);
  333. formConfigOne[index].showPicker = false;
  334. },
  335. },
  336. {
  337. type: "picker",
  338. label: proxy.t("purchasePayment.paymentAccount"),
  339. prop: "accountManagementId",
  340. itemType: "onePicker",
  341. showPicker: false,
  342. readonly: false,
  343. fieldNames: {
  344. text: "label",
  345. value: "value",
  346. },
  347. data: [],
  348. changeFn: function (option, item, index) {
  349. proxy.formChange(option, item, formData);
  350. formConfigOne[index].showPicker = false;
  351. changeAccount(formData.data[item.prop]);
  352. },
  353. },
  354. {
  355. type: "input",
  356. label: proxy.t("purchasePayment.accountName"),
  357. prop: "name",
  358. itemType: "text",
  359. readonly: false,
  360. },
  361. {
  362. type: "input",
  363. label: proxy.t("purchasePayment.bankAccount"),
  364. prop: "accountOpening",
  365. itemType: "text",
  366. readonly: false,
  367. },
  368. {
  369. type: "input",
  370. label: proxy.t("purchasePayment.bankOfDeposit"),
  371. prop: "openingBank",
  372. itemType: "text",
  373. readonly: false,
  374. },
  375. {
  376. type: "input",
  377. label: proxy.t("purchasePayment.interbankNumber"),
  378. prop: "interbankNumber",
  379. itemType: "text",
  380. readonly: false,
  381. },
  382. ]);
  383. const supplierList = ref([]);
  384. const accountList = ref([]);
  385. const invoiceType = ref([]);
  386. const fundsPaymentMethod = ref([]);
  387. const contractList = ref([]);
  388. const changeSupply = (val) => {
  389. if (val) {
  390. proxy.get("/purchase/getListBySupplyId", { supplyId: val }).then((res) => {
  391. if (res.data && res.data.length > 0) {
  392. contractList.value = res.data.map((item) => {
  393. return {
  394. value: item.id,
  395. label: item.code,
  396. amount: item.amount,
  397. sumPayMoney: item.sumPayMoney,
  398. sumInvoiceMoney: item.sumInvoiceMoney,
  399. };
  400. });
  401. } else {
  402. contractList.value = [];
  403. }
  404. formOption.btnConfig.listConfig[0].data = contractList.value;
  405. });
  406. } else {
  407. contractList.value = [];
  408. }
  409. formData.data.payDetailList = [];
  410. };
  411. const changeMoney = () => {
  412. let money = 0;
  413. for (let i = 0; i < formData.data.payDetailList.length; i++) {
  414. if (formData.data.payDetailList[i].money) {
  415. money = parseFloat(
  416. Number(money) + Number(formData.data.payDetailList[i].money)
  417. ).toFixed(2);
  418. }
  419. }
  420. formData.data.amount = money;
  421. };
  422. const changePurchaseId = (val, index) => {
  423. const current = contractList.value.find((x) => x.value === val);
  424. if (current) {
  425. formData.data.payDetailList[index].amount = current.amount;
  426. formData.data.payDetailList[index].sumPayMoney = current.sumPayMoney;
  427. formData.data.payDetailList[index].sumInvoiceMoney =
  428. current.sumInvoiceMoney;
  429. } else {
  430. }
  431. };
  432. const changeType = (val) => {
  433. if (val == "1") {
  434. formConfig[3].type = "picker";
  435. proxy.get(`purchase/getAdvanceCode?money=${1}`).then((res) => {
  436. console.log(res, "aaa");
  437. });
  438. } else {
  439. formConfig[3].type = "pickerOne";
  440. }
  441. };
  442. const changeInvoiceType = (val) => {
  443. if (val == "1") {
  444. formConfig[7].type = "input";
  445. formData.data.rate = "13";
  446. } else if (val == "2") {
  447. formConfig[7].type = "input";
  448. formData.data.rate = "6";
  449. } else {
  450. formConfig[7].type = "inputOne";
  451. formData.data.rate = "";
  452. }
  453. };
  454. const changeAccount = (val) => {
  455. if (val) {
  456. let data = accountList.value.filter((item) => item.value === val);
  457. if (data && data.length > 0) {
  458. formData.data.name = data[0].bankName;
  459. formData.data.accountOpening = data[0].accountOpening;
  460. formData.data.openingBank = data[0].openingBank;
  461. formData.data.interbankNumber = data[0].interbankNumber;
  462. }
  463. }
  464. };
  465. const getDict = () => {
  466. proxy
  467. .post("/supplierInfo/page", { pageNum: 1, pageSize: 999 })
  468. .then((res) => {
  469. if (res.data.rows && res.data.rows.length > 0) {
  470. supplierList.value = res.data.rows.map((item) => {
  471. return {
  472. label: item.name,
  473. value: item.id,
  474. };
  475. });
  476. formConfig[0].data = supplierList.value;
  477. }
  478. });
  479. proxy
  480. .post("/accountManagement/page", { pageNum: 1, pageSize: 999 })
  481. .then((res) => {
  482. accountList.value = res.data.rows.map((item) => {
  483. return {
  484. bankName: item.name,
  485. accountOpening: item.accountOpening,
  486. openingBank: item.openingBank,
  487. interbankNumber: item.interbankNumber,
  488. label: item.alias,
  489. value: item.id,
  490. };
  491. });
  492. formConfigOne[2].data = accountList.value;
  493. });
  494. proxy.getDictOne(["invoice_type", "funds_payment_method"]).then((res) => {
  495. invoiceType.value = res["invoice_type"].data.map((x) => ({
  496. label: x.dictValue,
  497. value: x.dictKey,
  498. }));
  499. fundsPaymentMethod.value = res["funds_payment_method"].data.map((x) => ({
  500. label: x.dictValue,
  501. value: x.dictKey,
  502. }));
  503. formConfig[6].data = invoiceType.value;
  504. formConfigOne[1].data = fundsPaymentMethod.value;
  505. });
  506. };
  507. getDict();
  508. const handleSubmit = async () => {
  509. const data = await formDom.value.validateForm().then((status) => {
  510. if (status) {
  511. return false;
  512. } else {
  513. if (
  514. formData.data.payDetailList &&
  515. formData.data.payDetailList.length > 0
  516. ) {
  517. return formDomOne.value.validateForm().then((status1) => {
  518. if (status1) {
  519. return false;
  520. } else {
  521. return true;
  522. }
  523. });
  524. } else {
  525. showFailToast(proxy.t("purchasePayment.pleaseAddPaymentDetails"));
  526. return false;
  527. }
  528. }
  529. });
  530. if (data) {
  531. return { ...formData.data };
  532. }
  533. };
  534. defineExpose({
  535. handleSubmit,
  536. });
  537. </script>
  538. <style lang="scss" scoped>
  539. </style>