123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260 |
- <template>
- <div class="smmTarget-container" id="box">
- <div class="left-cont minHeight" id="left">
- <div class="left-top">
- <el-button
- v-permission="permissionBtn.dataSourcePermission.smmData_export"
- style="width: 100%"
- type="primary"
- plain
- size="medium"
- @click="exportClick"
- :loading="btnload"
- >导出Excel</el-button
- >
- <el-autocomplete
- style="margin: 20px 0; width: 100%"
- prefix-icon="el-icon-search"
- v-model="leftSearchVal"
- :fetch-suggestions="handleLeftSearch"
- :trigger-on-focus="false"
- placeholder="指标名称/指标ID"
- @select="handleSelectLeftSearchval"
- popper-class="el-autocomplete-suggestion-data-entry"
- clearable
- >
- <template slot-scope="scope">
- <div v-if="scope.item.nodata" style="text-align: center">
- 暂无数据
- </div>
- <div v-else>
- {{ scope.item.IndexName }}
- </div>
- </template>
- </el-autocomplete>
- </div>
- <!-- <ul class="classify-list">
- <li
- :class="[
- 'classify-item',
- { act: select_classify === item.TypeCode },
- ]"
- v-for="item in classifyList"
- :key="item.TypeCode"
- @click="changeClassify(item.TypeCode)"
- >
- {{ item.TypeName }}
- </li>
- </ul> -->
- <div class="scroll-wrap">
- <el-tree
- ref="treeRef"
- class="target_tree custom-tree"
- :data="classifyList"
- node-key="UniqueCode"
- :props="{
- label: 'ClassifyName',
- children: 'Children',
- }"
- draggable
- :current-node-key="select_node"
- :expand-on-click-node="false"
- check-strictly
- empty-text="暂无分类"
- @current-change="nodeChangeHandle"
- :default-expanded-keys="defaultShowNodes"
- @node-expand="handleNodeExpand"
- @node-collapse="handleNodeCollapse"
- :allow-drag="canDragHandle"
- :allow-drop="canDropHandle"
- @node-drop="dropOverHandle"
- >
- <div class="custom-tree-node" slot-scope="{ node, data }">
- <span
- class="text_oneLine"
- :style="`width:${
- (select_node === data.UniqueCode &&
- (node.Nodewidth || data.NodeWidth + 'px')) ||
- ''
- }`"
- >{{ data.ClassifyName }}</span
- >
- <div v-if="select_node === data.UniqueCode">
- <img
- src="~@/assets/img/data_m/move_ico.png"
- v-if="data.Button.MoveButton"
- alt=""
- style="width: 14px; height: 14px; margin-right: 5px"
- @click.stop="clickClassifyHandle('move', data, node)"
- />
- <img
- src="~@/assets/img/set_m/add.png"
- style="width: 14px; height: 14px; margin-right: 5px"
- @click.stop="clickClassifyHandle('add', data, node)"
- v-if="data.Button.AddButton"
- />
- <img
- src="~@/assets/img/set_m/edit.png"
- v-if="data.Button.OpButton"
- alt=""
- style="width: 14px; height: 14px; margin-right: 5px"
- @click.stop="clickClassifyHandle('edit', data, node)"
- />
- <img
- src="~@/assets/img/set_m/clean.png"
- v-if="data.Button.cleanButton"
- alt=""
- style="width: 14px; height: 14px; margin-right: 5px"
- @click.stop="clickClassifyHandle('clean', data, node)"
- />
- <img
- src="~@/assets/img/set_m/del.png"
- v-if="data.Button.DeleteButton"
- alt=""
- style="width: 14px; height: 14px"
- @click.stop="clickClassifyHandle('del', data, node)"
- />
- <img
- src="~@/assets/img/set_m/del_icon.png"
- v-if="data.Button.targetDelButton"
- alt=""
- style="width: 14px; height: 14px; margin-right: 5px"
- @click.stop="clickClassifyHandle('delTarget', data, node)"
- />
- </div>
- </div>
- </el-tree>
- <div class="add-cont" @click="addClassifyHandle">
- <img
- src="~@/assets/img/set_m/add_ico.png"
- alt=""
- style="width: 16px; height: 16px; margin: 10px"
- />
- <span>添加分类</span>
- </div>
- </div>
- <span
- class="move-btn resize"
- v-drag
- id="resize"
- @mousemove="dynamicNode && resetNodeStyle(dynamicNode)"
- >
- </span>
- </div>
- <div
- class="right-cont minHeight"
- id="right"
- v-loading="dataloading"
- element-loading-text="获取数据中..."
- >
- <template v-if="rightShow">
- <div class="right-box" @scroll="scrollHandle">
- <div class="data-header">
- <lz-table
- :tableOption="tableOption"
- tableType="header"
- ref="table"
- source="smm"
- />
- </div>
- <div class="data-cont" v-if="dateArr.length">
- <lz-table
- :tableOption="tableOption"
- tableType="data"
- :dateArr="dateArr"
- source="smm"
- />
- </div>
- <div v-else class="nodata"></div>
- </div>
- <div class="frequency-list" v-if="rightShow && !isShowSingleData">
- <el-button
- type="primary"
- class="frequency-btn"
- :plain="select_frequency !== item.key"
- v-for="item in frequencyList"
- :key="item.key"
- @click="changeFrequency(item.key)"
- >{{ item.key }}</el-button
- >
- </div>
- </template>
- <div v-else class="nodata-cont">
- <tableNoData text="暂无数据"/>
- </div>
- </div>
- <!-- 添加/编辑分类弹窗 -->
- <m-dialog
- :show.sync="openClassifyDia"
- width="700px"
- :title="classifyForm.title"
- @close="cancelDialogHandle"
- >
- <div class="dialog-cont smmTarget-dialog-cont">
- <el-form
- ref="classifyFormRef"
- label-position="left"
- hide-required-asterisk
- label-width="80px"
- :model="classifyForm"
- :rules="classifyFormRules"
- >
- <el-form-item
- label="一级目录"
- v-if="classifyForm.parent_classify_name"
- >
- <span>{{ classifyForm.parent_classify_name }}</span>
- </el-form-item>
- <el-form-item
- label="分类名称"
- prop="classify_name"
- v-if="classifyForm.type === 'classify'"
- >
- <el-input
- v-model="classifyForm.classify_name"
- style="width: 80%"
- placeholder="请输入分类名称"
- />
- </el-form-item>
- <el-form-item label="分类名称" prop="classifys_id" v-else>
- <el-cascader
- style="width: 80%"
- :key="cascaderKey"
- placeholder="请选择分类名称"
- v-model="classifyForm.classifys_id"
- :options="cascaderList"
- :props="{
- value: 'ClassifyId',
- label: 'ClassifyName',
- children: 'Children',
- }"
- />
- </el-form-item>
- </el-form>
- </div>
- <div class="dia-bot">
- <el-button
- type="primary"
- style="margin-right: 20px"
- @click="saveClassifyHandle"
- >保存</el-button
- >
- <el-button type="primary" plain @click="cancelDialogHandle"
- >取消</el-button
- >
- </div>
- </m-dialog>
- </div>
- </template>
- <script>
- import lzTable from "@/components/lzTable.vue";
- import { smmDataInterface } from "@/api/api.js";
- import mDialog from "@/components/mDialog.vue";
- import leftMixin from "./mixins/leftMixin.js";
- export default {
- name: "",
- components: { lzTable, mDialog },
- mixins: [leftMixin],
- watch: {},
- data() {
- return {
- exportBase: process.env.VUE_APP_API_ROOT + "/datamanage/export/smmList", //ssm数据导出接口
- dataloading: false,
- rightShow: false,
- select_classify: "",
- classifyList: [],
- select_frequency: "",
- frequencyList: [],
- tableOption: [],
- dateArr: [], //最长的日期数组
- btnload: false,
- page_no: 1,
- page_size: 20,
- havemore: true, //是否还有数据
- leftSearchVal: "", //左侧搜索值
- leftSearchTradeCode: "", //如果是搜索选择的 则有此code
- select_quota: "", // 选择的指标名
- select_Unit: "", // 选择的单位
- select_ModifyTime: "", //选中的更新时间
- select_breed: "", // 选中的分类名称
- isShowSingleData: false, //右侧是否展示的是单个指标数据
- singleDataCode: "",
- cascaderList: [], //移动指标分类列表
- cascaderKey: 0,
- openClassifyDia: false, //分类弹窗
- classifyForm: {
- title: "添加分类",
- classify_name: "", //分类名称
- classify_id: "", //分类id
- parent_classify_name: "", //如果是二级分类,这是所属一级分类的名称
- parent_classify_id: "", //如果是二级分类,这是所属一级分类的id
- type: "classify", //classify|index 对分类还是指标进行操作
- classifys_id: [], //如果是指标,这是选中的分类id[一级分类id,二级分类id]
- BaseFromSmmIndexId: "", //如果是指标,这是指标的唯一id
- }, //弹窗可编辑信息
- classifyFormRules: {
- classify_name: [
- { required: true, message: "分类名称不能为空", trigger: "blur" },
- ],
- }, //可编辑信息校验
- };
- },
- methods: {
- /* 获取分类 */
- getClassify() {
- smmDataInterface.classifyList().then((res) => {
- if (res.Ret !== 200) return;
- let Data = res.Data.List || [];
- //对分类数据做处理:
- this.classifyList = this.formatClassifyData(Data, 1, 0);
- });
- },
- formatClassifyData(arr, level, topParentNodeId) {
- arr.forEach((item) => {
- const { ClassifyId, BaseFromSmmIndexId, BaseFromSmmIndexCode } = item;
- //每条数据添加UniqueCode属性,由ClassifyId BaseFromSmmIndexId BaseFromSmmIndexCode拼接
- item.UniqueCode = `${ClassifyId}_${BaseFromSmmIndexId}_${BaseFromSmmIndexCode}`;
- //添加Button属性,用于控制操作栏
- item.Button = {
- AddButton: true,
- OpButton: true,
- DeleteButton: true,
- MoveButton: true,
- cleanButton: false,
- targetDelButton: false,
- };
- //未分类禁用所有操作栏
- if (item.ClassifyId === 0) {
- item.Button = {
- AddButton: false,
- OpButton: false,
- DeleteButton: false,
- MoveButton: false,
- cleanButton: false,
- targetDelButton: false,
- };
- }
- //二级分类禁用添加按钮
- if (item.Level === 2) {
- item.Button = {
- AddButton: false,
- OpButton: true,
- DeleteButton: true,
- MoveButton: true,
- cleanButton: false,
- targetDelButton: false,
- };
- }
- //指标禁用删除按钮
- if (item.BaseFromSmmIndexCode) {
- item.Button = {
- AddButton: false,
- OpButton: true,
- DeleteButton: false,
- MoveButton: true,
- cleanButton: true,
- targetDelButton: true,
- };
- //未分类下的指标,禁用清除按钮
- if (topParentNodeId === 0) {
- item.Button["cleanButton"] = false;
- }
- }
- //非一级分类添加一级父节点id
- if (level !== 1) {
- item.topParentNodeId = topParentNodeId;
- }
- if (item.Children && item.Children.length) {
- this.formatClassifyData(
- item.Children,
- level + 1,
- level === 1 ? item.ClassifyId : item.ParentId
- );
- }
- });
- return arr;
- },
- /* 获取频度 */
- async getFrequency(defaultSelect) {
- const res = await smmDataInterface.frequencyList({
- ClassifyId: this.select_classify,
- });
- if (res.Ret !== 200) return;
- this.frequencyList = res.Data
- ? res.Data.map((item) => {
- return {
- key: item.Frequency,
- };
- })
- : [];
- //设置当前选中的频度,若传入有默认选项则选中默认频度,否则选中列表第一个
- this.select_frequency =
- defaultSelect ||
- (this.frequencyList.length ? this.frequencyList[0].key : "");
- !this.frequencyList.length && this.nodataDeal();
- },
- /* 获取数据 */
- getDataList: _.throttle(function () {
- this.isShowSingleData = false;
- this.dataloading = true;
- smmDataInterface
- .dataList({
- ClassifyId: this.select_classify,
- Frequency: this.select_frequency,
- PageSize: this.page_size,
- CurrentIndex: this.page_no,
- })
- .then((res) => {
- this.rightShow = true;
- if (res.Ret !== 200) return;
- // 找出最多的页码 判断是否还有数据
- let page_arrs = res.Data.map((item) => item.Paging.Pages);
- let totalPage = Math.max.apply(Math, page_arrs);
- this.havemore = this.page_no < totalPage ? true : false;
- // 合并数据
- if (this.page_no === 1) {
- this.tableOption = res.Data;
- } else {
- this.tableOption.forEach((item) => {
- res.Data.forEach((_item) => {
- if (item.IndexCode === _item.IndexCode) {
- item.DataList = item.DataList.concat(_item.DataList);
- }
- });
- });
- }
- // 合并所有指标中的日期 作为日期数组
- let arr = res.Data.map((item) => {
- return item.DataList;
- });
- let obj = [];
- for (let i of arr) {
- for (let j of i) {
- obj.push(j.DataTime);
- }
- }
- let arr2 = [...new Set(obj)].sort().reverse();
- let concatArr = [...new Set([...this.dateArr, ...arr2])]
- .sort()
- .reverse();
- this.dateArr = this.page_no === 1 ? arr2 : concatArr;
- /* 不满6个追加6个空的显示一排 别问 问就是为了美观 */
- if (this.tableOption.length < 7)
- for (let i = 0; i < 7; i++) {
- this.tableOption.push({
- DataList: [],
- });
- if (this.tableOption.length >= 7) break;
- }
- //数据最大长度小于12个 追加数据满12个 别问 问就是为了美观
- if (this.dateArr.length < 12)
- for (let i = 0; i < 12; i++) {
- this.dateArr.push("");
- if (this.dateArr.length >= 12) break;
- }
- this.dataloading = false;
- this.page_no === 1 &&
- this.$nextTick(() => {
- this.rightShow && this.initWidth();
- });
- });
- }, 200),
- // 获取单个指标数据
- async getTargetDataList(code) {
- this.isShowSingleData = true;
- this.dataloading = true;
- try {
- const res = await smmDataInterface.getTargetDataList({
- IndexCode: code,
- });
- this.rightShow = true;
- if (res.Ret !== 200) return;
- const DataList = res.Data.Data || [];
- // 设置为没有更多数据
- this.haveMore = false;
- // 合并数据
- this.tableOption = [
- {
- DataList: DataList,
- ...res.Data,
- },
- ];
- // 这里是单个指标所以不用合并日期
- const arr = DataList.map((item) => item.DataTime);
- this.dateArr = [...new Set(arr)].sort().reverse();
- /* 不满6个追加6个空的显示一排 别问 问就是为了美观 */
- for (let i = 0; i < 7; i++) {
- this.tableOption.push({
- DataList: [],
- });
- if (this.tableOption.length >= 7) break;
- }
- //数据最大长度小于12个 追加数据满12个 别问 问就是为了美观
- if (this.dateArr.length < 12)
- for (let i = 0; i < 12; i++) {
- this.dateArr.push("");
- if (this.dateArr.length >= 12) break;
- }
- this.select_quota = res.Data.IndexName;
- this.select_Unit = res.Data.Unit;
- this.select_ModifyTime = res.Data.ModifyTime || "";
- this.dataloading = false;
- this.rightShow && this.initWidth();
- } catch (err) {
- console.log(err);
- }
- },
- /* 改变品种 */
- changeClassify(id) {
- this.select_classify = id;
- this.select_breed = id;
- this.leftSearchVal = "";
- this.leftSearchTradeCode = "";
- this.select_Unit = "";
- this.select_ModifyTime = "";
- },
- /* 改变频度 */
- changeFrequency(key) {
- this.select_frequency = key;
- this.leftSearchVal = "";
- this.getDataList();
- },
- initWidth() {
- this.$nextTick(() => {
- $(".right-box")[0].style.width =
- this.$refs.table.$el.clientWidth + 5 + "px";
- $(".right-box")[0].scrollTop = 0;
- $(".right-box")[0].scrollLeft = 0;
- });
- },
- /* 无频度的异常显示处理 7*12*/
- nodataDeal() {
- this.tableOption = [];
- this.dateArr = [];
- for (let i = 0; i < 7; i++) {
- this.tableOption.push({
- DataList: [],
- });
- if (this.tableOption.length >= 7) break;
- }
- for (let i = 0; i < 12; i++) {
- this.dateArr.push("");
- if (this.dateArr.length >= 12) break;
- }
- },
- /* 滚动加载 */
- scrollHandle(e) {
- if (this.isShowSingleData) return;
- const dom = e.target;
- let total = dom.scrollTop + dom.clientHeight;
- if (total >= dom.scrollHeight && this.havemore) {
- this.page_no++;
- console.log("load下一页");
- this.getDataList();
- }
- },
- /* 数据导出 */
- exportClick() {
- this.btnload = true;
- const link = document.createElement("a");
- link.href = this.exportSmmapi;
- link.download = "";
- link.click();
- console.log({
- IndexName: this.select_quota,
- IndexCode: this.leftSearchTradeCode,
- sendIndexCode: this.escapeStr(this.leftSearchTradeCode),
- TypeName: this.select_breed,
- sendTypeName: this.escapeStr(this.select_breed),
- Frequency: this.select_frequency,
- UnitName: this.select_Unit,
- ModifyTime: this.select_ModifyTime,
- sendToken: this.escapeStr(localStorage.getItem("auth") || ""),
- url: this.exportSmmapi,
- });
- setTimeout(() => {
- this.btnload = false;
- }, 5000);
- },
- //左侧搜索
- async handleLeftSearch(query, cb) {
- cb([]);
- if (!query) return;
- const res = await smmDataInterface.getTargetListByName({
- Keyword: query,
- });
- if (res.Ret === 200) {
- let arr = res.Data || [];
- if (!arr.length) {
- cb([{ nodata: true }]);
- } else {
- cb(arr);
- }
- }
- },
- // 选中左侧搜索值
- handleSelectLeftSearchval(e) {
- if (!e.IndexCode) return;
- //this.select_frequency=e.Frequency
- //this.select_classify=e.Type2+'#'+e.Type3
- this.leftSearchTradeCode = e.IndexCode;
- this.leftSearchVal = e.IndexName;
- this.select_quota = e.IndexName;
- this.select_Unit = e.Unit;
- this.select_ModifyTime = e.ModifyTime;
- this.select_breed = "";
- // 关闭watcher
- this.isAuto = false;
- // 获取单独指标数据
- this.getTargetDataList(e.IndexCode);
- this.$nextTick(() => {
- //找到父节点并展开
- const targetData = this.getTargetData(e.IndexCode, this.classifyList);
- if (targetData) {
- //一级节点
- const { topParentNodeId, UniqueCode } = targetData;
- this.handleNodeExpand({ UniqueCode: `${topParentNodeId}_0_` });
- //二级节点
- if (topParentNodeId !== 0) {
- const secondNodeId = UniqueCode.split("_")[0];
- this.handleNodeExpand({ UniqueCode: `${secondNodeId}_0_` });
- }
- //节点样式变化
- const tree = $(".target_tree")[0];
- let width = tree.offsetWidth;
- let label_width =
- width > 500 ? "auto" : width <= 500 ? 90 : 0.7 * width;
- targetData.NodeWidth = label_width;
- this.select_node = UniqueCode;
- this.$refs.treeRef.setCurrentNode(targetData);
- const node = this.$refs.treeRef.getCurrentNode();
- this.resetNodeStyle(node);
- }
- //this.handleScrollLeftWrap()
- });
- },
- // 左侧滚动
- handleScrollLeftWrap() {
- let top = $(".act")[0].offsetTop;
- $(".classify-list").animate({
- scrollTop: top - 200,
- });
- },
- getTargetData(code, arr) {
- for (const item of arr) {
- if (item.BaseFromSmmIndexCode === code) return item;
- if (item.Children && item.Children.length) {
- const _item = this.getTargetData(code, item.Children);
- if (_item) return _item;
- }
- }
- },
- // 对[#,;]转义
- escapeStr(str) {
- return str.replace(/#/g, escape("#")).replace(/;/g, escape(";"));
- },
- //节点操作:
- clickClassifyHandle(type, data, node) {
- const optionMap = {
- /* 'move':this.moveNode,移动 */
- add: this.addClassifyHandle, //添加分类
- edit: this.editClassifyHandle, //编辑分类/移动指标
- del: this.deleteClassifyHandle, //删除分类
- clean: this.cleanClassifyHandle, //清除指标分类
- delTarget: this.deleteTarget, //删除指标
- };
- optionMap[type] && optionMap[type](data, node);
- },
- //添加一二级分类
- addClassifyHandle(data = null, node = null) {
- this.classifyForm = {
- ...this.classifyForm,
- ...(data
- ? {
- title: "添加分类",
- classify_name: "",
- parent_classify_name: data.ClassifyName,
- parent_classify_id: data.ClassifyId,
- }
- : {
- title: "添加分类",
- classify_name: "",
- }),
- };
- this.openDialogHandle();
- },
- //编辑一二级分类,编辑指标
- async editClassifyHandle(data, node) {
- //console.log('data',data,'node',node)
- const { level, parent } = node;
- const parentNodeId = parent.data.ClassifyId;
- const { ClassifyName, topParentNodeId, ClassifyId, BaseFromSmmIndexId } =
- data;
- let tempForm = {
- parent_classify_name: "",
- parent_classify_id: "",
- };
- let type = "classify";
- let classifys_id = [];
- //是二级分类(二级,且父节点不是未分类节点)
- if (level === 2 && parentNodeId !== 0) {
- const { parent } = node;
- tempForm.parent_classify_id = data.ParentId;
- tempForm.parent_classify_name = parent.data.ClassifyName;
- }
- //是指标(三级,或二级,父节点为未分类节点)
- if (level === 3 || (level === 2 && parentNodeId === 0)) {
- type = "index";
- this.cascaderKey++; //更新el-cascader
- //获取cascaderList数据
- const res = await smmDataInterface.classifyNameList();
- if (res.Ret !== 200) return;
- this.cascaderList = res.Data.List;
- //如果指标不在未分类节点下,需回显值
- if (parentNodeId) {
- classifys_id = [topParentNodeId, parentNodeId];
- }
- }
- this.classifyForm = {
- ...{
- title: type === "index" ? "编辑指标" : "编辑分类",
- classify_name: ClassifyName,
- classify_id: ClassifyId,
- type,
- classifys_id,
- BaseFromSmmIndexId: BaseFromSmmIndexId || "",
- },
- ...tempForm,
- };
- this.openDialogHandle();
- },
- //删除一二级分类
- deleteClassifyHandle(data, node) {
- const { Children, ClassifyId } = data;
- //如果分类下有子分类或指标
- let hintText =
- Children && Children.length
- ? "删除分类将同步删除分类下所有子分类,确认删除吗?"
- : "删除分类不可恢复,确定删除吗?";
- this.$confirm(hintText, "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- //删除接口
- smmDataInterface
- .deleteClassifyItem({
- ClassifyId,
- })
- .then((res) => {
- if (res.Ret !== 200) return;
- this.$message.success("删除成功");
- this.getClassify();
- });
- })
- .catch(() => {});
- },
- //清除指标分类
- cleanClassifyHandle(data, node) {
- const { BaseFromSmmIndexId } = data;
- smmDataInterface
- .cleanClassify({
- BaseFromSmmIndexId,
- })
- .then((res) => {
- if (res.Ret !== 200) return;
- this.$message.success("清除分类成功");
- this.getClassify();
- });
- },
- //删除指标
- deleteTarget(data, node) {
- const { BaseFromSmmIndexId } = data;
- this.$confirm("指标删除后不可被引用,确认删除吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- smmDataInterface
- .deleteSMMtarget({
- BaseFromSmmIndexId,
- })
- .then((res) => {
- if (res.Ret !== 200) return;
- this.$message.success("删除成功");
- this.getClassify();
- });
- //删除指标接口
- })
- .catch(() => {});
- },
- //打开分类弹窗
- openDialogHandle() {
- //this.$refs.classifyFormRef.clearValidate();
- this.openClassifyDia = true;
- },
- //关闭分类弹窗
- cancelDialogHandle() {
- this.$refs.classifyFormRef.clearValidate();
- this.openClassifyDia = false;
- this.classifyForm.classify_name = "";
- this.classifyForm.type = "classify";
- },
- //保存更改
- async saveClassifyHandle() {
- const {
- type,
- title,
- classify_name,
- classifys_id,
- parent_classify_id,
- classify_id,
- BaseFromSmmIndexId,
- } = this.classifyForm;
- let res = null;
- let optionType = title.includes("添加") ? "添加" : "编辑";
- //对分类进行操作
- if (type === "classify") {
- //检查classify_name
- if (!classify_name.length) {
- this.$message.warning("请输入分类名称");
- return;
- }
- //添加分类
- if (title.includes("添加")) {
- res = await smmDataInterface.addClassifyItem({
- ParentId: parent_classify_id || 0,
- ClassifyName: classify_name,
- });
- //编辑分类
- } else {
- res = await smmDataInterface.editClassifyItem({
- ClassifyId: classify_id,
- ClassifyName: classify_name,
- });
- }
- }
- //对指标进行操作
- if (type === "index") {
- //检查classifys_id
- if (!classifys_id.length) {
- this.$message.warning("请选择分类");
- return;
- }
- //编辑指标(移动指标)
- res = await smmDataInterface.editSmmTarget({
- ClassifyId: classifys_id[1],
- BaseFromSmmIndexId: BaseFromSmmIndexId,
- });
- }
- if (res.Ret !== 200) return;
- this.$message.success(`${optionType}成功`);
- this.getClassify();
- this.cancelDialogHandle();
- },
- //改变选中节点
- nodeChangeHandle(data, node) {
- if (data.UniqueCode === this.select_node) return;
- const { level, parent } = node;
- const parentNodeId = parent.data.ClassifyId;
- const Children = data.Children || [];
- this.dynamicNode = node;
- this.select_node = data.UniqueCode;
- this.page_no = 1;
- this.page_size = 20;
- this.resetNodeStyle(node);
- //如果是二级分类 或是一级分类的未分类
- if (
- (level === 2 && parentNodeId !== 0 && Children.length) ||
- (level === 1 && data.ClassifyId === 0 && Children.length)
- ) {
- this.getClassifyData(data.ClassifyId);
- //如果是指标
- } else if (level === 3 || (level === 2 && parentNodeId === 0)) {
- this.getSmmData(data.BaseFromSmmIndexCode);
- //如果是一级分类或空的二级指标
- } else if (level === 1 || (level === 2 && !Children.length)) {
- this.rightShow = false;
- this.isShowSingleData = false;
- }
- },
- //获取二级分类的表格数据
- async getClassifyData(id) {
- this.select_classify = id;
- this.select_frequency = "";
- await this.getFrequency();
- this.getDataList();
- },
- //获取指标数据
- getSmmData(code) {
- this.singleDataCode = code;
- this.getTargetDataList(code);
- },
- //判断节点是否能放入
- canDropHandle(draggingNode, dropNode, type) {
- //console.log('drag',draggingNode)
- //console.log('drop',dropNode)
- const { level } = draggingNode;
- const dragParentId = draggingNode.data.ParentId;
- const dropClassifyId = dropNode.data.ClassifyId;
- const dropParentId = dropNode.data.ParentId;
- let canDrop = false;
- //level===1 一级节点 可以在一级节点之间移动 当dropNode不为未分类时,可以移动
- if (
- level === 1 &&
- dropNode.level === 1 &&
- type !== "inner" &&
- dropClassifyId !== 0
- ) {
- canDrop = true;
- }
- //level===2 二级节点 或 未分类下的指标
- if (level === 2) {
- //是未分类下的指标
- if (dragParentId === 0) {
- //在当前目录(未分类)内移动
- //移动到其他分类下的二级目录内
- if (
- (dropNode.level === 2 && dropParentId === 0 && type !== "inner") ||
- (dropNode.level === 2 && dropParentId !== 0 && type === "inner") ||
- (dropNode.level === 3 && type !== "inner") ||
- (dropNode.level === 1 && type === "inner" && dropClassifyId === 0)
- ) {
- canDrop = true;
- }
- } else {
- //是二级节点
- //在目录内移动
- //跨目录移动
- if (
- (dropNode.level === 2 && type !== "inner" && dropParentId !== 0) ||
- (dropNode.level === 1 && type === "inner" && dropClassifyId !== 0)
- ) {
- canDrop = true;
- }
- }
- }
- //level===3 指标
- if (level === 3) {
- if (
- (dropNode.level === 2 && type === "inner" && dropParentId !== 0) ||
- (dropNode.level === 3 && type !== "inner")
- ) {
- canDrop = true;
- }
- }
- return canDrop;
- },
- //拖拽移动节点处理
- dropOverHandle(draggingNode, dropNode, type, event) {
- const { level, data } = draggingNode;
- const parentNodeId = data.ParentId;
- //是指标
- if (level === 3 || (level === 2 && parentNodeId === 0)) {
- this.moveSMMTarge(draggingNode, dropNode, type, event);
- }
- //是目录
- if (level === 1 || (level == 2 && parentNodeId !== 0)) {
- this.moveCatalog(draggingNode, dropNode, type, event);
- }
- },
- //移动目录
- moveCatalog(drag, drop, type, event) {
- let PrevClassifyId = 0,
- NextClassifyId = 0,
- ClassifyId = 0,
- ParentId = 0;
- const list = drop.parent.childNodes;
- ParentId = drop.parent.data.ClassifyId || 0;
- ClassifyId = drag.data.ClassifyId;
- //目录间移动
- if (drag.level === drop.level) {
- //console.log(drop.data.ClassifyName)
- //找到最后进入的节点处于父节点的哪个位置
- const index = list.findIndex((item) => {
- return item.data.ClassifyId === drag.data.ClassifyId;
- });
- //如果在第一个
- if (index === 0) {
- PrevClassifyId = 0;
- NextClassifyId = list[index + 1].data.ClassifyId;
- } else if (index === list.length - 1) {
- //如果在最后一个
- PrevClassifyId = list[index - 1].data.ClassifyId;
- NextClassifyId = 0;
- } else {
- PrevClassifyId = list[index - 1].data.ClassifyId;
- NextClassifyId = list[index + 1].data.ClassifyId;
- }
- //跨目录移动,默认在第一个
- } else if (drag.level === 2 && type === "inner") {
- ParentId = drop.data.ClassifyId;
- PrevClassifyId = 0;
- NextClassifyId =
- drop.data.Children.length > 1 ? drop.data.Children[0].ClassifyId : 0;
- }
- //console.log('移动目录')
- /* console.log('ClassifyId',ClassifyId,'ParentId',ParentId)
- console.log('PrevClassifyId',PrevClassifyId,'NextClassifyId',NextClassifyId) */
- smmDataInterface
- .moveCatalog({
- ClassifyId,
- ParentId,
- PrevClassifyId,
- NextClassifyId,
- })
- .then((res) => {
- if (res.Ret !== 200) return;
- this.$message.success("移动成功!");
- this.getClassify();
- });
- },
- //移动指标
- moveSMMTarge(drag, drop, type, event) {
- let PrevBaseFromSmmIndexId = 0,
- NextBaseFromSmmIndexId = 0,
- ClassifyId = 0,
- BaseFromSmmIndexId = 0;
- BaseFromSmmIndexId = drag.data.BaseFromSmmIndexId;
- const list = drop.parent.childNodes;
- ClassifyId = drop.data.ClassifyId;
- if (type === "inner") {
- PrevBaseFromSmmIndexId = 0;
- NextBaseFromSmmIndexId =
- drop.data.Children > 1 ? drop.data.Children[0].BaseFromSmmIndexId : 0;
- } else {
- const index = list.findIndex((item) => {
- return item.data.BaseFromSmmIndexId === drag.data.BaseFromSmmIndexId;
- });
- if (index === 0) {
- PrevBaseFromSmmIndexId = 0;
- NextBaseFromSmmIndexId = list[index + 1].data.BaseFromSmmIndexId;
- } else if (index === list.length - 1) {
- PrevBaseFromSmmIndexId = list[index - 1].data.BaseFromSmmIndexId;
- NextBaseFromSmmIndexId = 0;
- } else {
- PrevBaseFromSmmIndexId = list[index - 1].data.BaseFromSmmIndexId;
- NextBaseFromSmmIndexId = list[index + 1].data.BaseFromSmmIndexId;
- }
- }
- /* console.log('ClassifyId',ClassifyId,'BaseFromSmmIndexId',BaseFromSmmIndexId)
- console.log('PrevBaseFromSmmIndexId',PrevBaseFromSmmIndexId,'NextBaseFromSmmIndexId',NextBaseFromSmmIndexId)
- console.log('移动指标') */
- smmDataInterface
- .moveSMMtarget({
- ClassifyId,
- BaseFromSmmIndexId,
- PrevBaseFromSmmIndexId,
- NextBaseFromSmmIndexId,
- })
- .then((res) => {
- if (res.Ret !== 200) return;
- this.$message.success("移动成功!");
- this.getClassify();
- });
- },
- },
- computed: {
- exportSmmapi() {
- // smm数据导出接口
- let urlStr = this.exportBase;
- // token
- urlStr += `?${localStorage.getItem("auth") || ""}`;
- if (this.isShowSingleData) {
- // 指标id
- urlStr += `&IndexCode=${
- this.isShowSingleData ? this.singleDataCode : ""
- }`;
- // 指标名称参数
- urlStr += `&IndexName=${this.select_quota}`;
- /* // 指标id
- urlStr+=`&IndexCode=${this.leftSearchTradeCode}` */
- // 分类名称
- urlStr += `&TypeName=${this.select_breed}`;
- // 频度
- urlStr += `&Frequency=${this.select_frequency}`;
- // 单位
- urlStr += `&UnitName=${this.select_Unit}`;
- // 修改时间
- urlStr += `&ModifyTime=${this.select_ModifyTime}`;
- } else {
- // 目录id
- urlStr += `&ClassifyId=${
- this.isShowSingleData ? "" : this.select_classify
- }`;
- }
- return this.escapeStr(urlStr);
- },
- },
- created() {},
- mounted() {
- this.getClassify();
- },
- };
- </script>
- <style lang="scss">
- @import "../css/customtree.scss";
- .smmTarget-dialog-cont {
- .el-cascader {
- .el-input {
- width: 100% !important;
- }
- }
- }
- </style>
- <style lang="scss" scoped>
- .smmTarget-container {
- display: flex;
- * {
- box-sizing: border-box;
- }
- .minHeight {
- height: calc(100vh - 120px);
- background-color: #fff;
- box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.05);
- border-radius: 4px;
- }
- div::-webkit-scrollbar {
- width: 5px !important;
- }
- .left-cont {
- min-width: 300px;
- width: 300px;
- margin-right: 20px;
- padding: 30px 0;
- overflow: hidden;
- position: relative;
- .left-top {
- padding: 0 20px;
- }
- .scroll-wrap {
- padding: 0 10px;
- height: calc(100vh - 280px);
- overflow-y: auto;
- .target_tree {
- color: #333;
- .label-input .el-input__inner {
- height: 25px;
- line-height: 25px;
- }
- .custom-tree-node {
- display: flex !important;
- justify-content: space-between;
- align-items: center;
- display: block;
- flex: 1;
- .node_label {
- margin-right: 2px;
- }
- .el-icon-view {
- color: #409eff;
- font-size: 18px;
- margin-left: 5px;
- }
- }
- }
- .add-cont {
- margin: 50px 0 20px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #409eff;
- font-size: 16px;
- cursor: pointer;
- }
- }
- .move-btn {
- height: 100%;
- width: 4px;
- position: absolute;
- right: 0px;
- top: 0;
- &:hover {
- cursor: col-resize;
- }
- }
- .classify-list {
- padding: 0 20px;
- /* margin-top: 20px; */
- height: calc(100vh - 280px);
- overflow-y: auto;
- .classify-item {
- font-size: 14px;
- color: #666;
- margin-bottom: 20px;
- &:hover {
- cursor: pointer;
- color: #409eff;
- }
- &.act {
- color: #409eff;
- }
- }
- }
- }
- .right-cont {
- width: 82%;
- padding: 30px;
- .right-box {
- max-width: 100%;
- max-height: calc(100vh - 230px);
- border-left: 1px solid #dcdfe6;
- border-right: 1px solid #dcdfe6;
- overflow: auto;
- .data-header {
- width: 100%;
- position: sticky;
- top: 0;
- z-index: 2;
- }
- .data-cont {
- height: calc(100vh - 444px);
- }
- .nodata {
- height: calc(100vh - 460px);
- border: 1px solid #dcdfe6;
- font-size: 16px;
- color: #999;
- }
- }
- .frequency-list {
- margin-top: 20px;
- display: flex;
- flex-wrap: wrap;
- .frequency-btn {
- width: 112px;
- margin: 0 30px 10px 0;
- }
- }
- .nodata-cont {
- width: 150px !important;
- text-align: center;
- color: #666;
- font-size: 16px;
- margin: 0 auto;
- }
- }
- }
- .dialog-cont {
- padding-left: 50px;
- }
- .dia-bot {
- display: flex;
- justify-content: center;
- }
- </style>
|