<template>
    <div>
        <el-card>
            <el-form :model="searchForm" label-width="auto" :inline="true">
                <el-form-item label="昵称：">
                    <el-input style="width:230px" clearable v-model="searchForm.user_name"
                        placeholder="请输入昵称"></el-input>
                </el-form-item>
                <el-form-item label="手机号：">
                    <el-input style="width:230px" clearable v-model="searchForm.user_mobile"
                        placeholder="请输入手机号"></el-input>
                </el-form-item>
                <el-form-item label="会员类型：">
                    <el-select style="width:210px" v-model="searchForm.member_days" placeholder="请选择会员天数" clearable>
                        <el-option :label="item.member_days==365?'1年':item.member_days>=30?item.member_days/30+'个月':item.member_days+'天'" :value="item.member_days" v-for="item in memberDay" />
                        <!-- <el-option label="否" :value="0" /> -->
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="会员类型：">
                    <el-input style="width:230px" clearable v-model="searchForm.member_days"
                        placeholder="请输入会员天数"></el-input>
                </el-form-item>
               -->
                <el-form-item label="">
                <el-button type="primary" @click="search">查询</el-button>
                <!-- <el-button type="default" @click="onSubmit">重置</el-button> -->
            </el-form-item>
            </el-form>
            <el-table :data="tableData" border style="width: 100%;margin-top:20px">
                <el-table-column prop="avatar" label="头像" width="100">
                    <template #default="scope">
                        <el-avatar :size="50" :src="scope.row.avatar" />
                    </template>
                </el-table-column>
                <el-table-column prop="user_name" label="昵称" width="120" />
                <el-table-column prop="user_mobile" label="手机号" width="120" />
                
                <el-table-column prop="is_member" label="订单类型" >
                    <template #default="scope">
                       <span v-if="scope.row.system_member.member_days==365">1年</span>
                       <span v-else-if="scope.row.system_member.member_days>=30">{{ scope.row.system_member.member_days/30+'个月' }}</span>
                       <span v-else-if="scope.row.system_member.member_days<30">{{ scope.row.system_member.member_days+'天' }}</span>
                    </template>
                </el-table-column>
              
                <el-table-column prop="is_member" label="订单金额" >
                    <template #default="scope">
                       <span>{{scope.row.amount_total}}元</span>
                    </template>
                </el-table-column>
                <el-table-column prop="is_member" label="实际支付金额" >
                    <template #default="scope">
                       <span>{{scope.row.payment_amount_total}}元</span>
                    </template>
                </el-table-column>
              
                <el-table-column prop="is_member" label="支付时间" >
                    <template #default="scope">
                       <span>{{formatDate(scope.row.pay_time)}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="80">
                    <template #default="scope">
                        <!-- <el-button type="danger" size="small" @click="deleteUser(scope.row.id)">删除</el-button> -->
                        <el-button size="small"
                            @click="openDetail(scope.row.order_id)">详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination style="margin-top:20px" :current-page="pageFrom.page" :page-size="pageFrom.page_size"
                :page-sizes="[10, 20, 30, 40]" layout="->,total, sizes, prev, pager, next, jumper" :total="total"
                @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </el-card>
        <vipDetail ref="vipDetailRef"></vipDetail>
    </div>
    
</template>

<script setup>
import userApi from "../../api/user";
import { onMounted, reactive, ref } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router'
import { formatDate } from "../../utils/format";
const router = useRouter();

// Dom 挂载之后
onMounted(() => {
    getUserList();
    getDays();
})
// 用户数据
let tableData = ref([]);
let total = ref(0);
// 搜索条件
const searchForm = reactive({
    user_name: '',
    order_status:2
})
const pageFrom = reactive({
    page: 1,
    page_size: 10,
})
const vipDetailRef = ref(null);
const openDetail = (id) => {
    vipDetailRef.value.init('view',id)
}
// 获取用户列表
const getUserList = async () => {
    if(searchForm.member_days==='') {
        delete searchForm.member_days
    };
    const res = await userApi.getVipList({ ...searchForm, ...pageFrom });
    console.log(res.data);
    tableData.value = res.data.data;
    total.value = res.data.total;
}
const handleSizeChange = (size) => {
    pageFrom.page_size = size;
    getUserList();
}
const handleCurrentChange = (current) => {
    pageFrom.page = current;
    getUserList();
}
const memberDay=ref([]);
const getDays = async () => {
    const res = await userApi.getVipSettingList();
    console.log(res.data);
    memberDay.value = res.data.sort((a, b) => a.member_days - b.member_days);
}
const search = () => {
   
    pageFrom.page = 1;
    getUserList();
}

</script>

<style lang="scss" scoped></style>