FinalYu %!s(int64=2) %!d(string=hai) anos
pai
achega
815de96ced

+ 80 - 28
chuanyi_client2/src/views/my_report/index.vue

@@ -17,7 +17,8 @@
               <span class="custom-tree-node1" slot-scope="{ node, data }">
                 <svg-icon v-if="data.id == -1" icon-class="reports"/>
                 <svg-icon v-else icon-class="report"/>
-                <span :title='data.reportName || data.itemName' style="margin-left: 2px;">{{ data.reportName || data.itemName }}</span>
+                <span :title='data.reportName || data.itemName'
+                      style="margin-left: 2px;">{{ data.reportName || data.itemName }}</span>
                 <span v-if="data.id != -1" style="position: absolute; right: 0; background: #ffffff;">
                   <el-button type="text" size="mini" style="color: #b6b6b6;"
                              @click="() => removeReportItem(node, data)" icon="el-icon-delete"></el-button>
@@ -61,16 +62,19 @@
             </el-option>
           </el-select>
         </el-form-item>
-<!--        <el-form-item label="四则运算表达式" prop="operationRule">-->
-<!--          <el-select v-model="reportForm.operationRule" filterable placeholder="请选择表达式" style="width: 100%;">-->
-<!--            <el-option-->
-<!--                v-for="item in this.dataModelList"-->
-<!--                :key="item.id"-->
-<!--                :label="item.operationRule"-->
-<!--                :value="item.id">-->
-<!--            </el-option>-->
-<!--          </el-select>-->
-<!--        </el-form-item>-->
+        <el-form-item label="数据类型" prop="reportValueFormat">
+          <el-radio v-model="reportForm.reportValueFormat" label="0">时段数据</el-radio>
+        </el-form-item>
+        <!--        <el-form-item label="四则运算表达式" prop="operationRule">-->
+        <!--          <el-select v-model="reportForm.operationRule" filterable placeholder="请选择表达式" style="width: 100%;">-->
+        <!--            <el-option-->
+        <!--                v-for="item in this.dataModelList"-->
+        <!--                :key="item.id"-->
+        <!--                :label="item.operationRule"-->
+        <!--                :value="item.id">-->
+        <!--            </el-option>-->
+        <!--          </el-select>-->
+        <!--        </el-form-item>-->
         <el-form-item style="text-align: center;">
           <el-button type="primary" @click="chooseReportEvent" style="margin-top: 20px;">确定</el-button>
           <el-button @click="dialogClose" style="margin-top: 20px;">取消</el-button>
@@ -101,7 +105,7 @@
 
 <script>
 import BreadcrumbView from '@/components/BreadcrumbView'
-import { showLoading } from '@/utils/cqcy'
+import {showLoading} from '@/utils/cqcy'
 import {
   delReportTableById,
   getAllDataModel,
@@ -112,6 +116,7 @@ import {
 } from "@/api/datasource";
 import {insertEChart, exportExcel, packtable} from 'luckytool'
 import ExcelJS from 'exceljs'
+import deepFill from "luckytool/src/deepfill";
 
 export default {
   name: "index",
@@ -135,7 +140,8 @@ export default {
       delFlag: 0,
       reportForm: {
         reportTemplate: null,
-        operationRule: null
+        reportValueFormat: '0'
+        // operationRule: null
       },
       reportDataList: [{
         id: -1,
@@ -144,7 +150,7 @@ export default {
       }],
       reportRules: {
         reportTemplate: [
-          { required: true, message: '请选择报表模板', trigger: 'change' }
+          {required: true, message: '请选择报表模板', trigger: 'change'}
         ],
         // operationRule: [
         //   { required: true, message: '请选择表达式', trigger: 'change' }
@@ -152,8 +158,7 @@ export default {
       }
     }
   },
-  watch: {
-  },
+  watch: {},
   beforeDestroy() {
   },
   created() {
@@ -274,18 +279,64 @@ export default {
         let temp = itemList[i]
         params.push({
           'itemGroupId': temp.itemGroupId,
-          'itemName': temp.itemName,
-          'dataModelId': temp.rule.id ? temp.rule.id : null
+          'itemName': temp.itemName
         })
       }
+      let p = {
+        'reportValueFormat': this.reportForm.reportValueFormat,
+        'tableDataDtoChList': params
+      }
 
-      this.getTableData(params, (res) => {
-        console.log('option==>',luckysheet.getAllSheets()[0])
-        console.log('table1==>',res)
+      this.getTableData(p, (res) => {
+        console.log('option==>', luckysheet.getAllSheets()[0])
+        console.log('table1==>', res)
         const optionData = packtable(res, luckysheet.getAllSheets()[0])
-        console.log('table2==>',optionData)
+        console.log('table2==>', optionData)
+        this.drawTableData(res, luckysheet.getAllSheets()[0])
       })
     },
+    drawTableData(sources, option) {
+      option.celldata.map(item => {
+        if (item.v.v) {
+          item.v.v = String(item.v.v).trim();
+          if (item.v.v.match(/\${([^}]+)}/g)) { // 替换${xxx}内部数据
+            let currDate = this.getNowFormatDate()
+            if (sources.length > 0 && sources[0].dataList.length > 0) {
+              currDate = sources[0].dataList[0].dh
+              currDate = currDate.substring(0, 10)
+            }
+            sources.forEach(source => {
+              let itemName = source.itemName
+              itemName = itemName.substring(itemName.lastIndexOf('.') + 1)
+              let name = '${' + source.itemGroupId + '.' + itemName + '}'
+              if (item.v.v === name) {
+                let dataList = source.dataList
+                for (let i = 0; i < dataList.length; i ++) {
+                  let p_r = parseInt(item.r) + i
+                  luckysheet.setCellValue(p_r, item.c, dataList[i].dv)
+                }
+              }
+            })
+
+            if (item.v.v.indexOf('${currDate}') > -1) {
+              let val = item.v.v
+              val = val.replace('${currDate}', currDate)
+              luckysheet.setCellValue(item.r, item.c, val)
+            }
+          }
+        }
+      })
+    },
+    getNowFormatDate() {
+      let date = new Date(),
+          year = date.getFullYear(), //获取完整的年份(4位)
+          month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
+          strDate = date.getDate() // 获取当前日(1-31)
+      if (month < 10) month = `0${month}` // 如果月份是个位数,在前面补0
+      if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数,在前面补0
+
+      return `${year}-${month}-${strDate}`
+    },
     /** 向 Excel 插入图表 */
     insertEChartInfo(chart) {
       let info = chart.info
@@ -492,7 +543,7 @@ export default {
             return '报表名称必须在20字以内'
           }
         }
-      }).then(({ value }) => {
+      }).then(({value}) => {
         if (!this.chooseReportTemplate) {
           this.$message({
             message: '请重新选择报表模版',
@@ -540,7 +591,8 @@ export default {
         exportExcel(luckysheet, reportName, ExcelJS).then((res) => {
           console.log("result==>", res);
           this.dialogDownloadReportTypeVisible = false
-        }).catch((err) => {})
+        }).catch((err) => {
+        })
       }
     },
     /** 取消保存报表 */
@@ -551,7 +603,7 @@ export default {
     },
     /** 弹出层关闭事件 */
     dialogClose(done) {
-      if (typeof(done) === 'function') {
+      if (typeof (done) === 'function') {
         done()
       } else {
         this.dialogReportTemplateVisible = false
@@ -568,9 +620,9 @@ export default {
 }
 
 .cy-nav-btn {
-  float: right!important;
-  margin-right: 20px!important;
-  margin-top: -20px!important;
+  float: right !important;
+  margin-right: 20px !important;
+  margin-top: -20px !important;
 }
 
 .cy-main {

+ 138 - 52
chuanyi_client2/src/views/report_template/index.vue

@@ -164,7 +164,7 @@
 
     <!-- 数据组选择 -->
     <el-dialog
-        :title="itemDataStep == 1 ? '选择数据项' : '选择四则运算表达式'"
+        title="选择数据项"
         width="80%"
         top="10vh"
         center
@@ -172,7 +172,7 @@
         :visible.sync="dialogDataItemVisible"
         :close-on-click-modal="false"
         :append-to-body="true">
-      <div v-if="itemDataStep == 1">
+      <div>
         <el-input placeholder="请输入关键字进行过滤" v-model="filterItemData"></el-input>
         <div style="height: 50vh; margin-top: 10px; overflow: auto;">
           <el-tree class="cy-item-tree"
@@ -198,48 +198,9 @@
           </el-tree>
         </div>
       </div>
-      <div v-if="itemDataStep == 2">
-        <el-table
-            :data="itemDataListByCalc"
-            :key="bomCheckKey"
-            style="width: 100%">
-          <el-table-column
-              label="数据项名称"
-              prop="itemName"
-              width="300">
-          </el-table-column>
-          <el-table-column
-              label="描述"
-              prop="describe"
-              width="150">
-            <template slot-scope="scope">
-              <el-tag
-                  :type="'primary'"
-                  disable-transitions>{{ scope.row.describe }}</el-tag>
-            </template>
-          </el-table-column>
-          <el-table-column
-              label="四则运算表达式"
-              prop="rule.operationRule"
-              width="300">
-          </el-table-column>
-          <el-table-column label="操作">
-            <template slot-scope="scope">
-              <el-button
-                  size="mini"
-                  @click="handleChoose(scope.$index, scope.row)">选择表达式</el-button>
-            </template>
-          </el-table-column>
-        </el-table>
-      </div>
       <div style="width: 100%;text-align: center;">
         <el-button type="primary"
-                   v-if="itemDataStep == 1"
                    @click="chooseItemTreeEvent"
-                   style="margin-top: 20px;">下一步</el-button>
-        <el-button type="primary"
-                   v-if="itemDataStep == 2"
-                   @click="chooseItemTreeEvent2"
                    style="margin-top: 20px;">确定</el-button>
       </div>
     </el-dialog>
@@ -292,6 +253,65 @@
       </div>
     </el-dialog>
 
+    <!-- 选择数据组数据 -->
+    <el-dialog
+        title="选择数据项"
+        width="80%"
+        top="10vh"
+        center
+        :before-close="dialogClose"
+        :visible.sync="dialogGroupItemVisible"
+        :close-on-click-modal="false"
+        :append-to-body="true">
+      <div>
+        <div>
+          <el-select filterable
+                     v-model="chooseDataGroup"
+                     placeholder="请选择数据组"
+                     style="width: calc(100% - 110px);">
+            <el-option
+                v-for="dict in dataGroupList"
+                :key="dict.id"
+                :label="dict.groupName"
+                :value="dict.id"
+            ></el-option>
+          </el-select>
+          <el-button size="mini" @click="addDataItem" style="float: right;width: 100px;margin-top: 4px;">选择数据项</el-button>
+        </div>
+        <div style="height: 50vh; margin-top: 10px; overflow: auto;">
+          <el-tree class="cy-item-tree"
+                   ref="itemTree"
+                   :data="chooseGroupItemList"
+                   :indent="10"
+                   node-key="id"
+                   show-checkbox
+                   :check-on-click-node="true"
+                   :filter-node-method="filterItemDataNode"
+                   :highlight-current="true"
+                   :default-expand-all="true">
+              <span class="custom-tree-node" slot-scope="{ node, data }">
+                <svg-icon v-if="!data.children || data.children.length == 0" icon-class="file"/>
+                <svg-icon v-else-if="node.expanded" icon-class="folder-open"/>
+                <svg-icon v-else icon-class="folder"/>
+                <span v-if="!data.children || data.children.length == 0" :title='data.itemName || "-"' style="margin-left: 2px;">
+<!--                  {{ data.describe-->
+<!--                    ? ((data.itemName ? data.itemName : '') + '【' + data.describe + '】')-->
+<!--                    : data.itemName ? data.itemName : '' }}-->
+                  {{ '【' + data.groupName + '】' + data.itemName + (data.describe ? ('(' + data.describe + ')') : '') }}
+                </span>
+                <span v-else :title='data.groupName || "-"' style="margin-left: 2px;">
+                  {{ data.groupName }}
+                </span>
+              </span>
+          </el-tree>
+        </div>
+      </div>
+      <div style="width: 100%;text-align: center;">
+        <el-button type="primary" style="margin-top: 20px;" @click="itemEvent">确定</el-button>
+        <el-button style="margin-top: 20px;" @click="dialogClose">取消</el-button>
+      </div>
+    </el-dialog>
+
   </div>
   <div v-else></div>
 </template>
@@ -301,7 +321,7 @@ import RulerView from '@/components/RulerView'
 import { insertEChart } from 'luckytool'
 import {
   getAllDataModel,
-  getAllItemGroup, getAllTableTemplate,
+  getAllItemGroup, getAllTableTemplate, getItemGroupById,
   getTableItemGroupById,
   getTableTemplateById,
   saveReportTemplate,
@@ -322,6 +342,7 @@ export default {
       dialogDataItemVisible: false,
       dialogDataModelVisible: false,
       dialogCommReportVisible: false,
+      dialogGroupItemVisible: false,
       menuLeft: 0,
       menuTop: 0,
       visibleChartMenu: false,
@@ -342,11 +363,11 @@ export default {
       dataGroupList: [],
       itemDataListByTree: [],
       itemDataListByCalc: [],
+      chooseGroupItemList: [],
       dataModelList: [],
       chooseDataModel: null,
       chooseDataItemIndex: null,
       bomCheckKey: 0,
-      itemDataStep: 1,
       chooseDataGroup: null,
       chooseItemData: [],
       filterItemData: '',
@@ -668,7 +689,6 @@ export default {
         })
         return
       }
-      this.itemDataStep = 1
       const loading = showLoading(this, '加载中,请稍候···')
       getTableItemGroupById(id).then(res => {
         loading.close()
@@ -708,14 +728,34 @@ export default {
         }
         chooseList.push(checkedNode)
       }
-      // this.chooseItemData = chooseList
-      this.getAllDataModel(chooseList)
-    },
-    /** 选择的数据项:第二步 */
-    chooseItemTreeEvent2() {
-      this.chooseItemData = JSON.parse(JSON.stringify(this.itemDataListByCalc))
-      this.itemDataStep = 1
+      this.chooseItemData = chooseList
       this.dialogDataItemVisible = false
+      if (this.dialogGroupItemVisible) {
+        this.initGroupItem()
+      }
+      // this.getAllDataModel(chooseList)
+    },
+    initGroupItem() {
+      let group = null
+      for (let i = 0; i < this.dataGroupList.length; i ++) {
+        if (this.dataGroupList[i].id == this.chooseDataGroup) {
+          group = this.dataGroupList[i]
+          break
+        }
+      }
+      this.chooseGroupItemList = this.chooseGroupItemList.filter(function (item, index) {
+        return item.itemGroupId != group.id;
+      })
+
+      for (let j = 0; j < this.chooseItemData.length; j ++) {
+        this.chooseItemData[j].groupName = group.groupName
+        this.chooseGroupItemList.push(this.chooseItemData[j])
+      }
+      let obj = {};
+      this.chooseGroupItemList = this.chooseGroupItemList.reduce(function(item, next) {
+        obj[next.id] ? '' : obj[next.id] = true && item.push(next)
+        return item;
+      }, [])
     },
     /** 查询所有数据模型 */
     getAllDataModel(itemList) {
@@ -726,7 +766,6 @@ export default {
       }
       getAllDataModel(params).then(res => {
         loading.close()
-        this.itemDataStep = 2
         if (!res.data) {
           this.chooseItemData = itemList
           return
@@ -798,6 +837,17 @@ export default {
     },
     /** 数据项 */
     dataEvent() {
+      let rangeWithFlatten = luckysheet.getRangeWithFlatten()
+      if (!rangeWithFlatten || rangeWithFlatten.length != 1) {
+        this.$message({
+          message: '请在 Excel 中选择图表需要存放的位置!',
+          type: 'warning'
+        })
+        return
+      }
+      this.chooseDataGroup = null
+      this.getDataGroupList()
+      this.dialogGroupItemVisible = true
     },
     /** 数据表 */
     dataEvent1() {
@@ -813,6 +863,41 @@ export default {
       this.getDataGroupList()
       this.dialogDataVisible = true
     },
+    itemEvent() {
+      if (this.chooseGroupItemList.length == 0) {
+        this.$message({
+          message: '请选择数据组项!',
+          type: 'warning'
+        })
+        return
+      }
+      let rangeWithFlatten = luckysheet.getRangeWithFlatten()
+      let c = rangeWithFlatten[0].c
+      let r = rangeWithFlatten[0].r
+      let fieldList = []
+      for (let i in this.chooseGroupItemList) {
+        let groupId = this.chooseGroupItemList[i].itemGroupId
+        let name = this.chooseGroupItemList[i].itemName
+        name = name.substring(name.lastIndexOf('.') + 1)
+        let v = '${' + groupId + '.' + name + '}'
+        let p_c = parseInt(c) + parseInt(i)
+        fieldList.push({
+          'name': v,
+          'r': r,
+          'c': p_c
+        })
+        luckysheet.setCellValue(r, p_c, v)
+      }
+      let tableTem = {
+        'item': this.chooseGroupItemList,
+        'field': fieldList
+      }
+      this.toolTable.push(tableTem)
+      this.chooseGroupItemList = []
+      this.chooseDataGroup = null
+      this.chooseItemData = []
+      this.dialogGroupItemVisible = false
+    },
     /** 数据字段添加 */
     transferEvent() {
       if (this.transferValue.length == 0) {
@@ -1105,6 +1190,7 @@ export default {
         this.dialogDataItemVisible = false
         this.dialogDataModelVisible = false
         this.dialogCommReportVisible = false
+        this.dialogGroupItemVisible = false
       }
     },
     /** 弹出层关闭事件 */