<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div>
                <el-button size="medium" type="primary" @click="tijiao">提交</el-button>
                <el-button size="medium" type="primary" @click="fenxiang">分享</el-button>
            </div>
            <div class="tabbox">
                <el-table class="com-table" ref="multipleTable" :data="infodatas" tooltip-effect="dark"
                    size="small" border style="width: 100%" @selection-change="handleSelectionChange">

                    <el-table-column
                          type="selection"
                          width="55"
                          align="center">
                        </el-table-column>
                    <el-table-column label="标题">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.expTitle" ></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="经验">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.marketExp" ></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="附件">
                        <template slot-scope="scope">
                            <span @click="downfile(scope.row)" style="cursor: pointer;">{{scope.row.fileName}}</span>
                        </template>
                    </el-table-column>

                    <el-table-column label="操作" width="210px" align="center">
                        <template slot-scope="scope">
                            <span @click="checkone(scope)" style="overflow: hidden;display: inline-block;width: 80px;float: left;">
                                <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList">
                                </myUpload>
                            </span>
                            <el-button size="mini" type="primary" @click="choline(1,scope)">添加</el-button>
                            <el-button size="mini" type="danger" @click="choline(2,scope)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </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'
    import uploadDown from '../../../components/uploadDown.vue'
    import deptTreeOnly from "../../../components/deptTreeOnly.vue"

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            myUpload,
            uploadDown,
            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,
                fileInfo: {
                    type: 'btn',
                    typename: '上传附件',
                    size:'mini',
                    btntype: 'primary',
                    uploadType: 'trainList',
                    url: '/market/cmkAttachInfo/upload',
                    fileList: [],
                },
                rovaList: [],
                vision: '',
                uploadstatus: false,
                mydisable: 1,
                opname: '',
                opno: '',
                attList: [],
                options: [],

                infodatas: [{fileName:''}],
                busiTime: [],
                demandTypeopt: [],
                carryChannelopt: [],
                checkexa: false,
                treeListonly: {},
                defaultList: [],
                closeList: false,
                depttype: 0,
                dialogStatuss: false,
                regionopt: [],
                chosts: 0,
                multipleSelection:[],
                nunm:0
            }
        },
        methods: {
            downfile(v){
                this.$http({
                    url: '/market/compatt/downfile',
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    responseType: "blob",
                    data: {"id": v.fileId, "fileName": v.fileName},
                }).then((response) => {
                    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                        let blob = new Blob([response.data], {
                            type: 'application/vnd.ms-excel'
                        });
                        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);
                    }
                });
            },
            tijiao(){
                let _this = this;
                this.$http({
                    url: "/market/cStoreScheTrainExpDetail/saveExpDetail",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: this.infodatas,
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '成功',
                            type: 'success'
                        });
                    }
                    this.getList(this.params, this.pageSize);
                });
            },
            fenxiang(){
                let param = [];
                let _this = this;
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    if(this.multipleSelection[i].id){
                        param.push({id:this.multipleSelection[i].id})
                    }
                }
                this.$http({
                    url: "/market/cStoreScheTrainExpDetail/shareExp",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: param,
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '成功',
                            type: 'success'
                        });
                    }
                });
            },
            checkone(v){
                this.nunm = v.$index
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.extField5 = this.$formatDate(v[0], "YYYY-MM") : '';
                v[1] ? this.params.extField4 = v[1] : '';
                this.getList(this.params, this.pageSize);
            },
            choline(v, n) {
                if (v == 1) {
                    this.infodatas.push({fileName:'',expId:this.$route.query.id,attList:[]})
                } else {
                    this.infodatas.splice(n.$index, 1)
                }
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                v.expId = this.$route.query.id
                this.$http({
                    url: "/market/cStoreScheTrainExpDetail/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: v,
                }).then((res) => {
                    this.infodatas = res.data;
                    this.loading = false;
                    this.infodatas.push({fileName:'',expId:this.$route.query.id,attList:[]})
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },


            //文件返回值
            uploadBack(v) {
                this.infodatas[this.nunm].attList = [];
                this.infodatas[this.nunm].attList.push(v.data.body);
                this.infodatas[this.nunm].fileId = v.data.body.fileCode;
                this.infodatas[this.nunm].fileName = v.data.body.fileName;
            },

            //功能栏
            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: "/sysmgr/csysdept/queryRegionDeptList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.regionopt = res.data[0].children;
                });
            },
        },
        mounted() {
            this.getList({}, 1);
            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: 100px;
            display: inline-block;
            text-align: left;

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

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

    .online {
        width: 100%;

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

        span {
            vertical-align: top;
        }

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

        .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;
            }
        }
    }

    .adv-type {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        // border: 1px solid #ddd;
        border-radius: 5px;
        padding: 20px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);

        div {
            width: 33%;
            text-align: center;
            height: 80px;
            overflow: hidden;
            min-width: 100px;
            cursor: pointer;
            padding-top: 10px;
            margin: 10px 0;
        }

        div:hover {
            background: #CFE8FC;
            border-radius: 5px;
        }

        span {
            width: 100%;
            display: inline-block;
            height: 40px;

            // line-height: 40px;
            i {
                color: #0074D9;
                font-size: 36px;
            }
        }
    }
</style>
