<template>
    <scTable ref="table" :apiObj="list.apiObj" :params="searchKey" @selectionChange="selectionChange" row-key="id">
        <el-table-column type="selection" width="50" fixed="left"></el-table-column>
        <el-table-column label="会员ID" prop="openid" width="220" fixed="left"></el-table-column>
        <el-table-column label="会员卡号" prop="card_no"></el-table-column>
        <el-table-column label="所属店铺" prop="money">
            <template #default="scope">
                <span v-if="scope.row.shop">{{ scope.row.shop.shop_name }}</span>
                <span v-else>-</span>
            </template>
        </el-table-column>
        <el-table-column label="总充值金额" prop="money">
            <template #default="scope">
                <el-tag>{{ $TOOL.money(scope.row.total_balance) }}</el-tag>
            </template>
        </el-table-column>
        <el-table-column label="累计消费" prop="money">
            <template #default="scope">
                <el-tag>{{ $TOOL.money(scope.row.total_consume) }}</el-tag>
            </template>
        </el-table-column>
        <el-table-column label="账户余额" prop="money">
            <template #default="scope">
                <el-tag>{{ $TOOL.money(scope.row.balance) }}</el-tag>
            </template>
        </el-table-column>
        <el-table-column label="加入时间" prop="create_at" width="180"></el-table-column>
        <el-table-column label="操作" width="160" align="right" fixed="right">
            <template #default="scope">
                <el-button-group>
                    <el-button text type="warning" size="small" @click="table_edit(scope.row)">详情</el-button>
                    <el-popconfirm title="确定要退款吗？" @confirm="table_del(scope.row, scope.$index)" v-if="scope.row.status > 0">
                        <template #reference>
                            <el-button text type="danger" size="small">退款</el-button>
                        </template>
                    </el-popconfirm>                    
                </el-button-group>
            </template>
        </el-table-column>
    </scTable>
</template>

<script>
export default {
    props: {
        type: { type: String, default: "1" }
    },
    data(){
        return {
            colorData:['','彩色','黑白'],
            duplexData:['','单面','双面'],
            list: {
                apiObj: this.$API.mUser.list
            },
            status: ['待支付','待打印', '打印失败', '已打印','申请退款','退款失败','已退款'],
            ostatus: ['-','店内打印', '远程自取', '商家配送'],
            payStatus:['-','微信','会员卡'],
            visible:false,
            dataSelect:[],
            dataSelectFull:[],
            searchKey:{}
        }
    },
    methods:{
        table_edit(data){
            this.$nextTick(() => {
                this.$refs.formMain.open("edit",this.type).setData(data)
            })
        },
        table_del(data){
            this.$confirm("确定要删除该数据吗？","删除确认",{type: 'warning'}).then(async ()=>{
                var resp = await this.$API.mPrice.del.post({"id":data.id,"type":""});
                if (resp.code == 0) {
                    return this.$message.error(resp.msg)
                }
                this.$message.success(resp.msg)
                this.$refs.table.refresh()
            }).catch(()=>{});
        },
        refresh(){
            this.$refs.table.refresh()
        },
        upData(data){
            this.$refs.table.upData(data)
        },
        handleSuccess(){
            this.$refs.table.refresh()
        },
    }
}
</script>

<style>
.price{display: flex;align-items: center;}
.del{text-decoration: line-through;margin-left: 5px;color: #f00;}
</style>