computedDialog.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <el-dialog
  3. :visible.sync="isOpenComputed"
  4. :close-on-click-modal="false"
  5. :modal-append-to-body="false"
  6. @close="cancelHandle"
  7. custom-class="computed-dialog"
  8. center
  9. width="1090px"
  10. top="8vh"
  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">{{ title }}</span>
  19. </div>
  20. <div class="dialog-main">
  21. <ul class="add-cont">
  22. <li class="add-li" v-for="(list, index) in addList" :key="index">
  23. <span class="li-tag">{{ list.tag }}</span>
  24. <el-select
  25. v-model="list.target"
  26. v-loadMore="searchLoad"
  27. :filterable="!list.target"
  28. clearable
  29. placeholder="请输入指标名称"
  30. style="width: 400px"
  31. @change="chooseTarget"
  32. @clear="clearHandle(index)"
  33. :disabled="calulateForm.view"
  34. remote
  35. :remote-method="searchTarget"
  36. @click.native="inputFocusHandle"
  37. >
  38. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  39. <el-option
  40. v-for="item in searchOptions"
  41. :key="item.EdbInfoId"
  42. :label="$parent.currentLang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName"
  43. :value="item.EdbInfoId"
  44. >
  45. <edbDetailPopover :info="item">
  46. <div slot="reference">{{$parent.currentLang==='en'?(item.EdbNameEn||item.EdbName):item.EdbName}}</div>
  47. </edbDetailPopover>
  48. </el-option>
  49. </el-select>
  50. <i class="el-icon-tickets" style="color:#409EFF;font-size:18px" @click="$emit('lookHistory',list.target)" v-if="list.target"/>
  51. <i
  52. class="el-icon-error del-tag"
  53. v-if="index > 3 && !calulateForm.view"
  54. @click="delTarget(index)"
  55. />
  56. <span :class="{
  57. 'target-date': true,
  58. 'newest': list.end_date===newestDate
  59. }" v-if="list.start_date">{{
  60. `${list.start_date}至${list.end_date}`
  61. }}</span>
  62. </li>
  63. </ul>
  64. <span class="add-icon" @click="addTargetHandle" v-if="!calulateForm.view">
  65. <i
  66. class="el-icon-circle-plus-outline"
  67. style="color: #5882ef; font-size: 16px"
  68. />
  69. 添加更多参数
  70. </span>
  71. <div class="computed-min">
  72. <div class="computed-top">
  73. <span style="margin-right: 8px">计算公式</span>
  74. <el-input placeholder="请输入公式" v-model="formula" clearable :disabled="calulateForm.view">
  75. </el-input>
  76. </div>
  77. <span class="example-txt"
  78. >公式示例:A*0.5+B*C*1.2+120-MAX(A,B,C)</span
  79. >
  80. <span class="example-txt">函数支持:MAX(),MIN(),ln(A),log(a,A)</span>
  81. </div>
  82. <el-form
  83. ref="diaForm"
  84. label-position="right"
  85. inline
  86. label-width="80px"
  87. :model="formData"
  88. :rules="formRules"
  89. :disabled="calulateForm.view"
  90. >
  91. <el-form-item label="指标名称" prop="targetName">
  92. <el-input
  93. v-model="formData.targetName"
  94. style="width: 340px"
  95. placeholder="请输入指标名称"
  96. />
  97. </el-form-item>
  98. <el-form-item label="单位" prop="unit">
  99. <selectUnit v-model="formData.unit" style="width: 340px" />
  100. </el-form-item>
  101. <el-form-item label="指标目录" prop="menu">
  102. <el-cascader
  103. v-model="formData.menu"
  104. :options="options"
  105. :props="levelProps"
  106. clearable
  107. placeholder="请选择指标目录"
  108. />
  109. </el-form-item>
  110. <el-form-item label="频度" prop="frequency">
  111. <el-select
  112. v-model="formData.frequency"
  113. placeholder="请选择频率"
  114. style="width: 340px"
  115. clearable
  116. >
  117. <el-option
  118. v-for="item in frequencyArr"
  119. :key="item"
  120. :label="item"
  121. :value="item"
  122. >
  123. </el-option>
  124. </el-select>
  125. </el-form-item>
  126. </el-form>
  127. </div>
  128. <div class="dia-bot" v-if="!calulateForm.view">
  129. <el-button
  130. type="primary"
  131. style="margin-right: 20px"
  132. @click="saveHandle"
  133. :loading="dataloading"
  134. v-if="title==='计算指标'"
  135. >生成计算指标</el-button
  136. >
  137. <el-button
  138. type="primary"
  139. style="margin-right: 20px"
  140. @click="saveHandle"
  141. v-else
  142. >保存</el-button
  143. >
  144. <el-button type="primary" plain @click="cancelHandle('cancel')">取消</el-button>
  145. </div>
  146. <el-popover
  147. placement="top-start"
  148. width="360"
  149. trigger="click">
  150. <p style="padding:30px;line-height:25px;" v-html="$parent.tips.get(type)"/>
  151. <span slot="reference" class="tip-label">公式说明</span>
  152. </el-popover>
  153. </el-dialog>
  154. </template>
  155. <script>
  156. import { dataBaseInterface } from '@/api/api.js';
  157. import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
  158. import { formRules } from '../databaseComponents/util';
  159. import { unitArr } from '@/utils/defaultOptions';
  160. const tag_arr = [];
  161. for(let i=0;i<26;i++) tag_arr.push(String.fromCharCode(65+i));
  162. export default {
  163. name: '',
  164. props: {
  165. isOpenComputed: {
  166. type: Boolean,
  167. },
  168. title: {
  169. type: String,
  170. default: '计算指标',
  171. },
  172. calulateForm: {
  173. type: Object,
  174. },
  175. calulateList: {
  176. type: Array,
  177. },
  178. edbSource: { // ''||'predict'
  179. type: String,
  180. default: ''
  181. }
  182. },
  183. computed: {
  184. type() {
  185. return this.edbSource ? 31 : 4;
  186. }
  187. },
  188. watch: {
  189. isOpenComputed(newval) {
  190. newval && this.getMenu();
  191. // newval && this.searchTarget('');
  192. /* 回显 */
  193. if (this.calulateList.length && newval) {
  194. this.addList = _.cloneDeep(this.calulateList);
  195. this.formula = this.calulateForm.formula;
  196. this.formData = {
  197. targetName: this.calulateForm.targetName,
  198. unit: this.calulateForm.unit,
  199. menu: this.calulateForm.menu,
  200. frequency: this.calulateForm.frequency,
  201. };
  202. this.searchOptions = this.calulateList.map(item => ({
  203. EdbInfoId: item.target,
  204. EdbName: item.edb_name,
  205. }))
  206. this.getNewestDate();
  207. }
  208. },
  209. },
  210. data() {
  211. return {
  212. options: [],
  213. levelProps: {
  214. label: 'ClassifyName',
  215. value: 'ClassifyId',
  216. children: 'Children',
  217. checkStrictly: true
  218. },
  219. frequencyArr: ['日度', '周度','旬度','月度', '季度', '年度'],
  220. formRules,
  221. unitArr,
  222. addList: [
  223. {
  224. tag: tag_arr[0],
  225. target: '',
  226. start_date: '',
  227. end_date: '',
  228. },
  229. {
  230. tag: tag_arr[1],
  231. target: '',
  232. start_date: '',
  233. end_date: '',
  234. },
  235. {
  236. tag: tag_arr[2],
  237. target: '',
  238. start_date: '',
  239. end_date: '',
  240. },
  241. {
  242. tag: tag_arr[3],
  243. target: '',
  244. start_date: '',
  245. end_date: '',
  246. },
  247. ],
  248. searchOptions: [],
  249. formula: '', //计算公式
  250. dataloading: false,
  251. formData: {
  252. targetName: '',
  253. unit: '',
  254. menu: '',
  255. frequency: '',
  256. },
  257. search_have_more: false,
  258. search_page: 1,
  259. current_search:'',
  260. newestDate: ''
  261. };
  262. },
  263. methods: {
  264. /* 获取目录结构 */
  265. async getMenu() {
  266. const res = this.edbSource === 'predict'
  267. ? await preDictEdbInterface.classifyListV2()
  268. : await dataBaseInterface.menuListV3()
  269. if (res.Ret !== 200) return
  270. this.filterNodes(res.Data.AllNodes||[]);
  271. this.options = res.Data.AllNodes || [];
  272. },
  273. // 递归改变第三级目录结构
  274. filterNodes(arr) {
  275. arr.length &&
  276. arr.forEach((item) => {
  277. item.Children.length && this.filterNodes(item.Children);
  278. if (!item.Children.length) {
  279. delete item.Children;
  280. }
  281. });
  282. },
  283. /* 添加额外的指标列 */
  284. addTargetHandle() {
  285. if(this.addList.length >= 26) return this.$message.warning('添加指标个数已达上限')
  286. let tag = this.addList[this.addList.length-1].tag;
  287. let index = tag_arr.findIndex(item => item === tag);
  288. const item = {
  289. tag: tag_arr[index+1],
  290. target: '',
  291. start_date: '',
  292. end_date: ''
  293. };
  294. this.addList.push(item);
  295. },
  296. /* 搜索指标 */
  297. searchTarget(query) {
  298. this.search_page = 1;
  299. this.current_search = query;
  300. this.searchApi(this.current_search);
  301. },
  302. /* 聚焦获取当前检索 */
  303. inputFocusHandle(e) {
  304. this.search_page = 1;
  305. this.current_search = e.target.value;
  306. this.searchApi(this.current_search);
  307. },
  308. async searchApi(query,page=1) {
  309. const res = this.edbSource === 'predict'
  310. ? await preDictEdbInterface.edbSearch({
  311. Keyword: query,
  312. CurrentIndex: page,
  313. FilterSource: this.type === 45 ? 3 : this.type === 66 ? 6 : 1,
  314. Frequency: this.type===64?'季度': ''
  315. })
  316. : await dataBaseInterface.targetSearchByPage({
  317. KeyWord:query,
  318. CurrentIndex: page,
  319. FilterSource: this.type === 14 ? 3 : this.type === 63 ? 6 : 1,
  320. Frequency: this.type===61?'季度': ''
  321. })
  322. if(res.Ret !== 200) return
  323. const { List,Paging } = res.Data;
  324. this.search_have_more = page < Paging.Pages;
  325. this.searchOptions = page === 1 ? List : this.searchOptions.concat(List);
  326. },
  327. searchLoad() {
  328. if(!this.search_have_more) return;
  329. this.searchApi(this.current_search,++this.search_page)
  330. },
  331. /* 选中指标 显示开始日期结束日期 */
  332. chooseTarget(val) {
  333. if (val) {
  334. const choose_obj = this.searchOptions.find(
  335. (item) => item.EdbInfoId === val
  336. );
  337. this.addList.forEach((list) => {
  338. if (list.target === val) {
  339. list.start_date = choose_obj.StartDate;
  340. list.end_date = choose_obj.EndDate;
  341. this.getNewestDate();
  342. }
  343. });
  344. }
  345. },
  346. /* 获取所选日期最早日期 */
  347. getNewestDate() {
  348. let dateArr = this.addList.filter(_ => _.end_date).map(_ => new Date(_.end_date).getTime())
  349. let earliestDate = Math.min(...dateArr);
  350. let sameDateArr = dateArr.filter(_ => _===earliestDate)
  351. if(dateArr.length === 1 || sameDateArr.length===dateArr.length) {
  352. this.newestDate = '';
  353. return
  354. }
  355. this.newestDate = this.$moment(Math.min(...dateArr)).format('YYYY-MM-DD');
  356. },
  357. /* 清空指标和关联日期 */
  358. clearHandle(index) {
  359. this.addList[index].start_date = '';
  360. this.addList[index].end_date = '';
  361. this.getNewestDate();
  362. },
  363. // 删除指标
  364. delTarget(index) {
  365. this.addList.splice(index, 1);
  366. this.getNewestDate();
  367. },
  368. async saveHandle() {
  369. if (!this.formula) return this.$message.warning('计算公式不能为空');
  370. await this.$refs.diaForm.validate();
  371. // 指标id数组
  372. let target_arr = this.addList
  373. .filter((item) => item.target)
  374. .map((item) => {
  375. return {
  376. EdbInfoId: item.target,
  377. FromTag: item.tag,
  378. };
  379. });
  380. let params = {
  381. CalculateFormula: this.formula,
  382. ClassifyId: this.formData.menu[this.formData.menu.length - 1] || 0,
  383. EdbName: this.formData.targetName,
  384. Frequency: this.formData.frequency,
  385. Unit: this.formData.unit,
  386. EdbInfoIdArr: target_arr,
  387. };
  388. this.dataloading = true;
  389. let res;
  390. if(this.edbSource === 'predict') {
  391. res = await preDictEdbInterface.calculateEdbSave(this.calulateForm.edb_id ? {...params,EdbInfoId:this.calulateForm.edb_id } : params)
  392. }else {
  393. res = this.calulateForm.edb_id
  394. ? await dataBaseInterface.calculateEdit({...params,EdbInfoId: this.calulateForm.edb_id})
  395. : await dataBaseInterface.calculateAdd(params)
  396. }
  397. this.dataloading = false;
  398. if (res.Ret !== 200) return
  399. this.$message.success(res.Msg);
  400. this.calulateForm.edb_id
  401. ? this.$emit('addCallBack','edit')
  402. : this.$emit('addCallBack','add',{ code:res.Data.UniqueCode,id:res.Data.EdbInfoId,classifyId:params.ClassifyId });
  403. this.init();
  404. },
  405. init() {
  406. this.$refs.diaForm.resetFields();
  407. this.addList = [
  408. {
  409. tag: tag_arr[0],
  410. target: '',
  411. start_date: '',
  412. end_date: '',
  413. },
  414. {
  415. tag: tag_arr[1],
  416. target: '',
  417. start_date: '',
  418. end_date: '',
  419. },
  420. {
  421. tag: tag_arr[2],
  422. target: '',
  423. start_date: '',
  424. end_date: '',
  425. },
  426. {
  427. tag: tag_arr[3],
  428. target: '',
  429. start_date: '',
  430. end_date: '',
  431. },
  432. ];
  433. this.searchOptions = [];
  434. this.formula = '';
  435. this.formData = {
  436. targetName: '',
  437. unit: '',
  438. menu: '',
  439. frequency: '',
  440. };
  441. },
  442. cancelHandle(type) {
  443. this.init();
  444. this.$emit('cancel');
  445. type==='cancel' && !this.calulateForm.edb_id && this.$emit('openPrev');
  446. },
  447. },
  448. created() {},
  449. mounted() {},
  450. };
  451. </script>
  452. <style lang="scss">
  453. .computed-dialog {
  454. overflow: hidden;
  455. div::-webkit-scrollbar {
  456. width: 6px !important;
  457. }
  458. .el-dialog__body {
  459. max-height: 700px;
  460. overflow: auto;
  461. }
  462. .dialog-main {
  463. padding: 25px 42px 25px 25px;
  464. .el-cascader .el-input {
  465. width: 340px;
  466. }
  467. .add-cont {
  468. display: flex;
  469. flex-wrap: wrap;
  470. justify-content: space-between;
  471. .add-li {
  472. position: relative;
  473. margin-bottom: 48px;
  474. .li-tag {
  475. font-size: 16px;
  476. margin-right: 8px;
  477. }
  478. .del-tag {
  479. position: absolute;
  480. right: -30px;
  481. top: 12px;
  482. font-size: 16px;
  483. cursor: pointer;
  484. }
  485. .target-date {
  486. color: #5882ef;
  487. position: absolute;
  488. bottom: -25px;
  489. left: 24px;
  490. &.newest {
  491. color: #f00;
  492. }
  493. }
  494. }
  495. }
  496. .add-icon {
  497. font-size: 16px;
  498. color: #5882ef;
  499. cursor: pointer;
  500. }
  501. .computed-min {
  502. margin: 50px 0;
  503. padding-bottom: 40px;
  504. border-bottom: 1px dashed #aab4cc;
  505. .example-txt {
  506. display: block;
  507. margin-left: 70px;
  508. margin-top: 15px;
  509. }
  510. }
  511. }
  512. .dia-bot {
  513. padding-bottom: 40px;
  514. display: flex;
  515. justify-content: center;
  516. }
  517. .tip-label {
  518. position: absolute;
  519. bottom: 30px;
  520. right: 30px;
  521. color: #409EFF;
  522. cursor: pointer;
  523. }
  524. }
  525. </style>