diffusionIndexDia.vue 14 KB

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