<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div style="padding-top: 10px;">
                <el-button size="medium" type="primary" @click="bohui(1)" v-if="stsben == 1">汇总</el-button>
                <el-button size="medium" type="primary" @click="bohui(2)" v-if="stsben == 1">驳回</el-button>
                <!-- <el-button size="medium" type="primary" @click="bohui(3)" v-if="stsben == 2">通过</el-button>
                <el-button size="medium" type="primary" @click="bohui(4)" v-if="stsben == 2">驳回</el-button> -->
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" tooltip-effect="dark"
                    :data="tableData" size="mini" border style="width: 100%">
                    <el-table-column :prop="item.name" :label="item.name" v-for="item in tableDatacs">
                        <template slot-scope="scope">
                            <!-- <el-input v-model="scope.row[item.name]"></el-input> -->
                            {{scope.row[item.name].value}}
                        </template>
                        <el-table-column :prop="items.name" :label="items.name" v-for="items in item.value"
                            v-if="item.sts">
                            <template slot-scope="scope">
                                <!-- <el-input v-model="scope.row[items.name]"></el-input> -->
                                {{scope.row[items.name].value}}
                            </template>
                            <el-table-column :prop="itemss.name" :label="itemss.name" v-for="itemss in items.value"
                                v-if="items.sts">
                                <template slot-scope="scope">
                                    <!-- <el-input v-model="scope.row[itemss.name]"></el-input> -->
                                    {{scope.row[itemss.name].value}}
                                </template>
                            </el-table-column>
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="操作" width="100px" align="center">
                        <template slot-scope="scope">
                            <!-- <el-button size="mini" type="primary" @click="tianbao(scope.row)">确认</el-button> -->
                            <el-button size="mini" type="primary" @click="downfile(scope.row)" :disabled="!scope.row.fileId">下载附件</el-button>
                            <!-- <el-button size="mini" type="danger" @click="jumpinfo(scope.row)" v-if="level == 1">删除</el-button> -->
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                    :total="total">
                </el-pagination>
            </div>
        </div>

    </fullscreen>

</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myMessage from "../../../components/myMessage.vue"
    import toolList from '../../../components/toolList'
    import myUpload from '../../../components/upload.vue'
    import deptTreeOnly from "../../../components/deptTreeOnly.vue"

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            myUpload,
            deptTreeOnly
        },
        data() {
            return {
                tooltit: '任务详情',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {},
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                tableDatacs: [],
                downinfosts: false,
                typeOptions: [],
                treeListonly: {},
                defaultList: [],
                closeList: false,
                depttype: 0,
                proceList: [],
                procests: false,
                rowIdList: [],
                rowIdListls: [],
                level: 0,
                shenpists: false,
                stsben: 0
            }
        },
        methods: {
            downfile(v) {
                let _this = this;
                let param = new FormData();
                param.append("rowId",v.rowId);
                _this.$http({
                    url: '/market/cChannelInfo/cIllegalCallTask/downLoadFile',
                    method: "post",
                    responseType: 'blob',
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: param,
                }).then((response) => {
                    if (response.data.result == 1) {
                        _this.$message({
                            message: response.data.desc,
                            type: 'error'
                        });
                        return
                    }else{
                        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                            let blob = new Blob([response.data], {
                                type: response.data.type
                            });
                            window.navigator.msSaveOrOpenBlob(blob, v.fileName);
                        } else {
                            /* 火狐谷歌的文件下载方式 */
                            var blob = new Blob([response.data])
                            var downloadElement = document.createElement('a')
                            var href = window.URL.createObjectURL(blob);
                            downloadElement.href = href;
                            downloadElement.download = v.fileName;
                            document.body.appendChild(downloadElement);
                            downloadElement.click();
                            document.body.removeChild(downloadElement);
                            window.URL.revokeObjectURL(href);
                        }
                    }
                });
            },
            tianbao(v) {
                let x = {}
                for (let item in v) {
                    if (item != 'rowId'&&item != 'fileId') {
                        x[item] = v[item]
                    }
                }
                this.$http({
                    url: "/market/cChannelInfo/cIllegalCallTaskRow/update",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        rowId: v.rowId,
                        fillContent: JSON.stringify(x)
                    },
                }).then((res) => {
                    if (res.data.result === 1) {
                        this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        this.$message({
                            message: '成功',
                            type: 'success'
                        });
                    }
                    this.getList({}, this.pageSize);
                });
            },
            bohui(v) {
                let url = '';
                if (v == 1) {
                    url = '/market/cChannelInfo/cIllegalCallTask/collectData';
                } else if (v == 2) {
                    url = '/market/cChannelInfo/cIllegalCallTask/submmitDataReject';
                } else if (v == 3) {
                    url = '/market/cChannelInfo/cIllegalCallTask/submmitApprovalPass';
                } else if (v == 4) {
                    url = '/market/cChannelInfo/cIllegalCallTask/submmitApprovalReject';
                }
                this.$http({
                    url: url,
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        missionId: this.$route.query.id.split(",")[1]
                    },
                }).then((res) => {
                    if (res.data.result === 1) {
                        this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        this.$message({
                            message: '成功',
                            type: 'success'
                        });
                    }
                    this.getList({}, this.pageSize);
                });
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.tableData = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
                // v.sts = 0;
                v.missionId = this.$route.query.id.split(",")[1];
                this.$http({
                    url: "/market/cChannelInfo/cIllegalCallTaskRow/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = [];
                    res.data.data.forEach(item => {
                        let x = JSON.parse(item.fillContent);
                        x.rowId = item.rowId;
                        x.fileId = item.fileId;
                        x.fileName = item.fileName;
                        this.tableData.push(x);
                    })
                    this.total = res.data.totalRecord;
                    this.loading = false;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                for (let i = 0; i < this.rowIdList.length; i++) {
                    this.rowIdListls.push(this.rowIdList[i])
                }
                this.getList(this.params, this.pageSize);
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.$http({
                    url: "/market/cChannelInfo/illegalCallTemp/query",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        tempId: this.$route.query.id.split(",")[0]
                    },
                }).then((res) => {
                    this.tableDatacs = JSON.parse(res.data.tempHead)
                    this.getList({}, 1);
                });
                let stsbtn = this.$route.query.id.split(",")[2];
                //下级提交
                if (stsbtn == 141 || stsbtn == 135 || stsbtn == 125 || stsbtn == '022' || stsbtn == '1') {
                    this.stsben = 1;
                }
                // if (stsbtn == '013' || stsbtn == '023' || stsbtn == '033') {
                //     this.stsben = 2;
                // }
            }
        },
        mounted() {
            this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .titbox {
        div {
            float: right;

            i {
                font-size: 22px;
                margin-left: 20px;
                cursor: pointer;
            }
        }
    }

    .tabbox {
        margin-top: 15px;
    }

    .pageBox {
        text-align: right;
        margin-top: 10px;
    }

    .info-line {
        width: 100%;
        display: block;
        padding-left: 20px;

        div {
            width: 50%;
            display: inline-block;
        }

        span {
            width: 80px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 100px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 100px);
        }

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 100px);
        }

        .tree {
            width: calc(50% - 60px);
            display: inline-block;
            margin-right: 20px;
            height: 300px;
            overflow-y: scroll;

            .el-icon-error {
                float: right;
                font-size: 20px;
                margin-top: 9px;
                cursor: pointer;
            }
        }

        .treeUser {
            margin: 0;
            border: 1px solid #ddd;

            p {
                background: #f4f4f4;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }

        .treeUserb {
            width: calc(100% - 100px);
            border: 1px solid #ddd;
            background: #f4f4f4;
            border-radius: 3px;
            height: auto;
            overflow: hidden;

            p {
                display: inline-block;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }
    }
</style>
