add.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="form">
  3. <van-nav-bar :title="$t('account.' + 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
  18. .post("/dictTenantData/page", {
  19. pageNum: 1,
  20. pageSize: 999,
  21. dictCode: "account_currency",
  22. tenantId: getUserInfo().tenantId,
  23. })
  24. .then((res) => {
  25. if (res.data.rows && res.data.rows.length > 0) {
  26. formOption.btnConfig.listConfig[0].data = res.data.rows.map((item) => {
  27. return {
  28. text: item.dictValue,
  29. value: item.dictKey,
  30. };
  31. });
  32. }
  33. });
  34. proxy.post("/corporation/page", { pageNum: 1, pageSize: 9999 }).then((res) => {
  35. if (res.data.rows && res.data.rows.length > 0) {
  36. formConfig[0].data = res.data.rows.map((item) => {
  37. return {
  38. ...item,
  39. label: item.name,
  40. value: item.id,
  41. };
  42. });
  43. }
  44. });
  45. };
  46. getDict();
  47. const formData = reactive({
  48. data: {
  49. corporationId: null,
  50. alias: null,
  51. name: null,
  52. openingBank: null,
  53. accountOpening: null,
  54. interbankNumber: null,
  55. beneficiaryName: null,
  56. beneficiaryBank: null,
  57. beneficiaryBankAddress: null,
  58. beneficiaryAccountNumber: null,
  59. swiftCode: null,
  60. beneficiaryAddress: null,
  61. accountRemainderList: [],
  62. },
  63. });
  64. const formDom = ref(null);
  65. const formOption = reactive({
  66. readonly: false, //用于控制整个表单是否只读
  67. disabled: false,
  68. labelAlign: "top",
  69. scroll: true,
  70. labelWidth: "62pk",
  71. hiddenSubmitBtn: false,
  72. btnConfig: {
  73. isNeed: true,
  74. prop: "accountRemainderList",
  75. plain: true,
  76. listTitle: proxy.t("account.accountBalance"),
  77. listConfig: [
  78. {
  79. type: "picker",
  80. label: proxy.t("account.currency"),
  81. prop: "currency",
  82. itemType: "onePicker",
  83. showPicker: false,
  84. readonly: false,
  85. fieldNames: {
  86. text: "text",
  87. value: "value",
  88. },
  89. data: [],
  90. },
  91. {
  92. type: "input",
  93. label: proxy.t("account.remainder"),
  94. prop: "remainder",
  95. itemType: "number",
  96. },
  97. ],
  98. clickFn: () => {
  99. if (formData.data.accountRemainderList && formData.data.accountRemainderList.length > 0) {
  100. formData.data.accountRemainderList.push({
  101. currency: null,
  102. remainder: null,
  103. });
  104. } else {
  105. formData.data.accountRemainderList = [
  106. {
  107. currency: null,
  108. remainder: null,
  109. },
  110. ];
  111. }
  112. },
  113. },
  114. });
  115. const formConfig = reactive([
  116. {
  117. type: "picker",
  118. label: proxy.t("account.company"),
  119. prop: "corporationId",
  120. itemType: "onePicker",
  121. showPicker: false,
  122. fieldNames: {
  123. text: "label",
  124. value: "value",
  125. },
  126. data: [],
  127. },
  128. {
  129. type: "input",
  130. label: proxy.t("account.alias"),
  131. prop: "alias",
  132. itemType: "text",
  133. },
  134. {
  135. type: "input",
  136. label: proxy.t("account.openingBank"),
  137. prop: "openingBank",
  138. itemType: "text",
  139. },
  140. {
  141. type: "input",
  142. label: proxy.t("account.accountName"),
  143. prop: "name",
  144. itemType: "text",
  145. },
  146. {
  147. type: "input",
  148. label: proxy.t("account.accountOpening"),
  149. prop: "accountOpening",
  150. itemType: "text",
  151. },
  152. {
  153. type: "input",
  154. label: proxy.t("account.interbankNumber"),
  155. prop: "interbankNumber",
  156. itemType: "text",
  157. },
  158. {
  159. type: "title",
  160. title: proxy.t("account.foreignExchange"),
  161. },
  162. {
  163. type: "input",
  164. label: proxy.t("account.beneficiaryName"),
  165. prop: "beneficiaryName",
  166. itemType: "text",
  167. },
  168. {
  169. type: "input",
  170. label: proxy.t("account.beneficiaryBank"),
  171. prop: "beneficiaryBank",
  172. itemType: "text",
  173. },
  174. {
  175. type: "input",
  176. label: proxy.t("account.beneficiaryBankAddress"),
  177. prop: "beneficiaryBankAddress",
  178. itemType: "text",
  179. },
  180. {
  181. type: "input",
  182. label: proxy.t("account.beneficiaryAccountNumber"),
  183. prop: "beneficiaryAccountNumber",
  184. itemType: "text",
  185. },
  186. {
  187. type: "input",
  188. label: proxy.t("account.swiftCode"),
  189. prop: "swiftCode",
  190. itemType: "text",
  191. },
  192. {
  193. type: "input",
  194. label: proxy.t("account.beneficiaryAddress"),
  195. prop: "beneficiaryAddress",
  196. itemType: "text",
  197. },
  198. ]);
  199. const rules = {
  200. corporationId: [{ required: true, message: proxy.t("account.companyMsg") }],
  201. alias: [{ required: true, message: proxy.t("account.aliasMsg") }],
  202. openingBank: [{ required: true, message: proxy.t("account.openingBankMsg") }],
  203. name: [{ required: true, message: proxy.t("account.accountNameMsg") }],
  204. accountOpening: [{ required: true, message: proxy.t("account.accountOpeningMsg") }],
  205. currency: [{ required: true, message: proxy.t("account.currencyMsg") }],
  206. remainder: [{ required: true, message: proxy.t("account.remainderMsg") }],
  207. };
  208. const isRepeat = (arr) => {
  209. var hash = {};
  210. for (var i in arr) {
  211. if (hash[arr[i].currency]) return true;
  212. hash[arr[i].currency] = true;
  213. }
  214. return false;
  215. };
  216. const onSubmit = () => {
  217. if (formData.data.accountRemainderList && formData.data.accountRemainderList.length > 0) {
  218. if (isRepeat(formData.data.accountRemainderList)) {
  219. showFailToast(proxy.t("account.submitMsgTwo"));
  220. } else {
  221. proxy.post("/accountManagement/" + route.query.type, formData.data).then(() => {
  222. showSuccessToast(proxy.t("common.addSuccess"));
  223. setTimeout(() => {
  224. history.back();
  225. }, 500);
  226. });
  227. }
  228. } else {
  229. showFailToast(proxy.t("account.submitMsgOne"));
  230. }
  231. };
  232. onMounted(() => {
  233. if (route.query.id) {
  234. proxy.post("/accountManagement/detail", { id: route.query.id }).then((res) => {
  235. formData.data = res.data;
  236. if (formData.data.accountRemainderList && formData.data.accountRemainderList.length > 0) {
  237. for (let i = 0; i < formData.data.accountRemainderList.length; i++) {
  238. let data = formOption.btnConfig.listConfig[0].data.filter((item) => item.value === formData.data.accountRemainderList[i].currency);
  239. if (data && data.length > 0) {
  240. formData.data.accountRemainderList[i].currencyName = data[0].text;
  241. }
  242. }
  243. }
  244. });
  245. }
  246. });
  247. </script>