dynamicRingdiffer.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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="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. {{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="等于0" :value="1" />
  107. <el-option label="跳过空值" :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. },
  227. watch: {
  228. isOpenDialog(newval) {
  229. /* 回显 */
  230. if (this.edbList.length && newval) {
  231. this.addList = _.cloneDeep(this.edbList);
  232. const{ formulaList,nullValueWay,maxNullWay } = this.info;
  233. this.formulaList = JSON.parse(formulaList).map(_=>({
  234. formula: _.f,
  235. date: _.d
  236. }));
  237. this.nullValueForm = {
  238. nullValueWay,
  239. maxNullWay
  240. }
  241. this.searchOptions = this.edbList.map(item => ({
  242. EdbInfoId: item.target,
  243. EdbName: item.name,
  244. }))
  245. }
  246. },
  247. },
  248. data() {
  249. return {
  250. addList: [
  251. {
  252. tag: tag_arr[0],
  253. name: '',
  254. target: '',
  255. start_date: '',
  256. end_date: '',
  257. },
  258. {
  259. tag: tag_arr[1],
  260. name: '',
  261. target: '',
  262. start_date: '',
  263. end_date: '',
  264. },
  265. {
  266. tag: tag_arr[2],
  267. name: '',
  268. target: '',
  269. start_date: '',
  270. end_date: '',
  271. },
  272. {
  273. tag: tag_arr[3],
  274. name: '',
  275. target: '',
  276. start_date: '',
  277. end_date: '',
  278. },
  279. ],
  280. searchOptions: [],
  281. formula: '', //计算公式
  282. dataloading: false,
  283. search_have_more: false,
  284. search_page: 1,
  285. current_search:'',
  286. formulaList: [
  287. { formula: '', }
  288. ],
  289. nullValueForm: {
  290. nullValueWay: 0,
  291. maxNullWay: 1
  292. },//空值处理
  293. nullWayOptions: [
  294. { label: '查找前后35天最近值',value: 0 },
  295. { label: '不计算',value: 1 },
  296. { label: '前值填充',value: 2 },
  297. { label: '后值填充',value: 3 },
  298. { label: '等于0',value: 4 },
  299. ],
  300. formTips: {
  301. 'null-val': `1、查找前后35天最近值:在参与计算的日期序列上某指标无值时,该指标往前/往后找距离最近的值作为当天的值进行计算,遍历允许跨年,往前最多35天,往后最多35天<br>
  302. 2、不计算:只要有一个指标在某个日期没有值(即空值),则计算指标在该日期没有值 <br>
  303. 3、前值填充:空值优先以最近的前值填充,没有前值时,用后值填充 <br>
  304. 4、后值填充:空值优先以最近的后值填充,没有前值时,用后值填充 <br>
  305. 5、等于0:空值以0值参与计算 <br>
  306. 注意:此处缺失值的处理,作用于数据全部时间段`,
  307. 'max-null-val': `MAX、MIN公式中指标存在空值时按如下规则处理:<br>
  308. 1、等于0,空值用0参与计算;<br>
  309. 2、跳过空值,去除空值指标,剩余指标进行计算,若该日期所有指标均为空值,则该日期无值;`,
  310. 'formula':`1、支持新增分段,实现不同分段使用不同的计算公式,若未新增分段,则所有日期序列用统一公式计算<br>
  311. 2、新增分段需配置新公式和时间节点,在时间节点之前(不含)使用新公式,在时间节点之后(含)使用已配置公式,每个分段公式支持修改<br>
  312. 3、分段时间节点不允许重复,不允许超出第一个指标的日期区间`
  313. },
  314. resultData: [],//
  315. };
  316. },
  317. methods: {
  318. /* 添加额外的指标列 */
  319. addTargetHandle() {
  320. let tag = this.addList[this.addList.length-1].tag;
  321. let index = tag_arr.findIndex(item => item === tag);
  322. const item = {
  323. tag: tag_arr[index+1],
  324. target: '',
  325. name: '',
  326. start_date: '',
  327. end_date: ''
  328. };
  329. this.addList.push(item);
  330. },
  331. /* 搜索指标 */
  332. searchTarget(query) {
  333. this.search_page = 1;
  334. this.current_search = query;
  335. this.searchApi(this.current_search);
  336. },
  337. /* 聚焦获取当前检索 */
  338. inputFocusHandle(e) {
  339. this.search_page = 1;
  340. this.current_search = e.target.value;
  341. this.searchApi(this.current_search);
  342. },
  343. searchApi(query,page=1) {
  344. preDictEdbInterface
  345. .edbSearch({
  346. Keyword: query,
  347. CurrentIndex: page
  348. })
  349. .then((res) => {
  350. if (res.Ret !== 200) return
  351. const { List,Paging } = res.Data;
  352. this.search_have_more = page < Paging.Pages;
  353. this.searchOptions = page === 1 ? List : this.searchOptions.concat(List);
  354. });
  355. },
  356. searchLoad() {
  357. if(!this.search_have_more) return;
  358. this.searchApi(this.current_search,++this.search_page)
  359. },
  360. /* 选中指标 显示开始日期结束日期 */
  361. chooseTarget(val) {
  362. if (val) {
  363. const choose_obj = this.searchOptions.find(
  364. (item) => item.EdbInfoId === val
  365. );
  366. this.addList.forEach((list) => {
  367. if (list.target === val) {
  368. list.name = choose_obj.EdbName;
  369. list.start_date = choose_obj.StartDate;
  370. list.end_date = choose_obj.EndDate;
  371. }
  372. });
  373. }
  374. },
  375. /* 清空指标和关联日期 */
  376. clearHandle(index) {
  377. this.addList[index].start_date = '';
  378. this.addList[index].end_date = '';
  379. this.addList[index].name = '';
  380. },
  381. // 删除指标
  382. delTarget(index) {
  383. this.addList.splice(index, 1);
  384. },
  385. saveHandle() {
  386. if (!this.formulaList[0].formula) return this.$message.warning(/* '计算公式不能为空' */this.$t('EtaBasePage.input_formula_valid'));
  387. // 指标id数组
  388. let target_arr = this.addList.filter(item => item.target);
  389. let formula = JSON.stringify(this.formulaList
  390. .filter((_,index) => index===0||(index>0&&_.formula&&_.date))
  391. .map(_ => ({f: _.formula,d: _.date}))
  392. )
  393. this.$emit('ensureBack',{arr:target_arr,formula,...this.nullValueForm})
  394. this.cancelHandle();
  395. },
  396. /* 获取数据 */
  397. async getResult() {
  398. if (!this.formulaList[0].formula) return this.$message.warning(/* '计算公式不能为空' */this.$t('EtaBasePage.input_formula_valid'));
  399. let EdbInfoIdArr = this.addList.filter(_ => _.target).map(_ => ({
  400. EdbInfoId: _.target,
  401. FromTag: _.tag
  402. }))
  403. const { nullValueWay,maxNullWay } = this.nullValueForm;
  404. let formula = JSON.stringify(this.formulaList
  405. .filter((_,index) => index===0||(index>0&&_.formula&&_.date))
  406. .map(_ => ({f: _.formula,d: _.date}))
  407. )
  408. const params = {
  409. RuleType: 9,
  410. EndDate: '',
  411. Value: formula,
  412. EmptyType: nullValueWay,
  413. MaxEmptyType: maxNullWay,
  414. EdbInfoIdArr
  415. }
  416. const { Ret,Data } = await preDictEdbInterface.getRuleNineData(params);
  417. if(Ret !== 200) return
  418. this.resultData = Data.DataList.map(_ => ({
  419. ..._,
  420. isPredict: _.DataTimestamp > this.$moment(Data.LatestDate+' 8:00').valueOf()
  421. })) || [];
  422. },
  423. /* 新增公式分段 */
  424. addFormulaHandle() {
  425. let addItem = {
  426. formula: this.formulaList[this.formulaList.length-1].formula,
  427. date: ''
  428. }
  429. this.formulaList.push(addItem)
  430. },
  431. /* 移除公式 */
  432. removeFormulaItem(index) {
  433. this.formulaList.splice(index,1)
  434. },
  435. /* 选择日期 检验 */
  436. selectFormulaDate(val,item) {
  437. const { start_date,end_date } = this.addList[0];
  438. if(!start_date) return
  439. let dateStamp = new Date(val).getTime(),
  440. startStamp = new Date(start_date).getTime(),
  441. endStamp = new Date(end_date).getTime();
  442. if (dateStamp > endStamp || dateStamp < startStamp) {
  443. item.date = '';
  444. return this.$message.warning('分段日期必须在第一个指标日期区间')
  445. }
  446. else if(this.formulaList.filter(_ => _.date===val).length>1) {
  447. item.date = '';
  448. return this.$message.warning('分段日期不可重复')
  449. }
  450. },
  451. init() {
  452. this.addList = [
  453. {
  454. tag: tag_arr[0],
  455. name: '',
  456. target: '',
  457. start_date: '',
  458. end_date: '',
  459. },
  460. {
  461. tag: tag_arr[1],
  462. name: '',
  463. target: '',
  464. start_date: '',
  465. end_date: '',
  466. },
  467. {
  468. tag: tag_arr[2],
  469. name: '',
  470. target: '',
  471. start_date: '',
  472. end_date: '',
  473. },
  474. {
  475. tag: tag_arr[3],
  476. name: '',
  477. target: '',
  478. start_date: '',
  479. end_date: '',
  480. },
  481. ];
  482. this.searchOptions = [];
  483. this.formula = '';
  484. this.resultData = [];
  485. this.formulaList = [
  486. { formula: '' }
  487. ]
  488. this.nullValueForm = {
  489. nullValueWay: 0,
  490. maxNullWay: 1
  491. }
  492. },
  493. cancelHandle() {
  494. this.init();
  495. this.$emit('update:isOpenDialog',false);
  496. },
  497. },
  498. mounted() {},
  499. };
  500. </script>
  501. <style lang="scss">
  502. .dynamic-differ-dialog {
  503. overflow: hidden;
  504. div::-webkit-scrollbar {
  505. width: 6px !important;
  506. }
  507. .el-dialog__body {
  508. max-height: 700px;
  509. overflow: auto;
  510. }
  511. .dialog-main {
  512. padding: 25px 42px 25px 25px;
  513. .el-cascader .el-input {
  514. width: 340px;
  515. }
  516. .add-cont {
  517. display: flex;
  518. flex-wrap: wrap;
  519. justify-content: space-between;
  520. .add-li {
  521. position: relative;
  522. margin-bottom: 48px;
  523. .li-tag {
  524. font-size: 16px;
  525. margin-right: 8px;
  526. }
  527. .del-tag {
  528. position: absolute;
  529. right: -30px;
  530. top: 12px;
  531. font-size: 16px;
  532. cursor: pointer;
  533. }
  534. .target-date {
  535. color: #5882ef;
  536. position: absolute;
  537. bottom: -25px;
  538. left: 24px;
  539. }
  540. }
  541. }
  542. .add-icon {
  543. font-size: 16px;
  544. color: #5882ef;
  545. cursor: pointer;
  546. }
  547. .computed-min {
  548. margin: 50px 0;
  549. .example-txt {
  550. display: block;
  551. margin-top: 10px;
  552. }
  553. .computed-section {
  554. display: flex;
  555. margin-top: 20px;
  556. }
  557. .label {
  558. padding:10px 10px 10px 0;
  559. }
  560. .formula-item {
  561. display: flex;
  562. align-items: center;
  563. margin-bottom: 15px;
  564. }
  565. .date-section-text {
  566. margin-left: 15px;
  567. }
  568. }
  569. }
  570. .dia-bot {
  571. padding-bottom: 40px;
  572. display: flex;
  573. justify-content: center;
  574. }
  575. }
  576. </style>