yumeng 1 週間 前
コミット
287cde66fb
1 ファイル変更122 行追加98 行削除
  1. 122 98
      src/views/dashboard/onlyOneDashboard.vue

+ 122 - 98
src/views/dashboard/onlyOneDashboard.vue

@@ -326,7 +326,7 @@
                             </div>
                             <div class="item">
                                 <span>媒体维度</span>
-                                <a-radio-group v-model="mediaDimension" @change="getProjectList">
+                                <a-radio-group v-model="mediaDimension" @change="handleMediaDimensionChange">
                                     <a-radio-button value="b">快手</a-radio-button>
                                     <a-radio-button value="a">头条</a-radio-button>
                                     <a-radio-button value="c">腾讯</a-radio-button>
@@ -351,13 +351,13 @@
                                     >
                                         数据请求中,请稍后。。。
                                     </a-select-option>
-                                    <a-select-option
-                                        v-for="(item, index) in dataDimensionList"
-                                        :key="index + 1"
-                                        :value="item.id"
-                                    >
-                                        {{ item.projectName }}
-                                    </a-select-option>
+                                    <a-select-option
+                                        v-for="(item, index) in dataDimensionList"
+                                        :key="item.projectId || item.id || index"
+                                        :value="item.projectId"
+                                    >
+                                        {{ item.projectName }}
+                                    </a-select-option>
                                 </a-select>
                             </div>
                             <div class="item">
@@ -420,17 +420,17 @@
         <a-row :gutter="24" style="margin-top: 20px" id="getWidth">
             <a-col :xl="24">
                 <a-card style="width: 100%" title="项目报表">
-                    <div slot="extra">
-                        <a-select
-                            v-model="category"
-                            style="width: 300px; margin-left: 10px"
-                            :mode="'default'"
-                            @change="getTableMediaList"
-                        >
-                            <a-select-option :value="0"> 全部 </a-select-option>
-                            <a-select-option :value="1"> 环比-10% </a-select-option>
-                        </a-select>
-                    </div>
+                    <div slot="extra">
+                        <a-select
+                            v-model="category"
+                            style="width: 300px; margin-left: 10px"
+                            :mode="'default'"
+                            @change="handleProjectCategoryChange"
+                        >
+                            <a-select-option :value="0"> 全部 </a-select-option>
+                            <a-select-option :value="1"> 环比-10% </a-select-option>
+                        </a-select>
+                    </div>
                     <a-table
                         size="middle"
                         :dataSource="designTopList"
@@ -458,10 +458,10 @@
                             <a-icon v-if="text && parseFloat(text) > 0" type="caret-up" style="color: #f00" />
                             <a-icon v-else type="caret-down" style="color: green" />
                         </span>
-                    </a-table>
-                </a-card>
-            </a-col>
-        </a-row>
+                    </a-table>
+                </a-card>
+            </a-col>
+        </a-row>
 
         <a-row :gutter="24" style="margin-top: 20px">
             <a-col :xl="24">
@@ -687,22 +687,7 @@ const aColumns = [
         scopedSlots: { customRender: 'newTrushUnitNum' },
     },
 ]
-const bColumns = [
-    {
-        title: '自定义基建数',
-        dataIndex: 'unitNum',
-        align: 'center',
-        scopedSlots: { customRender: 'unitNum' },
-        sorter: () => {},
-    },
-    {
-        title: '托管基建数',
-        dataIndex: 'trushUnitNum',
-        align: 'center',
-        scopedSlots: { customRender: 'trushUnitNum' },
-    },
-]
-const ttaColumns = [
+const ttaColumns = [
     {
         title: '今日上新数',
         dataIndex: 'materialUploadMediaNum',
@@ -733,15 +718,6 @@ const ttaColumns = [
     },
     
 ]
-const ttbColumns = [
-    {
-        title: '自定义基建数',
-        dataIndex: 'unitNum',
-        align: 'center',
-        scopedSlots: { customRender: 'unitNum' },
-        sorter: () => {},
-    },
-]
 const txColumns = [
     {
         title: '媒体上新数',
@@ -770,16 +746,10 @@ export default {
                 },
                 showQuickJumper: true,
                 // showSizeChanger: true,
-                pageSizeOptions: ['10', '30', '50'],
-                total: 0,
-                onChange: (current, pageSize) => {
-                    // 切换分页时的回调,
-                    // 当在页面定义change事件时,切记要把此处的事件清除,因为这两个事件重叠了,可能到时候会导致一些莫名的bug
-                    this.ipagination.current = current
-                    this.ipagination.pageSize = pageSize
-                    this.getTableMediaList()
-                },
-            },
+                pageSizeOptions: ['10', '30', '50'],
+                total: 0,
+                onChange: (current, pageSize) => {},
+            },
             tabListNoTitle: [
                 {
                     key: '2',
@@ -1009,15 +979,6 @@ export default {
         usesCostField() {
             return this.isBytedanceMedia() || this.isTencentMedia()
         },
-        isTodayRange() {
-            if (this.dateValue.length !== 2) {
-                return false
-            }
-            const startDate = this.dateValue[0].format('YYYY-MM-DD')
-            const endDate = this.dateValue[1].format('YYYY-MM-DD')
-            const today = moment().format('YYYY-MM-DD')
-            return startDate === endDate && endDate === today
-        },
         getSummaryField(mediaKey, fieldKey) {
             const fieldMap = {
                 kuaishou: {
@@ -1054,13 +1015,9 @@ export default {
                 return this.applyTencentColumnWidths([...columnsFixd, ...numColumns, ...txColumns])
             }
             if (this.isBytedanceMedia()) {
-                return this.isTodayRange()
-                    ? [...columnsFixd, ...numColumns, ...ttaColumns]
-                    : [...columnsFixd, ...numColumns, ...ttbColumns]
+                return [...columnsFixd, ...numColumns, ...ttaColumns]
             }
-            return this.isTodayRange()
-                ? [...columnsFixd, ...ksColumns, ...numColumns, ...aColumns]
-                : [...columnsFixd, ...ksColumns, ...numColumns, ...bColumns]
+            return [...columnsFixd, ...ksColumns, ...numColumns, ...aColumns]
         },
         getProjectTableScrollX() {
             return this.isTencentMedia() ? 1560 : 2400
@@ -1102,6 +1059,13 @@ export default {
             }
             return value
         },
+        normalizeProjectOption(item) {
+            return {
+                ...item,
+                projectId: item.projectId || item.id,
+                projectName: item.projectName || item.name,
+            }
+        },
         normalizeProjectReportRow(item, index = 0) {
             const baseRow = {
                 ...item,
@@ -1348,10 +1312,30 @@ export default {
                     this.searchLoading = false
                     // this.$error({
                     // 	title: '页面数据加载出错',
-                    // 	content: '请刷新重试或联系管理员查询'
-                    // });
-                })
-        },
+                    // 	content: '请刷新重试或联系管理员查询'
+                    // });
+                })
+        },
+        refreshDashboardData() {
+            this.spinning = true
+            this.spinningChart = true
+            this.resetLoading = true
+            this.designTopList = []
+            this.chartList = []
+            this.operateDetailList = []
+            this.operateGroupList = []
+            return Promise.all([
+                this.getChartMediaList(),
+                this.getTableMediaList(null),
+                this.getGroupData(),
+                this.getDetailData(),
+            ])
+                .finally(() => {
+                    this.spinning = false
+                    this.spinningChart = false
+                    this.resetLoading = false
+                })
+        },
 
         getSumData() {
             return new Promise((resolve) => {
@@ -1374,14 +1358,19 @@ export default {
         },
         getChartMediaList() {
             var params = {}
+            const mediaId = this.getCurrentMediaId()
             params.projectId = this.dataDimensionValue
-            params.mediaId = this.getCurrentMediaId()
+            params.mediaId = mediaId
             params.startTime = this.dateValue.length === 2 ? moment(this.dateValue[0]).format('YYYY-MM-DD') : null
             params.endTime = this.dateValue.length === 2 ? moment(this.dateValue[1]).format('YYYY-MM-DD') : null
             params.type = this.dataType
             return new Promise((resolve) => {
                 this.getAction(process.env.VUE_APP_BASE_STARE_URL + '/summary/report/getTrendCharge', params)
                     .then((res) => {
+                        if (mediaId !== this.getCurrentMediaId()) {
+                            resolve(null)
+                            return
+                        }
                         this.resetLoading = false
                         if (res.success) {
                             this.chartList = res.result.today
@@ -1405,13 +1394,13 @@ export default {
 
             this.designTopLoading = true
             var params = {}
+            const mediaId = this.getCurrentMediaId()
             params.projectId = this.dataDimensionValue
-            params.mediaId = this.getCurrentMediaId()
+            params.mediaId = mediaId
             params.startTime = this.dateValue.length === 2 ? moment(this.dateValue[0]).format('YYYY-MM-DD') : null
             params.endTime = this.dateValue.length === 2 ? moment(this.dateValue[1]).format('YYYY-MM-DD') : null
-            params.pageNo = this.ipagination.current
-            params.pageSize = this.ipagination.pageSize
-            params.category = this.category
+            params.allData = true
+            params.category = this.category
 
             //  target: 'unitNum',
             // order: 'descend',
@@ -1434,12 +1423,16 @@ export default {
             return new Promise((resolve) => {
                 this.getAction(process.env.VUE_APP_BASE_STARE_URL + '/summary/report/getProjectReport', params)
                     .then((res) => {
+                        if (mediaId !== this.getCurrentMediaId()) {
+                            resolve(null)
+                            return
+                        }
                         this.designTopLoading = false
                         if (res.success) {
                             this.designTopList = res.result.list.map((item, index) =>
                                 this.normalizeProjectReportRow(item, index)
                             )
-                            this.ipagination.total = res.result.total
+                            this.ipagination.total = this.designTopList.length
                             resolve(res.result)
                         } else {
                             resolve(null)
@@ -1457,13 +1450,20 @@ export default {
             this.dataDimensionList = []
             this.dataDimensionValue = null
             this.columns = this.getCurrentTableColumns()
+            const mediaId = this.getCurrentMediaId()
             return new Promise((resolve) => {
-                this.getAction('/ctop/project/getProjectListByMediaId?mediaId=' + this.getCurrentMediaId())
+                this.getAction('/ctop/project/getProjectListByMediaId?mediaId=' + mediaId)
                     .then((res) => {
+                        if (mediaId !== this.getCurrentMediaId()) {
+                            resolve(null)
+                            return
+                        }
                         this.specificLoading = false
                         if (res.success) {
-                            this.dataDimensionList = res.result
-                            resolve(res.result)
+                            this.dataDimensionList = (res.result || []).map((item) =>
+                                this.normalizeProjectOption(item)
+                            )
+                            resolve(this.dataDimensionList)
                         } else {
                             resolve(null)
                         }
@@ -1474,17 +1474,31 @@ export default {
                     })
             })
         },
+        handleMediaDimensionChange(e) {
+            if (e && e.target && e.target.value) {
+                this.mediaDimension = e.target.value
+            }
+            this.target = ''
+            this.order = 'descend'
+            this.ipagination.current = 1
+            this.getProjectList().finally(() => {
+                this.refreshDashboardData()
+            })
+        },
+        handleProjectCategoryChange() {
+            this.ipagination.current = 1
+            this.getTableMediaList(null)
+        },
         sort(pagination, filters, sorter, { currentDataSource }) {
-            this.ipagination.current = pagination.current
-            this.ipagination.pageSize = pagination.pageSize
-
-            if (sorter.order) {
-                this.order = sorter.order ? sorter.order : 'descend'
-                this.target = sorter.columnKey
-                this.getTableMediaList({
-                    target: sorter.columnKey,
-                    order: sorter.order ? sorter.order : 'descend',
+            if (sorter.order) {
+                this.order = sorter.order ? sorter.order : 'descend'
+                this.target = sorter.columnKey
+                this.getTableMediaList({
+                    target: sorter.columnKey,
+                    order: sorter.order ? sorter.order : 'descend',
                 })
+            } else {
+                this.getTableMediaList(null)
             }
         },
         buildRowKey(item, index, preferredKeys = [], prefix = 'row') {
@@ -1514,14 +1528,19 @@ export default {
             this.operateGroupLoading = true
             let that = this
             let params = {}
-            params.mediaId = this.getCurrentMediaId()
+            const mediaId = this.getCurrentMediaId()
+            params.mediaId = mediaId
             params.startTime = this.dateValue.length === 2 ? moment(this.dateValue[0]).format('YYYY-MM-DD') : null
             params.endTime = this.dateValue.length === 2 ? moment(this.dateValue[1]).format('YYYY-MM-DD') : null
             params.userId = this.userInfo().id
-
+
             return new Promise((resolve) => {
                 that.getAction(process.env.VUE_APP_BASE_STARE_URL + '/summary/report/getOperateGroupInfo', params)
                     .then((res) => {
+                        if (mediaId !== this.getCurrentMediaId()) {
+                            resolve(null)
+                            return
+                        }
                         this.operateGroupLoading = false
                         if (res.success) {
                             this.operateGroupList = this.normalizeTableRows(
@@ -1544,13 +1563,18 @@ export default {
             this.operateDetailLoading = true
             let that = this
             let params = {}
-            params.mediaId = this.getCurrentMediaId()
+            const mediaId = this.getCurrentMediaId()
+            params.mediaId = mediaId
             params.startTime = this.dateValue.length === 2 ? moment(this.dateValue[0]).format('YYYY-MM-DD') : null
             params.endTime = this.dateValue.length === 2 ? moment(this.dateValue[1]).format('YYYY-MM-DD') : null
             params.userId = this.userInfo().id
             return new Promise((resolve) => {
                 that.getAction(process.env.VUE_APP_BASE_STARE_URL + '/summary/report/getOperateInfo', params)
                     .then((res) => {
+                        if (mediaId !== this.getCurrentMediaId()) {
+                            resolve(null)
+                            return
+                        }
                         this.operateDetailLoading = false
                         if (res.success) {
                             this.operateDetailList = this.normalizeTableRows(