index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <van-nav-bar
  3. title="产线配置"
  4. left-text=""
  5. left-arrow
  6. @click-left="onClickLeft"
  7. @click-right="onClickRight"
  8. >
  9. <template #right> 添加 </template>
  10. </van-nav-bar>
  11. <van-search
  12. v-model="req.keyword"
  13. placeholder="请输入搜索关键词"
  14. @search="onRefresh"
  15. />
  16. <van-pull-refresh v-model="loading" @refresh="onRefresh">
  17. <div class="list">
  18. <van-list
  19. v-model:loading="loading"
  20. :finished="finished"
  21. finished-text="没有更多了"
  22. @load="onLoad"
  23. style="margin-bottom: 60px"
  24. >
  25. <commonList
  26. :data="listData"
  27. @onClick="toDtl"
  28. :config="listConfig"
  29. ></commonList>
  30. </van-list>
  31. </div>
  32. </van-pull-refresh>
  33. </template>
  34. <script setup>
  35. import { ref, getCurrentInstance } from 'vue'
  36. import commonList from '@/components/common-list.vue'
  37. import { useRoute } from 'vue-router'
  38. const loading = ref(false)
  39. const router = useRoute()
  40. const req = ref({
  41. pageNum: 1,
  42. keyword: null,
  43. definition: '1',
  44. })
  45. const finished = ref(false)
  46. const proxy = getCurrentInstance().proxy
  47. const listData = ref([])
  48. const listConfig = ref([
  49. {
  50. label: '产线名称',
  51. prop: 'name',
  52. },
  53. {
  54. label: '负责人名称',
  55. prop: 'personLiableName',
  56. },
  57. {
  58. label: '产线类型',
  59. prop: 'typeName',
  60. },
  61. ])
  62. //车间类型
  63. const typeList = ref([
  64. {
  65. label: '普通产线',
  66. value: '1',
  67. },
  68. {
  69. label: '半自动化产线',
  70. value: '2',
  71. },
  72. {
  73. label: '自动化产线',
  74. value: '3',
  75. },
  76. ])
  77. const onRefresh = () => {
  78. req.value.pageNum = 1
  79. finished.value = false
  80. getList('refresh')
  81. }
  82. const onLoad = () => {
  83. }
  84. const onClickLeft = () => proxy.$router.push('/main/working')
  85. const onClickRight = () => {
  86. proxy.$router.push({
  87. path: 'factoryAdd',
  88. query: {
  89. type: 'add',
  90. },
  91. })
  92. }
  93. const toDtl = (row) => {
  94. proxy.$router.push({
  95. path: 'factoryAdd',
  96. query: {
  97. id: row.id,
  98. type: 'edit',
  99. },
  100. })
  101. }
  102. const treeToList = (arr) => {
  103. let res = [] // 用于存储递归结果(扁平数据)
  104. // 递归函数
  105. let fn = (source) => {
  106. source.forEach((el) => {
  107. res.push(el)
  108. el.children && el.children.length > 0 ? fn(el.children) : '' // 子级递归
  109. })
  110. }
  111. fn(arr)
  112. return res
  113. }
  114. const getList = (type) => {
  115. loading.value = true
  116. proxy
  117. .post('/assemblyLine/page', req.value)
  118. .then((res) => {
  119. listData.value =
  120. type === 'refresh'
  121. ? res.data.rows
  122. : listData.value.concat(res.data.rows)
  123. if (req.value.pageNum * 10 >= res.data.total) {
  124. finished.value = true
  125. }
  126. req.value.pageNum++
  127. loading.value = false
  128. listData.value = res.data.rows.map((item) => {
  129. return {
  130. ...item,
  131. typeName: typeList.value.find((v) => v.value == item.type)
  132. .label,
  133. }
  134. })
  135. console.log(listData.value)
  136. })
  137. .catch((err) => {
  138. loading.value = false
  139. })
  140. }
  141. getList()
  142. </script>
  143. <style lang="scss" scoped>
  144. .list {
  145. min-height: 70vh;
  146. }
  147. </style>