<style lang="scss">
    .del{
            display: inline-block;
            vertical-align: top;
            font-size: 28px;
            font-weight: 500;
            margin-left: 10px;
            color: #000;
            cursor: pointer;
    }
</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="4">
                    <el-form-item label="比赛名称" prop="match_id">
                        <el-select v-model="queryParams.match_id" placeholder="请选择比赛" size="mini" @change="getData()">
                            <el-option v-for="item in matchList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <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="3">
                    <el-form-item label="报名类型">
                        <el-select clearable @clear="getData()" v-model="queryParams.signup_type" placeholder="请选择" size="mini" @change="getData()">
                            <el-option v-for="item in signupTypeList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <el-form-item label="订单状态">
                        <el-select clearable @clear="getData()" v-model="queryParams.order_status" placeholder="请选择" size="mini" @change="getData()">
                            <el-option v-for="item in orderStatusList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <el-form-item label="支付状态">
                        <el-select clearable @clear="getData()" v-model="queryParams.pay_status" placeholder="请选择" size="mini" @change="getData()">
                            <el-option v-for="item in payStatusList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </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="选手名称"/>
                <el-table-column prop="phone" label="手机号"/>
                <el-table-column prop="match_name" label="报名赛事"/>
                <el-table-column prop="match_group_name" label="赛事分组"/>
                <el-table-column prop="signup_type" label="报名类型">
                    <template slot-scope="scope">
                        <span v-if="scope.row.signup_type==2" style="color:red;">选手</span>
                        <span v-else>游客</span>
                    </template>
                </el-table-column>
                <el-table-column prop="total_fee" label="报名费用"/>
                <el-table-column prop="order_status" label="订单状态" width="150">
                    <template slot-scope="scope">
                        <!-- <span v-if="scope.row.order_status==1" style="color:#67c23a;">已支付</span> -->
                        <el-button v-if="scope.row.order_status==1" type="success" size="mini">已支付</el-button>
                        <span v-else>未支付</span>
                        <el-button v-if="scope.row.order_status==0" @click="editOld(scope.row)" size="mini" type="primary">我是老用户</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="out_trade_no" label="订单号" width="180"/>
                <el-table-column prop="transaction_id" label="微信支付单号" width="180"/>
                <el-table-column prop="pay_status" label="支付状态" width="150">
                    <template slot-scope="scope">
                        <!-- <span v-if="scope.row.pay_status==1" class="color:green;">已支付</span> -->
                        <el-button v-if="scope.row.pay_status==1" type="success" size="mini">已支付</el-button>
                        <span v-else>未支付</span>
                    </template>
                </el-table-column>
                <el-table-column prop="pay_time" label="支付时间" width="160" show-overflow-tooltip />
                <el-table-column prop="ctime" label="下单时间" width="160"/>
                <el-table-column prop="remark" label="备注" width="160"/>
                <el-table-column prop="date" label="操作" fixed="right" width="150">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row.id)" size="mini" type="warning">编辑</el-button>
                        <el-button @click="del(scope.row.id)" size="mini" type="danger" :disabled="scope.row.pay_status==1">删除</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>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="赛事名称" prop="match_id">
                        <el-select v-model="form.match_id" placeholder="请选择比赛" disabled>
                            <el-option v-for="item in matchList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                </el-form-item>
                <el-form-item label="选手名称" prop="player_id">
                    <el-input v-model="form.user_name" disabled placeholder=""></el-input>
                </el-form-item>
                <el-form-item label="报名类型" prop="match_id">
                        <el-select v-model="form.signup_type" placeholder="请选择比赛" disabled>
                            <el-option v-for="item in signupTypeList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                </el-form-item>
                <el-form-item label="报名费用" prop="total_fee">
                    <el-input v-model="form.total_fee" disabled placeholder=""></el-input>
                </el-form-item>
                <el-form-item label="支付状态" prop="match_id">
                        <el-select v-model="form.pay_status" placeholder="请选择" disabled>
                            <el-option v-for="item in orderStatusList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                </el-form-item>
                <el-form-item label="订单状态" prop="match_id">
                        <el-select v-model="form.order_status" placeholder="请选择">
                            <el-option v-for="item in orderStatusList" :key='item.id' :label="item.name" :value="item.id"></el-option>
                        </el-select>
                </el-form-item>
                <el-form-item label="备注" prop="match_id">
                        <el-input v-model="form.remark" placeholder="" type="textarea"></el-input>
                </el-form-item>



            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="open=false">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 点评 -->
        <el-dialog title="老用户处理" :visible.sync="open1" width="500px" append-to-body>
            <el-form ref="form1" :model="form1" label-width="80px">
                <el-form-item label="报名类型">
                    <el-select v-model="form1.signup_type" placeholder="请选择报名类型">
                        <el-option
                            v-for="item in signupTypeList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="赛事分组">
                    <el-select v-model="form1.match_group" placeholder="请选择赛事分组">
                        <el-option
                            v-for="item in groupList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="开户类型">
                    <el-select v-model="form1.player_type" placeholder="请选择开户类型">
                        <el-option
                            v-for="item in playerType"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="参赛角色">
                    <el-select v-model="form1.role_type" placeholder="请选择参赛角色">
                        <el-option
                            v-for="item in playerRole"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="saveOldUser" size="mini">确 定</el-button>
                <el-button @click="open1=false" size="mini">取 消</el-button>
            </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()
            },
            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:"已支付"},
                {id:-1,name:"已退款"}
            ],
            payStatusList:[
                {id:0,name:"未支付"},
                {id:1,name:"已支付"}
            ],
            signupTypeList:[
                {id:1,name:"游客"},
                {id:2,name:"选手"},
            ],
            playerType:[
                {label:"游客",value:0},
                {label:"普通选手",value:1},
                {label:"种子选手",value:2},
                {label:"开户选手",value:3}
            ],
            playerRole:[
                {label:"游客",value:1},
                {label:"选手",value:2}
            ]
        }
    },
    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.delSignupOrder({ 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.getSignupList(this.queryParams).then(res=>{
                this.list=res.data.data.list
                this.total = res.data.data.total;
                this.loading = false;
            })
        },
        edit(id){
            this.title = "订单详情"
            this.$api.getSignupOrderDetail({id:id}).then(res=>{
                this.form = res.data.data
                this.open = true
            })
        },
        editOld(row){
            this.open1 = true;
            this.form1 = row;
        },
        saveOldUser(){
            this.$api.saveOldUser(this.form1).then(res=>{
                if(res.data.code==0){
                    this.$message.success("处理成功!")
                }else{
                    this.$message.error(res.data.message)
                }
            })
        },
        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);
        },
        /** 提交按钮 */
        submitForm() {
            console.log(this.form)
            this.$refs["form"].validate(valid => {
                if (valid) {
                if (this.form.id != null) {
                    this.$api.editSignupOrder(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.$api.getGroups(this.queryParams).then(res=>{
            this.groupList = res.data.data.list;
           })
           this.getData()
       })
    }
}
</script>