SCITargetbase.vue 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. <template>
  2. <div class="smmTarget-container" id="box">
  3. <div class="left-cont minHeight" id="left">
  4. <div class="left-top">
  5. <el-button
  6. v-permission="permissionBtn.dataSourcePermission.hongtao3Data_export"
  7. style="width: 100%"
  8. type="primary"
  9. plain
  10. size="medium"
  11. @click="exportClick"
  12. :loading="btnload"
  13. >导出Excel</el-button
  14. >
  15. <el-autocomplete
  16. style="margin: 20px 0; width: 100%"
  17. prefix-icon="el-icon-search"
  18. v-model="leftSearchVal"
  19. :fetch-suggestions="handleLeftSearch"
  20. :trigger-on-focus="false"
  21. placeholder="指标名称/指标ID"
  22. @select="handleSelectLeftSearchval"
  23. popper-class="el-autocomplete-suggestion-data-entry"
  24. clearable
  25. >
  26. <template slot-scope="scope">
  27. <div v-if="scope.item.nodata" style="text-align: center">
  28. 暂无数据
  29. </div>
  30. <div v-else>
  31. {{ scope.item.IndexName }}
  32. </div>
  33. </template>
  34. </el-autocomplete>
  35. </div>
  36. <div class="scroll-wrap">
  37. <el-tree
  38. ref="treeRef"
  39. class="target_tree custom-tree"
  40. :data="classifyList"
  41. node-key="UniqueCode"
  42. :props="{
  43. label: 'ClassifyName',
  44. children: 'Children',
  45. }"
  46. draggable
  47. :current-node-key="select_node"
  48. :expand-on-click-node="false"
  49. check-strictly
  50. empty-text="暂无分类"
  51. @current-change="nodeChangeHandle"
  52. :default-expanded-keys="defaultShowNodes"
  53. @node-expand="handleNodeExpand"
  54. @node-collapse="handleNodeCollapse"
  55. :allow-drag="canDragHandle"
  56. :allow-drop="canDropHandle"
  57. @node-drop="dropOverHandle"
  58. >
  59. <div class="custom-tree-node" slot-scope="{ node, data }">
  60. <span
  61. class="text_oneLine"
  62. :style="`width:${
  63. (select_node === data.UniqueCode &&
  64. (node.Nodewidth || data.NodeWidth + 'px')) ||
  65. ''
  66. }`"
  67. >{{ data.ClassifyName }}</span
  68. >
  69. <div v-if="select_node === data.UniqueCode">
  70. <img
  71. src="~@/assets/img/data_m/move_ico.png"
  72. v-if="data.Button.MoveButton"
  73. alt=""
  74. style="width: 14px; height: 14px; margin-right: 5px"
  75. @click.stop="clickClassifyHandle('move', data, node)"
  76. />
  77. <img
  78. src="~@/assets/img/set_m/add.png"
  79. style="width: 14px; height: 14px; margin-right: 5px"
  80. @click.stop="clickClassifyHandle('add', data, node)"
  81. v-if="data.Button.AddButton&&permissionBtn.isShowBtn('dataSourcePermission','hongtao3Data_classifyOpt_add')"
  82. />
  83. <img
  84. src="~@/assets/img/set_m/edit.png"
  85. v-if="data.Button.OpButton&&permissionBtn.isShowBtn('dataSourcePermission','hongtao3Data_classifyOpt_edit')"
  86. alt=""
  87. style="width: 14px; height: 14px; margin-right: 5px"
  88. @click.stop="clickClassifyHandle('edit', data, node)"
  89. />
  90. <img
  91. src="~@/assets/img/set_m/clean.png"
  92. v-if="data.Button.cleanButton"
  93. alt=""
  94. style="width: 14px; height: 14px; margin-right: 5px"
  95. @click.stop="clickClassifyHandle('clean', data, node)"
  96. />
  97. <img
  98. src="~@/assets/img/set_m/del.png"
  99. v-if="data.Button.DeleteButton&&permissionBtn.isShowBtn('dataSourcePermission','hongtao3Data_classifyOpt_delete')"
  100. alt=""
  101. style="width: 14px; height: 14px"
  102. @click.stop="clickClassifyHandle('del', data, node)"
  103. />
  104. <img
  105. src="~@/assets/img/set_m/del_icon.png"
  106. v-if="data.Button.targetDelButton&&permissionBtn.isShowBtn('dataSourcePermission','hongtao3Data_classifyOpt_delete')"
  107. alt=""
  108. style="width: 14px; height: 14px; margin-right: 5px"
  109. @click.stop="clickClassifyHandle('delTarget', data, node)"
  110. />
  111. </div>
  112. </div>
  113. </el-tree>
  114. <div class="add-cont" @click="addClassifyHandle" v-if="permissionBtn.isShowBtn('dataSourcePermission','hongtao3Data_classifyOpt_add')">
  115. <img
  116. src="~@/assets/img/set_m/add_ico.png"
  117. alt=""
  118. style="width: 16px; height: 16px; margin: 10px"
  119. />
  120. <span>添加分类</span>
  121. </div>
  122. </div>
  123. <span
  124. class="move-btn resize"
  125. v-drag
  126. id="resize"
  127. @mousemove="dynamicNode && resetNodeStyle(dynamicNode)"
  128. >
  129. </span>
  130. </div>
  131. <div
  132. class="right-cont minHeight"
  133. id="right"
  134. v-loading="dataloading"
  135. element-loading-text="获取数据中..."
  136. >
  137. <template v-if="rightShow">
  138. <div class="right-box" @scroll="scrollHandle">
  139. <div class="data-header">
  140. <lz-table
  141. :tableOption="tableOption"
  142. tableType="header"
  143. ref="table"
  144. source="smm"
  145. />
  146. </div>
  147. <div class="data-cont" v-if="dateArr.length">
  148. <lz-table
  149. :tableOption="tableOption"
  150. tableType="data"
  151. :dateArr="dateArr"
  152. source="smm"
  153. />
  154. </div>
  155. <div v-else class="nodata"></div>
  156. </div>
  157. <div class="frequency-list" v-if="rightShow && !isShowSingleData">
  158. <el-button
  159. type="primary"
  160. class="frequency-btn"
  161. :plain="select_frequency !== item.key"
  162. v-for="item in frequencyList"
  163. :key="item.key"
  164. @click="changeFrequency(item.key)"
  165. >{{ item.key }}</el-button
  166. >
  167. </div>
  168. </template>
  169. <div v-else class="nodata-cont">
  170. <tableNoData text="暂无数据"/>
  171. </div>
  172. </div>
  173. <!-- 添加/编辑分类弹窗 -->
  174. <m-dialog
  175. :show.sync="openClassifyDia"
  176. width="700px"
  177. :title="classifyForm.title"
  178. @close="cancelDialogHandle"
  179. >
  180. <div class="dialog-cont smmTarget-dialog-cont">
  181. <el-form
  182. ref="classifyFormRef"
  183. label-position="left"
  184. hide-required-asterisk
  185. label-width="80px"
  186. :model="classifyForm"
  187. :rules="classifyFormRules"
  188. >
  189. <el-form-item
  190. label="一级目录"
  191. v-if="classifyForm.parent_classify_name"
  192. >
  193. <span>{{ classifyForm.parent_classify_name }}</span>
  194. </el-form-item>
  195. <el-form-item
  196. label="分类名称"
  197. prop="classify_name"
  198. v-if="classifyForm.type === 'classify'"
  199. >
  200. <el-input
  201. v-model="classifyForm.classify_name"
  202. style="width: 80%"
  203. placeholder="请输入分类名称"
  204. />
  205. </el-form-item>
  206. <el-form-item label="分类名称" prop="classifys_id" v-else>
  207. <el-cascader
  208. style="width: 80%"
  209. :key="cascaderKey"
  210. placeholder="请选择分类名称"
  211. v-model="classifyForm.classifys_id"
  212. :options="cascaderList"
  213. :props="{
  214. value: 'ClassifyId',
  215. label: 'ClassifyName',
  216. children: 'Children',
  217. }"
  218. />
  219. </el-form-item>
  220. </el-form>
  221. </div>
  222. <div class="dia-bot">
  223. <el-button
  224. type="primary"
  225. style="margin-right: 20px"
  226. @click="saveClassifyHandle"
  227. >保存</el-button
  228. >
  229. <el-button type="primary" plain @click="cancelDialogHandle"
  230. >取消</el-button
  231. >
  232. </div>
  233. </m-dialog>
  234. </div>
  235. </template>
  236. <script>
  237. import lzTable from "@/components/lzTable.vue";
  238. import { sciDataInterface } from "@/api/api.js";
  239. import mDialog from "@/components/mDialog.vue";
  240. import leftMixin from "./mixins/leftMixin.js";
  241. export default {
  242. name: "",
  243. components: { lzTable, mDialog },
  244. mixins: [leftMixin],
  245. watch: {},
  246. data() {
  247. return {
  248. exportBase: process.env.VUE_APP_API_ROOT + "/datamanage/export/sciList", //sci数据导出接口
  249. dataloading: false,
  250. rightShow: false,
  251. select_classify: "",
  252. classifyList: [],
  253. select_frequency: "",
  254. frequencyList: [],
  255. tableOption: [],
  256. dateArr: [], //最长的日期数组
  257. btnload: false,
  258. page_no: 1,
  259. page_size: 20,
  260. havemore: true, //是否还有数据
  261. leftSearchVal: "", //左侧搜索值
  262. leftSearchTradeCode: "", //如果是搜索选择的 则有此code
  263. select_quota: "", // 选择的指标名
  264. select_Unit: "", // 选择的单位
  265. select_ModifyTime: "", //选中的更新时间
  266. select_breed: "", // 选中的分类名称
  267. isShowSingleData: false, //右侧是否展示的是单个指标数据
  268. singleDataCode: "",
  269. cascaderList: [], //移动指标分类列表
  270. cascaderKey: 0,
  271. openClassifyDia: false, //分类弹窗
  272. classifyForm: {
  273. title: "添加分类",
  274. classify_name: "", //分类名称
  275. classify_id: "", //分类id
  276. parent_classify_name: "", //如果是二级分类,这是所属一级分类的名称
  277. parent_classify_id: "", //如果是二级分类,这是所属一级分类的id
  278. type: "classify", //classify|index 对分类还是指标进行操作
  279. classifys_id: [], //如果是指标,这是选中的分类id[一级分类id,二级分类id]
  280. BaseFromSmmIndexId: "", //如果是指标,这是指标的唯一id
  281. }, //弹窗可编辑信息
  282. classifyFormRules: {
  283. classify_name: [
  284. { required: true, message: "分类名称不能为空", trigger: "blur" },
  285. ],
  286. }, //可编辑信息校验
  287. };
  288. },
  289. methods: {
  290. /* 获取分类 */
  291. getClassify() {
  292. sciDataInterface.classifyList().then((res) => {
  293. if (res.Ret !== 200) return;
  294. let Data = res.Data.List || [];
  295. //对分类数据做处理:
  296. this.classifyList = this.formatClassifyData(Data, 1, 0);
  297. });
  298. },
  299. formatClassifyData(arr, level, topParentNodeId) {
  300. arr.forEach((item) => {
  301. const { ClassifyId, BaseFromSciIndexId, BaseFromSciIndexCode } = item;
  302. //每条数据添加UniqueCode属性,由ClassifyId BaseFromSmmIndexId BaseFromSmmIndexCode拼接
  303. item.UniqueCode = `${ClassifyId}_${BaseFromSciIndexId}_${BaseFromSciIndexCode}`;
  304. //添加Button属性,用于控制操作栏
  305. item.Button = {
  306. AddButton: true,
  307. OpButton: true,
  308. DeleteButton: true,
  309. MoveButton: true,
  310. cleanButton: false,
  311. targetDelButton: false,
  312. };
  313. //未分类禁用所有操作栏
  314. if (item.ClassifyId === 0) {
  315. item.Button = {
  316. AddButton: false,
  317. OpButton: false,
  318. DeleteButton: false,
  319. MoveButton: false,
  320. cleanButton: false,
  321. targetDelButton: false,
  322. };
  323. }
  324. //二级分类禁用添加按钮
  325. if (item.Level === 2) {
  326. item.Button = {
  327. AddButton: false,
  328. OpButton: true,
  329. DeleteButton: true,
  330. MoveButton: true,
  331. cleanButton: false,
  332. targetDelButton: false,
  333. };
  334. }
  335. //指标禁用删除按钮
  336. if (item.BaseFromSciIndexCode) {
  337. item.Button = {
  338. AddButton: false,
  339. OpButton: true,
  340. DeleteButton: false,
  341. MoveButton: true,
  342. cleanButton: true,
  343. targetDelButton: true,
  344. };
  345. //未分类下的指标,禁用清除按钮
  346. if (topParentNodeId === 0) {
  347. item.Button["cleanButton"] = false;
  348. }
  349. }
  350. //非一级分类添加一级父节点id
  351. if (level !== 1) {
  352. item.topParentNodeId = topParentNodeId;
  353. }
  354. if (item.Children && item.Children.length) {
  355. this.formatClassifyData(
  356. item.Children,
  357. level + 1,
  358. level === 1 ? item.ClassifyId : item.ParentId
  359. );
  360. }
  361. });
  362. return arr;
  363. },
  364. /* 获取频度 */
  365. async getFrequency(defaultSelect) {
  366. const res = await sciDataInterface.frequencyList({
  367. ClassifyId: this.select_classify,
  368. });
  369. if (res.Ret !== 200) return;
  370. this.frequencyList = res.Data
  371. ? res.Data.map((item) => {
  372. return {
  373. key: item.Frequency,
  374. };
  375. })
  376. : [];
  377. //设置当前选中的频度,若传入有默认选项则选中默认频度,否则选中列表第一个
  378. this.select_frequency =
  379. defaultSelect ||
  380. (this.frequencyList.length ? this.frequencyList[0].key : "");
  381. !this.frequencyList.length && this.nodataDeal();
  382. },
  383. /* 获取数据 */
  384. getDataList: _.throttle(function () {
  385. this.isShowSingleData = false;
  386. this.dataloading = true;
  387. sciDataInterface
  388. .dataList({
  389. ClassifyId: this.select_classify,
  390. Frequency: this.select_frequency,
  391. PageSize: this.page_size,
  392. CurrentIndex: this.page_no,
  393. })
  394. .then((res) => {
  395. this.rightShow = true;
  396. if (res.Ret !== 200) return;
  397. // 找出最多的页码 判断是否还有数据
  398. let page_arrs = res.Data.map((item) => item.Paging.Pages);
  399. let totalPage = Math.max.apply(Math, page_arrs);
  400. this.havemore = this.page_no < totalPage ? true : false;
  401. // 合并数据
  402. if (this.page_no === 1) {
  403. this.tableOption = res.Data;
  404. } else {
  405. this.tableOption.forEach((item) => {
  406. res.Data.forEach((_item) => {
  407. if (item.IndexCode === _item.IndexCode) {
  408. item.DataList = item.DataList.concat(_item.DataList);
  409. }
  410. });
  411. });
  412. }
  413. // 合并所有指标中的日期 作为日期数组
  414. let arr = res.Data.map((item) => {
  415. return item.DataList;
  416. });
  417. let obj = [];
  418. for (let i of arr) {
  419. for (let j of i) {
  420. obj.push(j.DataTime);
  421. }
  422. }
  423. let arr2 = [...new Set(obj)].sort().reverse();
  424. let concatArr = [...new Set([...this.dateArr, ...arr2])]
  425. .sort()
  426. .reverse();
  427. this.dateArr = this.page_no === 1 ? arr2 : concatArr;
  428. /* 不满6个追加6个空的显示一排 别问 问就是为了美观 */
  429. if (this.tableOption.length < 7)
  430. for (let i = 0; i < 7; i++) {
  431. this.tableOption.push({
  432. DataList: [],
  433. });
  434. if (this.tableOption.length >= 7) break;
  435. }
  436. //数据最大长度小于12个 追加数据满12个 别问 问就是为了美观
  437. if (this.dateArr.length < 12)
  438. for (let i = 0; i < 12; i++) {
  439. this.dateArr.push("");
  440. if (this.dateArr.length >= 12) break;
  441. }
  442. this.dataloading = false;
  443. this.page_no === 1 &&
  444. this.$nextTick(() => {
  445. this.rightShow && this.initWidth();
  446. });
  447. });
  448. }, 200),
  449. // 获取单个指标数据
  450. async getTargetDataList(code) {
  451. this.isShowSingleData = true;
  452. this.dataloading = true;
  453. try {
  454. const res = await sciDataInterface.getTargetDataList({
  455. IndexCode: code,
  456. });
  457. this.rightShow = true;
  458. if (res.Ret !== 200) return;
  459. const DataList = res.Data.Data || [];
  460. // 设置为没有更多数据
  461. this.haveMore = false;
  462. // 合并数据
  463. this.tableOption = [
  464. {
  465. DataList: DataList,
  466. ...res.Data,
  467. },
  468. ];
  469. // 这里是单个指标所以不用合并日期
  470. const arr = DataList.map((item) => item.DataTime);
  471. this.dateArr = [...new Set(arr)].sort().reverse();
  472. /* 不满6个追加6个空的显示一排 别问 问就是为了美观 */
  473. for (let i = 0; i < 7; i++) {
  474. this.tableOption.push({
  475. DataList: [],
  476. });
  477. if (this.tableOption.length >= 7) break;
  478. }
  479. //数据最大长度小于12个 追加数据满12个 别问 问就是为了美观
  480. if (this.dateArr.length < 12)
  481. for (let i = 0; i < 12; i++) {
  482. this.dateArr.push("");
  483. if (this.dateArr.length >= 12) break;
  484. }
  485. this.select_quota = res.Data.IndexName;
  486. this.select_Unit = res.Data.Unit;
  487. this.select_ModifyTime = res.Data.ModifyTime || "";
  488. this.dataloading = false;
  489. this.rightShow && this.initWidth();
  490. } catch (err) {
  491. console.log(err);
  492. }
  493. },
  494. /* 改变频度 */
  495. changeFrequency(key) {
  496. this.select_frequency = key;
  497. this.leftSearchVal = "";
  498. this.getDataList();
  499. },
  500. initWidth() {
  501. this.$nextTick(() => {
  502. $(".right-box")[0].style.width =
  503. this.$refs.table.$el.clientWidth + 5 + "px";
  504. $(".right-box")[0].scrollTop = 0;
  505. $(".right-box")[0].scrollLeft = 0;
  506. });
  507. },
  508. /* 无频度的异常显示处理 7*12*/
  509. nodataDeal() {
  510. this.tableOption = [];
  511. this.dateArr = [];
  512. for (let i = 0; i < 7; i++) {
  513. this.tableOption.push({
  514. DataList: [],
  515. });
  516. if (this.tableOption.length >= 7) break;
  517. }
  518. for (let i = 0; i < 12; i++) {
  519. this.dateArr.push("");
  520. if (this.dateArr.length >= 12) break;
  521. }
  522. },
  523. /* 滚动加载 */
  524. scrollHandle(e) {
  525. if (this.isShowSingleData) return;
  526. const dom = e.target;
  527. let total = dom.scrollTop + dom.clientHeight;
  528. if (total >= dom.scrollHeight && this.havemore) {
  529. this.page_no++;
  530. console.log("load下一页");
  531. this.getDataList();
  532. }
  533. },
  534. /* 数据导出 */
  535. exportClick() {
  536. this.btnload = true;
  537. const link = document.createElement("a");
  538. //const testSrc = process.env.VUE_APP_API_ROOT+`/datamanage/export/sciQuotasData?TypeCodes=300系不锈钢%23价格,300系不锈钢%23成本,FeNi%23价格`
  539. link.href = this.exportSciapi;
  540. //link.href=testSrc
  541. link.download = "";
  542. link.click();
  543. console.log({
  544. IndexName: this.select_quota,
  545. IndexCode: this.leftSearchTradeCode,
  546. sendIndexCode: this.escapeStr(this.leftSearchTradeCode),
  547. TypeName: this.select_breed,
  548. sendTypeName: this.escapeStr(this.select_breed),
  549. Frequency: this.select_frequency,
  550. UnitName: this.select_Unit,
  551. ModifyTime: this.select_ModifyTime,
  552. sendToken: this.escapeStr(localStorage.getItem("auth") || ""),
  553. url: this.exportSciapi,
  554. });
  555. setTimeout(() => {
  556. this.btnload = false;
  557. }, 5000);
  558. },
  559. //左侧搜索
  560. async handleLeftSearch(query, cb) {
  561. cb([]);
  562. if (!query) return;
  563. const res = await sciDataInterface.getTargetListByName({
  564. Keyword: query,
  565. });
  566. if (res.Ret === 200) {
  567. let arr = res.Data || [];
  568. if (!arr.length) {
  569. cb([{ nodata: true }]);
  570. } else {
  571. cb(arr);
  572. }
  573. }
  574. },
  575. // 选中左侧搜索值
  576. handleSelectLeftSearchval(e) {
  577. if (!e.IndexCode) return;
  578. //this.select_frequency=e.Frequency
  579. //this.select_classify=e.Type2+'#'+e.Type3
  580. this.leftSearchTradeCode = e.IndexCode;
  581. this.leftSearchVal = e.IndexName;
  582. this.select_quota = e.IndexName;
  583. this.select_Unit = e.Unit;
  584. this.select_ModifyTime = e.ModifyTime;
  585. this.select_breed = "";
  586. // 关闭watcher
  587. this.isAuto = false;
  588. // 获取单独指标数据
  589. this.getTargetDataList(e.IndexCode);
  590. this.$nextTick(() => {
  591. //找到父节点并展开
  592. const targetData = this.getTargetData(e.IndexCode, this.classifyList);
  593. if (targetData) {
  594. //一级节点
  595. const { topParentNodeId, UniqueCode } = targetData;
  596. this.handleNodeExpand({ UniqueCode: `${topParentNodeId}_0_` });
  597. //二级节点
  598. if (topParentNodeId !== 0) {
  599. const secondNodeId = UniqueCode.split("_")[0];
  600. this.handleNodeExpand({ UniqueCode: `${secondNodeId}_0_` });
  601. }
  602. //节点样式变化
  603. const tree = $(".target_tree")[0];
  604. let width = tree.offsetWidth;
  605. let label_width =
  606. width > 500 ? "auto" : width <= 500 ? 90 : 0.7 * width;
  607. targetData.NodeWidth = label_width;
  608. this.select_node = UniqueCode;
  609. this.$refs.treeRef.setCurrentNode(targetData);
  610. const node = this.$refs.treeRef.getCurrentNode();
  611. this.resetNodeStyle(node);
  612. }
  613. });
  614. },
  615. getTargetData(code, arr) {
  616. for (const item of arr) {
  617. if (item.BaseFromSciIndexCode === code) return item;
  618. if (item.Children && item.Children.length) {
  619. const _item = this.getTargetData(code, item.Children);
  620. if (_item) return _item;
  621. }
  622. }
  623. },
  624. // 对[#,;]转义
  625. escapeStr(str) {
  626. return str.replace(/#/g, escape("#")).replace(/;/g, escape(";"));
  627. },
  628. //节点操作:
  629. clickClassifyHandle(type, data, node) {
  630. const optionMap = {
  631. /* 'move':this.moveNode,移动 */
  632. add: this.addClassifyHandle, //添加分类
  633. edit: this.editClassifyHandle, //编辑分类/移动指标
  634. del: this.deleteClassifyHandle, //删除分类
  635. clean: this.cleanClassifyHandle, //清除指标分类
  636. delTarget: this.deleteTarget, //删除指标
  637. };
  638. optionMap[type] && optionMap[type](data, node);
  639. },
  640. //添加一二级分类
  641. addClassifyHandle(data = null, node = null) {
  642. this.classifyForm = {
  643. ...this.classifyForm,
  644. ...(data
  645. ? {
  646. title: "添加分类",
  647. classify_name: "",
  648. parent_classify_name: data.ClassifyName,
  649. parent_classify_id: data.ClassifyId,
  650. }
  651. : {
  652. title: "添加分类",
  653. classify_name: "",
  654. }),
  655. };
  656. this.openDialogHandle();
  657. },
  658. //编辑一二级分类,编辑指标
  659. async editClassifyHandle(data, node) {
  660. //console.log('data',data,'node',node)
  661. const { level, parent } = node;
  662. const parentNodeId = parent.data.ClassifyId;
  663. const { ClassifyName, topParentNodeId, ClassifyId, BaseFromSciIndexId } =
  664. data;
  665. let tempForm = {
  666. parent_classify_name: "",
  667. parent_classify_id: "",
  668. };
  669. let type = "classify";
  670. let classifys_id = [];
  671. //是二级分类(二级,且父节点不是未分类节点)
  672. if (level === 2 && parentNodeId !== 0) {
  673. const { parent } = node;
  674. tempForm.parent_classify_id = data.ParentId;
  675. tempForm.parent_classify_name = parent.data.ClassifyName;
  676. }
  677. //是指标(三级,或二级,父节点为未分类节点)
  678. if (level === 3 || (level === 2 && parentNodeId === 0)) {
  679. type = "index";
  680. this.cascaderKey++; //更新el-cascader
  681. //获取cascaderList数据
  682. const res = await sciDataInterface.classifyNameList();
  683. if (res.Ret !== 200) return;
  684. this.cascaderList = res.Data.List;
  685. //如果指标不在未分类节点下,需回显值
  686. if (parentNodeId) {
  687. classifys_id = [topParentNodeId, parentNodeId];
  688. }
  689. }
  690. this.classifyForm = {
  691. ...{
  692. title: type === "index" ? "编辑指标" : "编辑分类",
  693. classify_name: ClassifyName,
  694. classify_id: ClassifyId,
  695. type,
  696. classifys_id,
  697. BaseFromSciIndexId: BaseFromSciIndexId || "",
  698. },
  699. ...tempForm,
  700. };
  701. this.openDialogHandle();
  702. },
  703. //删除一二级分类
  704. deleteClassifyHandle(data, node) {
  705. const { Children, ClassifyId } = data;
  706. //如果分类下有子分类或指标
  707. let hintText =
  708. Children && Children.length
  709. ? "删除分类将同步删除分类下所有子分类,确认删除吗?"
  710. : "删除分类不可恢复,确定删除吗?";
  711. this.$confirm(hintText, "提示", {
  712. confirmButtonText: "确定",
  713. cancelButtonText: "取消",
  714. type: "warning",
  715. })
  716. .then(() => {
  717. //删除接口
  718. sciDataInterface
  719. .deleteClassifyItem({
  720. ClassifyId,
  721. })
  722. .then((res) => {
  723. if (res.Ret !== 200) return;
  724. this.$message.success("删除成功");
  725. this.getClassify();
  726. });
  727. })
  728. .catch(() => {});
  729. },
  730. //清除指标分类
  731. cleanClassifyHandle(data, node) {
  732. const { BaseFromSciIndexId } = data;
  733. sciDataInterface
  734. .cleanClassify({
  735. BaseFromSciIndexId,
  736. })
  737. .then((res) => {
  738. if (res.Ret !== 200) return;
  739. this.$message.success("清除分类成功");
  740. this.getClassify();
  741. });
  742. },
  743. //删除指标
  744. deleteTarget(data, node) {
  745. const { BaseFromSciIndexId } = data;
  746. this.$confirm("指标删除后不可被引用,确认删除吗?", "提示", {
  747. confirmButtonText: "确定",
  748. cancelButtonText: "取消",
  749. type: "warning",
  750. })
  751. .then(() => {
  752. sciDataInterface
  753. .deleteSCItarget({
  754. BaseFromSciIndexId,
  755. })
  756. .then((res) => {
  757. if (res.Ret !== 200) return;
  758. this.$message.success("删除成功");
  759. this.getClassify();
  760. });
  761. })
  762. .catch(() => {});
  763. },
  764. //打开分类弹窗
  765. openDialogHandle() {
  766. //this.$refs.classifyFormRef.clearValidate();
  767. this.openClassifyDia = true;
  768. },
  769. //关闭分类弹窗
  770. cancelDialogHandle() {
  771. this.$refs.classifyFormRef.clearValidate();
  772. this.openClassifyDia = false;
  773. this.classifyForm.classify_name = "";
  774. this.classifyForm.type = "classify";
  775. },
  776. //保存更改
  777. async saveClassifyHandle() {
  778. const {
  779. type,
  780. title,
  781. classify_name,
  782. classifys_id,
  783. parent_classify_id,
  784. classify_id,
  785. BaseFromSciIndexId,
  786. } = this.classifyForm;
  787. let res = null;
  788. let optionType = title.includes("添加") ? "添加" : "编辑";
  789. //对分类进行操作
  790. if (type === "classify") {
  791. //检查classify_name
  792. if (!classify_name.length) {
  793. this.$message.warning("请输入分类名称");
  794. return;
  795. }
  796. //添加分类
  797. if (title.includes("添加")) {
  798. res = await sciDataInterface.addClassifyItem({
  799. ParentId: parent_classify_id || 0,
  800. ClassifyName: classify_name,
  801. });
  802. //编辑分类
  803. } else {
  804. res = await sciDataInterface.editClassifyItem({
  805. ClassifyId: classify_id,
  806. ClassifyName: classify_name,
  807. });
  808. }
  809. }
  810. //对指标进行操作
  811. if (type === "index") {
  812. //检查classifys_id
  813. if (!classifys_id.length) {
  814. this.$message.warning("请选择分类");
  815. return;
  816. }
  817. //编辑指标(移动指标)
  818. res = await sciDataInterface.editSciTarget({
  819. ClassifyId: classifys_id[1],
  820. BaseFromSciIndexId: BaseFromSciIndexId,
  821. });
  822. }
  823. if (res.Ret !== 200) return;
  824. this.$message.success(`${optionType}成功`);
  825. this.getClassify();
  826. this.cancelDialogHandle();
  827. },
  828. //改变选中节点
  829. nodeChangeHandle(data, node) {
  830. if (data.UniqueCode === this.select_node) return;
  831. const { level, parent } = node;
  832. const parentNodeId = parent.data.ClassifyId;
  833. const Children = data.Children || [];
  834. this.dynamicNode = node;
  835. this.select_node = data.UniqueCode;
  836. this.page_no = 1;
  837. this.page_size = 20;
  838. this.resetNodeStyle(node);
  839. //如果是二级分类 或是一级分类的未分类
  840. if (
  841. (level === 2 && parentNodeId !== 0 && Children.length) ||
  842. (level === 1 && data.ClassifyId === 0 && Children.length)
  843. ) {
  844. this.getClassifyData(data.ClassifyId);
  845. //如果是指标
  846. } else if (level === 3 || (level === 2 && parentNodeId === 0)) {
  847. this.getSCIData(data.BaseFromSciIndexCode);
  848. //如果是一级分类或空的二级指标
  849. } else if (level === 1 || (level === 2 && !Children.length)) {
  850. this.rightShow = false;
  851. this.isShowSingleData = false;
  852. }
  853. },
  854. //获取二级分类的表格数据
  855. async getClassifyData(id) {
  856. this.select_classify = id;
  857. this.select_frequency = "";
  858. await this.getFrequency();
  859. this.getDataList();
  860. },
  861. //获取指标数据
  862. getSCIData(code) {
  863. this.singleDataCode = code;
  864. this.getTargetDataList(code);
  865. },
  866. //判断节点是否能放入
  867. canDropHandle(draggingNode, dropNode, type) {
  868. const { level } = draggingNode;
  869. const dragParentId = draggingNode.data.ParentId;
  870. const dropClassifyId = dropNode.data.ClassifyId;
  871. const dropParentId = dropNode.data.ParentId;
  872. let canDrop = false;
  873. //level===1 一级节点 可以在一级节点之间移动 当dropNode不为未分类时,可以移动
  874. if (
  875. level === 1 &&
  876. dropNode.level === 1 &&
  877. type !== "inner" &&
  878. dropClassifyId !== 0
  879. ) {
  880. canDrop = true;
  881. }
  882. //level===2 二级节点 或 未分类下的指标
  883. if (level === 2) {
  884. //是未分类下的指标
  885. if (dragParentId === 0) {
  886. //在当前目录(未分类)内移动
  887. //移动到其他分类下的二级目录内
  888. if (
  889. (dropNode.level === 2 && dropParentId === 0 && type !== "inner") ||
  890. (dropNode.level === 2 && dropParentId !== 0 && type === "inner") ||
  891. (dropNode.level === 3 && type !== "inner") ||
  892. (dropNode.level === 1 && type === "inner" && dropClassifyId === 0)
  893. ) {
  894. canDrop = true;
  895. }
  896. } else {
  897. //是二级节点
  898. //在目录内移动
  899. //跨目录移动
  900. if (
  901. (dropNode.level === 2 && type !== "inner" && dropParentId !== 0) ||
  902. (dropNode.level === 1 && type === "inner" && dropClassifyId !== 0)
  903. ) {
  904. canDrop = true;
  905. }
  906. }
  907. }
  908. //level===3 指标
  909. if (level === 3) {
  910. if (
  911. (dropNode.level === 2 && type === "inner" && dropParentId !== 0) ||
  912. (dropNode.level === 3 && type !== "inner")
  913. ) {
  914. canDrop = true;
  915. }
  916. }
  917. return canDrop;
  918. },
  919. //拖拽移动节点处理
  920. dropOverHandle(draggingNode, dropNode, type, event) {
  921. const { level, data } = draggingNode;
  922. const parentNodeId = data.ParentId;
  923. //是指标
  924. if (level === 3 || (level === 2 && parentNodeId === 0)) {
  925. this.moveSCITarget(draggingNode, dropNode, type, event);
  926. }
  927. //是目录
  928. if (level === 1 || (level == 2 && parentNodeId !== 0)) {
  929. this.moveCatalog(draggingNode, dropNode, type, event);
  930. }
  931. },
  932. //移动目录
  933. moveCatalog(drag, drop, type, event) {
  934. let PrevClassifyId = 0,
  935. NextClassifyId = 0,
  936. ClassifyId = 0,
  937. ParentId = 0;
  938. const list = drop.parent.childNodes;
  939. ParentId = drop.parent.data.ClassifyId || 0;
  940. ClassifyId = drag.data.ClassifyId;
  941. //目录间移动
  942. if (drag.level === drop.level) {
  943. //console.log(drop.data.ClassifyName)
  944. //找到最后进入的节点处于父节点的哪个位置
  945. const index = list.findIndex((item) => {
  946. return item.data.ClassifyId === drag.data.ClassifyId;
  947. });
  948. //如果在第一个
  949. if (index === 0) {
  950. PrevClassifyId = 0;
  951. NextClassifyId = list[index + 1].data.ClassifyId;
  952. } else if (index === list.length - 1) {
  953. //如果在最后一个
  954. PrevClassifyId = list[index - 1].data.ClassifyId;
  955. NextClassifyId = 0;
  956. } else {
  957. PrevClassifyId = list[index - 1].data.ClassifyId;
  958. NextClassifyId = list[index + 1].data.ClassifyId;
  959. }
  960. //跨目录移动,默认在第一个
  961. } else if (drag.level === 2 && type === "inner") {
  962. ParentId = drop.data.ClassifyId;
  963. PrevClassifyId = 0;
  964. NextClassifyId =
  965. drop.data.Children.length > 1 ? drop.data.Children[0].ClassifyId : 0;
  966. }
  967. //console.log('移动目录')
  968. /* console.log('ClassifyId',ClassifyId,'ParentId',ParentId)
  969. console.log('PrevClassifyId',PrevClassifyId,'NextClassifyId',NextClassifyId) */
  970. sciDataInterface
  971. .moveCatalog({
  972. ClassifyId,
  973. ParentId,
  974. PrevClassifyId,
  975. NextClassifyId,
  976. })
  977. .then((res) => {
  978. if (res.Ret !== 200) return;
  979. this.$message.success("移动成功!");
  980. this.getClassify();
  981. });
  982. },
  983. //移动指标
  984. moveSCITarget(drag, drop, type, event) {
  985. let PrevBaseFromSciIndexId = 0,
  986. NextBaseFromSciIndexId = 0,
  987. ClassifyId = 0,
  988. BaseFromSciIndexId = 0;
  989. BaseFromSciIndexId = drag.data.BaseFromSciIndexId;
  990. const list = drop.parent.childNodes;
  991. ClassifyId = drop.data.ClassifyId;
  992. if (type === "inner") {
  993. PrevBaseFromSciIndexId = 0;
  994. NextBaseFromSciIndexId =
  995. drop.data.Children > 1 ? drop.data.Children[0].BaseFromSciIndexId : 0;
  996. } else {
  997. const index = list.findIndex((item) => {
  998. return item.data.BaseFromSciIndexId === drag.data.BaseFromSciIndexId;
  999. });
  1000. if (index === 0) {
  1001. PrevBaseFromSciIndexId = 0;
  1002. NextBaseFromSciIndexId = list[index + 1].data.BaseFromSciIndexId;
  1003. } else if (index === list.length - 1) {
  1004. PrevBaseFromSciIndexId = list[index - 1].data.BaseFromSciIndexId;
  1005. NextBaseFromSciIndexId = 0;
  1006. } else {
  1007. PrevBaseFromSciIndexId = list[index - 1].data.BaseFromSciIndexId;
  1008. NextBaseFromSciIndexId = list[index + 1].data.BaseFromSciIndexId;
  1009. }
  1010. }
  1011. /* console.log('ClassifyId',ClassifyId,'BaseFromSciIndexId',BaseFromSciIndexId)
  1012. console.log('PrevBaseFromSciIndexId',PrevBaseFromSciIndexId,'NextBaseFromSciIndexId',NextBaseFromSciIndexId)
  1013. console.log('移动指标') */
  1014. sciDataInterface
  1015. .moveSCItarget({
  1016. ClassifyId,
  1017. BaseFromSciIndexId,
  1018. PrevBaseFromSciIndexId,
  1019. NextBaseFromSciIndexId,
  1020. })
  1021. .then((res) => {
  1022. if (res.Ret !== 200) return;
  1023. this.$message.success("移动成功!");
  1024. this.getClassify();
  1025. });
  1026. },
  1027. },
  1028. computed: {
  1029. exportSciapi() {
  1030. // sci数据导出接口
  1031. let urlStr = this.exportBase;
  1032. // token
  1033. urlStr += `?${localStorage.getItem("auth") || ""}`;
  1034. if (this.isShowSingleData) {
  1035. // 指标id
  1036. urlStr += `&IndexCode=${
  1037. this.isShowSingleData ? this.singleDataCode : ""
  1038. }`;
  1039. // 指标名称参数
  1040. urlStr += `&IndexName=${this.select_quota}`;
  1041. /* // 指标id
  1042. urlStr+=`&IndexCode=${this.leftSearchTradeCode}` */
  1043. // 分类名称
  1044. urlStr += `&TypeName=${this.select_breed}`;
  1045. // 频度
  1046. urlStr += `&Frequency=${this.select_frequency}`;
  1047. // 单位
  1048. urlStr += `&UnitName=${this.select_Unit}`;
  1049. // 修改时间
  1050. urlStr += `&ModifyTime=${this.select_ModifyTime}`;
  1051. } else {
  1052. // 目录id
  1053. urlStr += `&ClassifyId=${
  1054. this.isShowSingleData ? "" : this.select_classify
  1055. }`;
  1056. }
  1057. return this.escapeStr(urlStr);
  1058. },
  1059. },
  1060. created() {},
  1061. mounted() {
  1062. this.getClassify();
  1063. },
  1064. };
  1065. </script>
  1066. <style lang="scss">
  1067. @import "../css/customtree.scss";
  1068. .smmTarget-dialog-cont {
  1069. .el-cascader {
  1070. .el-input {
  1071. width: 100% !important;
  1072. }
  1073. }
  1074. }
  1075. </style>
  1076. <style lang="scss" scoped>
  1077. .smmTarget-container {
  1078. display: flex;
  1079. * {
  1080. box-sizing: border-box;
  1081. }
  1082. .minHeight {
  1083. height: calc(100vh - 120px);
  1084. background-color: #fff;
  1085. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.05);
  1086. border-radius: 4px;
  1087. }
  1088. div::-webkit-scrollbar {
  1089. width: 5px !important;
  1090. }
  1091. .left-cont {
  1092. min-width: 300px;
  1093. width: 300px;
  1094. margin-right: 20px;
  1095. padding: 30px 0;
  1096. overflow: hidden;
  1097. position: relative;
  1098. .left-top {
  1099. padding: 0 20px;
  1100. }
  1101. .scroll-wrap {
  1102. padding: 0 10px;
  1103. height: calc(100vh - 280px);
  1104. overflow-y: auto;
  1105. .target_tree {
  1106. color: #333;
  1107. .label-input .el-input__inner {
  1108. height: 25px;
  1109. line-height: 25px;
  1110. }
  1111. .custom-tree-node {
  1112. display: flex !important;
  1113. justify-content: space-between;
  1114. align-items: center;
  1115. display: block;
  1116. flex: 1;
  1117. .node_label {
  1118. margin-right: 2px;
  1119. }
  1120. .el-icon-view {
  1121. color: #409eff;
  1122. font-size: 18px;
  1123. margin-left: 5px;
  1124. }
  1125. }
  1126. }
  1127. .add-cont {
  1128. margin: 50px 0 20px;
  1129. display: flex;
  1130. align-items: center;
  1131. justify-content: center;
  1132. color: #409eff;
  1133. font-size: 16px;
  1134. cursor: pointer;
  1135. }
  1136. }
  1137. .move-btn {
  1138. height: 100%;
  1139. width: 4px;
  1140. position: absolute;
  1141. right: 0px;
  1142. top: 0;
  1143. &:hover {
  1144. cursor: col-resize;
  1145. }
  1146. }
  1147. .classify-list {
  1148. padding: 0 20px;
  1149. /* margin-top: 20px; */
  1150. height: calc(100vh - 280px);
  1151. overflow-y: auto;
  1152. .classify-item {
  1153. font-size: 14px;
  1154. color: #666;
  1155. margin-bottom: 20px;
  1156. &:hover {
  1157. cursor: pointer;
  1158. color: #409eff;
  1159. }
  1160. &.act {
  1161. color: #409eff;
  1162. }
  1163. }
  1164. }
  1165. }
  1166. .right-cont {
  1167. width: 82%;
  1168. padding: 30px;
  1169. .right-box {
  1170. max-width: 100%;
  1171. max-height: calc(100vh - 230px);
  1172. border-left: 1px solid #dcdfe6;
  1173. border-right: 1px solid #dcdfe6;
  1174. overflow: auto;
  1175. .data-header {
  1176. width: 100%;
  1177. position: sticky;
  1178. top: 0;
  1179. z-index: 2;
  1180. }
  1181. .data-cont {
  1182. height: calc(100vh - 444px);
  1183. }
  1184. .nodata {
  1185. height: calc(100vh - 460px);
  1186. border: 1px solid #dcdfe6;
  1187. font-size: 16px;
  1188. color: #999;
  1189. }
  1190. }
  1191. .frequency-list {
  1192. margin-top: 20px;
  1193. display: flex;
  1194. flex-wrap: wrap;
  1195. .frequency-btn {
  1196. width: 112px;
  1197. margin: 0 30px 10px 0;
  1198. }
  1199. }
  1200. .nodata-cont {
  1201. width: 150px !important;
  1202. text-align: center;
  1203. color: #666;
  1204. font-size: 16px;
  1205. margin: 0 auto;
  1206. }
  1207. }
  1208. }
  1209. .dialog-cont {
  1210. padding-left: 50px;
  1211. }
  1212. .dia-bot {
  1213. display: flex;
  1214. justify-content: center;
  1215. }
  1216. </style>