add.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <div class="form">
  3. <van-nav-bar :title="$t('accountPayment.name')" :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">
  5. <template #date>
  6. <div style="width: 100%">
  7. <van-cell-group inset>
  8. <van-field
  9. v-model="formData.data.expensesTime"
  10. is-link
  11. readonly
  12. :label="$t('accountPayment.expensesTime')"
  13. :placeholder="$t('common.pleaseSelect')"
  14. style="padding: 0 !important"
  15. :required="true"
  16. @click="clickDate" />
  17. <van-popup v-model:show="showPicker" round position="bottom">
  18. <van-picker-group
  19. :title="$t('accountPayment.expensesTime')"
  20. :tabs="[$t('common.selectDate'), $t('common.selectTime')]"
  21. @confirm="onConfirm"
  22. @cancel="onCancel">
  23. <van-date-picker v-model="currentDate" />
  24. <van-time-picker v-model="currentTime" :columns-type="columnsType" />
  25. </van-picker-group>
  26. </van-popup>
  27. </van-cell-group>
  28. </div>
  29. </template>
  30. </testForm>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { ref, getCurrentInstance, onMounted, reactive } from "vue";
  35. import { showSuccessToast } from "vant";
  36. import { useRoute } from "vue-router";
  37. import { getUserInfo, formatDate } from "@/utils/auth";
  38. import testForm from "@/components/testForm/index.vue";
  39. const proxy = getCurrentInstance().proxy;
  40. const onClickLeft = () => history.back();
  41. const route = useRoute();
  42. const showPicker = ref(false);
  43. const currentDate = ref([]);
  44. const currentTime = ref([]);
  45. const columnsType = ["hour", "minute", "second"];
  46. const onConfirm = () => {
  47. formData.data.expensesTime = currentDate.value.join("-") + " " + currentTime.value.join(":");
  48. showPicker.value = false;
  49. };
  50. const onCancel = () => {
  51. showPicker.value = false;
  52. };
  53. const clickDate = () => {
  54. currentDate.value = formatDate(new Date(formData.data.expensesTime), "yyyy-MM-dd").split("-");
  55. currentTime.value = formatDate(new Date(formData.data.expensesTime), "hh:mm:ss").split(":");
  56. showPicker.value = true;
  57. };
  58. const formData = reactive({
  59. data: {
  60. expensesTime: "",
  61. },
  62. });
  63. const formDom = ref(null);
  64. const formOption = reactive({
  65. readonly: false, //用于控制整个表单是否只读
  66. disabled: false,
  67. labelAlign: "top",
  68. scroll: true,
  69. labelWidth: "62pk",
  70. hiddenSubmitBtn: false,
  71. });
  72. const formConfig = reactive([
  73. {
  74. type: "title",
  75. title: proxy.t("accountPayment.requestInformation"),
  76. },
  77. {
  78. type: "input",
  79. label: proxy.t("accountPayment.businessManagementName"),
  80. prop: "businessManagementName",
  81. itemType: "text",
  82. readonly: true,
  83. },
  84. {
  85. type: "input",
  86. label: proxy.t("accountPayment.currencyAmount"),
  87. prop: "currencyAmount",
  88. itemType: "text",
  89. readonly: true,
  90. },
  91. {
  92. type: "input",
  93. label: proxy.t("accountPayment.paymentMethodText"),
  94. prop: "paymentMethodText",
  95. itemType: "text",
  96. readonly: true,
  97. },
  98. {
  99. type: "input",
  100. label: proxy.t("accountPayment.collectionName"),
  101. prop: "name",
  102. itemType: "text",
  103. readonly: true,
  104. },
  105. {
  106. type: "input",
  107. label: proxy.t("accountPayment.accountOpening"),
  108. prop: "accountOpening",
  109. itemType: "text",
  110. readonly: true,
  111. },
  112. {
  113. type: "input",
  114. label: proxy.t("accountPayment.openingBank"),
  115. prop: "openingBank",
  116. itemType: "text",
  117. readonly: true,
  118. },
  119. {
  120. type: "input",
  121. label: proxy.t("accountPayment.interbankNumber"),
  122. prop: "interbankNumber",
  123. itemType: "text",
  124. readonly: true,
  125. },
  126. {
  127. type: "title",
  128. title: proxy.t("accountPayment.paymentInformation"),
  129. },
  130. {
  131. type: "picker",
  132. label: proxy.t("accountPayment.accountManagementId"),
  133. prop: "accountManagementId",
  134. itemType: "onePicker",
  135. showPicker: false,
  136. fieldNames: {
  137. text: "label",
  138. value: "value",
  139. },
  140. data: [],
  141. },
  142. {
  143. type: "picker",
  144. label: proxy.t("accountPayment.currency"),
  145. prop: "currency",
  146. itemType: "onePicker",
  147. showPicker: false,
  148. readonly: true,
  149. fieldNames: {
  150. text: "label",
  151. value: "value",
  152. },
  153. data: [],
  154. },
  155. {
  156. type: "input",
  157. label: proxy.t("accountPayment.amount"),
  158. prop: "amount",
  159. itemType: "number",
  160. readonly: true,
  161. },
  162. {
  163. type: "slot",
  164. slotName: "date",
  165. },
  166. {
  167. type: "input",
  168. label: proxy.t("accountPayment.remark"),
  169. prop: "remark",
  170. itemType: "textarea",
  171. },
  172. ]);
  173. const rules = {
  174. accountManagementId: [{ required: true, message: proxy.t("accountPayment.accountManagementIdMsg") }],
  175. currency: [{ required: true, message: proxy.t("accountPayment.currencyMsg") }],
  176. amount: [{ required: true, message: proxy.t("accountPayment.amountMsg") }],
  177. expensesTime: [{ required: true, message: proxy.t("accountPayment.expensesTimeMsg") }],
  178. };
  179. const onSubmit = () => {
  180. proxy.post("/accountPayment/add", formData.data).then(() => {
  181. showSuccessToast(proxy.t("common.addSuccess"));
  182. setTimeout(() => {
  183. history.back();
  184. }, 500);
  185. });
  186. };
  187. const fundsPayment = ref([]);
  188. const gerFundsPayment = () => {
  189. return proxy
  190. .post("/dictTenantData/page", {
  191. pageNum: 1,
  192. pageSize: 999,
  193. tenantId: getUserInfo().tenantId,
  194. dictCode: "funds_payment_method",
  195. })
  196. .then((res) => {
  197. fundsPayment.value = res.data.rows;
  198. });
  199. };
  200. const accountList = ref([]);
  201. const gerAccountList = () => {
  202. return proxy.post("/accountManagement/page", { pageNum: 1, pageSize: 9999 }).then((res) => {
  203. if (res.data.rows && res.data.rows.length > 0) {
  204. accountList.value = res.data.rows.map((item) => {
  205. return {
  206. label: item.alias + " (" + item.name + ")",
  207. value: item.id,
  208. };
  209. });
  210. formConfig[9].data = accountList.value;
  211. }
  212. });
  213. };
  214. const gerCurrency = () => {
  215. return proxy
  216. .post("/dictTenantData/page", {
  217. pageNum: 1,
  218. pageSize: 999,
  219. tenantId: getUserInfo().tenantId,
  220. dictCode: "account_currency",
  221. })
  222. .then((res) => {
  223. if (res.data.rows && res.data.rows.length > 0) {
  224. formConfig[10].data = res.data.rows.map((item) => {
  225. return {
  226. label: item.dictValue,
  227. value: item.dictKey,
  228. };
  229. });
  230. }
  231. });
  232. };
  233. onMounted(() => {
  234. Promise.all([gerFundsPayment(), gerAccountList(), gerCurrency()]).then(() => {
  235. if (route.query.id) {
  236. proxy.post("/accountPayment/detail", { id: route.query.id }).then((res) => {
  237. formData.data = res.data;
  238. formData.data.expensesTime = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
  239. formData.data.currencyAmount = formData.data.currency + " " + formData.data.amount;
  240. let paymentMethodText = "";
  241. if (formData.data.paymentMethod && fundsPayment.value && fundsPayment.value.length > 0) {
  242. let list = fundsPayment.value.filter((item) => item.dictKey == formData.data.paymentMethod);
  243. if (list && list.length > 0) {
  244. paymentMethodText = list[0].dictValue;
  245. }
  246. }
  247. formData.data.paymentMethodText = paymentMethodText;
  248. });
  249. }
  250. });
  251. });
  252. </script>