dynamicRingdiffer.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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">{{ title }}</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="请输入指标名称"
  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. >
  40. </el-option>
  41. </el-select>
  42. <i
  43. class="el-icon-error del-tag"
  44. v-if="index > 3"
  45. @click="delTarget(index)"
  46. />
  47. <span class="target-date" v-if="list.start_date">{{
  48. `${list.start_date}至${list.end_date}`
  49. }}</span>
  50. </li>
  51. </ul>
  52. <span class="add-icon" @click="addTargetHandle">
  53. <i
  54. class="el-icon-circle-plus-outline"
  55. style="color: #5882ef; font-size: 16px"
  56. />
  57. 添加更多参数
  58. </span>
  59. <div class="computed-min">
  60. <div class="computed-top">
  61. <span>计算公式</span>
  62. <el-input placeholder="请输入公式" v-model="formula" clearable style="margin: 0 8px"/>
  63. <el-button type="primary" @click="getResult">一键计算</el-button>
  64. </div>
  65. <span class="example-txt"
  66. >公式示例:A*0.5+B*C*1.2+120-MAX(A,B,C)</span
  67. >
  68. <span class="example-txt">函数支持:MAX(),MIN()</span>
  69. </div>
  70. <el-table
  71. border
  72. :data="resultData"
  73. v-if="resultData.length"
  74. max-height="320"
  75. >
  76. <el-table-column
  77. v-for="item in tableColums"
  78. :key="item.label"
  79. :label="item.label"
  80. :width="item.widthsty"
  81. :min-width="item.minwidthsty"
  82. align="center"
  83. >
  84. <template slot-scope="scope">
  85. <span :style="scope.row.isPredict&&'color: orange'">{{ scope.row[item.key] }}</span>
  86. </template>
  87. </el-table-column>
  88. <div slot="empty" style="padding:20px 0 30px;">
  89. <tableNoData text="暂无指标" size="mini"/>
  90. </div>
  91. </el-table>
  92. </div>
  93. <div class="dia-bot">
  94. <el-button
  95. type="primary"
  96. style="margin-right: 20px"
  97. @click="saveHandle"
  98. >保存</el-button
  99. >
  100. <el-button type="primary" plain @click="cancelHandle">取消</el-button>
  101. </div>
  102. </el-dialog>
  103. </template>
  104. <script>
  105. import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
  106. const tag_arr = [];
  107. for(var i=0;i<26;i++) tag_arr.push(String.fromCharCode(65+i));
  108. export default {
  109. name: '',
  110. props: {
  111. isOpenDialog: {
  112. type: Boolean,
  113. },
  114. title: {
  115. type: String,
  116. default: '设置环比增加值',
  117. },
  118. dialog_formula: {
  119. type: String,
  120. },
  121. edbList: {
  122. type: Array,
  123. },
  124. },
  125. watch: {
  126. isOpenDialog(newval) {
  127. /* 回显 */
  128. if (this.edbList.length && newval) {
  129. this.addList = _.cloneDeep(this.edbList);
  130. this.formula = this.dialog_formula;
  131. this.searchOptions = this.edbList.map(item => ({
  132. EdbInfoId: item.target,
  133. EdbName: item.name,
  134. }))
  135. }
  136. },
  137. },
  138. data() {
  139. return {
  140. addList: [
  141. {
  142. tag: tag_arr[0],
  143. name: '',
  144. target: '',
  145. start_date: '',
  146. end_date: '',
  147. },
  148. {
  149. tag: tag_arr[1],
  150. name: '',
  151. target: '',
  152. start_date: '',
  153. end_date: '',
  154. },
  155. {
  156. tag: tag_arr[2],
  157. name: '',
  158. target: '',
  159. start_date: '',
  160. end_date: '',
  161. },
  162. {
  163. tag: tag_arr[3],
  164. name: '',
  165. target: '',
  166. start_date: '',
  167. end_date: '',
  168. },
  169. ],
  170. searchOptions: [],
  171. formula: '', //计算公式
  172. dataloading: false,
  173. search_have_more: false,
  174. search_page: 1,
  175. current_search:'',
  176. tableColums: [
  177. {
  178. label: '日期',
  179. key: 'DataTime',
  180. },
  181. {
  182. label: '环比增加值',
  183. key: 'Value',
  184. },
  185. ],
  186. resultData: [],//
  187. };
  188. },
  189. methods: {
  190. /* 添加额外的指标列 */
  191. addTargetHandle() {
  192. let tag = this.addList[this.addList.length-1].tag;
  193. let index = tag_arr.findIndex(item => item === tag);
  194. const item = {
  195. tag: tag_arr[index+1],
  196. target: '',
  197. name: '',
  198. start_date: '',
  199. end_date: ''
  200. };
  201. this.addList.push(item);
  202. },
  203. /* 搜索指标 */
  204. searchTarget(query) {
  205. this.search_page = 1;
  206. this.current_search = query;
  207. this.searchApi(this.current_search);
  208. },
  209. /* 聚焦获取当前检索 */
  210. inputFocusHandle(e) {
  211. this.search_page = 1;
  212. this.current_search = e.target.value;
  213. this.searchApi(this.current_search);
  214. },
  215. searchApi(query,page=1) {
  216. preDictEdbInterface
  217. .edbSearch({
  218. Keyword: query,
  219. CurrentIndex: page
  220. })
  221. .then((res) => {
  222. if (res.Ret !== 200) return
  223. const { List,Paging } = res.Data;
  224. this.search_have_more = page < Paging.Pages;
  225. this.searchOptions = page === 1 ? List : this.searchOptions.concat(List);
  226. });
  227. },
  228. searchLoad() {
  229. if(!this.search_have_more) return;
  230. this.searchApi(this.current_search,++this.search_page)
  231. },
  232. /* 选中指标 显示开始日期结束日期 */
  233. chooseTarget(val) {
  234. if (val) {
  235. const choose_obj = this.searchOptions.find(
  236. (item) => item.EdbInfoId === val
  237. );
  238. this.addList.forEach((list) => {
  239. if (list.target === val) {
  240. list.name = choose_obj.EdbName;
  241. list.start_date = choose_obj.StartDate;
  242. list.end_date = choose_obj.EndDate;
  243. }
  244. });
  245. }
  246. },
  247. /* 清空指标和关联日期 */
  248. clearHandle(index) {
  249. this.addList[index].start_date = '';
  250. this.addList[index].end_date = '';
  251. this.addList[index].name = '';
  252. },
  253. // 删除指标
  254. delTarget(index) {
  255. this.addList.splice(index, 1);
  256. },
  257. saveHandle() {
  258. if (!this.formula) return this.$message.warning('计算公式不能为空');
  259. // 指标id数组
  260. let target_arr = this.addList.filter(item => item.target);
  261. this.$emit('ensureBack',{arr:target_arr,formula: this.formula})
  262. this.cancelHandle();
  263. },
  264. /* 获取数据 */
  265. async getResult() {
  266. if (!this.formula) return this.$message.warning('计算公式不能为空');
  267. let EdbInfoIdArr = this.addList.filter(_ => _.target).map(_ => ({
  268. EdbInfoId: _.target,
  269. FromTag: _.tag
  270. }))
  271. const params = {
  272. RuleType: 9,
  273. EndDate: '',
  274. Value: this.formula,
  275. EdbInfoIdArr
  276. }
  277. const { Ret,Data } = await preDictEdbInterface.getRuleNineData(params);
  278. if(Ret !== 200) return
  279. this.resultData = Data.DataList.map(_ => ({
  280. ..._,
  281. isPredict: _.DataTimestamp > this.$moment(Data.LatestDate+' 8:00').valueOf()
  282. })) || [];
  283. },
  284. init() {
  285. this.addList = [
  286. {
  287. tag: tag_arr[0],
  288. name: '',
  289. target: '',
  290. start_date: '',
  291. end_date: '',
  292. },
  293. {
  294. tag: tag_arr[1],
  295. name: '',
  296. target: '',
  297. start_date: '',
  298. end_date: '',
  299. },
  300. {
  301. tag: tag_arr[2],
  302. name: '',
  303. target: '',
  304. start_date: '',
  305. end_date: '',
  306. },
  307. {
  308. tag: tag_arr[3],
  309. name: '',
  310. target: '',
  311. start_date: '',
  312. end_date: '',
  313. },
  314. ];
  315. this.searchOptions = [];
  316. this.formula = '';
  317. this.resultData = [];
  318. },
  319. cancelHandle() {
  320. this.init();
  321. this.$emit('update:isOpenDialog',false);
  322. },
  323. },
  324. mounted() {},
  325. };
  326. </script>
  327. <style lang="scss">
  328. .dynamic-differ-dialog {
  329. overflow: hidden;
  330. div::-webkit-scrollbar {
  331. width: 6px !important;
  332. }
  333. .el-dialog__body {
  334. max-height: 700px;
  335. overflow: auto;
  336. }
  337. .dialog-main {
  338. padding: 25px 42px 25px 25px;
  339. .el-cascader .el-input {
  340. width: 340px;
  341. }
  342. .add-cont {
  343. display: flex;
  344. flex-wrap: wrap;
  345. justify-content: space-between;
  346. .add-li {
  347. position: relative;
  348. margin-bottom: 48px;
  349. .li-tag {
  350. font-size: 16px;
  351. margin-right: 8px;
  352. }
  353. .del-tag {
  354. position: absolute;
  355. right: -30px;
  356. top: 12px;
  357. font-size: 16px;
  358. cursor: pointer;
  359. }
  360. .target-date {
  361. color: #5882ef;
  362. position: absolute;
  363. bottom: -25px;
  364. left: 24px;
  365. }
  366. }
  367. }
  368. .add-icon {
  369. font-size: 16px;
  370. color: #5882ef;
  371. cursor: pointer;
  372. }
  373. .computed-min {
  374. margin: 50px 0;
  375. .example-txt {
  376. display: block;
  377. margin-left: 70px;
  378. margin-top: 15px;
  379. }
  380. }
  381. }
  382. .dia-bot {
  383. padding-bottom: 40px;
  384. display: flex;
  385. justify-content: center;
  386. }
  387. }
  388. </style>