index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <van-nav-bar title="物料库" left-text="" left-arrow @click-left="onClickLeft" @click-right="onClickRight">
  3. <template #right> 添加 </template>
  4. </van-nav-bar>
  5. <van-search v-model="req.keyword" placeholder="请输入搜索关键词" @search="onRefresh" />
  6. <van-pull-refresh v-model="loading" @refresh="onRefresh">
  7. <div class="list">
  8. <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad" style="margin-bottom: 60px">
  9. <commonList :data="listData" @onClick="toDtl" :config="listConfig"></commonList>
  10. </van-list>
  11. </div>
  12. </van-pull-refresh>
  13. </template>
  14. <script setup>
  15. import { ref, getCurrentInstance } from "vue";
  16. import commonList from "@/components/common-list.vue";
  17. import { useRoute } from "vue-router";
  18. const loading = ref(false);
  19. const router = useRoute();
  20. const req = ref({
  21. pageNum: 1,
  22. keyword: null,
  23. definition: "2",
  24. });
  25. const finished = ref(false);
  26. const proxy = getCurrentInstance().proxy;
  27. const listData = ref([]);
  28. const classification = ref([]);
  29. const listConfig = ref([
  30. {
  31. label: "物料分类",
  32. prop: "productClassifyName",
  33. },
  34. {
  35. label: "物料编码",
  36. prop: "code",
  37. },
  38. {
  39. label: "物料名称",
  40. prop: "name",
  41. },
  42. ]);
  43. const onRefresh = () => {
  44. req.value.pageNum = 1;
  45. finished.value = false;
  46. getList("refresh");
  47. };
  48. const onLoad = () => {
  49. getClassification();
  50. };
  51. const onClickLeft = () => proxy.$router.push("/main/working");
  52. const onClickRight = () => {
  53. proxy.$router.push({
  54. path: "materialLibraryAdd",
  55. query: {
  56. type: 'add'
  57. },
  58. });
  59. };
  60. proxy.uploadDdRightBtn(onClickRight,'添加')
  61. const toDtl = (row) => {
  62. proxy.$router.push({
  63. path: "materialLibraryAdd",
  64. query: {
  65. id: row.id,
  66. type: 'edit'
  67. },
  68. });
  69. };
  70. const treeToList = (arr) => {
  71. let res = []; // 用于存储递归结果(扁平数据)
  72. // 递归函数
  73. let fn = (source) => {
  74. source.forEach((el) => {
  75. res.push(el);
  76. el.children && el.children.length > 0 ? fn(el.children) : ""; // 子级递归
  77. });
  78. };
  79. fn(arr);
  80. return res;
  81. };
  82. const getClassification = () => {
  83. if (classification.value && classification.value.length > 0) {
  84. getList();
  85. } else {
  86. proxy.post("/productClassify/tree", { parentId: "", name: "", definition: "2" }).then((res) => {
  87. classification.value = treeToList(res.data);
  88. getList();
  89. });
  90. }
  91. };
  92. const getList = (type) => {
  93. loading.value = true;
  94. proxy
  95. .post("/productInfo/page", req.value)
  96. .then((res) => {
  97. res.data.rows = res.data.rows.map((item) => {
  98. return {
  99. ...item,
  100. productClassifyName: item.classifyNameGroup.join(" / "),
  101. };
  102. });
  103. listData.value = type === "refresh" ? res.data.rows : listData.value.concat(res.data.rows);
  104. if (req.value.pageNum * 10 >= res.data.total) {
  105. finished.value = true;
  106. }
  107. req.value.pageNum++;
  108. loading.value = false;
  109. })
  110. .catch((err) => {
  111. loading.value = false;
  112. });
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .list {
  117. min-height: 70vh;
  118. }
  119. </style>