quteElePage.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <!-- 树节点调整排序 -->
  3. <hc-dialog
  4. v-model="isShow"
  5. title="引用元素表"
  6. widths="56rem"
  7. isTable
  8. @close="dialogClose"
  9. @save="submitClick"
  10. :loading="submitLoading"
  11. >
  12. <hc-body split :options="{ sizes: [14, 96] }">
  13. <template #left>
  14. <hc-card scrollbar>
  15. <ElTree
  16. :load="treeLoadNode"
  17. :props="treeProps"
  18. accordion
  19. highlight-current
  20. lazy
  21. @node-click="treeNodeTap"
  22. />
  23. </hc-card>
  24. </template>
  25. <hc-card>
  26. <template #header>
  27. <div class="w-400px">
  28. <hc-search-input
  29. v-model="searchForm.titleName"
  30. @search="searchClick"
  31. />
  32. </div>
  33. </template>
  34. <hc-table
  35. :column="tableColumn"
  36. :datas="tableData"
  37. :loading="tableLoading"
  38. :index-style="{ width: 60 }"
  39. is-check
  40. :check-style="{ width: 29 }"
  41. @selection-change="tableCheckChange"
  42. >
  43. </hc-table>
  44. <template #action>
  45. <hc-pages :pages="searchForm" @change="pageChange" />
  46. </template>
  47. </hc-card>
  48. </hc-body>
  49. </hc-dialog>
  50. </template>
  51. <script setup>
  52. import { ref, watch, nextTick } from "vue";
  53. import mainApi from "~api/desk/wbs";
  54. import privateApi from "~api/wbs/private";
  55. import { arrToId, getArrValue, isNullES } from "js-fast-way";
  56. //事件
  57. const emit = defineEmits(["close"]);
  58. //双向绑定
  59. // eslint-disable-next-line no-undef
  60. const isShow = defineModel("modelValue", {
  61. default: false,
  62. });
  63. const props = defineProps({
  64. projectId: {
  65. type: [String, Number],
  66. default: "1",
  67. },
  68. });
  69. const porjectId = ref(props.projectId);
  70. //监听显示
  71. watch(isShow, (val) => {
  72. if (val) {
  73. } else {
  74. emit("close");
  75. }
  76. });
  77. //关闭弹窗
  78. const dialogClose = () => {
  79. isShow.value = false;
  80. emit("close");
  81. };
  82. //树配置
  83. const treeProps = {
  84. label: "title",
  85. children: "children",
  86. isLeaf: "isLeaf",
  87. };
  88. //获取数据
  89. const tabTypeLazyTree = async (parentId = "12345678910") => {
  90. //发起请求
  91. const { data } = await mainApi.tabTypeLazyTreeAll({
  92. parentId,
  93. current: 1,
  94. size: 1000,
  95. });
  96. const records = getArrValue(data?.records);
  97. records.forEach((item) => {
  98. item.isLeaf = !item.hasChildren;
  99. });
  100. return { data: records, total: data?.total };
  101. };
  102. const treeLoadNode = async (node, resolve) => {
  103. if (node.level === 0) {
  104. const resData = await tabTypeLazyTree();
  105. resolve(resData?.data);
  106. } else {
  107. const resData = await tabTypeLazyTree(
  108. node?.data?.primaryKeyId,
  109. "",
  110. false,
  111. {
  112. current: 1,
  113. size: 2000,
  114. }
  115. );
  116. resolve(resData?.data);
  117. }
  118. };
  119. //树节点被点击
  120. const nodeInfo = ref({});
  121. const treeNodeTap = (data, node) => {
  122. nodeInfo.value = data;
  123. searchForm.value.parentId = data.id;
  124. if (node?.level === 1) {
  125. searchClick();
  126. } else if (node?.level === 2) {
  127. searchForm.value.total = 1;
  128. tableData.value = [data];
  129. }
  130. };
  131. //搜索表单
  132. const searchForm = ref({ current: 1, size: 30, total: 0 });
  133. //搜索
  134. const searchClick = () => {
  135. const { parentId } = searchForm.value;
  136. if (isNullES(parentId)) {
  137. window?.$message?.warning("请先在左侧点击一个节点");
  138. return;
  139. }
  140. searchForm.value.current = 1;
  141. getTableData();
  142. };
  143. //分页
  144. const pageChange = ({ current, size }) => {
  145. const { parentId } = searchForm.value;
  146. if (isNullES(parentId)) {
  147. window?.$message?.warning("请先在左侧点击一个节点");
  148. return;
  149. }
  150. searchForm.value.current = current;
  151. searchForm.value.size = size;
  152. getTableData();
  153. };
  154. //表格数据
  155. const tableData = ref([]);
  156. const tableColumn = ref([
  157. { key: "title", name: "名称" },
  158. { key: "elementTotal", name: "总量", width: 80, align: "center" },
  159. { key: "tabOwner", name: "所属方", width: 140, align: "center" },
  160. { key: "fillRate", name: "填报率", width: 80, align: "center" },
  161. { key: "action", name: "操作", width: 220, align: "center" },
  162. ]);
  163. //获取表格数据
  164. const tableLoading = ref(false);
  165. const getTableData = async () => {
  166. tableData.value = [];
  167. tableLoading.value = true;
  168. const { data } = await mainApi.tabTypeLazyTreeAll({
  169. ...searchForm.value,
  170. total: null,
  171. });
  172. tableLoading.value = false;
  173. tableData.value = getArrValue(data?.records);
  174. searchForm.value.total = data?.total || 0;
  175. };
  176. //表格被选择
  177. const tableCheckKeys = ref([]);
  178. const tableCheckChange = (rows) => {
  179. tableCheckKeys.value = rows;
  180. };
  181. const submitLoading = ref(false);
  182. const submitClick = async () => {
  183. let ids = arrToId(tableCheckKeys.value);
  184. submitLoading.value = true;
  185. const { error, code, data, msg } = await privateApi.projecttabInfo({
  186. primaryKeyIds: ids,
  187. projectId: porjectId.value,
  188. });
  189. submitLoading.value = false;
  190. //判断状态
  191. if (!error && code === 200) {
  192. window.$message.success(msg);
  193. dialogClose();
  194. }
  195. };
  196. </script>