computedDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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()</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-select
  103. v-model="formData.menu"
  104. placeholder="请选择分类"
  105. style="width: 340px"
  106. clearable
  107. >
  108. <el-option
  109. v-for="item in options"
  110. :key="item.ClassifyId"
  111. :label="item.ClassifyName"
  112. :value="item.ClassifyId"
  113. />
  114. </el-select> -->
  115. <el-cascader
  116. v-model="formData.menu"
  117. :options="options"
  118. :props="{
  119. label: 'ClassifyName',
  120. value: 'ClassifyId',
  121. children: 'Children',
  122. }"
  123. style="width: 90%"
  124. placeholder="请选择所属分类"
  125. />
  126. </el-form-item>
  127. <el-form-item label="频度" prop="frequency">
  128. <el-select
  129. v-model="formData.frequency"
  130. placeholder="请选择频率"
  131. style="width: 340px"
  132. clearable
  133. >
  134. <el-option
  135. v-for="item in frequencyArr"
  136. :key="item"
  137. :label="item"
  138. :value="item"
  139. >
  140. </el-option>
  141. </el-select>
  142. </el-form-item>
  143. </el-form>
  144. </div>
  145. <div class="dia-bot" v-if="!calulateForm.view">
  146. <el-button
  147. type="primary"
  148. style="margin-right: 20px"
  149. @click="saveHandle"
  150. :loading="dataloading"
  151. v-if="title==='计算指标'"
  152. >生成计算指标</el-button
  153. >
  154. <el-button
  155. type="primary"
  156. style="margin-right: 20px"
  157. @click="saveHandle"
  158. v-else
  159. >保存</el-button
  160. >
  161. <el-button type="primary" plain @click="cancelHandle('cancel')">取消</el-button>
  162. </div>
  163. <el-popover
  164. placement="top-start"
  165. width="360"
  166. trigger="click">
  167. <p style="padding:30px;line-height:25px;" v-html="$parent.tips.get(31)"/>
  168. <span slot="reference" class="tip-label">公式说明</span>
  169. </el-popover>
  170. </el-dialog>
  171. </template>
  172. <script>
  173. import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
  174. import { formRules } from '@/views/dataEntry_manage/databaseComponents/util';
  175. import { unitArr } from '@/utils/defaultOptions';
  176. const tag_arr = [];
  177. for(let i=0;i<26;i++) tag_arr.push(String.fromCharCode(65+i));
  178. export default {
  179. name: '',
  180. props: {
  181. isOpenComputed: {
  182. type: Boolean,
  183. },
  184. title: {
  185. type: String,
  186. default: '计算指标',
  187. },
  188. calulateForm: {
  189. type: Object,
  190. },
  191. calulateList: {
  192. type: Array,
  193. },
  194. },
  195. watch: {
  196. isOpenComputed(newval) {
  197. newval && this.getMenu();
  198. /* 回显 */
  199. if (this.calulateList.length && newval) {
  200. this.addList = _.cloneDeep(this.calulateList);
  201. this.formula = this.calulateForm.formula;
  202. this.formData = {
  203. targetName: this.calulateForm.targetName,
  204. unit: this.calulateForm.unit,
  205. menu: this.calulateForm.menu,
  206. frequency: this.calulateForm.frequency,
  207. };
  208. this.searchOptions = this.calulateList.map(item => ({
  209. EdbInfoId: item.target,
  210. EdbName: item.edb_name,
  211. }))
  212. this.getNewestDate();
  213. }
  214. },
  215. },
  216. data() {
  217. return {
  218. options: [],
  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. getMenu() {
  266. preDictEdbInterface.classifyListV2().then(res => {
  267. if(res.Ret !== 200) return
  268. this.options = res.Data.AllNodes || [];
  269. })
  270. },
  271. /* 添加额外的指标列 */
  272. addTargetHandle() {
  273. if(this.addList.length >= 26) return this.$message.warning('添加指标个数已达上限')
  274. let tag = this.addList[this.addList.length-1].tag;
  275. let index = tag_arr.findIndex(item => item === tag);
  276. const item = {
  277. tag: tag_arr[index+1],
  278. target: '',
  279. start_date: '',
  280. end_date: ''
  281. };
  282. this.addList.push(item);
  283. },
  284. /* 搜索指标 */
  285. searchTarget(query) {
  286. this.search_page = 1;
  287. this.current_search = query;
  288. this.searchApi(this.current_search);
  289. },
  290. /* 聚焦获取当前检索 */
  291. inputFocusHandle(e) {
  292. this.search_page = 1;
  293. this.current_search = e.target.value;
  294. this.searchApi(this.current_search);
  295. },
  296. searchApi(query,page=1) {
  297. preDictEdbInterface
  298. .edbSearch({
  299. Keyword: query,
  300. CurrentIndex: page
  301. })
  302. .then((res) => {
  303. if (res.Ret !== 200) return
  304. const { List,Paging } = res.Data;
  305. this.search_have_more = page < Paging.Pages;
  306. this.searchOptions = page === 1 ? List : this.searchOptions.concat(List);
  307. });
  308. },
  309. searchLoad() {
  310. if(!this.search_have_more) return;
  311. this.searchApi(this.current_search,++this.search_page)
  312. },
  313. /* 选中指标 显示开始日期结束日期 */
  314. chooseTarget(val) {
  315. if (val) {
  316. const choose_obj = this.searchOptions.find(
  317. (item) => item.EdbInfoId === val
  318. );
  319. this.addList.forEach((list) => {
  320. if (list.target === val) {
  321. list.start_date = choose_obj.StartDate;
  322. list.end_date = choose_obj.EndDate;
  323. this.getNewestDate();
  324. }
  325. });
  326. }
  327. },
  328. /* 获取所选日期最早日期 */
  329. getNewestDate() {
  330. let dateArr = this.addList.filter(_ => _.end_date).map(_ => new Date(_.end_date).getTime())
  331. let earliestDate = Math.min(...dateArr);
  332. let sameDateArr = dateArr.filter(_ => _===earliestDate)
  333. if(dateArr.length === 1 || sameDateArr.length===dateArr.length) {
  334. this.newestDate = '';
  335. return
  336. }
  337. this.newestDate = this.$moment(Math.min(...dateArr)).format('YYYY-MM-DD');
  338. },
  339. /* 清空指标和关联日期 */
  340. clearHandle(index) {
  341. this.addList[index].start_date = '';
  342. this.addList[index].end_date = '';
  343. this.getNewestDate();
  344. },
  345. // 删除指标
  346. delTarget(index) {
  347. this.addList.splice(index, 1);
  348. this.getNewestDate();
  349. },
  350. saveHandle() {
  351. if (!this.formula) return this.$message.warning('计算公式不能为空');
  352. this.$refs.diaForm.validate((valid) => {
  353. if (valid) {
  354. // 指标id数组
  355. let target_arr = this.addList
  356. .filter((item) => item.target)
  357. .map((item) => {
  358. return {
  359. EdbInfoId: item.target,
  360. FromTag: item.tag,
  361. };
  362. });
  363. let params = {
  364. CalculateFormula: this.formula,
  365. ClassifyId: this.formData.menu[this.formData.menu.length - 1],
  366. EdbName: this.formData.targetName,
  367. Frequency: this.formData.frequency,
  368. Unit: this.formData.unit,
  369. EdbInfoIdArr: target_arr,
  370. };
  371. this.dataloading = true;
  372. const params2 = { ... params,EdbInfoId: this.calulateForm.edb_id };
  373. preDictEdbInterface.calculateEdbSave(this.calulateForm.edb_id ? params2 : params).then((res) => {
  374. this.dataloading = false;
  375. if (res.Ret !== 200) return
  376. this.$message.success(this.calulateForm.edb_id ? '编辑成功' : '新增成功');
  377. this.calulateForm.edb_id ? this.$emit('addCallBack','edit') : this.$emit('addCallBack','add',{
  378. code:res.Data.UniqueCode,
  379. id:res.Data.EdbInfoId,
  380. classifyId:params.ClassifyId
  381. });
  382. this.init();
  383. });
  384. }
  385. });
  386. },
  387. init() {
  388. this.$refs.diaForm.resetFields();
  389. this.addList = [
  390. {
  391. tag: tag_arr[0],
  392. target: '',
  393. start_date: '',
  394. end_date: '',
  395. },
  396. {
  397. tag: tag_arr[1],
  398. target: '',
  399. start_date: '',
  400. end_date: '',
  401. },
  402. {
  403. tag: tag_arr[2],
  404. target: '',
  405. start_date: '',
  406. end_date: '',
  407. },
  408. {
  409. tag: tag_arr[3],
  410. target: '',
  411. start_date: '',
  412. end_date: '',
  413. },
  414. ];
  415. this.searchOptions = [];
  416. this.formula = '';
  417. this.formData = {
  418. targetName: '',
  419. unit: '',
  420. menu: '',
  421. frequency: '',
  422. };
  423. },
  424. cancelHandle(type) {
  425. this.init();
  426. this.$emit('cancel');
  427. type==='cancel' && !this.calulateForm.edb_id && this.$emit('openPrev');
  428. },
  429. },
  430. created() {},
  431. mounted() {},
  432. };
  433. </script>
  434. <style lang="scss">
  435. .computed-dialog {
  436. overflow: hidden;
  437. div::-webkit-scrollbar {
  438. width: 6px !important;
  439. }
  440. .el-dialog__body {
  441. max-height: 700px;
  442. overflow: auto;
  443. }
  444. .dialog-main {
  445. padding: 25px 42px 25px 25px;
  446. .el-cascader .el-input {
  447. width: 340px;
  448. }
  449. .add-cont {
  450. display: flex;
  451. flex-wrap: wrap;
  452. justify-content: space-between;
  453. .add-li {
  454. position: relative;
  455. margin-bottom: 48px;
  456. .li-tag {
  457. font-size: 16px;
  458. margin-right: 8px;
  459. }
  460. .del-tag {
  461. position: absolute;
  462. right: -30px;
  463. top: 12px;
  464. font-size: 16px;
  465. cursor: pointer;
  466. }
  467. .target-date {
  468. color: #5882ef;
  469. position: absolute;
  470. bottom: -25px;
  471. left: 24px;
  472. &.newest {
  473. color: #f00;
  474. }
  475. }
  476. }
  477. }
  478. .add-icon {
  479. font-size: 16px;
  480. color: #5882ef;
  481. cursor: pointer;
  482. }
  483. .computed-min {
  484. margin: 50px 0;
  485. padding-bottom: 40px;
  486. border-bottom: 1px dashed #aab4cc;
  487. .example-txt {
  488. display: block;
  489. margin-left: 70px;
  490. margin-top: 15px;
  491. }
  492. }
  493. }
  494. .dia-bot {
  495. padding-bottom: 40px;
  496. display: flex;
  497. justify-content: center;
  498. }
  499. .tip-label {
  500. position: absolute;
  501. bottom: 30px;
  502. right: 30px;
  503. color: #409EFF;
  504. cursor: pointer;
  505. }
  506. }
  507. </style>