<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="会员名称" width="150" fixed="left" prop="name"></el-table-column>
        <el-table-column label="会员卡号" width="150" prop="user_no"></el-table-column>
        <el-table-column label="手机号码" width="150" prop="tel"></el-table-column>
        <el-table-column label="可用余额(元)" prop="login_at" width="180">
            <template #default="scope">
                {{scope.row.format_balance?scope.row.format_balance:'0.00'}}
            </template>
        </el-table-column>
        <el-table-column label="累计消费金额(元)" prop="login_at" width="180">
            <template #default="scope">
                {{scope.row.format_total?scope.row.format_total:'0.00'}}
            </template>
        </el-table-column>
        <el-table-column label="性别" width="150" prop="format_sex" align="center"></el-table-column>
        <el-table-column label="会员生日" width="150" prop="brithday">
            <template #default="scope">
                {{scope.row.brithday?scope.row.brithday:'-'}}
            </template>
        </el-table-column>
        <el-table-column label="最后充值时间" prop="login_at" width="180">
            <template #default="scope">
                {{scope.row.last_at?scope.row.last_at:'-'}}
            </template>
        </el-table-column>
        <el-table-column label="注册时间" prop="create_at" width="180"></el-table-column>
        <el-table-column label="注册IP" prop="create_ip" width="180"></el-table-column>
        <el-table-column label="操作" width="160" align="left" fixed="right">
            <template #default="scope">
                <el-button-group>
                    <!-- <el-button text type="primary" size="small" @click="table_edit(scope.row)">编辑</el-button> -->
                    <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                        <template #reference>
                            <el-button text type="danger" size="small">删除</el-button>
                        </template>
                    </el-popconfirm>                    
                </el-button-group>
            </template>
        </el-table-column>
    </scTable>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
</template>
<script>
import formMain from './form';
export default {
    components: {
        formMain
    },
    data(){
        return {
            list: {
                apiObj: this.$API.storeUser.get
            },
            dataSelect:[],
            dataSelectFull:[],
            searchKey:{}
        }
    },
    methods: {
        table_edit(data){
            this.$nextTick(() => {
                this.$refs.formMain.open("edit").setData(data)
            })
        },
        async table_del(data){
            var resp = await this.$API.storeUser.del.post({"id":data.id});
            if (resp.code == 0) {
                return this.$message.warning(resp.msg)
            }
            this.$message.success(resp.msg);
            this.$refs.table.refresh()
        },
        refresh(){
            this.$refs.table.refresh()
        },
        upData(data){
            this.$refs.table.upData(data)
        },
        handleSuccess(){
            this.$refs.table.refresh()
        },
        sortChange(event){
            if (event.order) {
                var data = {
                    "field":event.prop,
                    "order":event.order
                }
                this.$refs.table.upData(data)
            } else {
                this.$refs.table.reload(this.searchKey)
            }
            return ;
        },
        selectionChange(event){
            this.dataSelect = [];
            var arr = [];
            var arrCompany = [];
            event.forEach(function(val,index){
                arr[index] = val.id;
                arrCompany[index] = val;
            });
            this.dataSelectFull = arrCompany;
            this.dataSelect = arr;
            this.$emit("success",this.dataSelect);
            this.$emit("successFull",this.dataSelectFull);
        },
        table_passwd(row){
            this.$nextTick(() => {
                this.$refs.userPasswd.open("edit").setData(row)
            })
        },
    }
}
</script>