ソースを参照

月报:另存为

洪海涛 4 年 前
コミット
778b972fa1

+ 48 - 9
src/store/modules/monthlyReport/edit/index.js

@@ -23,6 +23,7 @@ import {
   setDeptArch,
   setIndexTitle,
   arrToObj,
+  objToArr,
   setTableHeader
 } from './utils'
 import { message } from '@/utils/mesDebounce'
@@ -65,7 +66,13 @@ export default {
     reportList: [], // 默认为用户
     pageType: 'edit', // edit:(月报编辑和新建); readAll:(查看月报详情)
     loading: false,
-    clientTypeList: []
+    clientTypeList: [],
+    // 单业务线编辑时,数据迁移
+    saveAsTargetList: []
+    // saveAsData: {
+    //   tableRow: '',
+    //   targetSubReportId: ''
+    // }
   },
   mutations: {
     // 页面基础数据赋值
@@ -518,27 +525,53 @@ export default {
       state.clientTypeList = list
       setDeptArch(state.clientTypeList)
     },
-    // 数据另存为
-    SAVE_AS(state, { tableHeaders, tableRows, subReportName }) {
+    /**
+    * 数据另存为
+    *
+    */
+    SAVE_AS(state, { tableHeaders, tableRows, subReportid, key = 'only' }) {
       // setTableHeader(data.tableHeaders)
-      const rowData = arrToObj(
+      const rowData = objToArr(
         [tableRows],
         tableHeaders
       )
       const find = (arr) => {
         arr.forEach(elm => {
           if (elm.title === '线上问题') {
-            elm.content[0].tableRows.push(rowData)
+            // console.log(532, elm, rowData)
+            // console.log(elm.content[0].tableRows, rowData)
+            elm.content[0].tableRows.push(rowData[0])
           }
           if (elm.children && elm.children.length) {
             find(elm.children)
           }
         })
       }
-      for (let i = state.reportData.length - 1; i >= 0; i--) {
-        const elm = state.reportData[i]
-        if (elm.reportName === subReportName) {
-          find(elm.reportCatalog.children)
+      // 多业务线转移
+      if (state.pageType === 'editAll') {
+        for (let i = state.reportData.length - 1; i >= 0; i--) {
+          const elm = state.reportData[i]
+          if (elm.reportName === subReportid) {
+            find(elm.reportCatalog.children)
+          }
+        }
+      } else {
+        // 单业务线转移
+        // 判断数据是否存在,不存在,就插入
+        if (state.saveAsTargetList.filter(elm => elm.targetSubReportId === subReportid).length) {
+          state.saveAsTargetList.forEach(elm => {
+            if (elm.targetSubReportId === subReportid) {
+              if (!elm.tableRow) {
+                elm.tableRow = []
+              }
+              elm.tableRow.push(rowData[0])
+            }
+          })
+        } else {
+          state.saveAsTargetList.push({
+            targetSubReportId: subReportid,
+            tableRow: [rowData[0]]
+          })
         }
       }
     }
@@ -642,6 +675,10 @@ export default {
         type: 'Tag'
       }
       params.reportCatalog = reportDataBack(params.reportCatalog)
+      if (state.saveAsTargetList.length) {
+        params.saveAsTargetList = _.cloneDeep(state.saveAsTargetList)
+      }
+      params.dependence = null
       const res = await updateSubReport(params)
       if (res.code === 200) {
         callback()
@@ -657,6 +694,7 @@ export default {
         if (`${elm.id}` === tabsActive) {
           return {
             ...elm,
+            dependence: null,
             reportCatalog: { ...reportDataBack({ ...tabPageData }) }
           }
         }
@@ -700,6 +738,7 @@ export default {
         if (`${elm.id}` === tabsActive) {
           return {
             ...elm,
+            dependence: null,
             reportCatalog: { ...reportDataBack({ ...tabPageData }) }
           }
         }

+ 7 - 1
src/store/modules/monthlyReport/edit/utils.js

@@ -117,7 +117,7 @@ export function arrToObj(arr, headerList) {
     const obj = {}
     // elm.tableItems && elm.tableItems.length && elm.tableItems.forEach((item, index) => {
     headerList.forEach((helm, index) => {
-      const { headerKey, displayType, itemInfo, selectType } = helm
+      const { headerKey, displayType, name, itemInfo, selectType } = helm
       const item = elm.tableItems[index]
       if (item) {
         obj[headerKey] = item.value
@@ -129,6 +129,9 @@ export function arrToObj(arr, headerList) {
             obj[headerKey] = strToArr(obj[headerKey])
           }
         }
+        if (name === '原因') {
+          obj.operationTarget = elm.operationTarget
+        }
         if (!itemInfo) {
           headerList[index].itemInfo = _.clone(item)
         }
@@ -181,6 +184,9 @@ export function objToArr(obj, tableHeaders) {
             param.value = JSON.stringify(param.value)
           }
         }
+        if (item.name === '原因') {
+          param.operationTarget = elm.operationTarget
+        }
         if (!elms.tableItems) {
           elms.tableItems = []
         }

+ 36 - 1
src/views/monthlyReport/childrenPage/editReport/components/MrTable.vue

@@ -59,8 +59,21 @@
                   v-for="(btnItem, btnIndex) in item.defaultValue"
                   :key="btnIndex"
                 >
+                  <!--另存为-->
+                  <span v-if="btnItem.value === '另存为' && isShowButton(scope.row, item)" style="margin-right: 10px">
+                    <el-dropdown @command="(command) => saveAsRow(command, scope.row, item)">
+                      <el-button type="text">
+                        迁移&nbsp;&nbsp;<!--<i class="el-icon-arrow-down el-icon--right" />-->
+                      </el-button>
+                      <el-dropdown-menu slot="dropdown">
+                        <el-dropdown-item v-for="subItem in subReportInfo.filter(subElm => subReportInfoFilter(subElm) )" :key="subItem.id" :command="subItem">
+                          {{ subItem.reportName }}
+                        </el-dropdown-item>
+                      </el-dropdown-menu>
+                    </el-dropdown>
+                  </span>
                   <el-button
-                    v-if="isShowButton(scope.row, item)"
+                    v-else-if="isShowButton(scope.row, item)"
                     style="margin-right: 10px"
                     type="text"
                     @click.stop="btnFun(btnItem, scope)"
@@ -322,6 +335,9 @@ export default {
     subReportName() {
       return this.$store.state.monthlyReportEdit.subReportName
     },
+    subReportInfo() {
+      return this.$store.state.monthlyReportEdit.subReportInfo
+    },
     editKeys() {
       return this.$store.state.monthlyReportEdit.editKeys
     }
@@ -375,6 +391,9 @@ export default {
       if (btnItem.value === '删除') {
         this.tableData.splice(scope.$index, 1)
       }
+      if (btnItem.value === '另存为') {
+        console.log(btnItem, scope, this.columns)
+      }
       if (btnItem.value === '标记') {
         this.$refs.markingIssues.modalShow = true
         this.$nextTick(() => {
@@ -390,6 +409,15 @@ export default {
         this.$refs.Analysis.open(scope.row.analyticFeedback, scope.$index)
       }
     },
+    // 另存为
+    saveAsRow(command, row, item) {
+      console.log(414)
+      this.$store.commit('monthlyReportEdit/SAVE_AS', {
+        tableHeaders: this.columns,
+        tableRows: row,
+        subReportid: command.id
+      })
+    },
     // 分析反馈问题更新
     upDataAnalysis({ rowIndex, analyticFeedback }) {
       if (this.pageType.search(/edit/) < 0) {
@@ -573,6 +601,13 @@ export default {
           }
         })
       }
+    },
+    subReportInfoFilter(elm) {
+      const { subReportId } = this.$route.query;
+      if(this.pageType === 'edit'){
+        return `${elm.id}` !== `${subReportId}`
+      }
+      return  this.tabsActive.indexOf(elm.id) < 0
     }
   }
 }