adjustData.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <template>
  2. <div class="adjust-data-container">
  3. <div class="wrap-top">
  4. <div>
  5. <ul class="min-top" v-if="!edb_id">
  6. <li>
  7. <label style="margin-right:5px;">选择指标:</label>
  8. <el-select
  9. v-model="select_target"
  10. v-loadMore="searchLoad"
  11. :filterable="!select_target"
  12. clearable
  13. placeholder="请输入指标名称"
  14. style="width: 200px"
  15. remote
  16. :remote-method="getTarget"
  17. @click.native="inputFocusHandle"
  18. @change="chooseTarget"
  19. @blur="search_have_more = false"
  20. >
  21. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  22. <el-option
  23. v-for="item in searchOptions"
  24. :key="item.EdbInfoId"
  25. :label="eta_lang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName"
  26. :value="item.EdbInfoId"
  27. >
  28. </el-option>
  29. </el-select>
  30. <i class="el-icon-tickets" style="color:#409EFF;font-size:18px" @click="isLookHistory=true;lookEdbId=select_target" v-if="select_target"/>
  31. </li>
  32. <li v-show="old_edb_info.id">
  33. <label style="margin-right:5px;"> 查询结果:</label>
  34. <span style="margin-right: 20px">指标ID:{{old_edb_info.id}}</span>
  35. <span>指标名称:{{old_edb_info.name}}</span>
  36. </li>
  37. </ul>
  38. <div v-if="edb_id" style="margin-bottom:20px">
  39. <span style="display:inline-block;margin-right:30px">原指标ID:{{EDBInfoOfCalculateData.FromEdbCode}}</span>
  40. <span>原指标名称:{{EDBInfoOfCalculateData.FromEdbName}}</span>
  41. </div>
  42. <el-form
  43. ref="form"
  44. label-position="right"
  45. inline
  46. label-width="80px"
  47. :model="formData"
  48. :rules="formRules"
  49. >
  50. <el-form-item label="指标名称" prop="targetName">
  51. <el-input
  52. v-model="formData.targetName"
  53. style="width: 150px"
  54. placeholder="请输入指标名称"
  55. />
  56. </el-form-item>
  57. <el-form-item label="单位" prop="unit">
  58. <selectUnit
  59. v-model="formData.unit"
  60. style="width: 150px"
  61. />
  62. </el-form-item>
  63. <el-form-item label="指标目录" prop="menu">
  64. <el-cascader
  65. v-model="formData.menu"
  66. :options="classifyOptions"
  67. :props="{
  68. label: 'ClassifyName',
  69. value: 'ClassifyId',
  70. children: 'Children',
  71. emitPath: false,
  72. checkStrictly: true
  73. }"
  74. clearable
  75. placeholder="请选择指标目录"
  76. />
  77. </el-form-item>
  78. <el-form-item label="频度" prop="frequency">
  79. <el-select
  80. v-model="formData.frequency"
  81. placeholder="请选择频度"
  82. style="width: 150px"
  83. clearable
  84. >
  85. <el-option
  86. v-for="item in frequencyArr"
  87. :key="item"
  88. :label="item"
  89. :value="item"
  90. >
  91. </el-option>
  92. </el-select>
  93. </el-form-item>
  94. </el-form>
  95. </div>
  96. <div class="right-handle">
  97. <div>
  98. <el-button type="primary" size="medium" @click="saveSheetHandle">保存</el-button>
  99. <el-button type="primary" size="medium" plain @click="$router.go(-1)">取消</el-button>
  100. </div>
  101. <el-tooltip>
  102. <div slot="content" v-html="tips"></div>
  103. <div class="tips-cont">
  104. <span>使用说明</span>
  105. <i class="el-icon-question" style="color: #999;"></i>
  106. </div>
  107. </el-tooltip>
  108. </div>
  109. </div>
  110. <div class="main">
  111. <div class="table-cont" v-if="!edb_id">
  112. <el-table
  113. :data="filterList"
  114. border
  115. height="650"
  116. ref="table"
  117. >
  118. <el-table-column
  119. v-for="item in tableColums"
  120. :key="item.key"
  121. :label="item.label"
  122. :width="item.widthsty"
  123. :min-width="item.minwidthsty"
  124. align="center"
  125. >
  126. <template slot-scope="scope">
  127. <span>{{ scope.row[item.key] }}</span>
  128. </template>
  129. </el-table-column>
  130. <div slot="empty" style="padding: 50px 0;">
  131. <tableNoData text="暂无数据" size="mini"/>
  132. </div>
  133. </el-table>
  134. </div>
  135. <div id="excel-container"></div>
  136. </div>
  137. <!-- 指标历史记录 -->
  138. <edbHistoryDialog
  139. :isOpenDialog.sync="isLookHistory"
  140. :edbId="lookEdbId"
  141. />
  142. </div>
  143. </template>
  144. <script>
  145. import {dataBaseInterface} from '@/api/modules/chartApi'
  146. import { formRules } from '../databaseComponents/util';
  147. import { unitArr } from '@/utils/defaultOptions';
  148. import { mapState } from 'vuex';
  149. export default {
  150. data() {
  151. return {
  152. edb_id: this.$route.query.edbid,
  153. select_target: '',
  154. formData: {
  155. targetName: '',
  156. menu: '',
  157. frequency: '',
  158. unit: ''
  159. },
  160. formRules,
  161. unitArr,
  162. frequencyArr: ['日度', '周度','旬度', '月度', '季度', '年度'],
  163. classifyOptions: [],
  164. searchOptions: [],
  165. search_have_more: false,
  166. search_page: 1,
  167. current_search: '',
  168. old_edb_info: {
  169. id: '',
  170. name: ''
  171. },
  172. old_edb_data: [],
  173. rowHeight: 48,
  174. page_size: 20,
  175. start_index: 0,
  176. end_index: 49,
  177. tableColums: [
  178. { label: '日期',key:'DataTime' },
  179. { label: '值',key:'Value' }
  180. ],
  181. tips: `数据调整:<br>1、将所选指标的历史数据经过调整后保存,该指标更新时将在调整数据的基础上更新最新数据;<br>
  182. 2、支持对所选指标添加未来的数据,指标更新到未来相同的日期时,进行数据更正;<br>
  183. 3、选中表格,使用“Ctrl+F”可调用快速查找功能,支持快速定位到表格中的数据;<br>
  184. 注:系统只取A、B列数据`,
  185. excelData: [
  186. {
  187. r:0,
  188. c:0,
  189. v:{
  190. m:"日期",
  191. v:"日期",
  192. bg:'#bbb'
  193. },
  194. },
  195. {
  196. r:0,
  197. c:1,
  198. v:{
  199. m:"值",
  200. v:"值",
  201. bg:'#bbb'
  202. },
  203. },
  204. ],
  205. /* 查看历史弹窗 */
  206. isLookHistory: false,
  207. lookEdbId: 0,
  208. EDBInfoOfCalculateData:{},
  209. }
  210. },
  211. computed: {
  212. excelOptions() {
  213. return {
  214. container: 'excel-container',
  215. lang: 'zh', // 设定表格语言
  216. showinfobar: false,//顶部info
  217. showsheetbar:false,//底部sheet页 暂禁止添加多个表格
  218. showtoolbarConfig:{
  219. image: false,//图片
  220. print: false,//打印
  221. chart: false, // '图表'
  222. postil: false, //'批注'
  223. pivotTable: false, //'数据透视表'
  224. function: false, // '公式'
  225. frozenMode: false, // '冻结方式'
  226. sortAndFilter: false, // '排序和筛选'
  227. conditionalFormat: false, // '条件格式'
  228. dataVerification: false, // '数据验证'
  229. splitColumn: false, // '分列'
  230. screenshot: false, // '截图'
  231. findAndReplace: false, // '查找替换'
  232. },
  233. cellRightClickConfig: {
  234. insertColumn: false,
  235. matrix: false,
  236. chart: false, // 图表生成
  237. image: false, // 插入图片
  238. link: false, // 插入链接
  239. copyAs: false,
  240. },
  241. data: [{
  242. column: 2,
  243. scrollTop: 0,
  244. scrollLeft: 0,
  245. defaultColWidth: 200,
  246. defaultRowHeight: 20,
  247. frozen: [
  248. {
  249. type: 'row'
  250. }
  251. ],
  252. celldata: this.excelData,
  253. }],
  254. hook:{
  255. cellUpdateBefore(r,c,value){
  256. // 禁止更新第一行
  257. if(r===0) return false
  258. // if(c===0&&value) {
  259. // console.log(value)
  260. // console.log(isNaN(value)&&!isNaN(Date.parse(value)))
  261. // if(isNaN(value)&&!isNaN(Date.parse(value))) {
  262. // return true
  263. // }else {
  264. // bus.$message.warning('请输入正确的日期格式')
  265. // return false
  266. // }
  267. // }
  268. },
  269. cellMousedownBefore(e,{r,c}){
  270. if(r===0) return false
  271. },
  272. cellAllRenderBefore(a,b,c) {
  273. // console.log(a,b,c)
  274. },
  275. rangePasteBefore(range,data) {
  276. console.log(range,data)
  277. }
  278. },
  279. }
  280. },
  281. filterList() {
  282. return this.old_edb_data.slice(this.start_index,this.end_index)
  283. },
  284. total_length() {
  285. return this.old_edb_data.length;
  286. },
  287. ...mapState({
  288. eta_lang: state => state.edb.eta_lang,
  289. })
  290. },
  291. mounted() {
  292. this.getMenu();
  293. if(this.$route.query.edbid) {
  294. this.getEdaData(this.edb_id)
  295. this.getEDBInfoOfCalculate()
  296. }else {
  297. this.$refs.table.bodyWrapper && this.$refs.table.bodyWrapper.addEventListener('scroll',this.loadMoreData)
  298. this.initExcelOptions();
  299. }
  300. },
  301. beforeDestroy() {
  302. luckysheet.destroy();
  303. this.$refs.table && this.$refs.table.bodyWrapper && this.$refs.table.bodyWrapper.removeEventListener('scroll',this.loadMoreData)
  304. },
  305. methods: {
  306. // 获取计算指标与基础指标关联信息
  307. async getEDBInfoOfCalculate(){
  308. const res=await dataBaseInterface.getEDBInfoCalculateMap({EdbInfoId:Number(this.edb_id)})
  309. if(res.Ret===200){
  310. this.EDBInfoOfCalculateData=res.Data
  311. }
  312. },
  313. async getEdaData() {
  314. const res = await dataBaseInterface.targetList({
  315. PageSize: 100000,
  316. CurrentIndex: this.page_no,
  317. EdbInfoId: this.edb_id,
  318. })
  319. if (res.Ret!==200) return
  320. let arr = res.Data.Item.DataList ||[];
  321. this.old_edb_data = arr;
  322. this.formData = {
  323. targetName: res.Data.Item.EdbName,
  324. menu: res.Data.ClassifyList[0].ClassifyId,
  325. frequency: res.Data.Item.Frequency,
  326. unit: res.Data.Item.Unit
  327. }
  328. this.resetData()
  329. },
  330. /* 获取目录结构 */
  331. getMenu() {
  332. dataBaseInterface.menuListV3().then((res) => {
  333. if (res.Ret === 200) {
  334. this.filterNodes(res.Data.AllNodes||[])
  335. this.classifyOptions = res.Data.AllNodes || [];
  336. }
  337. });
  338. },
  339. // 递归改变第三级目录结构
  340. filterNodes(arr) {
  341. arr.length &&
  342. arr.forEach((item) => {
  343. item.Children.length && this.filterNodes(item.Children);
  344. if (!item.Children.length) {
  345. delete item.Children;
  346. }
  347. });
  348. },
  349. /* 指标列表 */
  350. getTarget(query) {
  351. this.search_page = 1;
  352. this.current_search = query;
  353. this.searchApi(this.current_search);
  354. },
  355. /* 聚焦获取当前检索 */
  356. inputFocusHandle(e) {
  357. this.search_page = 1;
  358. this.current_search = e.target.value;
  359. this.searchApi(this.current_search);
  360. },
  361. searchApi(query,page=1) {
  362. dataBaseInterface.targetSearchByPage({
  363. KeyWord:query,
  364. CurrentIndex: page
  365. }).then(res => {
  366. if(res.Ret !== 200) return
  367. const { List,Paging } = res.Data;
  368. this.search_have_more = page < Paging.Pages;
  369. let arr = page === 1 ? List : this.searchOptions.concat(List);
  370. this.searchOptions = this.$route.query.edbid ? arr.filter(item => item.EdbInfoId !== this.$route.query.edb_id) : arr;
  371. })
  372. },
  373. searchLoad() {
  374. if(!this.search_have_more) return;
  375. this.searchApi(this.current_search,++this.search_page)
  376. },
  377. /* 选择指标 */
  378. async chooseTarget(val) {
  379. if(val) {
  380. this.old_edb_info = {
  381. id: this.searchOptions.find(_ => _.EdbInfoId === val) ? this.searchOptions.find(_ => _.EdbInfoId === val).EdbCode : '',
  382. name: this.searchOptions.find(_ => _.EdbInfoId === val) ? this.searchOptions.find(_ => _.EdbInfoId === val).EdbName : ''
  383. }
  384. const res = await dataBaseInterface.targetList({
  385. PageSize: 100000,
  386. CurrentIndex: this.page_no,
  387. EdbInfoId: val,
  388. })
  389. if (res.Ret!==200) return
  390. let arr = res.Data.Item.DataList ||[];
  391. this.old_edb_data = arr;
  392. this.resetData()
  393. }else {
  394. this.old_edb_info = {};
  395. this.old_edb_data = [];
  396. this.resetData()
  397. }
  398. },
  399. /* 选择指标后重置数据 */
  400. resetData() {
  401. this.excelData = [
  402. {
  403. r:0,
  404. c:0,
  405. v:{
  406. m:"日期",
  407. v:"日期",
  408. bg:'#bbb'
  409. },
  410. },
  411. {
  412. r:0,
  413. c:1,
  414. v:{
  415. m:"值",
  416. v:"值",
  417. bg:'#bbb'
  418. },
  419. },
  420. ]
  421. this.old_edb_data.forEach((item,index) => {
  422. this.excelData.push({
  423. r: index+1,
  424. c:0,
  425. v:{
  426. m:item.DataTime,
  427. v:item.DataTime
  428. },
  429. })
  430. this.excelData.push({
  431. r: index+1,
  432. c:1,
  433. v:{
  434. m:item.Value,
  435. v:item.Value
  436. },
  437. })
  438. })
  439. luckysheet.create(this.excelOptions)
  440. },
  441. /* 滚动加载当前数据 */
  442. loadMoreData() {
  443. const scrollTop = this.$refs.table.bodyWrapper.scrollTop;
  444. this.start_index = Math.floor(scrollTop/this.rowHeight);
  445. this.end_index = this.start_index + this.page_size;
  446. $('.el-table__body')[0].style=`transform: translateY(${this.start_index*this.rowHeight}px)`
  447. },
  448. /* 保存 */
  449. async saveSheetHandle() {
  450. let data = luckysheet.getAllSheets()[0]
  451. await this.$refs.form.validate();
  452. // console.log(data.celldata)
  453. if(data.celldata.length < 3) return this.$message.warning('请输入表格内容');
  454. const { targetName,menu,frequency,unit} = this.formData;
  455. //处理数据格式
  456. let result_obj = {},DataList=[];
  457. data.celldata.forEach(item => {
  458. if(result_obj[item.r]&&item.c===1) {
  459. result_obj[item.r] = {
  460. Date: result_obj[item.r].v.m,
  461. Value: Number(item.v.m)
  462. }
  463. } else {
  464. result_obj[item.r] = item
  465. }
  466. })
  467. for(let key in result_obj) {
  468. if(result_obj[key].Date && !isNaN(result_obj[key].Value)) DataList.push(result_obj[key]);
  469. }
  470. const { Ret,Data } = await dataBaseInterface.adjustEdbEdit({
  471. EdbName: targetName,
  472. Frequency: frequency,
  473. Unit: unit,
  474. ClassifyId: menu,
  475. EdbInfoId: Number(this.edb_id)|| 0,
  476. FromEdbInfoId: this.select_target || 0,
  477. DataList
  478. })
  479. if(Ret !== 200) return
  480. this.$message.success('保存成功')
  481. const { UniqueCode,EdbInfoId } = Data;
  482. this.$router.replace({path:'/database', query: {
  483. code: UniqueCode,
  484. id: EdbInfoId
  485. }});
  486. },
  487. initExcelOptions() {
  488. this.$nextTick(() => {
  489. luckysheet.create(this.excelOptions)
  490. })
  491. },
  492. }
  493. }
  494. </script>
  495. <style lang="scss" scoped>
  496. *{ box-sizing: border-box; }
  497. .adjust-data-container {
  498. .wrap-top {
  499. display: flex;
  500. justify-content: space-between;
  501. /* align-items: center; */
  502. margin-bottom: 20px;
  503. padding: 20px;
  504. background: #fff;
  505. border: 1px solid #ececec;
  506. border-radius: 4px;
  507. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  508. z-index: 1;
  509. .min-top {
  510. margin-bottom: 10px;
  511. display: flex;
  512. align-items: center;
  513. color: #606266;
  514. li { margin-right: 35px; }
  515. }
  516. .right-handle {
  517. min-width: 155px;
  518. }
  519. .tips-cont {
  520. margin-top: 20px;
  521. }
  522. }
  523. .main {
  524. position: relative;
  525. height: 650px;
  526. display: flex;
  527. .table-cont {
  528. width: 260px;
  529. flex-shrink: 0;
  530. margin-right: 20px;
  531. /* height: 600px;
  532. overflow-y: scroll; */
  533. }
  534. #excel-container {
  535. margin:0;padding:0;
  536. width:100%;
  537. }
  538. }
  539. }
  540. </style>
  541. <style lang="scss">
  542. .luckysheet .toolbar {
  543. background: none;
  544. margin: 0;
  545. padding: 0;
  546. }
  547. .luckysheet-input-box {
  548. z-index: 99999;
  549. }
  550. </style>