Browse Source

批量计算,预测指标指数修匀

cxmo 1 year ago
parent
commit
85326d4001

+ 218 - 62
src/views/dataEntry_manage/databaseComponents/smoothEdbDialog.vue

@@ -9,6 +9,7 @@
         width="1200px"
         top="3vh"
         v-dialogDrag
+        class="smooth-edb-dialog"
     >
         <div slot="title" style="display: flex; align-items: center">
             <img
@@ -163,7 +164,7 @@
                         <span class="li-tag">{{ list.tag }}</span>
                         <el-select v-model="list.target" v-loadMore="searchLoad" :filterable="!list.target" clearable
                             placeholder="请输入指标名称" style="width: 400px" @change="(val)=>{chooseTargetList(val,index)}"
-                            @clear="clearHandle(index)" remote :remote-method="searchTarget"
+                            @clear="clearHandle(index)" remote :remote-method="getTarget"
                             @click.native="inputFocusHandle">
                             <i slot="prefix" class="el-input__icon el-icon-search"></i>
                             <el-option v-for="item in searchOptions" :key="item.EdbInfoId"
@@ -196,30 +197,38 @@
                             <el-form-item prop="targetName">
                                 <el-input
                                     v-model="targetList[index].targetName"
-                                    style="width: 340px"
+                                    style="width: 240px"
                                     placeholder="请输入指标名称"
                                 />
                             </el-form-item>
-                            <el-form-item prop="unit">
-                                <selectUnit 
-                                    v-model="targetList[index].unit" 
-                                    style="width: 340px" 
-                                />
-                            </el-form-item>
                             <el-form-item prop="menu">
                                 <el-cascader v-if="isOpenSmooth"
                                     v-model="targetList[index].menu"
                                     :options="catalogArr"
                                     :props="levelProps"
+                                    style="width: 200px" 
                                     clearable
                                     placeholder="请选择指标目录"
                                 />
                             </el-form-item>
+                            <el-form-item prop="unit">
+                                <selectUnit 
+                                    v-model="targetList[index].unit" 
+                                    style="width: 160px" 
+                                />
+                            </el-form-item>
+                            <el-form-item prop="alphaValue">
+                                <el-input
+                                    v-model.trim="targetList[index].alphaValue"
+                                    style="width: 180px"
+                                    placeholder="请输入alpha值"
+                                />
+                            </el-form-item>
                             <el-form-item prop="frequency">
                                 <el-select
                                     v-model="targetList[index].frequency"
                                     placeholder="请选择频度"
-                                    style="width: 340px"
+                                    style="width: 180px"
                                     clearable
                                 >
                                     <el-option
@@ -231,13 +240,7 @@
                                     </el-option>
                                 </el-select>
                             </el-form-item>
-                            <el-form-item prop="alphaValue">
-                                <el-input
-                                    v-model.trim="targetList[index].alphaValue"
-                                    style="width: 340px"
-                                    placeholder="请输入alpha值"
-                                />
-                            </el-form-item>
+                            
                         </el-form>
                     </li>
                 </ul>
@@ -246,7 +249,7 @@
                 <el-button
                     type="primary"
                     style="margin-right: 20px"
-                    @click="saveHandle"
+                    @click="saveBtnClick"
                     :loading="loading"
                     >指数修匀计算</el-button
                 >
@@ -265,6 +268,7 @@
 
 <script>
 import { dataBaseInterface } from '@/api/api.js';
+import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
 import { formRules } from './util';
 const tag_arr = [];
 for(let i=0;i<26;i++) tag_arr.push(String.fromCharCode(65+i));
@@ -284,6 +288,10 @@ export default {
                 edb_id:'',
                 oldedb_id:''
             }}
+        },
+        isPredict:{ //是不是预测指标
+            type:Boolean,
+            default:false,
         }
     },
     data() {
@@ -314,6 +322,7 @@ export default {
 
             tableData:[],
             page_no:1,
+            haveMore:false,
             tableColums:[
                     {
                     label: '指标ID',
@@ -391,17 +400,19 @@ export default {
             if(!this.search_have_more) return;
             this.searchApi(this.current_search,++this.search_page)
         },
-        searchApi(query,page=1){
-            dataBaseInterface.targetSearchByPage({
+        async searchApi(query,page=1){
+            const params = {
                 KeyWord:query,
                 CurrentIndex: page,
-            }).then(res => {
-                if(res.Ret !== 200) return
-                const { List,Paging } = res.Data;
-                this.search_have_more = page < Paging.Pages;
-                let arr = page === 1 ? List : this.searchOptions.concat(List);
-                this.searchOptions = arr;
-            })
+            }
+            const res = this.isPredict
+                ? await preDictEdbInterface.edbSearch(params)
+                : await dataBaseInterface.targetSearchByPage(params)
+            if(res.Ret !== 200) return
+            const { List,Paging } = res.Data;
+            this.search_have_more = page < Paging.Pages;
+            let arr = page === 1 ? List : this.searchOptions.concat(List);
+            this.searchOptions = arr;
         },
         /* 指标列表 */
         getTarget(query) {
@@ -416,12 +427,12 @@ export default {
             this.searchApi(this.current_search);
         },
         /* 获取目录结构 */
-        getMenu() {
-            dataBaseInterface.menuListV3().then((res) => {
-                if (res.Ret === 200) {
-                    this.catalogArr = res.Data.AllNodes || [];
-                }
-            });
+        async getMenu() {
+            const res = this.isPredict
+                ? await preDictEdbInterface.classifyListV2()
+                : await dataBaseInterface.menuListV3()
+            if(res.Ret!==200) return 
+            this.catalogArr = res.Data.AllNodes || [];
         },
         /* 选择指标 */
         chooseTarget(val) {
@@ -440,15 +451,11 @@ export default {
         chooseTargetList(val,index){
             if(val){
                 const obj = this.searchOptions.find(item => item.EdbInfoId === val);
-                const {tag,target} = this.targetList[index]
-                this.targetList[index] = {
-                    tag,target,
-                    targetName:`${obj.EdbName}指数修匀`,
-                    unit:obj.Unit,
-                    frequency:obj.Frequency,
-                    menu:obj.ClassifyId||'',
-                    alphaValue:obj.Formula||''
-                }
+                this.targetList[index].targetName = `${obj.EdbName}指数修匀`
+                this.targetList[index].unit = obj.Unit
+                this.targetList[index].frequency = obj.Frequency
+                this.targetList[index].menu = obj.ClassifyId||''
+                this.targetList[index].alphaValue =obj.Formula||''
             }
         },
         setDefaultOption(obj,type){
@@ -460,24 +467,25 @@ export default {
                 alphaValue:obj.Formula||''
             }
         },
-        getDataList(){
-            dataBaseInterface.targetList({
+        async getDataList(){
+            const params = {
                 PageSize: 10,
                 CurrentIndex: this.page_no,
                 EdbInfoId: this.select_target,
-            }).then(res => {
-                if(res.Ret === 200) {
-                    if(res.Data) {
-                        res.Data.Item.ModifyTime = res.Data.Item.ModifyTime.substr(0,10);
-                        this.tableData = [res.Data.Item] || [];
-                        this.haveMore =  this.page_no < res.Data.Paging.Pages ? true : false;
-                        this.dataList = this.page_no === 1 ? (res.Data.Item.DataList || []) : this.dataList.concat(res.Data.Item.DataList);
-                    }else {
-                        this.tableData = [];
-                        this.dataList = [];
-                    }
-                }
-            })
+            }
+            const res = this.isPredict
+                ? await preDictEdbInterface.edbDataInfo(params)
+                : await dataBaseInterface.targetList(params)
+            if(res.Ret!==200) return 
+            if(res.Data){
+                res.Data.Item.ModifyTime = res.Data.Item.ModifyTime.substr(0,10);
+                this.tableData = [res.Data.Item] || [];
+                this.haveMore =  this.page_no < res.Data.Paging.Pages ? true : false;
+                this.dataList = this.page_no === 1 ? (res.Data.Item.DataList || []) : this.dataList.concat(res.Data.Item.DataList);
+            }else{
+                this.tableData = [];
+                this.dataList = [];
+            }
         },
         handleSelectBtnClick(){
             //计算指标打开弹窗,基础指标打开新页面
@@ -489,13 +497,28 @@ export default {
                 window.open(href,'_blank');
             }
         },
-        scrollHandle(){},
-        delTarget(){},
+        scrollHandle(e){
+            const dom = e.target
+            let scrollTop = dom.scrollTop; //滑入屏幕上方的高度
+            let windowHeitht = dom.clientHeight; //页面的高度
+            let scrollHeight = dom.scrollHeight; //整个div的高度
+            let total = scrollTop + windowHeitht
+            if(total >= scrollHeight && this.haveMore){
+                this.page_no ++;
+                this.getDataList();
+            }
+        },
+        /* 删除已选指标 */
+		delTarget() {
+			this.tableData = [];
+			this.dataList = [];
+			this.select_target = '';
+			this.page_no = 1;
+		},
         delTargetList(index){
             this.targetList.splice(index, 1);
         },
         clearHandle(index){
-            console.log('?clear',index)
             const item = {...{tag:tag_arr[index],target:''},..._.cloneDeep(this.formData)}
             this.targetList.splice(index,1,item)
         },
@@ -514,6 +537,10 @@ export default {
             const item = {...{tag:tag_arr[index+1],target:''},..._.cloneDeep(this.formData)}
             this.targetList.push(item)
         },
+        saveBtnClick(){
+            this.computedSource===1?this.saveHandle():this.saveListHandle()
+        },
+        //常规编辑/保存指标
         async saveHandle(){
             if(!this.select_target){
                 this.$message.warning('指标不能为空')
@@ -532,16 +559,85 @@ export default {
                 Formula:alphaValue,
                 FromEdbInfoId:this.select_target
             }
-            const res = this.operationForm.edb_id 
-            ? await dataBaseInterface.calculateTargetEdit({ ...params,EdbInfoId: this.operationForm.edb_id })
-            : await dataBaseInterface.calculateTargetSave(params)
+
+            let res = null
+            if(this.isPredict){
+                let edit_params = { ...params,EdbInfoId: this.operationForm.edb_id }
+                res = await preDictEdbInterface.operateEdbSave(this.operationForm.edb_id ? edit_params : params)
+            }else{
+                res = this.operationForm.edb_id 
+                ? await dataBaseInterface.calculateTargetEdit({ ...params,EdbInfoId: this.operationForm.edb_id })
+                : await dataBaseInterface.calculateTargetSave(params)
+            }
             if(res.Ret!==200) return 
             this.$message.success(res.Msg)
             this.operationForm.edb_id 
                 ? this.$emit('addCallBack','edit') 
                 : this.$emit('addCallBack','add',{ code:res.Data.UniqueCode,id:res.Data.EdbInfoId,classifyId:params.ClassifyId });
             this.init();
+            this.loading = false;
+
+        },
+        //批量添加指标
+        async saveListHandle(){
+            //判断是否都选择了指标
+            const targetCheck = this.targetList.filter(item=>item.target)
+            if(targetCheck.length!==this.targetList.length){
+                this.$message.warning('请选择指标')
+                return
+            }
+            //判断每一项form-rules
+            for(let i = 0;i<targetCheck.length;i++){
+                await this.$refs[`list_form_${i}`][0].validate();
+            }
+            this.loading = true
+            const params = targetCheck.map(item=>{
+                return {
+                    CalculateId: item.tag,
+                    CalculateInfo: {
+                        ClassifyId: item.menu,
+                        EdbName: item.targetName,
+                        Formula: item.alphaValue,
+                        Frequency:item.frequency,
+                        FromEdbInfoId: item.target,
+                        Source:this.$route.path==='/database'?72:73,
+                        Unit: item.unit
+                    }
+                }
+            })
+
+            const res = this.$route.path==='/database'
+                ? await dataBaseInterface.batchCalculateTargetAdd(params)
+                : await preDictEdbInterface.batchCalculateTargetAdd(params)
+            if(res.Ret !== 200) return
+            const { Fail,Success } = res.Data;
+            if(Fail.length) {
+                let message = '';
+                Fail.forEach(item => {
+                    message+=`${item.CalculateId}:${item.Msg}</br>`
+                })
 
+                this.$message({
+                    dangerouslyUseHTMLString: true,
+                    message,
+                    type: 'error'
+                })
+                this.dealFailHandle(Fail)
+            }else {
+                this.$message.success('添加成功');
+                this.init();
+                this.$emit('addCallBack','add',{ code:Success[0].UniqueCode,id:Success[0].EdbInfoId,classifyId:Success[0].ClassifyId});
+                this.loading = false;
+            }
+        },
+        dealFailHandle(arr){
+            //从targetList中剔除成功的指标,重新赋予剩下的指标tag
+            const failTagArr = arr.map(_ =>_.CalculateId);
+            this.targetList = this.targetList.filter(_ => failTagArr.includes(_.tag));
+            this.targetList.forEach((item,index)=>{
+                item.tag = tag_arr[index]
+            })
+            this.loading = false;
         },
         cancelHandle(type) {
             this.init();
@@ -553,6 +649,12 @@ export default {
 </script>
 
 <style lang="scss">
+.smooth-edb-dialog{
+    .el-dialog__body{
+        padding: 25px 25px 30px !important;
+        padding-bottom: 5px !important;
+    }
+}
 .smooth-edb-dialog-wrap{
     .el-cascader .el-input {
         width: 340px;
@@ -618,5 +720,59 @@ export default {
         color: #409EFF;
         cursor: pointer;
     }
+    .batch-wrap{
+        padding:0 40px;
+        .target-ul {
+            display: flex;
+            flex-wrap: wrap;
+            justify-content: space-between;
+            .target-li {
+                position: relative;
+                margin-bottom: 30px;
+                .li-tag {
+                    font-size: 16px;
+                    margin-right: 8px;
+                }
+                .del-tag {
+                    position: absolute;
+                    right: -30px;
+                    top: 12px;
+                    font-size: 16px;
+                    cursor: pointer;
+                }
+                .target-date {
+                    color: #5882ef;
+                    position: absolute;
+                    bottom: -25px;
+                    left: 24px;
+                }
+            }
+        }
+        .add-icon {
+            font-size: 16px;
+            color: #5882ef;
+            cursor: pointer;
+        }
+        .form-ul {
+            padding-top: 20px;
+            margin-top: 20px;
+            border-top: 1px dashed #AAB4CC;
+            .form-li {
+                display: flex;
+                align-items: center;
+                margin-bottom: 15px;
+                .el-cascader>.el-input{
+                    width:100%;
+                }
+                .el-form-item{
+                    margin-bottom: 0;
+                }
+                .li-tag{
+                    margin-right: 20px;
+                }
+            }
+        }
+    }
+    
 }
 </style>

+ 1 - 1
src/views/dataEntry_manage/databaseComponents/util.js

@@ -23,7 +23,7 @@ export const formRules= {
 	],
 	alphaValue:[
 		{ validator:(rule,value,callback)=>{
-			if(Number(value)<0||Number(value)>1){
+			if(Number(value)<=0||Number(value)>=1){
 				callback(new Error("请输入>0,<1的数值"))
 			}else{
 				callback()

+ 1 - 0
src/views/dataEntry_manage/databaseList.vue

@@ -451,6 +451,7 @@
 			@cancel="computed_type=0"
 			@openPrev="isOpenComputed=true"
 			@addCallBack="addComputedCallBack"
+			@lookHistory="id => {isLookHistory=true;lookEdbId=id;}"
 		/>
 	</div>
 </template>

+ 29 - 3
src/views/predictEdb_manage/predictEdb.vue

@@ -402,6 +402,17 @@
       :isOpenDialog.sync="isLookHistory"
       :edbId="lookEdbId"
     />
+	<!-- 指数修匀弹窗 -->
+	<SmoothEdbDialog 
+			:is-open-smooth="computed_type==='alpha'"
+			:computed-source="computed_source"
+			:operationForm="operationForm"
+			:isPredict="true"
+			@cancel="computed_type=0"
+			@openPrev="isOpenComputed=true"
+			@addCallBack="addComputedCallBack"
+			@lookHistory="id => {isLookHistory=true;lookEdbId=id;}"
+		/>
 
 	</div>
 </template>
@@ -427,6 +438,7 @@ import diffusionIndexDialog from '@/views/dataEntry_manage/databaseComponents/di
 import { formulaTip } from '@/views/dataEntry_manage/databaseComponents/util';
 import dataAssociateChart from '@/views/dataEntry_manage/databaseComponents/dataAssociateChart.vue'
 import dataAssociateComputeData from '@/views/dataEntry_manage/databaseComponents/dataAssociateComputeData.vue'
+import SmoothEdbDialog from '@/views/dataEntry_manage/databaseComponents/smoothEdbDialog.vue';
 
 export default {
 	name:'',
@@ -446,7 +458,8 @@ export default {
 		batchComputedDialog,
 		diffusionIndexDialog,
 		dataAssociateChart,
-		dataAssociateComputeData
+		dataAssociateComputeData,
+		SmoothEdbDialog
 	},
 	mixins:[ leftMixin ],
 	beforeRouteLeave (to, from, next) {
@@ -540,6 +553,7 @@ export default {
 				[64,formulaTip.get(61)],
 				[65,formulaTip.get(62)],
 				[66,formulaTip.get(63)],
+				['alpha',formulaTip.get('alpha')]
 			]),//公式说明
 
 			isShowRuleDialog: false,
@@ -568,7 +582,8 @@ export default {
 				{  name: '年化',type: 55 },
 				{ name: '降频',type: 54 },
 				{ name: '扩散指数',type: 56 },
-				{ name: '累计值',type: 'accumulate' }
+				{ name: '累计值',type: 'accumulate' },
+				{ name: '指数修匀计算',type:'alpha'}
 			],
 			batchTypes: [
 				{ name: '同比值',type: 32 },
@@ -578,7 +593,8 @@ export default {
 				{ name: 'N数值环差值',type: 44 },
 				{ name: '升频',type: 45 },
 				{ name: '累计值转月/季值',type: 'toMonthSeason' },
-				{ name: '累计值',type: 'accumulate' }
+				{ name: '累计值',type: 'accumulate' },
+				{ name: '指数修匀计算',type:'alpha'}
 			],
       isOnlyMe:false,//只看我的
 
@@ -1033,6 +1049,7 @@ export default {
 					//计算指标
 					this.setComputedDialogForm(res.Data,type);
 					this.computed_type =[47,48].includes(Source)?'joint': Source;
+					this.computed_type = [72,73].includes(Source)? 'alpha': Source;
 				}
 
 			})
@@ -1104,6 +1121,15 @@ export default {
 					moveVal: Source === 46 ? CalculateFormula : '',
 					calendar_type: Source === 49 ? Calendar : '',
 				}
+
+				if([72,73].includes(Source)){
+					this.operationForm = {
+						edb_id: EdbInfoId,
+						oldedb_id: CalculateList[0].FromEdbInfoId,
+						oldEdb_name: CalculateList[0].FromEdbName,
+						EdbName,Frequency,Unit,ClassifyId,Formula:CalculateFormula,
+					}
+				}
 			}
 		},