index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <hc-drawer
  3. v-model="isShow"
  4. to-id="hc-main-box"
  5. is-close
  6. @close="drawerClose"
  7. >
  8. <hc-body split :options="{ sizes: [14, 96] }">
  9. <template #left>
  10. <hc-card scrollbar>
  11. <ElTree
  12. :load="treeLoadNode"
  13. :props="treeProps"
  14. accordion
  15. highlight-current
  16. lazy
  17. @node-click="treeNodeTap"
  18. />
  19. </hc-card>
  20. </template>
  21. <hc-card>
  22. <template #header>
  23. <div class="w-400px">
  24. <hc-search-input
  25. v-model="searchForm.titleName"
  26. @search="searchClick"
  27. />
  28. </div>
  29. </template>
  30. <template #extra>
  31. <el-button hc-btn type="primary" @click="editTable"
  32. >编辑表单</el-button
  33. >
  34. <el-button
  35. hc-btn
  36. type="danger"
  37. @click="batchDel"
  38. :loading="batchDelLoad"
  39. >删除元素表</el-button
  40. >
  41. <!-- el-button hc-btn type="warning">排序</el-button -->
  42. </template>
  43. <hc-table
  44. :column="tableColumn"
  45. :datas="tableData"
  46. :loading="tableLoading"
  47. :index-style="{ width: 60 }"
  48. is-check
  49. :check-style="{ width: 29 }"
  50. @selection-change="tableCheckChange"
  51. >
  52. <template #action="{ row }">
  53. <el-link type="primary" @click="rowNodeClick(row)"
  54. >分配节点</el-link
  55. >
  56. <el-link type="warning" @click="rowFormulaClick(row)"
  57. >公式配置</el-link
  58. >
  59. <el-link type="danger" @click="rowEditClick(row)"
  60. >编辑元素</el-link
  61. >
  62. </template>
  63. </hc-table>
  64. <template #action>
  65. <hc-pages :pages="searchForm" @change="pageChange" />
  66. </template>
  67. </hc-card>
  68. </hc-body>
  69. <!-- 分配节点 -->
  70. <HcWebTemplate v-model="webTemplateShow" :info="webTemplateInfo" />
  71. <!-- 编辑元素 -->
  72. <editElement v-model="editElementShow" :info="editElementInfo" />
  73. <!-- 编辑元素表单信息 -->
  74. <editEle
  75. :ownerTypeList="ownerTypeList"
  76. :tableTypelist="tableTypelist"
  77. :tab="editArr"
  78. v-model="editTableShow"
  79. :editType="1"
  80. @close="editTableClose"
  81. />
  82. </hc-drawer>
  83. </template>
  84. <script setup>
  85. import { ref, watch } from "vue";
  86. import { HcDelMsg } from "hc-vue3-ui";
  87. import { getArrValue, arrToId, isNullES } from "js-fast-way";
  88. import mainApi from "~api/desk/wbs";
  89. import privateApi from "~api/wbs/private";
  90. import HcWebTemplate from "./element/web-temp.vue";
  91. import editElement from "./element/edit-element.vue";
  92. import editEle from "./edit-ele.vue";
  93. import { getDictionaryData, getDictionaryVal } from "~uti/tools";
  94. //事件
  95. const emit = defineEmits(["close"]);
  96. //双向绑定
  97. const isShow = defineModel("modelValue", {
  98. default: false,
  99. });
  100. //监听显示
  101. watch(isShow, (val) => {
  102. if (val) getDataApi();
  103. });
  104. //处理相关数据
  105. const getDataApi = () => {
  106. getTreeData();
  107. };
  108. //树配置
  109. const treeProps = {
  110. label: "title",
  111. children: "children",
  112. isLeaf: "isLeaf",
  113. };
  114. //获取树接口
  115. const treeData = ref([]);
  116. const getTreeData = async () => {
  117. const { data } = await mainApi.tabTypeLazyTreeAll({
  118. parentId: "12345678910",
  119. current: 1,
  120. size: 1000,
  121. });
  122. treeData.value = getArrValue(data?.records);
  123. };
  124. //获取数据
  125. const tabTypeLazyTree = async (parentId = "12345678910") => {
  126. //发起请求
  127. const { data } = await mainApi.tabTypeLazyTreeAll({
  128. parentId,
  129. current: 1,
  130. size: 1000,
  131. });
  132. const records = getArrValue(data?.records);
  133. records.forEach((item) => {
  134. item.isLeaf = !item.hasChildren;
  135. });
  136. return { data: records, total: data?.total };
  137. };
  138. const treeLoadNode = async (node, resolve) => {
  139. if (node.level === 0) {
  140. const resData = await tabTypeLazyTree();
  141. resolve(resData?.data);
  142. } else {
  143. const resData = await tabTypeLazyTree(
  144. node?.data?.primaryKeyId,
  145. "",
  146. false,
  147. {
  148. current: 1,
  149. size: 2000,
  150. }
  151. );
  152. resolve(resData?.data);
  153. }
  154. };
  155. //树节点被点击
  156. const nodeInfo = ref({});
  157. const treeNodeTap = (data, node) => {
  158. nodeInfo.value = data;
  159. searchForm.value.parentId = data.id;
  160. if (node?.level === 1) {
  161. searchClick();
  162. } else if (node?.level === 2) {
  163. searchForm.value.total = 1;
  164. tableData.value = [data];
  165. }
  166. };
  167. //搜索表单
  168. const searchForm = ref({ current: 1, size: 30, total: 0 });
  169. //搜索
  170. const searchClick = () => {
  171. const { parentId } = searchForm.value;
  172. if (isNullES(parentId)) {
  173. window?.$message?.warning("请先在左侧点击一个节点");
  174. return;
  175. }
  176. searchForm.value.current = 1;
  177. getTableData();
  178. };
  179. //分页
  180. const pageChange = ({ current, size }) => {
  181. const { parentId } = searchForm.value;
  182. if (isNullES(parentId)) {
  183. window?.$message?.warning("请先在左侧点击一个节点");
  184. return;
  185. }
  186. searchForm.value.current = current;
  187. searchForm.value.size = size;
  188. getTableData();
  189. };
  190. //表格数据
  191. const tableData = ref([]);
  192. const tableColumn = ref([
  193. { key: "title", name: "名称" },
  194. { key: "elementTotal", name: "总量", width: 80, align: "center" },
  195. { key: "tabOwner", name: "所属方", width: 140, align: "center" },
  196. { key: "fillRate", name: "填报率", width: 80, align: "center" },
  197. { key: "action", name: "操作", width: 220, align: "center" },
  198. ]);
  199. //获取表格数据
  200. const tableLoading = ref(false);
  201. const getTableData = async () => {
  202. tableData.value = [];
  203. tableLoading.value = true;
  204. const { data } = await mainApi.tabTypeLazyTreeAll({
  205. ...searchForm.value,
  206. total: null,
  207. });
  208. tableLoading.value = false;
  209. tableData.value = getArrValue(data?.records);
  210. searchForm.value.total = data?.total || 0;
  211. };
  212. //表格被选择
  213. const tableCheckKeys = ref([]);
  214. const tableCheckChange = (rows) => {
  215. tableCheckKeys.value = rows;
  216. };
  217. //分配节点
  218. const webTemplateShow = ref(false);
  219. const webTemplateInfo = ref({});
  220. const rowNodeClick = (row) => {
  221. webTemplateInfo.value = row;
  222. webTemplateShow.value = true;
  223. };
  224. //公式配置
  225. const rowFormulaClick = (row) => {};
  226. //编辑元素
  227. const editElementShow = ref(false);
  228. const editElementInfo = ref({});
  229. const rowEditClick = (row) => {
  230. editElementInfo.value = row;
  231. editElementShow.value = true;
  232. };
  233. //编辑元素表单信息
  234. const editTableShow = ref(false);
  235. const editArr = ref([]);
  236. const editTable = async () => {
  237. if (tableCheckKeys.value.length < 1) {
  238. window?.$message?.warning("请先选择一个元素");
  239. return;
  240. }
  241. await getOwnerTypelist();
  242. await getTableTypelist();
  243. editArr.value = [];
  244. tableCheckKeys.value.forEach((ele) => {
  245. editArr.value.push({
  246. tableType: getDictionaryVal(tableTypelist.value, ele.tabType),
  247. tableOwner: getDictionaryVal(ownerTypeList.value, ele.tabOwner),
  248. nodeName: ele.title,
  249. Type: 10,
  250. id: ele.id,
  251. fillRate: ele.fillRate,
  252. });
  253. });
  254. editTableShow.value = true;
  255. };
  256. const ownerTypeList = ref([]);
  257. const getOwnerTypelist = async () => {
  258. const data = await getDictionaryData("owner_type");
  259. ownerTypeList.value = getArrValue(data);
  260. };
  261. //获取表单类型
  262. const tableTypelist = ref([]);
  263. const getTableTypelist = async () => {
  264. const data = await getDictionaryData("table_type");
  265. tableTypelist.value = getArrValue(data);
  266. };
  267. const editTableClose = () => {
  268. editTableShow.value = false;
  269. getTableData();
  270. };
  271. //关闭抽屉
  272. const drawerClose = () => {
  273. isShow.value = false;
  274. emit("close");
  275. };
  276. //删除元素表
  277. const batchDelLoad = ref(false);
  278. const batchDel = async () => {
  279. if (tableCheckKeys.value.length < 1) {
  280. window?.$message?.warning("请先选择一个元素");
  281. return;
  282. }
  283. HcDelMsg(async (resolve) => {
  284. //发起请求
  285. const ids = arrToId(tableCheckKeys.value);
  286. const { isRes } = await privateApi.delTabInfoAll(ids);
  287. resolve(); //关闭弹窗
  288. if (!isRes) return;
  289. window.$message.success("删除成功");
  290. getTableData().then();
  291. });
  292. };
  293. </script>