smoothEdbDialog.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <!-- 指数修匀计算弹窗 -->
  3. <el-dialog
  4. :visible.sync="isOpenSmooth"
  5. :close-on-click-modal="false"
  6. :modal-append-to-body="false"
  7. @close="cancelHandle"
  8. center
  9. width="1200px"
  10. top="3vh"
  11. v-dialogDrag
  12. >
  13. <div slot="title" style="display: flex; align-items: center">
  14. <img
  15. :src="$icons.computed"
  16. style="color: #fff; width: 16px; height: 16px; margin-right: 5px"
  17. />
  18. <span style="font-size: 16px">指数修匀</span>
  19. </div>
  20. <div class="smooth-edb-dialog-wrap">
  21. <!-- 常规计算 -->
  22. <div class="normal-wrap" v-if="computedSource===1">
  23. <div class="min-top">
  24. <label >选择指标:</label>
  25. <el-select
  26. v-model="select_target"
  27. v-loadMore="searchLoad"
  28. :filterable="!select_target"
  29. clearable
  30. placeholder="请输入指标名称"
  31. style="width: 85%"
  32. remote
  33. :remote-method="getTarget"
  34. @click.native="inputFocusHandle"
  35. @change="chooseTarget"
  36. @blur="search_have_more = false"
  37. :disabled="operationForm.view"
  38. >
  39. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  40. <el-option
  41. v-for="item in searchOptions"
  42. :key="item.EdbInfoId"
  43. :label="$parent.currentLang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName"
  44. :value="item.EdbInfoId"
  45. >
  46. </el-option>
  47. </el-select>
  48. <i class="el-icon-tickets" style="color:#409EFF;font-size:18px" @click="handleSelectBtnClick" v-if="select_target"/>
  49. </div>
  50. <div class="middle">
  51. <label>已选指标:</label>
  52. <el-table
  53. :data="tableData"
  54. style="box-shadow: 0px 3px 6px rgba(155, 170, 219, 0.2);margin-top:10px;"
  55. border>
  56. <el-table-column
  57. v-for="item in tableColums"
  58. :key="item.label"
  59. :label="item.label"
  60. :width="item.widthsty"
  61. :min-width="item.minwidthsty"
  62. align="center"
  63. >
  64. <template slot-scope="scope">
  65. <span>{{ scope.row[item.key] }}</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column
  69. width="110"
  70. align="center"
  71. label="操作"
  72. v-if="!operationForm.view"
  73. >
  74. <template slot-scope="scope">
  75. <span class="deletesty" @click="delTarget">删除</span>
  76. </template>
  77. </el-table-column>
  78. <div slot="empty" style="padding:20px 0 30px;">
  79. <tableNoData text="暂无指标" size="mini"/>
  80. </div>
  81. </el-table>
  82. <ul
  83. class="data-ul"
  84. ref="dataUl"
  85. @scroll="scrollHandle"
  86. v-if="dataList.length">
  87. <li
  88. class="value-item"
  89. v-for="(item, index) in dataList"
  90. :key="item.EdbDataId"
  91. >
  92. <span class="value-label">
  93. <i class="new-tag" v-if="index === 0"></i>
  94. {{item.DataTime}}
  95. </span>
  96. <span class="value-label" style="min-width:200px;text-align:center;">{{item.Value}}</span>
  97. </li>
  98. </ul>
  99. <div class="form-cont">
  100. <el-form
  101. ref="form"
  102. label-position="right"
  103. inline
  104. label-width="80px"
  105. :model="formData"
  106. :rules="formRules"
  107. :disabled="operationForm.view"
  108. >
  109. <el-form-item label="指标名称" prop="targetName">
  110. <el-input
  111. v-model="formData.targetName"
  112. style="width: 340px"
  113. placeholder="请输入指标名称"
  114. />
  115. </el-form-item>
  116. <el-form-item label="单位" prop="unit">
  117. <selectUnit
  118. v-model="formData.unit"
  119. style="width: 340px"
  120. />
  121. </el-form-item>
  122. <el-form-item label="指标目录" prop="menu">
  123. <el-cascader v-if="isOpenSmooth"
  124. v-model="formData.menu"
  125. :options="catalogArr"
  126. :props="levelProps"
  127. clearable
  128. placeholder="请选择指标目录"
  129. />
  130. </el-form-item>
  131. <el-form-item label="频度" prop="frequency">
  132. <el-select
  133. v-model="formData.frequency"
  134. placeholder="请选择频度"
  135. style="width: 340px"
  136. clearable
  137. >
  138. <el-option
  139. v-for="item in frequencyArr"
  140. :key="item"
  141. :label="item"
  142. :value="item"
  143. >
  144. </el-option>
  145. </el-select>
  146. </el-form-item>
  147. <el-form-item label="alpha值" prop="alphaValue">
  148. <el-input
  149. v-model.trim="formData.alphaValue"
  150. style="width: 340px"
  151. placeholder="请输入alpha值"
  152. />
  153. </el-form-item>
  154. </el-form>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- 批量计算 -->
  159. <div class="batch-wrap" v-else>
  160. <ul class="target-ul">
  161. <li class="target-li" v-for="(list, index) in targetList" :key="index">
  162. <span class="li-tag">{{ list.tag }}</span>
  163. <el-select v-model="list.target" v-loadMore="searchLoad" :filterable="!list.target" clearable
  164. placeholder="请输入指标名称" style="width: 400px" @change="(val)=>{chooseTargetList(val,index)}"
  165. @clear="clearHandle(index)" remote :remote-method="searchTarget"
  166. @click.native="inputFocusHandle">
  167. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  168. <el-option v-for="item in searchOptions" :key="item.EdbInfoId"
  169. :label="$parent.currentLang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName"
  170. :value="item.EdbInfoId">
  171. </el-option>
  172. </el-select>
  173. <i class="el-icon-tickets" style="color:#409EFF;font-size:18px"
  174. @click="$emit('lookHistory',list.target)" v-if="list.target" />
  175. <i class="el-icon-error del-tag" v-if="index > 1" @click="delTargetList(index)" />
  176. <span class="target-date" v-if="list.start_date">{{
  177. `${list.start_date}至${list.end_date}`
  178. }}</span>
  179. </li>
  180. </ul>
  181. <span class="add-icon" @click="addTargetHandle">
  182. <i class="el-icon-circle-plus-outline" style="color: #5882ef; font-size: 16px" />
  183. 添加更多指标
  184. </span>
  185. <ul class="form-ul">
  186. <li class="form-li" v-for="(list, index) in targetList" :key="index">
  187. <span class="li-tag">{{ list.tag }}</span>
  188. <el-form :ref="`list_form_${index}`"
  189. label-position="right"
  190. inline
  191. label-width="0px"
  192. :model="targetList[index]"
  193. :rules="formRules"
  194. >
  195. <el-form-item prop="targetName">
  196. <el-input
  197. v-model="targetList[index].targetName"
  198. style="width: 340px"
  199. placeholder="请输入指标名称"
  200. />
  201. </el-form-item>
  202. <el-form-item prop="unit">
  203. <selectUnit
  204. v-model="targetList[index].unit"
  205. style="width: 340px"
  206. />
  207. </el-form-item>
  208. <el-form-item prop="menu">
  209. <el-cascader v-if="isOpenSmooth"
  210. v-model="targetList[index].menu"
  211. :options="catalogArr"
  212. :props="levelProps"
  213. clearable
  214. placeholder="请选择指标目录"
  215. />
  216. </el-form-item>
  217. <el-form-item prop="frequency">
  218. <el-select
  219. v-model="targetList[index].frequency"
  220. placeholder="请选择频度"
  221. style="width: 340px"
  222. clearable
  223. >
  224. <el-option
  225. v-for="item in frequencyArr"
  226. :key="item"
  227. :label="item"
  228. :value="item"
  229. >
  230. </el-option>
  231. </el-select>
  232. </el-form-item>
  233. <el-form-item prop="alphaValue">
  234. <el-input
  235. v-model.trim="targetList[index].alphaValue"
  236. style="width: 340px"
  237. placeholder="请输入alpha值"
  238. />
  239. </el-form-item>
  240. </el-form>
  241. </li>
  242. </ul>
  243. </div>
  244. <div class="dia-bot" v-if="!operationForm.view">
  245. <el-button
  246. type="primary"
  247. style="margin-right: 20px"
  248. @click="saveHandle"
  249. :loading="loading"
  250. >指数修匀计算</el-button
  251. >
  252. <el-button type="primary" plain @click="cancelHandle('cancel')">取消</el-button>
  253. </div>
  254. <el-popover
  255. placement="top-start"
  256. width="500"
  257. trigger="click">
  258. <p style="padding:30px;line-height:25px;" v-html="$parent.tips.get('alpha')"/>
  259. <span slot="reference" class="tip-label">公式说明</span>
  260. </el-popover>
  261. </div>
  262. </el-dialog>
  263. </template>
  264. <script>
  265. import { dataBaseInterface } from '@/api/api.js';
  266. import { formRules } from './util';
  267. const tag_arr = [];
  268. for(let i=0;i<26;i++) tag_arr.push(String.fromCharCode(65+i));
  269. export default {
  270. props:{
  271. isOpenSmooth:{
  272. type:Boolean,
  273. default:false
  274. },
  275. computedSource:{ //常规 or 批量
  276. type:Number,
  277. default:1
  278. },
  279. operationForm:{
  280. type:Object,
  281. default:()=>{return{
  282. edb_id:'',
  283. oldedb_id:''
  284. }}
  285. }
  286. },
  287. data() {
  288. return {
  289. /* 常规 */
  290. formData:{
  291. targetName:'',
  292. unit:'',
  293. menu:'',
  294. frequency:'',
  295. alphaValue:''
  296. },
  297. formRules,
  298. frequencyArr: ['日度', '周度','旬度', '月度', '季度', '年度'],
  299. catalogArr:[],
  300. levelProps: {
  301. label: 'ClassifyName',
  302. value: 'ClassifyId',
  303. children: 'Children',
  304. emitPath: false,
  305. },
  306. select_target:'',
  307. search_page:1,
  308. search_have_more:false,
  309. searchOptions:[],
  310. current_search:'',
  311. tableData:[],
  312. page_no:1,
  313. tableColums:[
  314. {
  315. label: '指标ID',
  316. key: 'EdbCode',
  317. },
  318. {
  319. label: '指标名称',
  320. key: 'EdbName',
  321. },
  322. {
  323. label: '频度',
  324. key: 'Frequency',
  325. },
  326. {
  327. label: '单位',
  328. key: 'Unit',
  329. },
  330. {
  331. label: '起始时间',
  332. key: 'StartDate',
  333. minwidthsty: '100px'
  334. },
  335. {
  336. label: '更新时间',
  337. key: 'ModifyTime',
  338. minwidthsty: '110px'
  339. },
  340. {
  341. label: '来源',
  342. key: 'SourceName',
  343. },
  344. ],
  345. dataList:[],
  346. /* 批量 */
  347. targetList:[/* {
  348. tag:'A',
  349. target:123456 //edbid
  350. ...formData
  351. } */],
  352. formDataList:[],
  353. loading:false,
  354. };
  355. },
  356. watch:{
  357. isOpenSmooth(newVal){
  358. if(newVal){
  359. this.getMenu()
  360. if(this.operationForm.edb_id){
  361. this.select_target = this.operationForm.oldedb_id
  362. this.getDataList()
  363. this.setDefaultOption(this.operationForm,'edit')
  364. //回显时的默认options
  365. this.searchOptions = [
  366. {
  367. EdbInfoId: this.operationForm.oldedb_id,
  368. EdbName: this.operationForm.oldEdb_name,
  369. }
  370. ]
  371. }
  372. if(this.computedSource===2){
  373. this.addTargetHandle()
  374. this.addTargetHandle()
  375. }
  376. }
  377. }
  378. },
  379. methods: {
  380. init(){
  381. this.$refs.form&&(this.$refs.form.resetFields());
  382. Object.assign(this.$data, this.$options.data());
  383. },
  384. searchLoad() {
  385. if(!this.search_have_more) return;
  386. this.searchApi(this.current_search,++this.search_page)
  387. },
  388. searchApi(query,page=1){
  389. dataBaseInterface.targetSearchByPage({
  390. KeyWord:query,
  391. CurrentIndex: page,
  392. }).then(res => {
  393. if(res.Ret !== 200) return
  394. const { List,Paging } = res.Data;
  395. this.search_have_more = page < Paging.Pages;
  396. let arr = page === 1 ? List : this.searchOptions.concat(List);
  397. this.searchOptions = arr;
  398. })
  399. },
  400. /* 指标列表 */
  401. getTarget(query) {
  402. this.search_page = 1;
  403. this.current_search = query;
  404. this.searchApi(this.current_search);
  405. },
  406. /* 聚焦获取当前检索 */
  407. inputFocusHandle(e) {
  408. this.search_page = 1;
  409. this.current_search = e.target.value;
  410. this.searchApi(this.current_search);
  411. },
  412. /* 获取目录结构 */
  413. getMenu() {
  414. dataBaseInterface.menuListV3().then((res) => {
  415. if (res.Ret === 200) {
  416. this.catalogArr = res.Data.AllNodes || [];
  417. }
  418. });
  419. },
  420. /* 选择指标 */
  421. chooseTarget(val) {
  422. if(val) {
  423. let obj = this.searchOptions.find(item => item.EdbInfoId === val);
  424. //同步指标信息
  425. this.setDefaultOption(obj);
  426. this.page_no = 1;
  427. this.dataList.length ? this.$refs.dataUl.scrollTop = 0 : null;
  428. this.getDataList()
  429. }else {
  430. this.tableData = [];
  431. this.dataList = [];
  432. }
  433. },
  434. chooseTargetList(val,index){
  435. if(val){
  436. const obj = this.searchOptions.find(item => item.EdbInfoId === val);
  437. const {tag,target} = this.targetList[index]
  438. this.targetList[index] = {
  439. tag,target,
  440. targetName:`${obj.EdbName}指数修匀`,
  441. unit:obj.Unit,
  442. frequency:obj.Frequency,
  443. menu:obj.ClassifyId||'',
  444. alphaValue:obj.Formula||''
  445. }
  446. }
  447. },
  448. setDefaultOption(obj,type){
  449. this.formData = {
  450. targetName:`${obj.EdbName}${type==='edit'?'':'指数修匀'}`,
  451. unit:obj.Unit,
  452. frequency:obj.Frequency,
  453. menu:obj.ClassifyId||'',
  454. alphaValue:obj.Formula||''
  455. }
  456. },
  457. getDataList(){
  458. dataBaseInterface.targetList({
  459. PageSize: 10,
  460. CurrentIndex: this.page_no,
  461. EdbInfoId: this.select_target,
  462. }).then(res => {
  463. if(res.Ret === 200) {
  464. if(res.Data) {
  465. res.Data.Item.ModifyTime = res.Data.Item.ModifyTime.substr(0,10);
  466. this.tableData = [res.Data.Item] || [];
  467. this.haveMore = this.page_no < res.Data.Paging.Pages ? true : false;
  468. this.dataList = this.page_no === 1 ? (res.Data.Item.DataList || []) : this.dataList.concat(res.Data.Item.DataList);
  469. }else {
  470. this.tableData = [];
  471. this.dataList = [];
  472. }
  473. }
  474. })
  475. },
  476. handleSelectBtnClick(){
  477. //计算指标打开弹窗,基础指标打开新页面
  478. if(this.tableData[0].EdbType===2){
  479. this.$emit('lookHistory',this.select_target)
  480. }else{
  481. const {ClassifyId,UniqueCode,EdbInfoId} = this.tableData[0]
  482. let {href} = this.$router.resolve({path:`/database`,query:{code:UniqueCode,id:EdbInfoId,classifyId:ClassifyId}});
  483. window.open(href,'_blank');
  484. }
  485. },
  486. scrollHandle(){},
  487. delTarget(){},
  488. delTargetList(index){
  489. this.targetList.splice(index, 1);
  490. },
  491. clearHandle(index){
  492. console.log('?clear',index)
  493. const item = {...{tag:tag_arr[index],target:''},..._.cloneDeep(this.formData)}
  494. this.targetList.splice(index,1,item)
  495. },
  496. addTargetHandle(){
  497. if(this.targetList.length >= 26){
  498. this.$message.warning('添加指标个数已达上限')
  499. return
  500. }
  501. let tag = 'A'
  502. let index = -1
  503. if(this.targetList.length>=1){
  504. tag = this.targetList[this.targetList.length-1].tag;
  505. index = tag_arr.findIndex(item => item === tag);
  506. }
  507. const item = {...{tag:tag_arr[index+1],target:''},..._.cloneDeep(this.formData)}
  508. this.targetList.push(item)
  509. },
  510. async saveHandle(){
  511. if(!this.select_target){
  512. this.$message.warning('指标不能为空')
  513. return
  514. }
  515. await this.$refs.form.validate();
  516. this.loading = true;
  517. const {targetName,unit,menu,frequency,alphaValue} = this.formData
  518. let params = {
  519. Source:this.$route.path==='/database'?72:73,
  520. EdbName:targetName,
  521. Unit:unit,
  522. ClassifyId:menu,
  523. Frequency:frequency,
  524. Formula:alphaValue,
  525. FromEdbInfoId:this.select_target
  526. }
  527. const res = this.operationForm.edb_id
  528. ? await dataBaseInterface.calculateTargetEdit({ ...params,EdbInfoId: this.operationForm.edb_id })
  529. : await dataBaseInterface.calculateTargetSave(params)
  530. if(res.Ret!==200) return
  531. this.$message.success(res.Msg)
  532. this.operationForm.edb_id
  533. ? this.$emit('addCallBack','edit')
  534. : this.$emit('addCallBack','add',{ code:res.Data.UniqueCode,id:res.Data.EdbInfoId,classifyId:params.ClassifyId });
  535. this.init();
  536. },
  537. cancelHandle(type) {
  538. this.init();
  539. this.$emit('cancel');
  540. type==='cancel' && this.$emit('openPrev');
  541. },
  542. },
  543. };
  544. </script>
  545. <style lang="scss">
  546. .smooth-edb-dialog-wrap{
  547. .el-cascader .el-input {
  548. width: 340px;
  549. }
  550. .min-top {
  551. padding: 20px 30px;
  552. border: 1px solid #ECECEC;
  553. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.05);
  554. border-radius:4px;
  555. }
  556. .middle {
  557. margin-top: 20px;
  558. .data-ul {
  559. margin-top: 5px;
  560. border-bottom: 1px solid #dcdfe6;
  561. max-height: 140px;
  562. overflow-y: auto;
  563. .value-item {
  564. padding: 14px 0;
  565. border: 1px solid #dcdfe6;
  566. border-bottom: none;
  567. display: flex;
  568. justify-content: space-around;
  569. .value-label {
  570. position: relative;
  571. color: #666;
  572. }
  573. .new-tag {
  574. width: 6px;
  575. height: 6px;
  576. display: inline-block;
  577. position: absolute;
  578. left: -12px;
  579. top: 50%;
  580. transform: translateY(-50%);
  581. border-radius: 50%;
  582. background: #f00;
  583. }
  584. }
  585. }
  586. .form-cont {
  587. padding-top: 30px;
  588. margin-top: 30px;
  589. border-top: 1px dashed #AAB4CC;
  590. input::-webkit-outer-spin-button,
  591. input::-webkit-inner-spin-button {
  592. -webkit-appearance: none;
  593. }
  594. input[type="number"]{
  595. -moz-appearance: textfield;
  596. }
  597. }
  598. }
  599. .dia-bot {
  600. padding: 20px 0 30px;
  601. display: flex;
  602. justify-content: center;
  603. }
  604. .tip-label {
  605. position: absolute;
  606. bottom: 30px;
  607. right: 30px;
  608. color: #409EFF;
  609. cursor: pointer;
  610. }
  611. }
  612. </style>