<template>
    <div>
        <el-card class="box-card" :body-style="{ padding: '20px 20px 0 20px' }">
            <el-form :inline="true" :model="formSearch" class="demo-form-inline">
                <el-form-item label="团购状态">
                    <el-select v-model="formSearch.status" placeholder="团购状态">
                        <el-option label="未开始" value="-5"></el-option>
                        <el-option label="跟团中" value="1"></el-option>
                        <el-option label="预览中" value="-10"></el-option>
                        <el-option label="已结束" value="20"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="活动标题">
                    <el-input v-model="formSearch.title" placeholder="活动标题"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getGroupList();">查询</el-button>
                    <el-button type="success" @click="groupAdd();">新增团购</el-button>
                </el-form-item>
            </el-form>
        </el-card>

        <el-card style="margin-top: 10px" class="box-card">
            <el-table v-loading="loading" :data="tableData" border style="width: 100%" row-key="id"
                :tree-props="{ children: 'children' }">
                <el-table-column prop="shop.name" label="店铺">
                </el-table-column>
                <el-table-column prop="title" label="活动标题">
                </el-table-column>
                <el-table-column prop="status" label="团购状态">
                </el-table-column>
                <el-table-column label="开团时间">
                    <template slot-scope="scope">
                        <div>{{ scope.row.start_time }}</div>
                        <div>至</div>
                        <div>{{ scope.row.end_time }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="手机查看">
                    <template slot-scope="scope">
                        <el-image style="width: 100px; height: 100px" :src="scope.row.qr_code_url"></el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="create_status" label="创建结果">
                </el-table-column>
                <el-table-column prop="options" label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.parent_id == 0" @click="groupEdit(scope.row.id)" type="text"
                            size="small">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>


<script>
import { groupList } from "../../api/group";
export default {
    data() {
        return {
            formSearch: {
                status: "",
                title: "",
                page: 1,
                per_page: 20
            },
            loading: true,
            tableData: []
        }
    },
    mounted() {
        this.getGroupList();
    },
    methods: {
        getGroupList() {
            groupList(this.formSearch).then((res) => {
                this.tableData = res.data.data;
                this.loading = false;
            })
        },
        groupAdd() {
            this.$router.push({ path: "GROUP_GOODS_ADD", query: { id: 0 } });
        },
        groupEdit(id) {
            this.$router.push({ path: "GROUP_GOODS_EDIT", query: { id: id } });
        },
    }
}
</script>
