<style lang="scss">
    .del{
            display: inline-block;
            vertical-align: top;
            font-size: 28px;
            font-weight: 500;
            margin-left: 10px;
            color: #000;
            cursor: pointer;
    }
    .el-badge__content.is-fixed{
        top:10px;
        right: -10px;
    }
    .el-table tr{
        height: 45px;
    }
    .replyDiag{
        .consutlList{
            padding:20px;
            border:1px solid #ccc;
            height: 350px;
            overflow: scroll;
        }
        .el-dialog__body{
            padding:10px 20px!important;
        }
        .el-row{
            margin-bottom:15px;
        }
    }
</style>
<template>
    <section class="content data">
        <h4>顽主咨询</h4>
        <el-divider></el-divider>
        <el-form label-width="80px" class="filter-form">
            <el-row>
                <el-col :span="3">
                    <el-form-item label="选手名字">
                        <el-input clearable @clear="getData()" v-model="queryParams.username" placeholder="请输入选手名字/代码" size="mini"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-form-item style="margin-left:10px;" label-width="10">
                        <el-button type="primary" @click="getData" size="mini">筛选</el-button>
                        <el-button type="normal" @click="queryParams={},getData()" size="mini">重置</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="10">
                <el-col :span="6"></el-col>
            </el-row>
        </el-form>
        <el-table :data="list" height='55vh' style="width: 100%;margin-top:10px;" v-loading='loading'>
                <el-table-column prop="user_name" label="选手名称" width="200"/>
                <el-table-column prop="content" label="咨询内容">
                    <template slot-scope="scope">
                        <el-badge v-if="scope.row.unreply>0" :value="scope.row.unreply" class="item">
                            <p style="font-size:18px;">{{scope.row.last_content}}</p>
                        </el-badge>
                        <p v-else style="font-size:18px;">{{scope.row.last_content}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="reply_content" label="回复内容">
                    <template slot-scope="scope">
                        <p v-if="scope.row.unreply==0" style="font-size:18px;">{{scope.row.last_reply_content}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="ctime" label="咨询时间" width="250">
                    <template slot-scope="scope">
                        {{scope.row.ctime}}
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="操作" fixed="right" width="220">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row)" size="mini" type="primary">回复</el-button>
                        <el-button @click="del(scope.row.user_id)" size="mini" type="danger">删除</el-button>
                    </template>
                </el-table-column>
        </el-table>
        <Page
            ref="pageButton"
            :current="form.page"
            :page_size="form.page_size"
            :total="total"
            @pageChange="gopage"
        />
        <!-- 回复 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body class="replyDiag">
            <div class="consutlList">
                <el-row :gutter="1" v-for="(item,index) in form.all_consult_list" :key="index">
                    <el-col :span="3" v-if="item.user_id>0"><img :src="item.user_avatar" alt="" width="45px" height="45px" style="border-radius:5px;"/></el-col>
                    <el-col :span="20" v-if="item.user_id>0"><p style="padding-left:5px;font-size:18px;">{{item.content}}</p></el-col>
                    <el-col :span="20" v-if="item.user_id==0"><p style="padding-right:10px;text-align:right;font-size:18px;">{{item.reply_content}}</p></el-col>
                    <el-col :span="3" v-if="item.user_id==0"><img src="..\..\assets\wz.jpg" alt="" width="45px" height="45px" style="border-radius:5px;"/></el-col>
                </el-row>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-row :gutter="10">
                    <el-col :span="20">
                        <el-input v-model="form.reply_content" type="textarea" rows="5" placeholder="请输入你要回复的内容..."></el-input>
                    </el-col>
                    <el-col :span="4">
                        <el-button type="primary" @click="submitForm">发送</el-button>
                    </el-col>
                </el-row>
                </el-form>
            </div>
        </el-dialog>
    </section>
</template>
<script>
import Page from "../../components/Page";
export default {
    components: {
        Page,
    },
    data(){
        return{
            loading:false,
            queryParams:{
                match_id:0,
                page:1,
                stock_date:this.getNowDate()
            },
            form:{
                stock_date:this.getNowDate(),
                page:1,
                page_size:20,
                consult_list:[],
                all_consult_list:[]
            },
            form1:{},
            list:[{},{}],
            total:0,
            title:'新增用户',
            open:false,
            open1:false,
            rules:{
                match_id: [
                    { required: true, message: '请选择比赛', trigger: 'change' }
                ],
                player_id: [
                    { required: true, message: '请输入用户代码', trigger: 'blur' }
                ],
                stock_date: [
                    { required: true, message: '请选择持仓日期', trigger: 'blur' }
                ],
                today_fund: [
                    { required: true, message: '请输入今日资产', trigger: 'blur' }
                ],
                is_markt: [
                    { required: false, message: '请选择', trigger: 'change' }
                ]
            },
            matchList:[],
            playerList:[],
            groupList:[],
            stockList:[],
            missDayList:[
                {id:0,name:"否"},
                {id:1,name:"是"}
            ],
            orderStatusList:[
                {id:0,name:"未支付"},
                {id:1,name:"已支付"}
            ],
            signupTypeList:[
                {id:1,name:"选手"},
                {id:2,name:"游客"}
            ]
        }
    },
    methods:{
        updateRank(){
            this.loading = true
            this.$api.updateRank(this.queryParams).then((res)=>{
                this.loading = false
                this.$message({
                    message: "更新成功!",
                    type: "success",
                });
            })
        },
        getNowDate(){
            var y=new Date().getFullYear() 
            var m=Number(new Date().getMonth() + 1)
            var d = new Date().getDate()
            m=m>9?m:'0'+m;
            d=d>9?d:'0'+d
            return y+'-'+m+'-'+d;
        },
        autoCompleteData(){
            this.loading = true
            this.$api.autoCompleteData(this.queryParams).then((res)=>{
                this.getData();
                this.loading = false;
            })
        },
        downloadExcel(){
            this.$api.downloadRecords(this.queryParams).then((res)=>{
                var elink = document.createElement('a');
                let blob=new Blob([res.data], {type: 'application/vnd.ms-excel,charset=UTF-8'});
                let objUrl=URL.createObjectURL(blob);
                let file_name=decodeURIComponent(res.headers['content-disposition'].split('=')[1]);
                console.log(file_name)
                elink.download = "参赛数据";
                elink.style.display = 'none';                
                elink.href = objUrl;
                document.body.appendChild(elink);
                elink.click();
                document.body.removeChild(elink);      
                this.download_loading = false;
            })
        },
        del(id) {
        this.$confirm("确定删除吗?", "提示", {
            type: "warning",
        }).then(() => {
            this.$api.delConsult({ id: id }).then((res) => {
            this.$message({
                message: "删除成功",
                type: "success",
            });
            this.getData();
            });
        });
        },
        gopage(size) {
            if (size) {
                this.queryParams.page_size = size;
            }
            this.queryParams.page = this.$refs.pageButton.page;
            this.getData();
        },
        getData(){
            this.loading = true;
            this.$api.getWanzhuConsultList(this.queryParams).then(res=>{
                this.list=res.data.data.list
                this.total = res.data.data.total;
                this.loading = false;
            })
        },
        edit(row){
            this.title = "回复:"+row.user_name
            this.open = true
            this.form = row
        },
        editComment(id){
            this.title = "顽主点评"
            this.$api.getRecordInfo({id:id}).then(res=>{
                this.form1 = res.data.data
                this.open1 = true
            })
        },
        saveComment(){
            this.$api.updateComment({id:this.form1.id,wanzhu_comment:this.form1.wanzhu_comment}).then(response => {
                if(response.data.code != 0){
                    this.msgError(response.data.message);
                    return
                }
                this.msgSuccess("修改成功");
                this.open1 = false;
                this.getData();
            });
        },
        handleAdd(){
            this.open=true;
            this.title='新增数据';
            this.form={
                match_id:this.matchList[0].id,
                today_stock:[{code: "", name:"",fund:''}],
                today_stock_img:[],
                stock_date:this.getNowDate()
            }
        },
        addCode(){
             this.form.today_stock.push({code: "", name:"",fund:''})
        },
        handleSuccess(res, file) {
            console.log(res)
            this.form.today_stock_img.push(res.data.url);
        },
        triggerClick(){
            document.onkeyup = e =>{
              // 为了更加严谨所以添加了路由路径的判断
            if (e.keyCode === 13) {
            //回车后执行搜索方法
                this.submitForm()
            }
        }
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    this.form.pid = this.form.consult_list[this.form.consult_list.length-1].id;
                    this.$api.replyConsult(this.form).then(response => {
                        if(response.data.code != 0){
                            this.msgError(response.data.message);
                            return
                        }
                        this.msgSuccess("回复成功!");
                        this.open = false;
                        this.getData();
                    });
        }
      });
    },
    },
    created(){
       this.$api.getMatchList().then(res=>{
           this.matchList=res.data.data
           this.queryParams.match_id = this.matchList[0].id
           this.getData()
       })
       this.triggerClick()
    }
}
</script>