bottomTable.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div>
  3. <avue-crud
  4. ref="crudRef"
  5. v-model:search="search"
  6. v-model="form"
  7. :data="data"
  8. :option="option"
  9. v-model:page="page"
  10. @row-save="createRow"
  11. @row-update="updateRow"
  12. @row-del="deleteRow"
  13. @selection-change="selectionChange"
  14. @sortable-change="onSortChange"
  15. @search-change="searchChange"
  16. @search-reset="resetChange"
  17. @size-change="dataList"
  18. @current-change="dataList"
  19. />
  20. <CommonTable
  21. ref="commonTableRef"
  22. :tableTitle="tableTitle"
  23. :tableType="commonTableType"
  24. @selected-sure="onSelectedFinish"
  25. />
  26. </div>
  27. </template>
  28. <script setup>
  29. import { ref, getCurrentInstance } from "vue";
  30. import { useCrud } from "@/hooks/userCrud";
  31. import { getTableConfig } from "./configs";
  32. import { saveCompoents } from "@/api/craft/process/index";
  33. const props = defineProps({
  34. tableTitle: {
  35. default: "",
  36. type: String,
  37. },
  38. tableType: {
  39. default: "",
  40. type: String,
  41. },
  42. });
  43. const route = useRoute();
  44. const tableConfig = getTableConfig(route.params.id);
  45. // 传入一个url,后面不带/
  46. const { url, form, data, option, search, page, toDeleteIds, Methords, Utils } =
  47. useCrud({
  48. src: tableConfig[props.tableType].url,
  49. });
  50. const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  51. Methords; //增删改查
  52. const { selectionChange, multipleUpdate } = Methords; //选中和批量删除事件
  53. const crudRef = ref(null); //crudRef.value 获取avue-crud对象
  54. const startCreat = () => {
  55. if (props.tableType === "wuliaocaiji") {
  56. commonTableRef.value && commonTableRef.value.startSelect();
  57. } else {
  58. crudRef.value && crudRef.value.rowAdd();
  59. }
  60. };
  61. const saveSortData = async () => {
  62. multipleUpdate();
  63. };
  64. defineExpose({ startCreat, saveSortData });
  65. const onSortChange = () => {
  66. data.value.forEach((item) => {
  67. console.log(item.id);
  68. });
  69. };
  70. // ============公共弹窗table选择相关,物料采集等使用===============
  71. const commonTableRef = ref({});
  72. const commonTableType = ref("MARTERIAL");
  73. const onSelectedFinish = (itemValue) => {
  74. crudRef.value && crudRef.value.rowAdd();
  75. if (props.tableType === "wuliaocaiji") {
  76. form.value.itemName = itemValue.materialName;
  77. form.value.itemCode = itemValue.materialCode;
  78. form.value.itemModel = itemValue.spec;
  79. form.value.num = 1;
  80. form.value.traceType = "S";
  81. form.value.unit = itemValue.unitDictValue;
  82. }
  83. };
  84. onMounted(() => {
  85. url.value = tableConfig[props.tableType].url;
  86. option.value = Object.assign(option.value, {
  87. addBtn: false,
  88. searchShow: false,
  89. header: false,
  90. sortable: true,
  91. column: tableConfig[props.tableType].column,
  92. });
  93. dataList();
  94. });
  95. watch(
  96. () => props.tableType,
  97. () => {
  98. console.log("faslegb");
  99. url.value = tableConfig[props.tableType].url;
  100. option.value = Object.assign(option.value, {
  101. addBtn: false,
  102. searchShow: false,
  103. header: false,
  104. sortable: true,
  105. column: tableConfig[props.tableType].column,
  106. });
  107. dataList();
  108. }
  109. );
  110. </script>