Browse Source

指标计算 插入更改

Karsa 1 year ago
parent
commit
4132d12beb

+ 10 - 0
src/api/modules/sheetApi.js

@@ -277,6 +277,16 @@ export const getSystemDate = params => {
 	return http.post('/datamanage/excel_info/get_system_date',params)
 }
 
+/**
+ * 混合表格指标计算
+ * @param {*} params 
+ * EdbInfoId Source Formula Frequency Calendar MoveType MoveFrequency
+ * @returns 
+ */
+export const getMixedCalculateData = params => {
+	return http.post('/datamanage/excel_info/mixed/calculate',params)
+}
+
 
 /* =====自定义分析==== */
 

+ 61 - 27
src/views/datasheet_manage/components/MixedTable.vue

@@ -65,14 +65,14 @@
 
             <!-- 插入单元格禁止编辑 -->
             <template 
-              v-if="([4,5,6].includes(cell.DataType)&&!cell.CanEdit)
+              v-if="([4,5,6,7].includes(cell.DataType)&&!cell.CanEdit)
               ||disabled
               ||(cell.DataType===1&&[1,2].includes(cell.DataTimeType))"
             >
               
-              <!-- 单元格类型5显示指标浮窗 -->
+              <!-- 单元格类型5 7显示指标浮窗 -->
               <el-popover
-                v-if="cell.DataType===5&&!disabled"
+                v-if="[5,7].includes(cell.DataType)&&!disabled"
                 placement="top-start"
                 width="350"
                 trigger="hover"
@@ -82,6 +82,10 @@
                     <label style="min-width:80px;">指标名称</label> 
                     {{cellrelationEdbInfo.EdbName}}
                   </li>
+                  <li style="display:flex;margin:10px;">
+                    <label style="min-width:80px;">最新日期</label> 
+                    {{cellrelationEdbInfo.LatestDate}}
+                  </li>
                   <li style="display:flex;margin:10px;">
                     <label style="min-width:80px;">指标ID</label> 
                     {{cellrelationEdbInfo.EdbCode}}
@@ -177,6 +181,7 @@
 
     <!-- 指标计算弹窗 -->
     <calculateEdbDia
+      ref="calculateEdbDiaRef"
       :isShow.sync="isInsertCalculate"
       :info="insertCalculateInfo"
       @insert="insertCalculateData"
@@ -353,6 +358,9 @@ export default {
 
       //选择指标弹窗打开时选择日期更新弹窗数据
       this.isSelectTargetValueDialog&&this.$refs.selectTargetValueRef.chooseEdb(this.$refs.selectTargetValueRef.edbInfo)
+
+      //计算指标弹窗打开时选择日期更新弹窗数据
+      this.isInsertCalculate&&this.$refs.calculateEdbDiaRef.setChooseDate(cell)
     },
 
     /* 插入值 往左往上寻找同行同列是否有符合条件的一指标一日期 */
@@ -666,7 +674,7 @@ export default {
         pos = 'cell'
       }
       this.config.contextMenuOption = pos === 'cell' 
-        ? getRightClickMenu(pos,cell.DataType===1&&[1,2].includes(cell.DataTimeType))
+        ? getRightClickMenu(pos,(cell.DataType===1&&[1,2].includes(cell.DataTimeType))||cell.DataType===7)
         : getRightClickMenu(pos)
 
 
@@ -687,6 +695,12 @@ export default {
 
     /* 右键事件 */
     async handleContext(key) {
+
+      let editHandlesMap = {
+        1: this.insertDateOpen,
+        7: this.edbCalculateInsertOpen
+      }
+
       const keyMap = {
         'del': this.delColOrRow,//删除
         'insert-col-left': this.insertCol,//向左插入列
@@ -698,7 +712,7 @@ export default {
         'insert-sys-date': this.insertDateOpen,//导入系统日期
         'insert-edb-date': this.insertDateOpen,//导入指标日期
         'reset': this.clearCell, //清空
-        'cell-edit': this.insertDateOpen
+        'cell-edit': editHandlesMap[this.selectCell.DataType]
       }
       keyMap[key] && keyMap[key](key)
       
@@ -846,7 +860,7 @@ export default {
 
     /* 单元格类型5 浮到上面展示指标信息浮窗 */
     async getRelationEdbInfo({EdbInfoId,DataType}) {
-      if(DataType!==5||this.disabled) return
+      if(![5,7].includes(DataType)||this.disabled) return
 
       const res = await dataBaseInterface.targetDetail({EdbInfoId})
 
@@ -891,32 +905,51 @@ export default {
       resetDialogCellStyle();
       setRelationStyle({ key:this.insertTargetCell.Uid },'td-choose-insert-target');
 
-      this.isInsertCalculate = true;
-      this.insertCalculateInfo = {
-        ...item
+      if(item === 'cell-edit') { //编辑
+        const { Value,EdbInfoId } = this.insertTargetCell;
+
+        let menuInfo = this.config.contextMenuOption
+          .find(_ => _.key==='insert-edb-calculate').children
+          .find(menu => menu.source === JSON.parse(Value).source);
+
+        this.insertCalculateInfo = {
+          ...menuInfo,
+          EdbInfoId,
+          formStr: Value,
+        }
+      }else {
+        this.insertCalculateInfo = {
+          ...item
+        }
       }
+
+      this.isInsertCalculate = true;
     },
 
     /* 导入指标计算值 */
-    insertCalculateData(val) {
-      // this.insertTargetCell.DataType = 7;
-      // this.insertTargetCell.ShowValue = value;
-      // this.insertTargetCell.Value = value;
-      // this.insertTargetCell.EdbInfoId = edbId;
-      // this.insertTargetCell.DataTime = this.selectCell.ShowValue;
-
-      // this.$message.success('插入成功')
-
-      // //建立新的关联关系
-      // let relation = {
-      //   insert_cell: {
-      //     key: this.insertTargetCell.Uid,
-      //     relation_date: this.selectCell.Uid,
-      //     relation_edb: '',
-      //   }
-      // }
+    insertCalculateData(item) {
+      console.log(item)
+      const { insertValue,EdbInfoId,str,Date } = item;
+      this.insertTargetCell.DataType = 7;
+      this.insertTargetCell.ShowValue = insertValue;
+      this.insertTargetCell.Value = str;
+      this.insertTargetCell.EdbInfoId = EdbInfoId;
+      this.insertTargetCell.DataTime = Date;
 
-      // this.setRelation(relation,7);
+      this.$message.success('插入成功')
+
+      //如果日期有关联表格日期就建立新的关联关系
+      if(Date) {
+        let relation = {
+          insert_cell: {
+            key: this.insertTargetCell.Uid,
+            relation_date: this.selectCell.Uid,
+            relation_edb: '',
+          }
+        }
+  
+        this.setRelation(relation,7);
+      }
     },
 
     /* 初始化8行5列 */
@@ -1022,6 +1055,7 @@ export default {
     width: 104px;
     min-width: 104px;
     height: 35px;
+    max-height: 35px;
     background: #fff;
     text-align: center;
     word-break: break-all;

+ 187 - 52
src/views/datasheet_manage/components/calculateEdbDia.vue

@@ -9,49 +9,50 @@
       <div class="main">
 
         <section class="main-top">
-          <el-radio-group v-model="formData.edbFromSource" @change="initData">
-            <el-radio :label="1">表格指标</el-radio>
-            <el-radio :label="2">ETA指标&预测指标</el-radio>
-          </el-radio-group>
-
-        <template v-if="info.fromEdbKey===5">
-          <el-divider direction="vertical" style="margin: 0 20px;"/>
-          
-          <el-radio-group 
-            v-model="formData.source"
-          >
-            <el-radio :label="1">累计值转月</el-radio>
-            <el-radio :label="2">累计值转季值</el-radio>
-          </el-radio-group>
-        </template>
-
-        <template v-else-if="info.fromEdbKey===62">
-          <el-divider direction="vertical" style="margin: 0 20px;"/>     
-          <el-radio-group 
-            v-model="formData.source"
-          >
-            <el-radio :label="62">累计值</el-radio>
-            <el-radio :label="63">年初至今累计值</el-radio>
-          </el-radio-group>
-        </template>
+
+          <template v-if="info.fromEdbKey===5">
+            <el-radio-group 
+              v-model="formData.source"
+              @change="changeSource"
+            >
+              <el-radio :label="1">累计值转月</el-radio>
+              <el-radio :label="2">累计值转季值</el-radio>
+            </el-radio-group>
+          </template>
+
+          <template v-else-if="info.fromEdbKey===62">
+            <el-divider direction="vertical" style="margin: 0 20px;"/>     
+            <el-radio-group 
+              v-model="formData.source"
+              @change="changeSource"
+            >
+              <el-radio :label="62">累计值</el-radio>
+              <el-radio :label="63">年初至今累计值</el-radio>
+            </el-radio-group>
+          </template>
 
           <selectTarget
-            v-show="formData.edbFromSource===2"
             :defaultId="search_edb"
             :defaultOpt="searchOptions"
             ref="selectRef"
-            @select="e => { selectEdbInfo = e ||null }"
+            @select="selectTargetHandle"
             :filter="false"
             style="margin: 20px 0"
           />
-        </section>
 
-        <tableEdbListSection 
-          v-if="formData.edbFromSource===1"
-        />
+          <!-- 表格已存在的指标列表 -->
+          <div class="edb-list">
+              <el-tag 
+                :effect="selectEdbInfo&&selectEdbInfo.EdbInfoId===item.EdbInfoId?'dark':'plain'" 
+                v-for="(item,index) in edbArrFromTable" 
+                :key="index"
+                @click="selectTableEdbHandle(item)"
+              >{{ item.ShowValue }}</el-tag>
+          </div>
+        </section>
         
-        <edbDetailSection 
-          v-if="formData.edbFromSource===2"
+        <!-- 指标详情 -->
+        <edbDetailSection
           :tableData="selectEdbInfo?[selectEdbInfo]:[]"
         />
 
@@ -154,18 +155,24 @@
         </section>
 
         <!-- 计算结果 -->
-        <section class="result-section" v-if="calculateResult.List">
+        <section class="result-section" v-if="showResult">
           <label>计算结果:</label>
-          <ul class="data-cont">
-              <li v-for="(item,index) in result.List" :key="index" :class="[{'choose': item.DataTime===result.Date},'data-li']">
+          <ul class="data-cont" v-if="calculateShowData.length">
+              <li 
+                v-for="(item,index) in calculateShowData" 
+                :key="index" 
+                :class="[{'choose': item.DataTime===chooseItem.Date || (!chooseItem.Date&&index===0)},'data-li']"
+              >
                 <span>{{item.DataTime}}</span>
                 <span style="min-width:150px">{{item.Value}}</span>
               </li>
           </ul>
+
+          <tableNoData text="无对应的数据" size="mini" v-else/>
         </section>
 
         <section class="bot">
-          <el-button type="primary" @click="insertData" v-if="chooseItem">插入值</el-button>
+          <el-button type="primary" @click="insertData" v-if="showResult">插入值</el-button>
           <el-button type="primary" @click="calculateHandle" v-else>计算</el-button>
           <el-button type="primary" plain @click="cancelHandle">取消</el-button>
 
@@ -173,15 +180,16 @@
 
       </div>
 
-
     </div>
   </div>    
 </template>
 <script>
+import { dataBaseInterface } from '@/api/api.js';
+import * as sheetInterface from "@/api/modules/sheetApi.js";
+import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
 import { resetDialogCellStyle } from "../common/customTable";
 import selectTarget from '@/views/chartRelevance_manage/components/selectTarget.vue';
 import edbDetailSection from './edbDetailSection.vue';
-import tableEdbListSection from './tableEdbListSection.vue';
 import { formRules } from '@/views/dataEntry_manage/databaseComponents/util';
 export default {
   props: {
@@ -192,17 +200,40 @@ export default {
       type: Object
     }
   },
-  components: { selectTarget,edbDetailSection,tableEdbListSection },
+  components: { selectTarget,edbDetailSection },
+  computed: {
+    edbArrFromTable() {
+       return this.$parent.config.data.flat().filter(_ =>_.DataType === 2)
+    },
+    calculateShowData() {
+      if(this.chooseItem.Date) {
+        let index = this.calculateAllResult.findIndex(_ => _.DataTime===this.chooseItem.Date)
+        if(index === -1) return []
+
+        return this.calculateAllResult.slice(index-2,index+2);
+        
+      }else {
+        return this.calculateAllResult.slice(0,5);
+      }
+    }
+  },
   watch: {
     isShow(nval) {
-      const { source } = this.info
+      if(!nval) return
+      console.log(this.info)
+      const { source,formStr,EdbInfoId } = this.info;
+
       this.formData.source = source;
+      //回显
+      if(EdbInfoId) {
+        this.formData = { ...JSON.parse(formStr) }
+        this.selectTableEdbHandle({EdbInfoId})
+      }
     }
   },
   data() {
     return {
       formData: {
-        edbFromSource: 1,
         source: this.info.fromEdbKey,
         nNum: 1,
 				moveType: 1,
@@ -210,11 +241,15 @@ export default {
 				moveVal: '',
 				calendarType: '公历',
 				valueType: '期末值',
+        alphaValue: 0,
       },
       formRules,
 
-      calculateResult: {},
-      chooseItem: null,
+      showResult: false,
+      calculateAllResult: [], //计算全部数据
+      chooseItem: {
+        Date: ''
+      },//要插入表格的项
 
       search_edb: '',
       searchOptions: [],
@@ -241,28 +276,118 @@ export default {
 
   },
   methods:{
-    /* 计算 */
+    /* 计算结果 */
     async calculateHandle() {
       await this.$refs.form.validate();
+      
+      const {  
+        source,
+        nNum,
+				moveType,
+				moveUnit,
+				calendarType,
+      } = this.formData;
+
+      const valueMap = {
+        22: 'moveVal',
+        51: 'valueType',
+        'alpha': 'alphaValue'
+      }
+
+      let Date = this.$parent.selectCell.DataType === 1 ? this.$parent.selectCell.ShowValue : ''
+
+      const res = await sheetInterface.getMixedCalculateData({
+        Date,
+        Source: source,
+        Formula: valueMap[this.info.fromEdbKey] ? String(this.formData[valueMap[this.info.fromEdbKey]]) : String(nNum),
+        EdbInfoId: this.selectEdbInfo.EdbInfoId,
+        MoveFrequency: moveUnit,
+        MoveType: moveType, 
+        Calendar: calendarType
+      })
+      if(res.Ret!==200) return 
+
+      this.showResult = true;
+      this.calculateAllResult = res.Data || [];
+
+      // if(!this.result.Date && Date) return this.$message.warning('所选指标所选日期无值')
+      this.chooseItem = {
+          Date,
+          EdbInfoId: this.selectEdbInfo.EdbInfoId,
+          insertValue: Date ? this.calculateAllResult.find(_ => _.DataTime===Date).Value : this.calculateAllResult[0].Value,
+          str: JSON.stringify(this.formData)
+        }
+      
     },
 
     /* 插入值 */
     insertData() {
-      if(this.$parent.selectCell.DataType !== 1){
-        this.$message.warning('请在表格中选择日期')
-        return
-      }
 
+      // if(this.$parent.selectCell.DataType !== 1) return this.$message.warning('请在表格中选择日期')
+        
+      if(!this.calculateShowData.length) return this.$message.warning('该日期无数据')
+      
       this.$emit('insert',this.chooseItem)
       this.cancelHandle();
     },
 
+    /* 设置关联表格的日期 */
+    setChooseDate(cell) {
+      if(cell.DataType !== 1) {
+        this.chooseItem.Date = '';
+        return
+      } 
+
+      this.chooseItem.Date = cell.DataTime;
+    },
+
+    /* 选择指标 */
+    async selectTargetHandle(e) {
+      this.changeSource();
+      if(!e) {
+        this.selectEdbInfo = null
+        return
+      }
+
+      const res = e.EdbInfoType === 1 
+        ? await preDictEdbInterface.edbDataInfo({EdbInfoId:e.EdbInfoId,CurrentIndex: 1})
+        : await dataBaseInterface.targetList({EdbInfoId:e.EdbInfoId,CurrentIndex: 1})
+
+      if(res.Ret !== 200) return
+
+      const { EdbInfoId,EdbCode,EdbName,Frequency,Unit,StartDate,ModifyTime,SourceName,PredictDataList,DataList } = res.Data.Item;
+      this.selectEdbInfo = {
+        EdbCode,EdbName,Frequency,Unit,StartDate,ModifyTime,SourceName,EdbInfoId,
+        DataList: PredictDataList ? [...PredictDataList,...DataList].slice(0,5) : DataList.slice(0,5)
+      };
+      console.log(this.selectEdbInfo)
+    },
+
+    /* 选择表格指标 */
+    async selectTableEdbHandle(item) {
+      const res = await dataBaseInterface.targetDetail({EdbInfoId:item.EdbInfoId})
+      if(res.Ret !== 200) return
+
+      const { EdbInfoId,EdbInfoType,EdbName } = res.Data;
+      this.search_edb = EdbName;
+      this.selectTargetHandle({EdbInfoId,EdbInfoType,EdbName})
+    },
+
+    /*  */
+    changeSource() {
+      this.showResult = false;
+      this.calculateAllResult = [];
+      this.chooseItem = { Date: '' };
+    },
+
     initData() {
       this.search_edb='';
-      this.calculateResult = {};
-      this.chooseItem = null;
+      this.selectEdbInfo = null;
+      this.showResult = false;
+      this.calculateAllResult = [];
+      this.chooseItem = { Date: '' };
       this.formData = {
-        edbFromSource: this.formData.edbFromSource,
+        source: this.formData.source, 
         nNum: 1,
 				moveType: 1,
 				moveUnit: '天',
@@ -307,9 +432,19 @@ export default {
 
   .main {
     padding: 20px;
+    max-height: calc(100vh - 350px);
+    min-height: 300px;
+    overflow-y: auto;
     .main-top {
       margin-bottom: 20px;
     }
+    .edb-list {
+      display: flex;
+      gap: 10px;
+      .el-tag {
+        cursor: pointer;
+      }
+    }
     .form-section { margin: 20px 0; }
     .bot {
       display: flex;

+ 3 - 12
src/views/datasheet_manage/components/edbDetailSection.vue

@@ -18,27 +18,18 @@
           <span>{{ scope.row[item.key] }}</span>
         </template>
       </el-table-column>
-      <el-table-column
-        width="110"
-        align="center"
-        label="操作"
-      >
-        <template>
-          <!-- <span class="deletesty" @click="delTarget">删除</span> -->
-        </template>
-      </el-table-column>
-      <div slot="empty" style="padding: 20px 0">
+      <div slot="empty">
         <tableNoData text="暂无指标" size="mini" />
       </div>
     </el-table>
     <ul
       class="data-ul"
       ref="dataUl"
-      v-if="dataList.length"
+      v-if="tableData[0]&&tableData[0].DataList.length"
     >
       <li
         class="value-item"
-        v-for="(item, index) in dataList"
+        v-for="(item, index) in tableData[0].DataList"
         :key="item.EdbDataId"
       >
         <span class="value-label">

+ 0 - 56
src/views/datasheet_manage/components/tableEdbListSection.vue

@@ -1,56 +0,0 @@
-<template>
-  <el-table
-      :data="tableData"
-      style="box-shadow: 0px 3px 6px rgba(155, 170, 219, 0.2); margin-top: 10px"
-      border
-    >
-      <el-table-column
-        v-for="item in tableColums"
-        :key="item.label"
-        :label="item.label"
-        :width="item.widthsty"
-        :min-width="item.minwidthsty"
-        align="center"
-      >
-        <template slot-scope="scope">
-          <span>{{ scope.row[item.key] }}</span>
-        </template>
-      </el-table-column>
-  </el-table>    
-</template>
-<script>
-export default {
-  data() {
-    return {
-      tableData: [{
-        EdbName: '对我的群无',
-        LatestDate: '2023-05-21',
-        latestValue: '151'
-      }],
-      tableColums: [
-        {
-					label: '指标名称',
-					key: 'EdbName',
-				},
-				{
-					label: '最新日期',
-					key: 'LatestDate',
-				},
-				{
-					label: '最新数据',
-					key: 'latestValue',
-				}
-      ]
-    }
-  },
-  mounted(){
-
-  },
-  methods:{
-
-  },
-}
-</script>
-<style scoped lang='scss'>
-
-</style>