icpiConsumption.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div class="icpc-container coal-similarity-container">
  3. <span
  4. class="slide-btn-icon"
  5. :class="{'slide-left':isLeftWrapShow,'slide-right':!isLeftWrapShow}"
  6. @click="isLeftWrapShow = !isLeftWrapShow"
  7. >
  8. <i :class="{'el-icon-d-arrow-left':isLeftWrapShow,'el-icon-d-arrow-right':!isLeftWrapShow}"></i>
  9. </span>
  10. <div class="left-cont minHeight" v-show="isLeftWrapShow">
  11. <div class="left-top">
  12. <el-button
  13. style="width: 100%;"
  14. type="primary"
  15. plain
  16. size="medium"
  17. @click="exportClick"
  18. :loading="btnload"
  19. >导出Excel</el-button
  20. >
  21. <el-autocomplete
  22. style="margin-top: 20px; width: 100%"
  23. prefix-icon="el-icon-search"
  24. v-model="leftSearchVal"
  25. :fetch-suggestions="handleLeftSearch"
  26. :trigger-on-focus="false"
  27. placeholder="指标名称/指标ID"
  28. @select="handleSelectLeftSearchval"
  29. popper-class="el-autocomplete-suggestion-data-entry"
  30. @clear="clearSearchVal"
  31. clearable
  32. >
  33. <template slot-scope="scope">
  34. <div v-if="scope.item.nodata" style="text-align: center">
  35. 暂无数据
  36. </div>
  37. <div v-else>
  38. {{ scope.item.IndexName }}
  39. </div>
  40. </template>
  41. </el-autocomplete>
  42. </div>
  43. <ul class="classify-list">
  44. <li
  45. :class="['classify-item', { act: select_classify === item.BaseFromIcpiClassifyId }]"
  46. v-for="item in classifyList"
  47. :key="item.BaseFromIcpiClassifyId"
  48. @click="changeClassify(item)"
  49. >
  50. {{ item.ClassifyName }}
  51. </li>
  52. </ul>
  53. </div>
  54. <div
  55. class="right-cont minHeight"
  56. v-loading="dataloading"
  57. element-loading-text="获取数据中..."
  58. >
  59. <div class="right-box" v-if="rightShow" @scroll="scrollHandle">
  60. <template v-if="dateArr.length">
  61. <div class="data-header">
  62. <lz-table
  63. :tableOption="tableOption"
  64. tableType="header"
  65. ref="table"
  66. source="icpi"
  67. />
  68. </div>
  69. <div class="data-cont">
  70. <lz-table
  71. :tableOption="tableOption"
  72. tableType="data"
  73. :dateArr="dateArr"
  74. source="icpi"
  75. />
  76. </div>
  77. </template>
  78. <tableNoData v-else text="暂无数据" class="nodata"></tableNoData>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import lzTable from "@/components/lzTable.vue";
  85. import { lzDataInterface } from "@/api/api.js";
  86. import { icpiInterface } from "@/api/api.js";
  87. export default {
  88. name: "icpiConsumption",
  89. components: { lzTable },
  90. data() {
  91. return {
  92. isLeftWrapShow:true,
  93. dataloading: false,
  94. rightShow: false,
  95. exportBase: process.env.VUE_APP_API_ROOT + "/data_source/icpi/export/icpiDataList", //数据导出接口
  96. select_classify: "",
  97. classifyList: [],
  98. tableOption: [],
  99. dateArr: [], //最长的日期数组
  100. btnload: false,
  101. leftSearchVal: "", //左侧搜索值
  102. pageParams:{
  103. PageSize:20,
  104. CurrentIndex:1,
  105. KeyWord:''
  106. },
  107. havemore:true
  108. };
  109. },
  110. computed: {
  111. exportIcpiApi() {
  112. // 数据导出接口
  113. let urlStr = this.exportBase;
  114. // token
  115. urlStr += `?${localStorage.getItem("auth") || ""}`;
  116. // 分类Id参数
  117. urlStr += `&BaseFromIcpiClassifyId=${this.select_classify}`;
  118. urlStr += `&KeyWord=${this.pageParams.KeyWord}`;
  119. return this.escapeStr(urlStr);
  120. },
  121. },
  122. created() {
  123. this.getClassify();
  124. },
  125. methods: {
  126. /* 获取分类 */
  127. getClassify() {
  128. icpiInterface.classifyList().then((res) => {
  129. if (res.Ret !== 200) return;
  130. this.classifyList = res.Data || [];
  131. this.select_classify =
  132. this.select_classify || this.classifyList[0].BaseFromIcpiClassifyId;
  133. this.getDataList()
  134. });
  135. },
  136. /* 获取数据 */
  137. getDataList() {
  138. this.dataloading = true;
  139. icpiInterface.dataList({
  140. BaseFromIcpiClassifyId: Number(this.select_classify),
  141. PageSize:this.pageParams.PageSize,
  142. CurrentIndex:this.pageParams.CurrentIndex,
  143. KeyWord:this.pageParams.KeyWord
  144. }).then((res) => {
  145. this.rightShow = true;
  146. if (res.Ret !== 200) return;
  147. // 找出最多的页码 判断是否还有数据
  148. let page_arrs = res.Data.map((item) => item.Paging?item.Paging.Pages:0);
  149. let totalPage = Math.max.apply(Math, page_arrs);
  150. this.havemore = this.pageParams.CurrentIndex < totalPage ? true : false;
  151. // 设置表格数据
  152. this.setDataList(res.Data);
  153. this.CurrentIndex === 1 &&
  154. this.$nextTick(() => {
  155. this.initWidth();
  156. });
  157. }).finally(()=>{
  158. this.dataloading = false;
  159. })
  160. },
  161. /* 改变品种 */
  162. changeClassify(item) {
  163. this.select_classify = item.BaseFromIcpiClassifyId;
  164. this.leftSearchVal = ""
  165. this.pageParams.KeyWord=''
  166. this.pageParams.CurrentIndex=1
  167. this.getDataList()
  168. },
  169. initWidth() {
  170. $(".right-box")[0].style.width =
  171. this.$refs.table ? this.$refs.table.$el.clientWidth + 2 + "px":'0';
  172. $(".right-box")[0].scrollTop = 0;
  173. $(".right-box")[0].scrollLeft = 0;
  174. },
  175. // 对[#,;]转义
  176. escapeStr(str) {
  177. return str.replace(/#/g, escape("#")).replace(/;/g, escape(";"));
  178. },
  179. /* 导出 */
  180. exportClick() {
  181. this.btnload = true;
  182. const link = document.createElement("a");
  183. link.href = this.exportIcpiApi;
  184. link.download = "";
  185. link.click();
  186. setTimeout(() => {
  187. this.btnload = false;
  188. }, 2000);
  189. },
  190. //左侧搜索
  191. async handleLeftSearch(query, cb) {
  192. cb([]);
  193. if (!query) return;
  194. const res = await icpiInterface.dataList({
  195. KeyWord: query
  196. });
  197. if (res.Ret === 200) {
  198. let arr = res.Data || [];
  199. if (!arr.length) {
  200. cb([{ nodata: true }]);
  201. } else {
  202. cb(arr);
  203. }
  204. }
  205. },
  206. // 选中左侧搜索值
  207. handleSelectLeftSearchval(e) {
  208. if (!e.BaseFromIcpiIndexId) return;
  209. this.rightShow = false;
  210. this.leftSearchVal = e.IndexName;
  211. this.pageParams.KeyWord=e.IndexName
  212. this.select_classify = e.BaseFromIcpiClassifyId;
  213. this.pageParams.CurrentIndex=1
  214. this.getDataList()
  215. this.$nextTick(() => {
  216. this.rightShow = true;
  217. this.handleScrollLeftWrap();
  218. });
  219. },
  220. clearSearchVal(){
  221. this.pageParams.KeyWord=''
  222. this.getDataList()
  223. },
  224. // 左侧滚动
  225. handleScrollLeftWrap() {
  226. let top = $(".act")[0].offsetTop;
  227. $(".classify-list").animate({
  228. scrollTop: top - 200,
  229. });
  230. },
  231. /* 滚动加载 */
  232. scrollHandle(e) {
  233. const dom = e.target;
  234. let total = dom.scrollTop + dom.clientHeight;
  235. if (total >= dom.scrollHeight && this.havemore) {
  236. this.pageParams.CurrentIndex++;
  237. // console.log("load下一页");
  238. this.getDataList();
  239. }
  240. },
  241. // 设置表格数据
  242. setDataList(data) {
  243. if(this.pageParams.CurrentIndex==1){
  244. this.tableOption = data;
  245. /* 不满7个追加7个空的显示一排 别问 问就是为了美观 */
  246. if (this.tableOption.length < 7){
  247. for (let i = 0; i < 7; i++) {
  248. this.tableOption.push({
  249. DataList: [],
  250. });
  251. if (this.tableOption.length >= 7) break;
  252. }
  253. }
  254. }else{
  255. this.tableOption.forEach((item) => {
  256. data.forEach((_item) => {
  257. if (item.IndexCode === _item.IndexCode) {
  258. item.DataList = item.DataList.concat(_item.DataList);
  259. }
  260. });
  261. });
  262. }
  263. // 合并所有日期
  264. let arr = this.tableOption.map((item) => item.DataList);
  265. let obj = [];
  266. arr.forEach((dataList) => {
  267. obj.push(...dataList.map((item) => item.DataTime));
  268. });
  269. // 日期去重倒序排序
  270. this.dateArr = [...new Set(obj)].sort().reverse();
  271. //数据最大长度小于13个 追加数据满13个 别问 问就是为了美观
  272. if (this.dateArr.length < 13){
  273. for (let i = 0; i < 13; i++) {
  274. this.dateArr.push("");
  275. if (this.dateArr.length >= 13) break;
  276. }
  277. }
  278. },
  279. },
  280. };
  281. </script>
  282. <style lang="scss" scoped>
  283. @import "../css/coalCommon.scss";
  284. </style>