adjustData.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <div class="adjust-data-container">
  3. <div class="wrap-top">
  4. <div class="left-handle">
  5. <ul class="min-top" v-if="!edb_id">
  6. <li>
  7. <label style="margin-right:5px;">{{$t('AdjustDataPage.choose_edb')}}:</label>
  8. <el-select
  9. v-model="select_target"
  10. v-loadMore="searchLoad"
  11. :filterable="!select_target"
  12. clearable
  13. :placeholder="$t('Edb.InputHolderAll.input_name')"
  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="toHistoryPage(select_target,$route.matched);lookEdbId=select_target" v-if="select_target"/>
  31. </li>
  32. <li v-show="old_edb_info.id">
  33. <label style="margin-right:5px;"> {{$t('AdjustDataPage.search_res')}}:</label>
  34. <span style="margin-right: 20px">{{$t('Edb.Detail.e_id')}}:{{old_edb_info.id}}</span>
  35. <span>{{$t('Edb.Detail.e_name')}}:{{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">{{$t('AdjustDataPage.or_edbid')}}:{{EDBInfoOfCalculateData.FromEdbCode}}</span>
  40. <span>{{$t('AdjustDataPage.or_edbname')}}:{{EDBInfoOfCalculateData.FromEdbName}}</span>
  41. </div>
  42. </div>
  43. <div class="right-handle">
  44. <div>
  45. <el-button type="primary" size="medium" @click="saveSheetHandle"><!-- 保存 -->{{$t('Dialog.confirm_save_btn')}}</el-button>
  46. <el-button type="primary" size="medium" plain @click="$router.go(-1)"><!-- 取消 -->{{$t('Dialog.back_btn')}}</el-button>
  47. </div>
  48. <el-tooltip>
  49. <div slot="content" v-html="tips"></div>
  50. <div class="tips-cont">
  51. <span><!-- 使用说明 -->{{$t('AdjustDataPage.usetip_msg')}}</span>
  52. <i class="el-icon-question" style="color: #999;"></i>
  53. </div>
  54. </el-tooltip>
  55. </div>
  56. <el-form
  57. ref="form"
  58. label-position="right"
  59. inline
  60. label-width="120px"
  61. :model="formData"
  62. :rules="formRules"
  63. >
  64. <el-form-item :label="$t('Edb.Detail.e_name')" prop="targetName">
  65. <el-input
  66. v-model="formData.targetName"
  67. style="width: 150px"
  68. :placeholder="$t('Edb.InputHolderAll.input_name')"
  69. />
  70. </el-form-item>
  71. <el-form-item :label="$t('Edb.Detail.e_unit')" prop="unit">
  72. <selectUnit
  73. v-model="formData.unit"
  74. style="width: 120px"
  75. />
  76. </el-form-item>
  77. <el-form-item :label="$t('Edb.Detail.e_menu')" prop="menu">
  78. <el-cascader
  79. v-model="formData.menu"
  80. :options="classifyOptions"
  81. :props="{
  82. label: 'ClassifyName',
  83. value: 'ClassifyId',
  84. children: 'Children',
  85. emitPath: false,
  86. checkStrictly: true
  87. }"
  88. clearable
  89. :placeholder="$t('Edb.InputHolderAll.input_menu')"
  90. />
  91. </el-form-item>
  92. <el-form-item :label="$t('Edb.Detail.e_fre')" prop="frequency">
  93. <el-select
  94. v-model="formData.frequency"
  95. :placeholder="$t('Edb.InputHolderAll.input_fre')"
  96. style="width: 120px"
  97. clearable
  98. >
  99. <el-option
  100. v-for="item in frequencyArr"
  101. :key="item"
  102. :label="item"
  103. :value="item"
  104. >
  105. </el-option>
  106. </el-select>
  107. </el-form-item>
  108. </el-form>
  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="$t('Table.prompt_slogan')" 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,frequencyArr } 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: this.$t('Edb.Detail.e_date'),key:'DataTime' },
  179. { label: this.$t('Edb.Detail.e_value'),key:'Value' }
  180. ],
  181. tips: this.$t('AdjustDataPage.usetip'),
  182. excelData: [
  183. {
  184. r:0,
  185. c:0,
  186. v:{
  187. m:"日期",
  188. v:"日期",
  189. bg:'#bbb'
  190. },
  191. },
  192. {
  193. r:0,
  194. c:1,
  195. v:{
  196. m:"值",
  197. v:"值",
  198. bg:'#bbb'
  199. },
  200. },
  201. ],
  202. /* 查看历史弹窗 */
  203. isLookHistory: false,
  204. lookEdbId: 0,
  205. EDBInfoOfCalculateData:{},
  206. }
  207. },
  208. computed: {
  209. excelOptions() {
  210. return {
  211. container: 'excel-container',
  212. lang: 'zh', // 设定表格语言
  213. showinfobar: false,//顶部info
  214. showsheetbar:false,//底部sheet页 暂禁止添加多个表格
  215. showtoolbarConfig:{
  216. image: false,//图片
  217. print: false,//打印
  218. chart: false, // '图表'
  219. postil: false, //'批注'
  220. pivotTable: false, //'数据透视表'
  221. function: false, // '公式'
  222. frozenMode: false, // '冻结方式'
  223. sortAndFilter: false, // '排序和筛选'
  224. conditionalFormat: false, // '条件格式'
  225. dataVerification: false, // '数据验证'
  226. splitColumn: false, // '分列'
  227. screenshot: false, // '截图'
  228. findAndReplace: false, // '查找替换'
  229. },
  230. cellRightClickConfig: {
  231. insertColumn: false,
  232. matrix: false,
  233. chart: false, // 图表生成
  234. image: false, // 插入图片
  235. link: false, // 插入链接
  236. copyAs: false,
  237. },
  238. data: [{
  239. column: 2,
  240. scrollTop: 0,
  241. scrollLeft: 0,
  242. defaultColWidth: 200,
  243. defaultRowHeight: 20,
  244. frozen: [
  245. {
  246. type: 'row'
  247. }
  248. ],
  249. celldata: this.excelData,
  250. }],
  251. hook:{
  252. cellUpdateBefore(r,c,value){
  253. // 禁止更新第一行
  254. if(r===0) return false
  255. // if(c===0&&value) {
  256. // console.log(value)
  257. // console.log(isNaN(value)&&!isNaN(Date.parse(value)))
  258. // if(isNaN(value)&&!isNaN(Date.parse(value))) {
  259. // return true
  260. // }else {
  261. // bus.$message.warning('请输入正确的日期格式')
  262. // return false
  263. // }
  264. // }
  265. },
  266. cellMousedownBefore(e,{r,c}){
  267. if(r===0) return false
  268. },
  269. cellAllRenderBefore(a,b,c) {
  270. // console.log(a,b,c)
  271. },
  272. rangePasteBefore(range,data) {
  273. console.log(range,data)
  274. }
  275. },
  276. }
  277. },
  278. filterList() {
  279. return this.old_edb_data.slice(this.start_index,this.end_index)
  280. },
  281. total_length() {
  282. return this.old_edb_data.length;
  283. },
  284. ...mapState({
  285. eta_lang: state => state.edb.eta_lang,
  286. })
  287. },
  288. mounted() {
  289. this.getMenu();
  290. if(this.$route.query.edbid) {
  291. this.getEdaData(this.edb_id)
  292. this.getEDBInfoOfCalculate()
  293. }else {
  294. this.$refs.table.bodyWrapper && this.$refs.table.bodyWrapper.addEventListener('scroll',this.loadMoreData)
  295. this.initExcelOptions();
  296. }
  297. },
  298. beforeDestroy() {
  299. luckysheet.destroy();
  300. this.$refs.table && this.$refs.table.bodyWrapper && this.$refs.table.bodyWrapper.removeEventListener('scroll',this.loadMoreData)
  301. },
  302. methods: {
  303. // 获取计算指标与基础指标关联信息
  304. async getEDBInfoOfCalculate(){
  305. const res=await dataBaseInterface.getEDBInfoCalculateMap({EdbInfoId:Number(this.edb_id)})
  306. if(res.Ret===200){
  307. this.EDBInfoOfCalculateData=res.Data
  308. }
  309. },
  310. async getEdaData() {
  311. const res = await dataBaseInterface.targetList({
  312. PageSize: 100000,
  313. CurrentIndex: this.page_no,
  314. EdbInfoId: this.edb_id,
  315. })
  316. if (res.Ret!==200) return
  317. let arr = res.Data.Item.DataList ||[];
  318. this.old_edb_data = arr;
  319. this.formData = {
  320. targetName: res.Data.Item.EdbName,
  321. menu: res.Data.ClassifyList[0].ClassifyId,
  322. frequency: res.Data.Item.Frequency,
  323. unit: res.Data.Item.Unit
  324. }
  325. this.resetData()
  326. },
  327. /* 获取目录结构 */
  328. getMenu() {
  329. dataBaseInterface.menuListV3().then((res) => {
  330. if (res.Ret === 200) {
  331. this.filterNodes(res.Data.AllNodes||[])
  332. this.classifyOptions = res.Data.AllNodes || [];
  333. }
  334. });
  335. },
  336. // 递归改变第三级目录结构
  337. filterNodes(arr) {
  338. arr.length &&
  339. arr.forEach((item) => {
  340. item.Children.length && this.filterNodes(item.Children);
  341. if (!item.Children.length) {
  342. delete item.Children;
  343. }
  344. });
  345. },
  346. /* 指标列表 */
  347. getTarget(query) {
  348. this.search_page = 1;
  349. this.current_search = query;
  350. this.searchApi(this.current_search);
  351. },
  352. /* 聚焦获取当前检索 */
  353. inputFocusHandle(e) {
  354. this.search_page = 1;
  355. this.current_search = e.target.value;
  356. this.searchApi(this.current_search);
  357. },
  358. searchApi(query,page=1) {
  359. dataBaseInterface.targetSearchByPage({
  360. KeyWord:query,
  361. CurrentIndex: page
  362. }).then(res => {
  363. if(res.Ret !== 200) return
  364. const { List,Paging } = res.Data;
  365. this.search_have_more = page < Paging.Pages;
  366. let arr = page === 1 ? List : this.searchOptions.concat(List);
  367. this.searchOptions = this.$route.query.edbid ? arr.filter(item => item.EdbInfoId !== this.$route.query.edb_id) : arr;
  368. })
  369. },
  370. searchLoad() {
  371. if(!this.search_have_more) return;
  372. this.searchApi(this.current_search,++this.search_page)
  373. },
  374. /* 选择指标 */
  375. async chooseTarget(val) {
  376. if(val) {
  377. this.old_edb_info = {
  378. id: this.searchOptions.find(_ => _.EdbInfoId === val) ? this.searchOptions.find(_ => _.EdbInfoId === val).EdbCode : '',
  379. name: this.searchOptions.find(_ => _.EdbInfoId === val) ? this.searchOptions.find(_ => _.EdbInfoId === val).EdbName : ''
  380. }
  381. const res = await dataBaseInterface.targetList({
  382. PageSize: 100000,
  383. CurrentIndex: this.page_no,
  384. EdbInfoId: val,
  385. })
  386. if (res.Ret!==200) return
  387. let arr = res.Data.Item.DataList ||[];
  388. this.old_edb_data = arr;
  389. this.resetData()
  390. }else {
  391. this.old_edb_info = {};
  392. this.old_edb_data = [];
  393. this.resetData()
  394. }
  395. },
  396. /* 选择指标后重置数据 */
  397. resetData() {
  398. this.excelData = [
  399. {
  400. r:0,
  401. c:0,
  402. v:{
  403. m:"日期",
  404. v:"日期",
  405. bg:'#bbb'
  406. },
  407. },
  408. {
  409. r:0,
  410. c:1,
  411. v:{
  412. m:"值",
  413. v:"值",
  414. bg:'#bbb'
  415. },
  416. },
  417. ]
  418. this.old_edb_data.forEach((item,index) => {
  419. this.excelData.push({
  420. r: index+1,
  421. c:0,
  422. v:{
  423. m:item.DataTime,
  424. v:item.DataTime
  425. },
  426. })
  427. this.excelData.push({
  428. r: index+1,
  429. c:1,
  430. v:{
  431. m:item.Value,
  432. v:item.Value
  433. },
  434. })
  435. })
  436. luckysheet.create(this.excelOptions)
  437. },
  438. /* 滚动加载当前数据 */
  439. loadMoreData() {
  440. const scrollTop = this.$refs.table.bodyWrapper.scrollTop;
  441. this.start_index = Math.floor(scrollTop/this.rowHeight);
  442. this.end_index = this.start_index + this.page_size;
  443. $('.el-table__body')[0].style=`transform: translateY(${this.start_index*this.rowHeight}px)`
  444. },
  445. /* 保存 */
  446. async saveSheetHandle() {
  447. let data = luckysheet.getAllSheets()[0]
  448. await this.$refs.form.validate();
  449. // console.log(data.celldata)
  450. if(data.celldata.length < 3) return this.$message.warning(this.$t('AdjustDataPage.input_content_msg'));
  451. const { targetName,menu,frequency,unit} = this.formData;
  452. //处理数据格式
  453. let result_obj = {},DataList=[];
  454. data.celldata.forEach(item => {
  455. if(result_obj[item.r]&&item.c===1) {
  456. result_obj[item.r] = {
  457. Date: result_obj[item.r].v.m,
  458. Value: Number(item.v.m)
  459. }
  460. } else {
  461. result_obj[item.r] = item
  462. }
  463. })
  464. for(let key in result_obj) {
  465. if(result_obj[key].Date && !isNaN(result_obj[key].Value)) DataList.push(result_obj[key]);
  466. }
  467. const { Ret,Data } = await dataBaseInterface.adjustEdbEdit({
  468. EdbName: targetName,
  469. Frequency: frequency,
  470. Unit: unit,
  471. ClassifyId: menu,
  472. EdbInfoId: Number(this.edb_id)|| 0,
  473. FromEdbInfoId: this.select_target || 0,
  474. DataList
  475. })
  476. if(Ret !== 200) return
  477. // this.$message.success('保存成功')
  478. this.$message.success(this.$t('MsgPrompt.saved_msg'))
  479. const { UniqueCode,EdbInfoId } = Data;
  480. this.$router.replace({path:'/database', query: {
  481. code: UniqueCode,
  482. id: EdbInfoId
  483. }});
  484. },
  485. initExcelOptions() {
  486. this.$nextTick(() => {
  487. luckysheet.create(this.excelOptions)
  488. })
  489. },
  490. }
  491. }
  492. </script>
  493. <style lang="scss" scoped>
  494. *{ box-sizing: border-box; }
  495. .adjust-data-container {
  496. .wrap-top {
  497. display: flex;
  498. flex-wrap: wrap;
  499. justify-content: space-between;
  500. /* align-items: center; */
  501. margin-bottom: 20px;
  502. padding: 20px;
  503. background: #fff;
  504. border: 1px solid #ececec;
  505. border-radius: 4px;
  506. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  507. z-index: 1;
  508. .min-top {
  509. margin-bottom: 10px;
  510. display: flex;
  511. flex-wrap: wrap;
  512. align-items: center;
  513. color: #606266;
  514. li { margin-right: 35px; }
  515. }
  516. .left-handle{
  517. flex: 1;
  518. }
  519. .right-handle {
  520. min-width: 155px;
  521. display: flex;
  522. flex-direction: row-reverse;
  523. align-items: center;
  524. }
  525. .el-form{
  526. width:100%;
  527. }
  528. .tips-cont {
  529. margin-right: 20px;
  530. }
  531. }
  532. .main {
  533. position: relative;
  534. height: 650px;
  535. display: flex;
  536. .table-cont {
  537. width: 260px;
  538. flex-shrink: 0;
  539. margin-right: 20px;
  540. /* height: 600px;
  541. overflow-y: scroll; */
  542. }
  543. #excel-container {
  544. margin:0;padding:0;
  545. width:100%;
  546. }
  547. }
  548. }
  549. </style>
  550. <style lang="scss">
  551. .luckysheet .toolbar {
  552. background: none;
  553. margin: 0;
  554. padding: 0;
  555. }
  556. .luckysheet-input-box {
  557. z-index: 99999;
  558. }
  559. </style>