<style lang="scss" scoped>
::v-deep.import-padding-top .ant-modal-body {
    padding-top: 10px;
}

::v-deep.vue-treeselect__control {
    line-height: 20px !important;
}

::v-deep .table-page-search-wrapper .ant-form-item .ant-form-item-control {
    height: auto !important;
    line-height: 20px !important;
}

// ::v-deep .table-page-search-wrapper .ant-form-inline .ant-form-item {
//     margin-bottom: 0;
// }
.adver-position-radio {
    margin-bottom: 15px;

    .create-web-url-class {
        width: 320px;
        height: 110px;
        background-color: #f9f8f8;
        display: flex;

        .web-url-img {
            width: 53px;

            img {
                width: 100%;
            }
        }

        .web-url-content {
            margin-top: 10px;
            margin-left: 10px;

            .url-content-id {
                margin-top: 10px;
            }
        }
    }

    .creative-label-content {
        width: 400px;
        height: 200px;
        padding: 10px;
        border: 1px solid #eee;

        .label-content-select-tag {
            height: 80%;
            overflow: auto;
        }

        .tag-select-class {
            margin-bottom: 15px;
        }
    }

    .examin-form-icon {
        font-size: 18px;
        color: #1890ff;
        cursor: pointer;
        margin-left: 10px;
    }
}

.search-bar {
    display: flex;
    align-items: center;
}

.search-box p {
    display: inline-block;
    border: 1px solid #f2f2f2;
    border-radius: 5px;
    margin-right: 10px;
    padding: 5px 10px;
    cursor: pointer;
}

.card-person-drawer {
    width: 100%;
    height: 90%;
    overflow: hidden;
    padding: 10px 0px;
    display: flex;
    flex-wrap: wrap;
    margin-right: -10px;

    ::v-deep .ant-card-body {
        padding: 0;
    }

    ::v-deep .ant-card-head {
        padding: 0 5px;
    }

    .card-item {
        width: calc(20% - 10px);
        margin: 10px 5px;
        float: left;
    }

    .card-item-else {
        width: calc(20% - 10px);
        margin: 10px 5px;
        float: left;
    }
}
</style>
<style scoped>
.showNumBox {
    margin: 10px 0;
}

.showNumBox .ant-card-body {
    display: flex;
    justify-content: center;
}

.showNumBox p,
.showNumBox span {
    text-align: center;
    line-height: 40px;
    font-size: 30px;
    font-weight: 600;
    color: red;
    margin: 0;
}

.search-box .ant-card-body {
    padding: 5px 15px;
}

.showNumBox .ant-card-body .styleElse {
    line-height: 60px;
    height: 40px;
    font-size: 16px;
    font-weight: 400;
    margin-left: 10px;
}

.ant-modal-wrap .yincang .ant-modal-content .ant-modal-footer {
    display: none !important;
}

.yincang .ant-col-6 p {
    text-align: left;
    color: red;
    font-size: 16px;
    font-weight: 500;
}

.ant-table-thead div {
    font-weight: 700;
}

.tool-tip {
    position: absolute;
    top: 65px;
    right: 10px;
}
</style>
<style lang="less" scoped>
.ant-card-head .ant-tabs-bar {
    padding: 0;
}

.search-box .ant-card-body {
    padding: 5px 15px;
}

.search-box {
    padding: 15px 10px;
}

.search-box p {
    display: inline-block;
    border: 1px solid #f2f2f2;
    border-radius: 5px;
    margin-right: 10px;
    padding: 5px 10px;
    cursor: pointer;
}

.statistics .ant-col-6 .ant-card-body .styleElse {
    line-height: 60px;
    height: 40px;
    font-size: 16px;
    font-weight: 400;
    margin-left: 10px;
}

.ant-modal-wrap .yincang .ant-modal-content .ant-modal-footer {
    display: none !important;
}

.yincang .ant-col-6 p {
    text-align: left;
    color: red;
    font-size: 16px;
    font-weight: 500;
}

.ant-table-thead div {
    font-weight: 700;
}

.tool-tip {
    position: absolute;
    top: 65px;
    right: 10px;
}

.statistics {
    .ant-card-bordered {
        border: none;
    }

    .ant-card-head .ant-tabs {
        clear: both;
        margin-bottom: -13px;
        color: rgba(0, 0, 0, 0.65);
        font-weight: normal;
        font-size: 14px;
    }

    .duibi {
        position: absolute;
        right: 24px;
        top: 15px;
    }

    p {
        margin-bottom: 0;
    }
}
</style>

<style lang="less" scoped>
.middle-button {
    margin: 0 8px;
}

.newPlanStatic {
    .divider {
        height: 62px;
    }

    .showNumBox {
        background: white;
        overflow: hidden;
        margin: 15px 0;
        padding: 30px 0;
        text-align: center;

        .ant-card-body {
            padding-top: 0;
        }

        .title {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 22px;
            display: inline-block;
        }
    }

    .tabbody {
        background: white;
        padding: 0 24px;
        margin-bottom: 15px;

        .ant-tabs-bar {
            margin: 0;
        }
    }

    .chartBox {
        background: white;
        padding: 20px 0;
    }

    .tableBody {
        background: white;
        padding: 20px;
    }
}
</style>
<style>
.display-none-selset {
    display: none !important;
}
</style>
<template>
    <div class="newPlanStatic config-project">
        <div class="tabbody">
            <a-tabs v-model="tabKey" @change="tabChange">
                <a-tab-pane :key="1" tab="项目明细"></a-tab-pane>
                <a-tab-pane :key="3" tab="设计明细"></a-tab-pane>
                <a-tab-pane :key="2" tab="汇总" v-if="this.userInfo().roleName == '管理员' || this.userInfo().roleName == '媒介'"></a-tab-pane>
                <div slot="tabBarExtraContent">
                    <a-button type="primary" @click="newCreat(1)"> 导入明细</a-button> &nbsp;
                    <a-button type="primary" @click="newCreat(2)"> 导入汇总</a-button>
                </div>
            </a-tabs>
        </div>
        <a-card>
            <div class="table-page-search-wrapper">
                <a-form layout="inline" :form="form" hide-required-mark :selfUpdate="true">
                    <div style="margin-bottom: 15px; color: red; font-weight: 700">
                        <span
                        >建议导入频率：每天导入汇总、明细数据</span
                        >
                    </div>
                    <a-row :gutter="24">

                        <a-col :md="6" :sm="6" :xxl="6">
                            <a-form-item label="时间选择">
                                <a-month-picker
                                    v-model="dateMonth"
                                    picker="month"
                                    placeholder="请选择月份"
                                    v-decorator="['statMonth', { initialValue: moment() }]"
                                    style="width: 100%; height: 32px"
                                />
                            </a-form-item>
                        </a-col>
                        <a-col :md="6" :sm="6" :xxl="6" v-if="tabKey == 3">
                            <a-form-item label="角色">
                                <a-radio-group v-model="designRole">
                                    <a-radio-button buttonStyle="solid" :value="1">剪辑</a-radio-button>
                                    <a-radio-button buttonStyle="solid" :value="2">拍摄</a-radio-button>
                                    <a-radio-button buttonStyle="solid" :value="3">编导</a-radio-button>
                                </a-radio-group>
                            </a-form-item>
                        </a-col>


                        <a-col :md="6" :sm="6" :xxl="6">
                            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                                <a-button type="primary" icon="search" @click="handleQueryList">查询</a-button>
                                <a-button type="primary" @click="handleResetForm" icon="reload" class="middle-button"
                                >重置</a-button>
                                          <a-button
                                              @click="exportExcel"
                                              :loading="visibleLoading"
                                              style="margin-right: 15px"
                                          >
                        导 出
                    </a-button>
                            </span>
                        </a-col>
                    </a-row>

                </a-form>
            </div>
        </a-card>

        <a-row style="margin-bottom: 15px; margin-top: 12px" v-if="this.tabKey == 1">
            <a-col :span="24">
                <div class="tableBody" style="min-height: 200px; padding-bottom: 50px">
                    <a-table
                        :columns="columns"
                        :dataSource="recordList"
                        :pagination="ipaginationRecord"
                        :loading="dataLoading"
                        bordered
                        size="middle"
                        style="word-break: break-all; font-size: 16px; font-weight: 600"
                        id="outTable"
                        ref="accountTable"
                        rowKey="number"

                    >
             <span slot="color" slot-scope="text, record">
                 <p v-if="record.color == 2"><font color="green">{{ record.effRate }}%</font></p>
                 <p v-if="record.color == 1">{{ record.effRate }}%</p>

          </span>
                        <span slot="mediaEffRate" slot-scope="text, record">
                 <p>{{ record.mediaEffRate }}%</p>
          </span>

                    </a-table>

                </div>
            </a-col>
        </a-row>


        <a-row style="margin-bottom: 15px; margin-top: 12px" v-if="this.tabKey == 3">
            <a-col :span="24">
                <div class="tableBody" style="min-height: 200px; padding-bottom: 50px">
                    <a-table
                        :columns="designColumns"
                        :dataSource="designList"
                        :pagination="ipaginationRecord"
                        :loading="dataLoading"
                        bordered
                        size="middle"
                        style="word-break: break-all; font-size: 16px; font-weight: 600"
                        id="outTable"
                        ref="accountTable"
                        rowKey="number"

                    >
         <span slot="effRate" slot-scope="text, record">
                 <p v-if="record.color == 2"><font color="green">{{ record.effRate }}%</font></p>
                 <p v-if="record.color == 1">{{ record.effRate }}%</p>

          </span>
                        <span slot="mediaEffRate" slot-scope="text, record">
                 <p>{{ record.mediaEffRate }}%</p>
          </span>

                    </a-table>
                </div>
            </a-col>
        </a-row>


        <a-row style="margin-bottom: 15px; margin-top: 12px" v-if="this.tabKey == 2">
            <a-col :span="24">
                <div class="tableBody" style="min-height: 200px; padding-bottom: 50px">
                    <a-table
                        :columns="totalColumns"
                        :dataSource="totalList"
                        :pagination="ipaginationRecord"
                        :loading="dataLoading"
                        bordered
                        size="middle"
                        style="word-break: break-all; font-size: 16px; font-weight: 600"
                        id="outTable"
                        ref="accountTable"
                        rowKey="number"

                    >
                    </a-table>

                </div>
            </a-col>
        </a-row>


        <a-modal
            v-if="scoreVisible"
            title="导入数据"
            :visible="scoreVisible"
            :confirmLoading="exportLoading"
            dialog-class="web-url-modal"
            @cancel="
                scoreVisible = false
                dataFile = undefined
            "
            @ok="importFile"

        >
            <a-form-item
                label="上传数据"
                :labelCol="{ xs: { span: 24 }, sm: { span: 5 } }"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 16 } }"
                id="fileUpload"
                class="require-class fileUpload"
            >
                <a-upload
                    name="file"
                    :multiple="false"
                    :headers="tokenHeader"
                    :file-list="fileList"
                    :showUploadList="false"
                    :beforeUpload="beforeUpload"
                    @change="handleChange"
                    style="margin-right: 20px"
                >
                    <a-button>
                        <a-icon type="upload"/>
                        {{ loadDisabled ? '上传中,请稍后' : '文件上传' }}
                    </a-button>
                </a-upload>
            </a-form-item>
        </a-modal>

    </div>
</template>

<script>
import {TreeSelect} from 'ant-design-vue'

const SHOW_PARENT = TreeSelect.SHOW_PARENT
import ARow from 'ant-design-vue/es/grid/Row'
import ACol from 'ant-design-vue/es/grid/Col'
import moment from 'moment'
import {getAction, postAction, downFile, downFilePost} from '@/api/manage'
import checkBoxGroup from '@/components/formComponents/checkBoxGroup'
import selectCheckAll from '@/views/modules/kuaishouapp/account/stepForm/stepModule/test'
import qs from 'qs'
import {mapGetters} from 'vuex'
import selectTreeAccount from '@/components/formComponents/selectAccount.vue'
import liveDataAll from './components/live-data-service'

import Vue from 'vue'
import {ACCESS_TOKEN} from '@/store/mutation-types'
import $ from 'jquery'

const fileSuffix = ['xlsx', 'xls', 'csv']

function tqFun(qcArr1) {
    var tempArr = []

    function bbFun(qcArr) {
        for (var i = 0; i < qcArr.length; i++) {
            if (qcArr[i] instanceof Array) {
                bbFun(qcArr[i])
            } else {
                tempArr.push(qcArr[i])
            }
        }
        return tempArr
    }

    return bbFun(qcArr1)
}

export default {
    components: {
        ACol,
        ARow,
        checkBoxGroup,
        selectCheckAll,
        selectTreeAccount,
    },

    data() {
        return {
            visibleLoading: false,
            designRole: 1,
            dateMonth: null,
            importfileType: 1,
            tokenHeader: {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)},
            fileList: [],
            dataFile: null,
            loadDisabled: false,
            labelCheck: '地域',
            saleLoading: false,
            selectionRows: [],
            selectionRowsAll: [],
            config_id: null,
            appIds: [],
            appOptions: [],
            materialVisible: false,
            materialLoading: false,
            scheduleTimeData: [{scheduleTime: ''}],
            indexAll: 0,
            spinning: false,
            form: this.$form.createForm(this),
            priceForm: this.$form.createForm(this),
            variableForm: this.$form.createForm(this),
            variableLoading: false,
            exportLoading: false,
            dateRange: [moment().subtract(1, 'weeks'), moment()],
            noImg: require('@/assets/noImg.png'),
            scoreData: [
                {
                    score: '素材消耗达到2W+的概率',
                    you: '19.05%',
                    liang: '43.30%',
                    cha: '69.16%',
                },
            ],

            dateRanges: {
                昨天: [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                近三天: [moment().subtract(2, 'days'), moment()],
                近一周: [moment().subtract(6, 'days'), moment()],
                近14天: [moment().subtract(13, 'days'), moment()],
                近一月: [moment().subtract(1, 'months'), moment()],
            },


            recordList: [],
            totalList: [],
            ipaginationRecord: {
                current: 1,
                pageSize: 10,
                showTotal: (total, range) => {
                    return range[0] + '-' + range[1] + ' 共' + total + '条'
                },
                showQuickJumper: true,
                showSizeChanger: false,
                /* pageSizeOptions: ['10', '30', '50'],*/
                total: 0,
                onChange: (current, pageSize) => {
                    // 切换分页时的回调，
                    // 当在页面定义change事件时，切记要把此处的事件清除，因为这两个事件重叠了，可能到时候会导致一些莫名的bug
                    this.ipaginationRecord.current = current
                    this.ipaginationRecord.pageSize = pageSize
                    if (this.tabKey == 1) {

                        this.getProjectData()
                    }

                    if (this.tabKey == 2) {
                        this.getTotalData()
                    }

                    if (this.tabKey == 3) {
                        this.getDesignData()
                    }
                }

            },
            value: 'valid',


            operateDisabled: false,
            duration: 1000,
            //treeselect的参数
            treeValue: [],
            treeData: [],
            SHOW_PARENT,
            type: 3,
            dateValue: [moment().subtract(30, 'days'), moment()],
            operate: '',
            designList: [],
            tabKey: 1,
            loading: false,
            columns: [...liveDataAll.projectDataColumns()],
            totalColumns: [...liveDataAll.totalColumns()],
            designColumns: [...liveDataAll.designColumns()],
            saleInfoList: [],
            saleInfoListAll: [],
            salePersonList: [],
            dataSource: [],

            dataVideoList: [],
            checkVideo: [],
            checkPersonOne: '',
            checkPersonElse: [],
            sumContent: 0,
            tableTab: 1,

            newPlan: 0,
            effectPlan: 0,

            openOptions: false,

            target: 'createTime',
            order: 'descend',
            projectId: undefined,
            projectIdAll: undefined,
            dataLoading: false,
            modifyPriceVisible: false,
            modifyPriceLoading: false,
            modifyPriceDetail: null,
            accountVisible: false,
            againLoading: false,
            accountProjectDetail: null,
            regionData: [{label: '不限', value: 'unlimited'}],
            ageData: [{label: '不限', value: 'unlimited'}],
            scoreVisible: false,
            detailsData: undefined,
        }
    },
    methods: {
        moment,
        ...mapGetters(['userInfo']),
        exportExcel() {
            this.visibleLoading = true;
            var params = {};
            params.date = this.dateMonth
            downFile("/first/delivery/excel", params).then(
                (res) => {
                    this.visibleLoading = false;
                    let blob = new Blob([res], {
                        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    });
                    let downloadElement = document.createElement("a");
                    let href = window.URL.createObjectURL(blob); //创建下载的链接
                    downloadElement.href = href;

                    downloadElement.download = '首投有效率监控.xlsx'; //下载后文件名
                    document.body.appendChild(downloadElement);
                    downloadElement.click(); //点击下载
                    document.body.removeChild(downloadElement); //下载完成移除元素
                    window.URL.revokeObjectURL(href); //释放掉blob对象
                }
            );
        },

        getProjectData() {
            this.dataLoading = true
            getAction('/first/delivery/projectData', {
                date: this.dateMonth,
                pageSize: this.ipaginationRecord.pageSize,
                pageNo: this.ipaginationRecord.current
            }).then(
                (res) => {
                    if (res.success) {
                        this.recordList = res.result.list || []
                        this.ipaginationRecord.total = res.result.total || 0
                        this.dataLoading = false
                    } else {
                        this.$message.error('更新数据失败，请稍后重试！！！')
                        this.dataLoading = false
                    }
                }
            )
        },

        getTotalData() {
            this.dataLoading = true
            getAction('/first/delivery/getTotalData', {
                date: this.dateMonth,
                pageSize: this.ipaginationRecord.pageSize,
                pageNo: this.ipaginationRecord.current
            }).then(
                (res) => {
                    if (res.success) {
                        this.totalList = res.result.list || []
                        this.ipaginationRecord.total = res.result.total || 0
                        this.dataLoading = false
                    } else {
                        this.$message.error('更新数据失败，请稍后重试！！！')
                        this.dataLoading = false
                    }
                }
            )
        },

        getDesignData() {
            this.dataLoading = true
            getAction('/first/delivery/getDesignData', {
                date: this.dateMonth,
                pageSize: this.ipaginationRecord.pageSize,
                pageNo: this.ipaginationRecord.current,
                designRole: this.designRole
            }).then(
                (res) => {
                    if (res.success) {
                        this.designList = res.result.list || []
                        this.ipaginationRecord.total = res.result.total || 0
                        this.dataLoading = false
                    } else {
                        this.$message.error('更新数据失败，请稍后重试！！！')
                        this.dataLoading = false
                    }
                }
            )
        },

        handleChange() {
            this.loadDisabled = false
            this.$message.success('文件导入成功')
        },
        beforeUpload(file) {
            this.dataFile = $('.fileUpload').eq(0).find('input')[0].files[0]
            this.loadDisabled = true
            const size = (Number(file.size) / (1024 * 1024)).toFixed(2)
            const fileName = file.name
            const fileStrArr = fileName.split('.')
            const suffix = fileStrArr[fileStrArr.length - 1]

            let result = fileSuffix.some((item) => {
                return item === suffix
            })

            if (!result) {
                this.$message.error('不支持该文件类型')
                this.loadDisabled = false
                return Promise.reject()
            }
        },
        importFile() {
            this.exportLoading = true
            if (this.dataFile) {
                let formData = new FormData()
                formData.append('file', this.dataFile)
                let url = '';
                if (this.importfileType == 1) {
                    url = '/first/delivery/importExcelMaterials';
                }
                if (this.importfileType == 2) {
                    url = '/first/delivery/importExcelRatio';
                }
                postAction(url, formData).then((res) => {
                    if (res.success) {
                        this.exportLoading = false
                        this.scoreVisible = false
                        this.dataFile = undefined
                        this.handleResetForm()
                    } else {
                        this.$message.error(res.message)
                    }
                })
            } else {
                this.$message.error('请上传文件')
            }
        },
        disabledDate(current) {
            // console.log(current)
            return current && current > moment()
        },
        newCreat(id) {
            this.importfileType = id;
            this.scoreVisible = true
        },
        handleEdit(item) {
            item.edit = true
            item.accountName = item.liveAccountName + '(' + item.liveAccountId + ')'
        },
        handleQueryList(event) {
            this.ipaginationRecord.current = 1
            this.dateMonth = moment(this.dateMonth).format('YYYY-MM');
            if (this.tabKey == 1) {
                this.getProjectData()
            }
            if (this.tabKey == 2) {
                this.getTotalData()
            }

            if (this.tabKey == 3) {
                this.getDesignData()
            }

        },
        handleClose() {
            this.config_id = null
            const paramsData = this.form.getFieldsValue()
        },
        handleResetForm() {
            this.ipaginationRecord.current = 1
            this.ipaginationRecord.pageSize = 10
            this.dateMonth = moment(new Date()).format('YYYY-MM');
            this.form.resetFields()
            if (this.tabKey == 1) {
                this.getProjectData()
            }
            if (this.tabKey == 2) {
                this.getTotalData()
            }
            if (this.tabKey == 3) {
                this.designRole = 1
                this.getDesignData()
            }
        },
        score() {
        },
        dateChange(date, dateString) {
        },

        filterOption(input, option) {
            return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        },
        getDataSource(current, pageSize) {
            console.log(pageSize)
            // 切换分页时的回调，
            // 当在页面定义change事件时，切记要把此处的事件清除，因为这两个事件重叠了，可能到时候会导致一些莫名的bug
            this.$nextTick(() => {
                this.ipaginationRecord.current = current
                this.ipaginationRecord.pageSize = pageSize
                for (let i = 0; i < this.ipaginationRecord.current; i++) {
                    this.selectedRowKeysAll.push([])
                    this.selectionRowsAll.push([])
                }
                this.selectedRowKeys = this.selectedRowKeysAll[current - 1]
                this.selectionRows = this.selectionRowsAll[current - 1]
                const paramsData = this.form.getFieldsValue()
                this.handleGetTableList(paramsData)
            })
        },

        // 快手头条的切换
        tabChange(key) {
            this.ipaginationRecord.current = 1
            this.form.resetFields()

            if (this.tabKey == 1) {
                this.getProjectData()
            } else if (this.tabKey == 2) {
                this.getTotalData()
            } else if (this.tabKey == 3) {
                this.getDesignData()
            }


        },
        operateChange(value) {
            console.log(value)
            if (value) {
                this.accountDisabled = true
                this.accountId = ''
            } else {
                this.accountDisabled = false
            }
        },
    },
    watch: {
        dateValue(newName, oldName) {
            this.search()
        },
    },
    computed: {
        newDate() {
            var myDate = new Date()
            myDate.getYear() //获取当前年份(2位)
            var n = myDate.getFullYear() //获取完整的年份(4位,1970-????)
            var m = myDate.getMonth() //获取当前月份(0-11,0代表1月)
            var d = myDate.getDate() //获取当前日(1-31)
            var day = myDate.getHours()
            return day
        },
    },
    mounted() {
        this.dateMonth = moment(new Date()).format('YYYY-MM');
        this.getProjectData();
        console.log(1111111)
        console.log(this.userInfo().roleName)
    },
    activated: function () {
    },

    filters: {
        toPercentage(val) {
            if (typeof val != 'string') {
                return (val * 100).toFixed(2) + '%'
            } else {
                return val
            }
        },

    },
}
</script>
