add.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="form">
  3. <van-nav-bar
  4. :title="$t('workingProcedure.name')"
  5. :left-text="$t('common.back')"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. >
  9. </van-nav-bar>
  10. <testForm
  11. v-model="formData.data"
  12. :formOption="formOption"
  13. :formConfig="formConfig"
  14. :rules="rules"
  15. @onSubmit="onSubmit"
  16. ref="formDom"
  17. ></testForm>
  18. </div>
  19. </template>
  20. <script setup>
  21. import { ref, getCurrentInstance, onMounted, reactive } from "vue";
  22. import { showSuccessToast, showToast, showFailToast } from "vant";
  23. import { useRoute } from "vue-router";
  24. import { getUserInfo } from "@/utils/auth";
  25. import testForm from "@/components/testForm/index.vue";
  26. const proxy = getCurrentInstance().proxy;
  27. const route = useRoute();
  28. const show = ref(false);
  29. const typeModal = ref(false);
  30. const unitModal = ref(false);
  31. const classification = ref([]);
  32. const formData = reactive({
  33. data: {},
  34. });
  35. const formDom = ref(null);
  36. const formOption = reactive({
  37. readonly: false, //用于控制整个表单是否只读
  38. disabled: false,
  39. labelAlign: "top",
  40. scroll: true,
  41. labelWidth: "62pk",
  42. // hiddenSubmitBtn: true,
  43. });
  44. const formConfig = reactive([
  45. {
  46. type: "input",
  47. itemType: "text",
  48. label: proxy.t('workingProcedure.processName'),
  49. prop: "name",
  50. clearable: true,
  51. },
  52. {
  53. type: "input",
  54. itemType: "textarea",
  55. label: proxy.t('workingProcedure.processDescription'),
  56. prop: "remarks",
  57. },
  58. {
  59. type: "upload",
  60. label: proxy.t('workingProcedure.processFile'),
  61. prop: "fileList",
  62. },
  63. ]);
  64. const rules = {
  65. name: [{ required: true, message: proxy.t('workingProcedure.workshopTypeCanNotBeEmpty') }],
  66. fileList: [{ required: true, message: proxy.t('workingProcedure.pleaseUploadProcessFile') }],
  67. };
  68. const unitList = ref([]);
  69. const getUserList = () => {
  70. proxy.get("/system/user/list?pageNum=1&pageSize=10000", {}).then((res) => {
  71. formConfig[2].data = res.rows;
  72. });
  73. };
  74. getUserList();
  75. const fileList = ref([]);
  76. const onOversize = () => {
  77. showToast("文件大小不能超过 5MB");
  78. };
  79. const onClickLeft = () => history.back();
  80. const onSubmit = () => {
  81. console.log(formData);
  82. if (formData.data.fileList.length > 0) {
  83. proxy
  84. .post("/productionProcesses/" + route.query.type, formData.data)
  85. .then(() => {
  86. showSuccessToast(route.query.type === "add" ? proxy.t('common.addSuccess') : proxy.t('common.modifySuccess'));
  87. setTimeout(() => {
  88. history.back();
  89. }, 500);
  90. });
  91. } else {
  92. return showFailToast(proxy.t('workingProcedure.pleaseUploadProcessFile'));
  93. }
  94. };
  95. const treeToList = (arr) => {
  96. let res = []; // 用于存储递归结果(扁平数据)
  97. // 递归函数
  98. let fn = (source) => {
  99. source.forEach((el) => {
  100. res.push(el);
  101. el.children && el.children.length > 0 ? fn(el.children) : ""; // 子级递归
  102. });
  103. };
  104. fn(arr);
  105. return res;
  106. };
  107. onMounted(() => {
  108. if (route.query.id) {
  109. proxy
  110. .post("/productionProcesses/detail", { id: route.query.id })
  111. .then((resDetail) => {
  112. formData.data = resDetail.data;
  113. });
  114. proxy
  115. .post("/fileInfo/getList", { businessIdList: [route.query.id] })
  116. .then((res) => {
  117. if (res.data[route.query.id] && res.data[route.query.id].length > 0) {
  118. formData.data.fileList = res.data[route.query.id];
  119. formData.data.fileList = formData.data.fileList.map((item) => {
  120. return {
  121. ...item,
  122. url: item.fileUrl,
  123. };
  124. });
  125. } else {
  126. formData.data.fileList = [];
  127. fileList.value = [];
  128. }
  129. });
  130. }
  131. });
  132. </script>