add.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="form">
  3. <van-nav-bar
  4. title="工序管理"
  5. left-text="返回"
  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 } 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: '车间名称',
  49. prop: 'name',
  50. clearable: true,
  51. },
  52. {
  53. type: 'input',
  54. itemType: 'textarea',
  55. label: '备注',
  56. prop: 'remarks',
  57. },
  58. {
  59. type: 'upload',
  60. label: '文件上传',
  61. prop: 'fileList',
  62. },
  63. ])
  64. const rules = {
  65. name: [{ required: true, message: '车间类型不能为空' }],
  66. fileList: [{ required: true, message: '请上传工序文件' }],
  67. }
  68. const unitList = ref([])
  69. const getUserList = () => {
  70. proxy
  71. .get('/system/user/list?pageNum=1&pageSize=10000', {
  72. })
  73. .then((res) => {
  74. formConfig[2].data = res.rows
  75. })
  76. }
  77. getUserList()
  78. const fileList = ref([])
  79. const onOversize = () => {
  80. showToast('文件大小不能超过 5MB')
  81. }
  82. const onClickLeft = () => history.back()
  83. const onSubmit = () => {
  84. console.log(formData)
  85. proxy.post('/productionProcesses/' + route.query.type, formData.data).then(() => {
  86. showSuccessToast(route.query.type === 'add' ? '添加成功' : '修改成功')
  87. setTimeout(() => {
  88. history.back()
  89. }, 500)
  90. })
  91. }
  92. const treeToList = (arr) => {
  93. let res = [] // 用于存储递归结果(扁平数据)
  94. // 递归函数
  95. let fn = (source) => {
  96. source.forEach((el) => {
  97. res.push(el)
  98. el.children && el.children.length > 0 ? fn(el.children) : '' // 子级递归
  99. })
  100. }
  101. fn(arr)
  102. return res
  103. }
  104. onMounted(() => {
  105. if (route.query.id) {
  106. proxy
  107. .post('/productionProcesses/detail', { id: route.query.id })
  108. .then((resDetail) => {
  109. formData.data = resDetail.data
  110. })
  111. proxy.post("/fileInfo/getList", { businessIdList: [route.query.id] }).then((res) => {
  112. if (res.data[route.query.id] && res.data[route.query.id].length > 0) {
  113. formData.data.fileList = res.data[route.query.id];
  114. formData.data.fileList = formData.data.fileList.map((item) => {
  115. return {
  116. ...item,
  117. url: item.fileUrl,
  118. };
  119. });
  120. } else {
  121. formData.data.fileList = [];
  122. fileList.value = [];
  123. }
  124. });
  125. }
  126. })
  127. </script>