add.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. >
  18. <template #processRouteList>
  19. <div class="row">
  20. <div class="col" style="width: 50%">
  21. <van-checkbox-group
  22. v-model="formData.data.processRouteList"
  23. >
  24. <van-checkbox
  25. :name="i.id"
  26. v-for="i in processRouteListData"
  27. :key="i.id"
  28. >{{ i.name }}</van-checkbox
  29. >
  30. </van-checkbox-group>
  31. </div>
  32. <div class="col" style="width: 50%">
  33. <div v-for="(i, index) in formData.data.processRouteList" draggable="true">
  34. <van-icon name="arrow-up" @click="sortUp(i)" />
  35. <van-icon name="arrow-down" @click="sortdown(i)" />
  36. <span style="margin-right: 10px">{{
  37. index + 1
  38. }}</span>
  39. {{ getName2(i) }}
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <template #applicableProductsList>
  45. <div
  46. style="color: #999; width: calc(100vw - 32px)"
  47. @click="show = true"
  48. >
  49. 请选择
  50. </div>
  51. <div class="selectd" @click="show = true">
  52. <div>
  53. <van-tag
  54. v-for="i in formData.data.applicableProductsList"
  55. :key="i"
  56. closeable
  57. size="medium"
  58. type="primary"
  59. @close="deleteTag(i.id)"
  60. style="margin-right: 10px"
  61. >
  62. {{ getName(i) }}
  63. </van-tag>
  64. </div>
  65. </div>
  66. </template>
  67. </testForm>
  68. <van-popup
  69. v-model:show="show"
  70. closeable
  71. position="bottom"
  72. :style="{ height: '60%' }"
  73. >
  74. <div style="height: 50px; width: 100px"></div>
  75. <van-checkbox-group v-model="formData.data.applicableProductsList">
  76. <van-cell-group inset v-for="i in productInfoData" :key="i.id">
  77. <van-cell clickable :title="i.name">
  78. <template #right-icon>
  79. <van-checkbox :name="i.id"></van-checkbox>
  80. </template>
  81. </van-cell>
  82. </van-cell-group>
  83. </van-checkbox-group>
  84. </van-popup>
  85. </div>
  86. </template>
  87. <script setup>
  88. import { ref, getCurrentInstance, onMounted, reactive } from 'vue'
  89. import { showSuccessToast, showToast } from 'vant'
  90. import { useRoute } from 'vue-router'
  91. import { getUserInfo } from '@/utils/auth'
  92. import testForm from '@/components/testForm/index.vue'
  93. const proxy = getCurrentInstance().proxy
  94. const route = useRoute()
  95. const show = ref(false)
  96. const typeModal = ref(false)
  97. const unitModal = ref(false)
  98. const classification = ref([])
  99. const formData = reactive({
  100. data: {
  101. checked: [],
  102. },
  103. })
  104. const formDom = ref(null)
  105. const formOption = reactive({
  106. readonly: false, //用于控制整个表单是否只读
  107. disabled: false,
  108. labelAlign: 'top',
  109. scroll: true,
  110. labelWidth: '62pk',
  111. // hiddenSubmitBtn: true,
  112. })
  113. let selected = ref([])
  114. const sortUp = (id) => {
  115. let index = formData.data.processRouteList.findIndex((i) => i === id)
  116. if (index === 0) {
  117. return
  118. }
  119. let temp = formData.data.processRouteList[index]
  120. formData.data.processRouteList[index] = formData.data.processRouteList[index - 1]
  121. formData.data.processRouteList[index - 1] = temp
  122. }
  123. const sortdown = (id) => {
  124. let index = formData.data.processRouteList.findIndex((i) => i === id)
  125. if (index === formData.data.processRouteList.length - 1) {
  126. return
  127. }
  128. let temp = formData.data.processRouteList[index]
  129. formData.data.processRouteList[index] = formData.data.processRouteList[index + 1]
  130. formData.data.processRouteList[index + 1] = temp
  131. }
  132. const deleteTag = (id) => {
  133. let index = formData.data.applicableProductsList.findIndex((i) => i.id === id)
  134. formData.data.applicableProductsList.splice(index, 1)
  135. }
  136. const getName = (id) => {
  137. let name = ''
  138. productInfoData.value.forEach((i) => {
  139. if (i.id === id) {
  140. name = i.name
  141. }
  142. })
  143. return name
  144. }
  145. const getName2 = (id) => {
  146. let name = ''
  147. processRouteListData.value.forEach((i) => {
  148. if (i.id === id) {
  149. name = i.name
  150. }
  151. })
  152. return name
  153. }
  154. const formConfig = reactive([
  155. {
  156. type: 'input',
  157. itemType: 'text',
  158. label: '车间名称',
  159. prop: 'name',
  160. clearable: true,
  161. },
  162. {
  163. type: 'slot',
  164. label: '工艺线路',
  165. slotName: 'processRouteList',
  166. },
  167. {
  168. type: 'slot',
  169. label: '适用产品',
  170. slotName: 'applicableProductsList',
  171. },
  172. ])
  173. const rules = {
  174. name: [{ required: true, message: '车间类型不能为空' }],
  175. fileList: [{ required: true, message: '请上传工序文件' }],
  176. }
  177. const unitList = ref([])
  178. let processRouteListData = ref([])
  179. const getUserList = () => {
  180. proxy.get('/system/user/list?pageNum=1&pageSize=10000', {}).then((res) => {
  181. formConfig[2].data = res.rows
  182. })
  183. }
  184. getUserList()
  185. const fileList = ref([])
  186. const onOversize = () => {
  187. showToast('文件大小不能超过 5MB')
  188. }
  189. const onClickLeft = () => history.back()
  190. const onSubmit = () => {
  191. console.log(formData)
  192. formData.data.productList = formData.data.applicableProductsList.map(item=>{
  193. return {
  194. productId:item
  195. }
  196. })
  197. proxy
  198. .post('/technology/' + route.query.type, formData.data)
  199. .then(() => {
  200. showSuccessToast(
  201. route.query.type === 'add' ? '添加成功' : '修改成功'
  202. )
  203. setTimeout(() => {
  204. history.back()
  205. }, 500)
  206. })
  207. }
  208. const treeToList = (arr) => {
  209. let res = [] // 用于存储递归结果(扁平数据)
  210. // 递归函数
  211. let fn = (source) => {
  212. source.forEach((el) => {
  213. res.push(el)
  214. el.children && el.children.length > 0 ? fn(el.children) : '' // 子级递归
  215. })
  216. }
  217. fn(arr)
  218. return res
  219. }
  220. const getDtl = (id) => {
  221. proxy
  222. .post('/productionProcesses/page', { id: route.query.id })
  223. .then((resDetail) => {
  224. processRouteListData.value = resDetail.data.rows
  225. console.log(processRouteListData.value)
  226. })
  227. proxy
  228. .post('/productInfo/page', { pageNum: 1, pageSize: 10000 })
  229. .then((resDetail) => {
  230. productInfoData.value = resDetail.data.rows
  231. })
  232. }
  233. let productInfoData = ref([])
  234. onMounted(() => {
  235. if (route.query.id) {
  236. proxy
  237. .post('/technology/detail', { id: route.query.id })
  238. .then((resDetail) => {
  239. formData.data = {
  240. ...resDetail.data,
  241. processRouteList: resDetail.data.processRouteList.map(
  242. (item) => item.id
  243. ),
  244. applicableProductsList: resDetail.data.applicableProductsList.map(
  245. (item) => item.id
  246. ),
  247. }
  248. getDtl()
  249. })
  250. }else{
  251. getDtl()
  252. }
  253. })
  254. </script>
  255. <style scoped lang="scss">
  256. .row {
  257. overflow: hidden;
  258. width: calc(100vw - 32px);
  259. .col {
  260. width: 50%;
  261. float: left;
  262. box-sizing: border-box;
  263. padding: 0 10px;
  264. overflow: hidden;
  265. .van-icon-arrow-down,
  266. .van-icon-arrow-up {
  267. display: inline-block;
  268. height: 18px;
  269. margin: 1px 3px;
  270. line-height: 18px;
  271. background: #1989fa;
  272. width: 18px;
  273. color: #fff;
  274. border-radius: 9px;
  275. text-align: center;
  276. }
  277. }
  278. }
  279. </style>