add.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="form">
  3. <van-nav-bar :title="$t('invoice.' + route.query.type)" :left-text="$t('common.back')" left-arrow @click-left="onClickLeft"> </van-nav-bar>
  4. <testForm v-model="formData.data" :formOption="formOption" :formConfig="formConfig" :rules="rules" @onSubmit="onSubmit" ref="formDom"> </testForm>
  5. </div>
  6. </template>
  7. <script setup>
  8. import { ref, getCurrentInstance, onMounted, reactive } from "vue";
  9. import { showSuccessToast, showFailToast } from "vant";
  10. import { useRoute } from "vue-router";
  11. import { getUserInfo } from "@/utils/auth";
  12. import testForm from "@/components/testForm/index.vue";
  13. const proxy = getCurrentInstance().proxy;
  14. const onClickLeft = () => history.back();
  15. const route = useRoute();
  16. const getDict = () => {
  17. proxy.post("/supplierInfo/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  18. if (res.data.rows && res.data.rows.length > 0) {
  19. formConfig[0].data = res.data.rows.map((item) => {
  20. return {
  21. label: item.name,
  22. value: item.id,
  23. };
  24. });
  25. }
  26. });
  27. let query = {
  28. pageNum: 1,
  29. pageSize: 999,
  30. tenantId: getUserInfo().tenantId,
  31. };
  32. proxy.post("/dictTenantData/page", { ...query, dictCode: "invoice_type" }).then((res) => {
  33. if (res.data.rows && res.data.rows.length > 0) {
  34. formConfig[1].data = res.data.rows.map((item) => {
  35. return {
  36. label: item.dictValue,
  37. value: item.dictKey,
  38. };
  39. });
  40. }
  41. });
  42. proxy.get("/tenantUser/list", { pageNum: 1, pageSize: 10000, tenantId: getUserInfo().tenantId }).then((res) => {
  43. if (res.rows && res.rows.length > 0) {
  44. }
  45. });
  46. };
  47. getDict();
  48. const formData = reactive({
  49. data: {
  50. supplyId: null,
  51. money: null,
  52. type: null,
  53. remark: null,
  54. invoiceDetailsList: [],
  55. },
  56. });
  57. const formDom = ref(null);
  58. const formOption = reactive({
  59. readonly: false, //用于控制整个表单是否只读
  60. disabled: false,
  61. labelAlign: "top",
  62. scroll: true,
  63. labelWidth: "62pk",
  64. hiddenSubmitBtn: false,
  65. btnConfig: {
  66. isNeed: false,
  67. prop: "invoiceDetailsList",
  68. plain: true,
  69. listTitle: proxy.t("invoice.purchaseContract"),
  70. listConfig: [
  71. {
  72. type: "input",
  73. label: proxy.t("invoice.contractCode"),
  74. prop: "code",
  75. readonly: true,
  76. },
  77. {
  78. type: "input",
  79. label: proxy.t("invoice.contractMoney"),
  80. prop: "amount",
  81. readonly: true,
  82. },
  83. {
  84. type: "input",
  85. label: proxy.t("invoice.receivedInvoice"),
  86. prop: "sumInvoiceMoney",
  87. readonly: true,
  88. },
  89. {
  90. type: "input",
  91. label: proxy.t("invoice.relatedAmount"),
  92. prop: "money",
  93. itemType: "number",
  94. },
  95. ],
  96. },
  97. });
  98. const formConfig = reactive([
  99. {
  100. type: "picker",
  101. label: proxy.t("invoice.supplyName"),
  102. prop: "supplyId",
  103. itemType: "onePicker",
  104. showPicker: false,
  105. fieldNames: {
  106. text: "label",
  107. value: "value",
  108. },
  109. data: [],
  110. readonly: route.query.id,
  111. changeFn: (val, data) => {
  112. proxy.formChange(val, data, formData);
  113. proxy.get("/purchase/getNoInvoiceListBySupplyId", { supplyId: val.selectedValues[0] }).then((res) => {
  114. if (res.data && res.data.length > 0) {
  115. formData.data.invoiceDetailsList = res.data.map((item) => {
  116. return {
  117. purchaseId: item.id,
  118. code: item.code,
  119. amount: item.amount,
  120. sumInvoiceMoney: item.sumInvoiceMoney,
  121. money: null,
  122. remark: "",
  123. };
  124. });
  125. } else {
  126. formData.data.invoiceDetailsList = [];
  127. }
  128. });
  129. data.showPicker = false;
  130. },
  131. },
  132. {
  133. type: "picker",
  134. label: proxy.t("invoice.type"),
  135. prop: "type",
  136. itemType: "onePicker",
  137. showPicker: false,
  138. fieldNames: {
  139. text: "label",
  140. value: "value",
  141. },
  142. data: [],
  143. },
  144. {
  145. type: "input",
  146. label: proxy.t("invoice.invoiceAmount"),
  147. prop: "money",
  148. itemType: "number",
  149. },
  150. ]);
  151. const rules = {
  152. supplyId: [{ required: true, message: proxy.t("invoice.supplyNameMsg") }],
  153. type: [{ required: true, message: proxy.t("invoice.typeMsg") }],
  154. money: [{ required: true, message: proxy.t("invoice.invoiceAmountMsg") }],
  155. relatedAmount: [{ required: true, message: proxy.t("invoice.relatedAmountMsg") }],
  156. };
  157. const onSubmit = () => {
  158. if (!(formData.data.invoiceDetailsList && formData.data.invoiceDetailsList.length > 0)) {
  159. return showFailToast(proxy.t("invoice.supplierNoContract"));
  160. }
  161. let money = 0;
  162. for (let i = 0; i < formData.data.invoiceDetailsList.length; i++) {
  163. money = parseFloat(Number(money) + Number(formData.data.invoiceDetailsList[i].money)).toFixed(2);
  164. }
  165. if (Number(money) != Number(formData.data.money)) {
  166. return showFailToast(proxy.t("invoice.unequalAmounts"));
  167. }
  168. proxy.post("/invoice/" + route.query.type, formData.data).then(() => {
  169. showSuccessToast(route.query.type === "add" ? proxy.t("common.addSuccess") : proxy.t("common.modifySuccess"));
  170. setTimeout(() => {
  171. onClickLeft();
  172. }, 500);
  173. });
  174. };
  175. onMounted(() => {
  176. if (route.query.id) {
  177. proxy.post("/invoice/detail", { id: route.query.id }).then((res) => {
  178. res.data.type = res.data.type + "";
  179. res.data.invoiceDetailsList = res.data.invoiceDetailsVoList.map((item) => {
  180. return {
  181. code: item.purchaseCode,
  182. purchaseId: item.purchaseId,
  183. amount: item.purchaseAmount,
  184. sumInvoiceMoney: item.sumMoney,
  185. money: item.money,
  186. };
  187. });
  188. formData.data = res.data;
  189. });
  190. }
  191. });
  192. </script>