<template>
    <div>
        <!-- <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" label-width="160px">
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="商户分类" prop="category_id">
                            <el-select class="w-[280px]" v-model="queryParams.category_id" clearable placeholder="请选择商户分类">
                                <el-option label="全部" value=""></el-option>
                                <el-option v-for="(item, index) in dictData.mer_category_type" :key="index"
                                    :label="item.name" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="店铺类型" prop="type_id">
                            <el-select class="w-[280px]" v-model="queryParams.type_id" clearable placeholder="请选择店铺类型">
                                <el-option label="全部" value=""></el-option>
                                <el-option v-for="(item, index) in dictData.merchat_type" :key="index" :label="item.name"
                                    :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item>
                            <el-button type="primary" @click="resetPage">查询</el-button>
                            <el-button @click="resetParams">重置</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-card> -->
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <el-button v-perms="['merchat.merchant/add']" type="primary" @click="showDialog = true">
                <template #icon>
                    <icon name="el-icon-Plus" />
                </template>
                商品绑定
            </el-button>
            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" />
                    <!-- <el-table-column label="ID" prop="id" width="55" /> -->
                    <el-table-column label="商品图片" prop="imgs">
                        <template #default="{ row }">
                            <el-image style="width:50px;height:50px;" :src="row.goods_info.imgs" />
                        </template>
                    </el-table-column>
                    <el-table-column label="商品名称" prop="goods_info.name" show-overflow-tooltip />
                    <el-table-column label="规格型号" prop="goods_info.spec" show-overflow-tooltip />
                    <el-table-column label="商品分类" prop="goods_info.class_name" show-overflow-tooltip />
                    <el-table-column label="商品品牌" prop="goods_info.brand_name" show-overflow-tooltip />
                    <el-table-column label="商品单位" prop="goods_info.unit_name" show-overflow-tooltip />
                    <el-table-column label="购货价格" prop="goods_info.buy" show-overflow-tooltip />
                    <el-table-column label="销货价格" prop="goods_info.sell" show-overflow-tooltip />
                    <el-table-column label="零售价格" prop="goods_info.retail" show-overflow-tooltip />
                    <el-table-column label="标签" prop="goods_info.sys_labels_text" show-overflow-tooltip />
                    <el-table-column label="数量" prop="nums" width="170">
                    </el-table-column>
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <el-dialog v-model="showDialog" title="绑定商品" width="70%">
            <goodsPop @offPop="showDialog = false, getLists()" :mer_id="mer_id"></goodsPop>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup name="merchantLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiBindGoodstLists } from '@/api/merchant'
import { useRoute } from 'vue-router';
const route = useRoute()
const showDialog = ref(false)
let mer_id = route.query.mer_id;

// 查询条件
const queryParams = reactive({
    mer_id: mer_id,
})

// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map(({ mer_id }) => mer_id)
}

// 获取字典数据
const { dictData } = useDictData('mer_category_type,merchat_type,show_status,off_status,financial_type')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiBindGoodstLists,
    params: queryParams
})

getLists()
</script>

