adjustData.vue 17 KB

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