<template>
	asd
</template>

<!-- <template>
    <van-pull-refresh v-model="loading" :success-text="$store.state.data.successText" @refresh="handlePullDownRefresh"
        class="mobile-app-container" style="height: calc(100vh - 96px);overflow-y: auto;">
        <van-sticky>
            <van-search class="solid-bottom" v-model="queryParams.goodsName" show-action placeholder="请输入搜索关键词" @search="handleQuery">
                <template #action>
                    <div @click="handleQuery">搜索</div>
                </template>
            </van-search>
        </van-sticky>
        <van-list v-model:loading="loading" :finished="goodsList.length >= total"
            :finished-text="$store.state.data.finishedText" @load="handleReachBottom" v-if="goodsList.length > 0">
            <van-cell v-for="item in goodsList" :key="item.goodsId" :title="item.goodsName">
                <template #title>
                    <div style="height:11vh">
                        {{ item.goodsName }}
                    </div>
                </template>
            </van-cell>
        </van-list>
        <van-skeleton :row="10" v-if="loading"/>
        <van-empty :description="$store.state.data.emptyDescription" v-else-if="loading == false&&goodsList.length == 0"/>
    </van-pull-refresh>
</template>


<script setup name="Goods">
import { listGoods, getGoods, delGoods, addGoods, updateGoods } from "@/api/common/goods";

const { proxy } = getCurrentInstance();

const goodsList = ref([]);
const open = ref(false);
const loading = ref(true);
const finished = ref(false);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsName: null, goodsDescription: null, goodsImage: null, goodsPrice: null, goodsDiscount: null,
        goodsType: null, goodsCategory: null, goodsSales: null, goodsSalesM: null, goodsViews: null, goodsPraise: null, goodsEvaluation: null, goodsCount: null, storeId: null, status: null,
    },
    rules: {
        goodsName: [
            { required: true, message: "商品名称不能为空", trigger: "blur" }
        ], goodsDescription: [
            { required: true, message: "商品描述不能为空", trigger: "blur" }
        ], goodsCount: [
            { required: true, message: "商品描述不能为空", trigger: "blur" }
        ], storeId: [
            { required: true, message: "商品店铺ID不能为空", trigger: "blur" }
        ], status: [
            { required: true, message: "状态不能为空", trigger: "blur" }
        ],
    }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询商品信息列表 */
function getList() {
    loading.value = true;
    listGoods(queryParams.value)
        .then(response => {
            goodsList.value.push(...response.rows);
            total.value = response.total;
            if (goodsList.value.length >= total.value) finished.value = true;
            loading.value = false;
        })
        .catch(response => {
            loading.value = false;
        });
}

// 取消按钮
function cancel() {
    open.value = false;
    reset();
}

// 表单重置
function reset() {
    form.value = {
        goodsId: null, goodsName: null, goodsDescription: null, goodsImage: null, goodsPrice: null, goodsDiscount: null, goodsType: null, goodsCategory: null, goodsSales: null, goodsSalesM: null, goodsViews: null, goodsPraise: null, goodsEvaluation: null, goodsCount: null, storeId: null, status: 0, delFlag: null, createBy: null, createTime: null, updateBy: null, updateTime: null, remark: null
    };
    proxy.resetForm("goodsRef");
}

// 下拉刷新
function handlePullDownRefresh() {
   // console.log("handlePullDownRefresh")
    queryParams.value.pageNum = 1;
    goodsList.value = []
    getList();
}

// 滚动到底部的事件
function handleReachBottom() {
   // console.log("handleReachBottom")
    queryParams.value.pageNum++;
    getList();
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    goodsList.value = []
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.goodsId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
    reset();
    open.value = true;
    title.value = "添加商品信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
    reset();
    const goodsId = row.goodsId || ids.value
    getGoods(goodsId).then(response => {
        form.value = response.data;
        open.value = true;
        title.value = "修改商品信息";
    });
}

/** 提交按钮 */
function submitForm() {
    proxy.$refs["goodsRef"].validate(valid => {
        if (valid) {
            if (form.value.goodsId != null) {
                updateGoods(form.value).then(response => {
                    proxy.$modal.msgSuccess("修改成功");
                    open.value = false;
                    getList();
                });
            } else {
                addGoods(form.value).then(response => {
                    proxy.$modal.msgSuccess("新增成功");
                    open.value = false;
                    getList();
                });
            }
        }
    });
}

/** 删除按钮操作 */
function handleDelete(row) {
    const goodsIds = row.goodsId || ids.value;
    proxy.$modal.confirm('是否确认删除商品信息编号为"' + goodsIds + '"的数据项？').then(function () {
        return delGoods(goodsIds);
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
    proxy.download('system/goods/export', {
        ...queryParams.value
    }, `goods_${new Date().getTime()}.xlsx`)
}

getList();
</script> -->
