dynamicRingdiffer.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <el-dialog
  3. :visible.sync="isOpenDialog"
  4. :close-on-click-modal="false"
  5. :modal-append-to-body="false"
  6. @close="cancelHandle"
  7. custom-class="dynamic-differ-dialog"
  8. center
  9. width="1090px"
  10. top="8vh"
  11. v-dialogDrag
  12. >
  13. <div slot="title" style="display: flex; align-items: center">
  14. <span style="font-size: 16px"><!-- 设置环比增加值 -->{{ $t('PredictEditPage.set_mom_btn') }}</span>
  15. </div>
  16. <div class="dialog-main">
  17. <ul class="add-cont">
  18. <li class="add-li" v-for="(list, index) in addList" :key="index">
  19. <span class="li-tag">{{ list.tag }}</span>
  20. <el-select
  21. v-model="list.target"
  22. v-loadMore="searchLoad"
  23. :filterable="!list.target"
  24. clearable
  25. :placeholder="$t('Edb.InputHolderAll.input_name')"
  26. style="width: 400px"
  27. @change="chooseTarget"
  28. @clear="clearHandle(index)"
  29. remote
  30. :remote-method="searchTarget"
  31. @click.native="inputFocusHandle"
  32. >
  33. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  34. <el-option
  35. v-for="item in searchOptions"
  36. :key="item.EdbInfoId"
  37. :label="$parent.currentLang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName"
  38. :value="item.EdbInfoId"
  39. :disabled="!item.HaveOperaAuth"
  40. >
  41. <edbDetailPopover :info="item">
  42. <div slot="reference">
  43. <img
  44. :src="$icons.lock_ico2"
  45. width="18"
  46. height="18"
  47. style="vertical-align:middle"
  48. v-if="!item.HaveOperaAuth"
  49. />
  50. {{ $parent.currentLang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName}}
  51. </div>
  52. </edbDetailPopover>
  53. </el-option>
  54. </el-select>
  55. <i class="el-icon-tickets" style="color:#409EFF;font-size:18px" @click="$emit('lookHistory',list.target)" v-if="list.target"/>
  56. <i
  57. class="el-icon-error del-tag"
  58. v-if="index > 3"
  59. @click="delTarget(index)"
  60. />
  61. <span class="target-date" v-if="list.start_date">{{
  62. `${list.start_date}${$t('Common.to')}${list.end_date}`
  63. }}</span>
  64. </li>
  65. </ul>
  66. <span class="add-icon" @click="addTargetHandle">
  67. <i
  68. class="el-icon-circle-plus-outline"
  69. style="color: #5882ef; font-size: 16px"
  70. />
  71. <!-- 添加更多参数 -->{{$t('EtaBasePage.add_more_param')}}
  72. </span>
  73. <div class="computed-min">
  74. <div class="computed-section">
  75. <div>
  76. <label class="label"><!-- 空值处理 -->{{$t('EtaBasePage.null_val_deal')}}
  77. <el-tooltip placement="top">
  78. <div slot="content" v-html="formTips['null-val']" style="width:300px;line-height:20px;"/>
  79. <i class="el-icon-question"/>
  80. </el-tooltip>
  81. </label>
  82. <el-select
  83. v-model="nullValueForm.nullValueWay"
  84. placeholder="请选择"
  85. >
  86. <el-option
  87. v-for="item in nullWayOptions"
  88. :key="item.value"
  89. :label="item.label"
  90. :value="item.value"
  91. >
  92. </el-option>
  93. </el-select>
  94. </div>
  95. <div style="margin-left: 120px" v-if="showMaxNullDeal">
  96. <label class="label"><!-- MAX、MIN空值处理 --> {{$t('EtaBasePage.max_null_val')}}
  97. <el-tooltip placement="top">
  98. <div slot="content" v-html="formTips['max-null-val']" style="width:300px;line-height:20px;"/>
  99. <i class="el-icon-question"/>
  100. </el-tooltip>
  101. </label>
  102. <el-select
  103. v-model="nullValueForm.maxNullWay"
  104. placeholder="请选择"
  105. >
  106. <el-option :label="$t('EtaBasePage.null_val_deal_4')" :value="1" />
  107. <el-option :label="$t('EtaBasePage.max_null_val_2')" :value="2" />
  108. </el-select>
  109. </div>
  110. <el-button type="primary" @click="getResult" style="margin-left: 10px"><!-- 一键计算 -->{{$t('PredictEditPage.calculate_one_btn')}}</el-button>
  111. </div>
  112. <div class="computed-section">
  113. <label class="label"><!-- 计算公式 -->{{$t('EtaBasePage.calculate_formula')}}
  114. <el-tooltip placement="top">
  115. <div slot="content" v-html="formTips['formula']" style="width:300px;line-height:20px;"/>
  116. <i class="el-icon-question"/>
  117. </el-tooltip>
  118. </label>
  119. <ul class="formula-list">
  120. <li style="margin-bottom: 15px;">
  121. <el-input :placeholder="$t('EtaBasePage.input_formula_msg')" v-model="formulaList[0].formula" clearable style="width: 220px"/>
  122. <span v-if="formulaDateArr.length" class="date-section-text">{{formulaDateArr[formulaDateArr.length-1]}}(含)之后</span>
  123. <span class="example-txt">{{$t('EtaBasePage.formula_examp')}}:A*0.5+B*C*1.2+120-MAX(A,B,C) &nbsp;{{$t('EtaBasePage.func_examp')}}:MAX(),MIN(),ln(A),log(a,A),abs(),exp(),pow(),round()</span>
  124. </li>
  125. <li class="formula-item" v-for="(item,index) in formulaList.slice(1)" :key="index+1">
  126. <el-input
  127. :placeholder="$t('EtaBasePage.input_formula_msg')"
  128. v-model="item.formula"
  129. clearable
  130. style="width: 220px"
  131. />
  132. <el-date-picker
  133. v-model="item.date"
  134. type="date"
  135. value-format="yyyy-MM-dd"
  136. style="margin: 0 10px;width: 220px"
  137. :placeholder="$t('EtaBasePage.input_date_msg')"
  138. @change="selectFormulaDate($event,item)"
  139. />
  140. <i class="el-icon-circle-close" style="font-size:20px;" @click="removeFormulaItem(index+1)"/>
  141. <template v-if="formulaDateArr.length&&item.date">
  142. <span v-if="item.date===formulaDateArr[0]" class="date-section-text">{{formulaDateArr[0]}}之前</span>
  143. <span v-else class="date-section-text">{{formulaDateArr[formulaDateArr.findIndex(_ =>_ ===item.date)-1]}}(含)——{{item.date}}</span>
  144. </template>
  145. </li>
  146. </ul>
  147. </div>
  148. <el-button icon="el-icon-plus" style="margin-left:70px;" @click="addFormulaHandle"><!-- 新增分段 -->{{$t('EtaBasePage.add_segm')}}</el-button>
  149. </div>
  150. <el-table
  151. border
  152. :data="resultData"
  153. v-if="resultData.length"
  154. max-height="320"
  155. >
  156. <el-table-column
  157. v-for="item in tableColums"
  158. :key="item.label"
  159. :label="item.label"
  160. :width="item.widthsty"
  161. :min-width="item.minwidthsty"
  162. align="center"
  163. >
  164. <template slot-scope="scope">
  165. <span :style="scope.row.isPredict&&'color: orange'">{{ scope.row[item.key] }}</span>
  166. </template>
  167. </el-table-column>
  168. <div slot="empty" style="padding:20px 0 30px;">
  169. <tableNoData :text="$t('Table.no_edb_msg')" size="mini"/>
  170. </div>
  171. </el-table>
  172. </div>
  173. <div class="dia-bot">
  174. <el-button
  175. type="primary"
  176. style="margin-right: 20px"
  177. @click="saveHandle"
  178. ><!-- 保存 -->{{$t('Dialog.confirm_save_btn')}}</el-button
  179. >
  180. <el-button type="primary" plain @click="cancelHandle"><!-- 取消 -->{{$t('Dialog.cancel_btn')}}</el-button>
  181. </div>
  182. </el-dialog>
  183. </template>
  184. <script>
  185. import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
  186. const tag_arr = [];
  187. for(var i=0;i<26;i++) tag_arr.push(String.fromCharCode(65+i));
  188. export default {
  189. name: '',
  190. props: {
  191. isOpenDialog: {
  192. type: Boolean,
  193. },
  194. title: {
  195. type: String,
  196. default: '设置环比增加值',
  197. },
  198. info: {
  199. type: Object,
  200. },
  201. edbList: {
  202. type: Array,
  203. },
  204. },
  205. computed: {
  206. /* max空值处理显示 当输入的公式包含MAX、MIN且空值处理为0时,输入公式失焦后出现右侧选项; */
  207. showMaxNullDeal() {
  208. let haveMaxOrMin = this.formulaList.some(_ => _.formula.toUpperCase().includes('MAX') || _.formula.toUpperCase().includes('MIN'))
  209. return haveMaxOrMin && this.nullValueForm.nullValueWay===4
  210. },
  211. formulaDateArr() {
  212. return this.formulaList.map(_ => _.date).filter(_ => _).sort((a,b) => new Date(a)-new Date(b))
  213. },
  214. tableColums(){
  215. return [
  216. {
  217. label: /* '日期' */this.$t('PredictEditPage.result_column1'),
  218. key: 'DataTime',
  219. },
  220. {
  221. label: /* '环比增加值' */this.$t('PredictEditPage.result_column2'),
  222. key: 'Value',
  223. },
  224. ]
  225. },
  226. formTips(){
  227. return {
  228. 'null-val':this.$t('EtaBasePage.null_val_del_hint'),
  229. 'max-null-val':this.$t('EtaBasePage.max_null_val_hint'),
  230. 'formula':this.$t('EtaBasePage.formula_examp_hint')
  231. }
  232. },
  233. nullWayOptions(){
  234. return [
  235. { label: this.$t('EtaBasePage.null_val_deal_0'),value: 0 },
  236. { label: this.$t('EtaBasePage.null_val_deal_1'),value: 1 },
  237. { label: this.$t('EtaBasePage.null_val_deal_2'),value: 2 },
  238. { label: this.$t('EtaBasePage.null_val_deal_3'),value: 3 },
  239. { label: this.$t('EtaBasePage.null_val_deal_4'),value: 4 },
  240. ]
  241. },
  242. },
  243. watch: {
  244. isOpenDialog(newval) {
  245. /* 回显 */
  246. if (this.edbList.length && newval) {
  247. this.addList = _.cloneDeep(this.edbList);
  248. const{ formulaList,nullValueWay,maxNullWay } = this.info;
  249. this.formulaList = JSON.parse(formulaList).map(_=>({
  250. formula: _.f,
  251. date: _.d
  252. }));
  253. this.nullValueForm = {
  254. nullValueWay,
  255. maxNullWay
  256. }
  257. this.searchOptions = this.edbList.map(item => ({
  258. EdbInfoId: item.target,
  259. EdbName: item.name,
  260. }))
  261. }
  262. },
  263. },
  264. data() {
  265. return {
  266. addList: [
  267. {
  268. tag: tag_arr[0],
  269. name: '',
  270. target: '',
  271. start_date: '',
  272. end_date: '',
  273. },
  274. {
  275. tag: tag_arr[1],
  276. name: '',
  277. target: '',
  278. start_date: '',
  279. end_date: '',
  280. },
  281. {
  282. tag: tag_arr[2],
  283. name: '',
  284. target: '',
  285. start_date: '',
  286. end_date: '',
  287. },
  288. {
  289. tag: tag_arr[3],
  290. name: '',
  291. target: '',
  292. start_date: '',
  293. end_date: '',
  294. },
  295. ],
  296. searchOptions: [],
  297. formula: '', //计算公式
  298. dataloading: false,
  299. search_have_more: false,
  300. search_page: 1,
  301. current_search:'',
  302. formulaList: [
  303. { formula: '', }
  304. ],
  305. nullValueForm: {
  306. nullValueWay: 0,
  307. maxNullWay: 1
  308. },//空值处理
  309. resultData: [],//
  310. };
  311. },
  312. methods: {
  313. /* 添加额外的指标列 */
  314. addTargetHandle() {
  315. let tag = this.addList[this.addList.length-1].tag;
  316. let index = tag_arr.findIndex(item => item === tag);
  317. const item = {
  318. tag: tag_arr[index+1],
  319. target: '',
  320. name: '',
  321. start_date: '',
  322. end_date: ''
  323. };
  324. this.addList.push(item);
  325. },
  326. /* 搜索指标 */
  327. searchTarget(query) {
  328. this.search_page = 1;
  329. this.current_search = query;
  330. this.searchApi(this.current_search);
  331. },
  332. /* 聚焦获取当前检索 */
  333. inputFocusHandle(e) {
  334. this.search_page = 1;
  335. this.current_search = e.target.value;
  336. this.searchApi(this.current_search);
  337. },
  338. searchApi(query,page=1) {
  339. preDictEdbInterface
  340. .edbSearch({
  341. Keyword: query,
  342. CurrentIndex: page
  343. })
  344. .then((res) => {
  345. if (res.Ret !== 200) return
  346. const { List,Paging } = res.Data;
  347. this.search_have_more = page < Paging.Pages;
  348. this.searchOptions = page === 1 ? List : this.searchOptions.concat(List);
  349. });
  350. },
  351. searchLoad() {
  352. if(!this.search_have_more) return;
  353. this.searchApi(this.current_search,++this.search_page)
  354. },
  355. /* 选中指标 显示开始日期结束日期 */
  356. chooseTarget(val) {
  357. if (val) {
  358. const choose_obj = this.searchOptions.find(
  359. (item) => item.EdbInfoId === val
  360. );
  361. this.addList.forEach((list) => {
  362. if (list.target === val) {
  363. list.name = choose_obj.EdbName;
  364. list.start_date = choose_obj.StartDate;
  365. list.end_date = choose_obj.EndDate;
  366. }
  367. });
  368. }
  369. },
  370. /* 清空指标和关联日期 */
  371. clearHandle(index) {
  372. this.addList[index].start_date = '';
  373. this.addList[index].end_date = '';
  374. this.addList[index].name = '';
  375. },
  376. // 删除指标
  377. delTarget(index) {
  378. this.addList.splice(index, 1);
  379. },
  380. saveHandle() {
  381. if (!this.formulaList[0].formula) return this.$message.warning(/* '计算公式不能为空' */this.$t('EtaBasePage.input_formula_valid'));
  382. // 指标id数组
  383. let target_arr = this.addList.filter(item => item.target);
  384. let formula = JSON.stringify(this.formulaList
  385. .filter((_,index) => index===0||(index>0&&_.formula&&_.date))
  386. .map(_ => ({f: _.formula,d: _.date}))
  387. )
  388. this.$emit('ensureBack',{arr:target_arr,formula,...this.nullValueForm})
  389. this.cancelHandle();
  390. },
  391. /* 获取数据 */
  392. async getResult() {
  393. if (!this.formulaList[0].formula) return this.$message.warning(/* '计算公式不能为空' */this.$t('EtaBasePage.input_formula_valid'));
  394. let EdbInfoIdArr = this.addList.filter(_ => _.target).map(_ => ({
  395. EdbInfoId: _.target,
  396. FromTag: _.tag
  397. }))
  398. const { nullValueWay,maxNullWay } = this.nullValueForm;
  399. let formula = JSON.stringify(this.formulaList
  400. .filter((_,index) => index===0||(index>0&&_.formula&&_.date))
  401. .map(_ => ({f: _.formula,d: _.date}))
  402. )
  403. const params = {
  404. RuleType: 9,
  405. EndDate: '',
  406. Value: formula,
  407. EmptyType: nullValueWay,
  408. MaxEmptyType: maxNullWay,
  409. EdbInfoIdArr
  410. }
  411. const { Ret,Data } = await preDictEdbInterface.getRuleNineData(params);
  412. if(Ret !== 200) return
  413. this.resultData = Data.DataList.map(_ => ({
  414. ..._,
  415. isPredict: _.DataTimestamp > this.$moment(Data.LatestDate+' 8:00').valueOf()
  416. })) || [];
  417. },
  418. /* 新增公式分段 */
  419. addFormulaHandle() {
  420. let addItem = {
  421. formula: this.formulaList[this.formulaList.length-1].formula,
  422. date: ''
  423. }
  424. this.formulaList.push(addItem)
  425. },
  426. /* 移除公式 */
  427. removeFormulaItem(index) {
  428. this.formulaList.splice(index,1)
  429. },
  430. /* 选择日期 检验 */
  431. selectFormulaDate(val,item) {
  432. const { start_date,end_date } = this.addList[0];
  433. if(!start_date) return
  434. let dateStamp = new Date(val).getTime(),
  435. startStamp = new Date(start_date).getTime(),
  436. endStamp = new Date(end_date).getTime();
  437. if (dateStamp > endStamp || dateStamp < startStamp) {
  438. item.date = '';
  439. return this.$message.warning('分段日期必须在第一个指标日期区间')
  440. }
  441. else if(this.formulaList.filter(_ => _.date===val).length>1) {
  442. item.date = '';
  443. return this.$message.warning('分段日期不可重复')
  444. }
  445. },
  446. init() {
  447. this.addList = [
  448. {
  449. tag: tag_arr[0],
  450. name: '',
  451. target: '',
  452. start_date: '',
  453. end_date: '',
  454. },
  455. {
  456. tag: tag_arr[1],
  457. name: '',
  458. target: '',
  459. start_date: '',
  460. end_date: '',
  461. },
  462. {
  463. tag: tag_arr[2],
  464. name: '',
  465. target: '',
  466. start_date: '',
  467. end_date: '',
  468. },
  469. {
  470. tag: tag_arr[3],
  471. name: '',
  472. target: '',
  473. start_date: '',
  474. end_date: '',
  475. },
  476. ];
  477. this.searchOptions = [];
  478. this.formula = '';
  479. this.resultData = [];
  480. this.formulaList = [
  481. { formula: '' }
  482. ]
  483. this.nullValueForm = {
  484. nullValueWay: 0,
  485. maxNullWay: 1
  486. }
  487. },
  488. cancelHandle() {
  489. this.init();
  490. this.$emit('update:isOpenDialog',false);
  491. },
  492. },
  493. mounted() {},
  494. };
  495. </script>
  496. <style lang="scss">
  497. .dynamic-differ-dialog {
  498. overflow: hidden;
  499. div::-webkit-scrollbar {
  500. width: 6px !important;
  501. }
  502. .el-dialog__body {
  503. max-height: 700px;
  504. overflow: auto;
  505. }
  506. .dialog-main {
  507. padding: 25px 42px 25px 25px;
  508. .el-cascader .el-input {
  509. width: 340px;
  510. }
  511. .add-cont {
  512. display: flex;
  513. flex-wrap: wrap;
  514. justify-content: space-between;
  515. .add-li {
  516. position: relative;
  517. margin-bottom: 48px;
  518. .li-tag {
  519. font-size: 16px;
  520. margin-right: 8px;
  521. }
  522. .del-tag {
  523. position: absolute;
  524. right: -30px;
  525. top: 12px;
  526. font-size: 16px;
  527. cursor: pointer;
  528. }
  529. .target-date {
  530. color: #5882ef;
  531. position: absolute;
  532. bottom: -25px;
  533. left: 24px;
  534. }
  535. }
  536. }
  537. .add-icon {
  538. font-size: 16px;
  539. color: #5882ef;
  540. cursor: pointer;
  541. }
  542. .computed-min {
  543. margin: 50px 0;
  544. .example-txt {
  545. display: block;
  546. margin-top: 10px;
  547. }
  548. .computed-section {
  549. display: flex;
  550. margin-top: 20px;
  551. }
  552. .label {
  553. padding:10px 10px 10px 0;
  554. }
  555. .formula-item {
  556. display: flex;
  557. align-items: center;
  558. margin-bottom: 15px;
  559. }
  560. .date-section-text {
  561. margin-left: 15px;
  562. }
  563. }
  564. }
  565. .dia-bot {
  566. padding-bottom: 40px;
  567. display: flex;
  568. justify-content: center;
  569. }
  570. }
  571. </style>