classifyMixin.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // 左侧树形分类
  2. import * as sheetInterface from '@/api/modules/sheetApi.js';
  3. export default {
  4. data() {
  5. return {};
  6. },
  7. directives: {
  8. drag(el, bindings) {
  9. el.onmousedown = function(e) {
  10. var init = e.clientX;
  11. var box = $("#box")[0]
  12. let total_wid = box.offsetWidth
  13. var left = $("#left")[0];
  14. var right = $("#right")[0];
  15. var initWidth = left.offsetWidth;
  16. document.onmousemove = function(e) {
  17. var end = e.clientX;
  18. if(end > 310){
  19. var newWidth = end - init + initWidth;
  20. // right.style.width = total_wid-end+80 +'px'
  21. right.style.width = total_wid - newWidth + 'px'
  22. left.style.width = newWidth + "px";
  23. }else{
  24. end = 350;
  25. // 最小宽度300
  26. left.style.width = 300 + "px";
  27. // right.style.width = total_wid-300-20 +'px'
  28. }
  29. };
  30. document.onmouseup = function() {
  31. document.onmousemove = document.onmouseup = null;
  32. e.releaseCapture && e.releaseCapture();
  33. };
  34. e.setCapture && e.setCapture();
  35. return false;
  36. };
  37. }
  38. },
  39. methods: {
  40. /* 根据unicode展开树结构并选中当前图表 重置图表配置 日期区间 */
  41. selectCurrentNode({ code, id, type }) {
  42. let deep_arr = _.cloneDeep(this.treeData);
  43. // 查找图表的分类父级id
  44. let arr = this.findParentNodeHandle(deep_arr, code).slice(1).reverse(); // 父的父的父-父的父-父
  45. this.defaultShowNodes = arr;
  46. this.select_node = code;
  47. this.$refs.treeRef.setCurrentKey(this.select_node);
  48. // // 重置筛选状态
  49. this.select_id = id;
  50. },
  51. // 查找树节点所有父节点
  52. findParentNodeHandle(arr, id) {
  53. // 遍历取父级code push数组
  54. for (let i of arr) {
  55. if (i.UniqueCode === id) {
  56. return [i.UniqueCode];
  57. }
  58. if (i.Children) {
  59. let node = this.findParentNodeHandle(i.Children, id);
  60. if (node) {
  61. return node.concat(i.UniqueCode);
  62. }
  63. }
  64. }
  65. },
  66. /* 拖动时node宽度跟随变化 */
  67. resetNodeStyle: _.debounce(function(node) {
  68. const tree = $('.target_tree')[0];
  69. let width = tree.offsetWidth;
  70. // let label_wid = width > 500 ? 'auto' : (width <= 300 && width < 360) ? 100 : 0.7*width;
  71. let label_wid =
  72. width > 500
  73. ? 'auto'
  74. : width <= 260
  75. ? 90
  76. : 0.6 * width;
  77. this.$set(node, 'Nodewidth', label_wid + 'px');
  78. },200),
  79. /* 双击label出现input修改框 */
  80. editNodeLabel(data,type='') {
  81. if(type === 'edit-tit') {
  82. if([2,3].includes(this.sheetDetailInfo.Source)) return
  83. // if(!this.permissionBtn.isShowBtn('etaTablePermission','etaTable_classifyOpt_edit')) return
  84. if(!this.isSheetBtnShow('classifyOpt_edit')) return
  85. this.$set(data,'isEditTit',true)
  86. this.sheet_title = data.ExcelName;
  87. this.$nextTick(() => {
  88. this.$refs.sheetEditTitRef.focus();
  89. });
  90. } else {
  91. //目录名称可以双击修改
  92. if(data.ExcelInfoId) return
  93. this.$set(data,'isEdit',true)
  94. this.new_label = data.ExcelClassifyName;
  95. this.$nextTick(() => {
  96. this.$refs.editVal.focus();
  97. });
  98. }
  99. },
  100. /* input失去焦点恢复node 修改最新的值*/
  101. changeValue(data,type='') {
  102. if(type === 'edit-tit') {
  103. if(!this.sheet_title) return this.$message.warning(this.$t('OnlineExcelPage.table_name_empty_msg') );
  104. data.isEditTit = false;
  105. data.ExcelName = this.sheet_title;
  106. console.log(data,'data');
  107. }else {
  108. if(!this.new_label) return this.$message.warning(this.$t('OnlineExcelPage.name_empty_msg') );
  109. this.$set(data,'isEdit',false)
  110. this.new_label !== data.ClassifyName && sheetInterface.classifyEdit({
  111. ExcelClassifyId: data.ExcelClassifyId,
  112. ExcelClassifyName: this.new_label,
  113. ParentId: data.ParentId,
  114. Source: this.sourceMap[this.$route.path]
  115. }).then(res => {
  116. if(res.Ret !== 200) return
  117. this.getTreeData();
  118. })
  119. }
  120. },
  121. /* 拖拽完成 */
  122. dropOverHandle(b, a, i, e) {
  123. // console.log(i, a);
  124. // 被拖拽节点对应的 Node、结束拖拽时最后进入的节点、被拖拽节点的放置位置
  125. let isSheet = b.data.ExcelInfoId ? true : false;
  126. let list=a.parent.childNodes;
  127. let targetIndex=0,PrevClassifyId=0,NextClassifyId=0,ParentClassifyId=0;
  128. let ClassifyId=isSheet?0:b.data.ExcelClassifyId,ExcelInfoId=isSheet?b.data.ExcelInfoId:0,PrevExcelInfoId=0,NextExcelInfoId=0;
  129. if(i!=='inner'){
  130. ParentClassifyId=a.parent.data.ExcelClassifyId||0
  131. list.forEach((item,index)=>{
  132. if(isSheet){
  133. if(item.data.ExcelInfoId===b.data.ExcelInfoId){
  134. targetIndex=index
  135. }
  136. }else{
  137. if(item.data.ExcelClassifyId===b.data.ExcelClassifyId){
  138. targetIndex=index
  139. }
  140. }
  141. })
  142. if(targetIndex===0){
  143. const data=list[targetIndex+1].data
  144. NextClassifyId=data.ExcelInfoId?0:data.ExcelClassifyId
  145. NextExcelInfoId=data.ExcelInfoId?data.ExcelInfoId:0
  146. }else if(targetIndex===list.length-1){
  147. const data=list[targetIndex-1].data
  148. PrevClassifyId=data.ExcelInfoId?0:data.ExcelClassifyId
  149. PrevExcelInfoId=data.ExcelInfoId?data.ExcelInfoId:0
  150. }else{
  151. const pData=list[targetIndex-1].data
  152. PrevClassifyId=pData.ExcelInfoId?0:pData.ExcelClassifyId
  153. PrevExcelInfoId=pData.ExcelInfoId?pData.ExcelInfoId:0
  154. const nData=list[targetIndex+1].data
  155. NextClassifyId=nData.ExcelInfoId?0:nData.ExcelClassifyId
  156. NextExcelInfoId=nData.ExcelInfoId?nData.ExcelInfoId:0
  157. }
  158. }else{
  159. ParentClassifyId=a.data.ExcelClassifyId||0
  160. }
  161. let params = {
  162. ClassifyId,
  163. ParentClassifyId,
  164. NextClassifyId,
  165. PrevClassifyId,
  166. ExcelInfoId,
  167. NextExcelInfoId,
  168. PrevExcelInfoId,
  169. Source: this.sourceMap[this.$route.path]
  170. }
  171. sheetInterface.classifyMove(params)
  172. .then((res) => {
  173. if (res.Ret !== 200) return;
  174. this.$message.success(this.$t('ETable.Msg.move_success_msg'));
  175. this.getTreeData();
  176. });
  177. },
  178. // 移动的为一级目录
  179. handleMoveCatalogue(b, a, i, e) {
  180. let list = a.parent.childNodes,
  181. targetIndex = 0,
  182. PrevClassifyId = 0,
  183. NextClassifyId = 0;
  184. list.forEach((item, index) => {
  185. if (item.data.ExcelClassifyId === b.data.ExcelClassifyId) {
  186. targetIndex = index;
  187. return;
  188. }
  189. });
  190. if (targetIndex === 0) {
  191. PrevClassifyId = 0;
  192. NextClassifyId = list[targetIndex + 1].data.ExcelClassifyId;
  193. } else if (targetIndex === list.length - 1) {
  194. PrevClassifyId = list[targetIndex - 1].data.ExcelClassifyId;
  195. NextClassifyId = 0;
  196. } else {
  197. PrevClassifyId = list[targetIndex - 1].data.ExcelClassifyId;
  198. NextClassifyId = list[targetIndex + 1].data.ExcelClassifyId;
  199. }
  200. sheetInterface
  201. .classifyMove({
  202. ClassifyId: b.data.ExcelClassifyId,
  203. PrevClassifyId: PrevClassifyId,
  204. NextClassifyId: NextClassifyId,
  205. })
  206. .then((res) => {
  207. if (res.Ret !== 200) return;
  208. this.$message.success(this.$t('ETable.Msg.move_success_msg'));
  209. this.getTreeData();
  210. });
  211. },
  212. // 移动的为表格
  213. handleMoveSheet(b, a, i, e) {
  214. let PrevSheetId = 0,
  215. NextSheetId = 0,
  216. targetIndex = 0,
  217. list = a.parent.data.Children;
  218. if (i === "inner") {
  219. PrevSheetId = 0;
  220. NextSheetId =
  221. a.data.Children.length > 1 ? a.data.Children[1].ExcelInfoId : 0;
  222. } else {
  223. list.forEach((item, index) => {
  224. if (item.ExcelInfoId === b.data.ExcelInfoId) {
  225. targetIndex = index;
  226. return;
  227. }
  228. });
  229. if (targetIndex === 0) {
  230. PrevSheetId = 0;
  231. NextSheetId = list[targetIndex + 1].ExcelInfoId;
  232. } else if (targetIndex === list.length - 1) {
  233. PrevSheetId = list[targetIndex - 1].ExcelInfoId;
  234. NextSheetId = 0;
  235. } else {
  236. PrevSheetId = list[targetIndex - 1].ExcelInfoId;
  237. NextSheetId = list[targetIndex + 1].ExcelInfoId;
  238. }
  239. }
  240. sheetInterface
  241. .sheetMove({
  242. ExcelClassifyId: a.data.ExcelClassifyId,
  243. ExcelInfoId: b.data.ExcelInfoId,
  244. ClassifyId: b.data.ExcelClassifyId,
  245. PrevExcelInfoId: PrevSheetId,
  246. NextExcelInfoId: NextSheetId,
  247. })
  248. .then((res) => {
  249. if (res.Ret !== 200) return;
  250. this.$message.success(this.$t('ETable.Msg.move_success_msg'));
  251. this.getTreeData();
  252. });
  253. },
  254. /* 拖拽覆盖添加背景色 */
  255. dropMouseOver(node1, node2, e) {
  256. if (
  257. (node1.level === 2 && node2.level === 1) &&
  258. (e.target.childNodes[0].className.includes("el-tree-node__content") ||
  259. e.target.className.includes("el-tree-node__content"))
  260. ) {
  261. e.target.childNodes[0].className.includes("el-tree-node__content")
  262. ? (e.target.childNodes[0].style.backgroundColor = "#409eff")
  263. : (e.target.style.backgroundColor = "#409eff");
  264. }
  265. },
  266. /* 拖拽离开/拖拽完成重置背景色 */
  267. dropMouseLeave(node1, node2, e) {
  268. let arrs = $(".el-tree-node__content");
  269. for (let a of arrs) {
  270. a.style.backgroundColor = "transparent";
  271. }
  272. },
  273. // 树节点展开
  274. handleNodeExpand(data) {
  275. // 保存当前展开的节点
  276. let flag = this.defaultShowNodes.some((item) => item === data.UniqueCode);
  277. if (!flag) {
  278. // 不存在则存到数组里
  279. this.defaultShowNodes.push(data.UniqueCode);
  280. }
  281. },
  282. // 树节点关闭
  283. handleNodeCollapse(data) {
  284. this.defaultShowNodes.some((item, index) => {
  285. if (item === data.UniqueCode) {
  286. // 删除关闭节点
  287. this.defaultShowNodes.length = index;
  288. }
  289. });
  290. },
  291. /* 判断节点是否能被拖拽 */
  292. canDragHandle(node) {
  293. if(!node.data.HaveOperaAuth) return
  294. let canMove = true;
  295. return canMove;
  296. },
  297. /* 判断节点是否能被拖入 */
  298. canDropHandle(draggingNode, dropNode, type) {
  299. let canDrop = false;
  300. // 指标
  301. if(draggingNode.data.ExcelInfoId){
  302. if(!(dropNode.level===1&&type!=='inner')){
  303. canDrop=true
  304. }
  305. }else{//目录
  306. if((dropNode.level+1==draggingNode.level&&type==='inner')||(dropNode.level===draggingNode.level&&type!=='inner')){
  307. canDrop=true
  308. }
  309. }
  310. return canDrop;
  311. },
  312. //判断自定义表格-编辑,另存为,刷新按钮是否显示
  313. isSheetBtnShow(type){
  314. const sheetType = {
  315. '/sheetList': 'etaTable_excel',
  316. '/sheetTimeList': 'etaTable_customize_data',
  317. '/sheetMixedList': 'etaTable_customize_mix',
  318. '/sheetAnalysisList': 'etaTable_analysis',
  319. '/sheetBalanceList':'etaTable_customize_balance'
  320. }
  321. return this.permissionBtn.isShowBtn('etaTablePermission',`${sheetType[this.$route.path]}_${type}`)
  322. }
  323. },
  324. };