<template>
    <div class="app-container">

        <!-- 查询和其他操作 -->
        <div class="filter-container">
            <el-button v-permission="['GET /admin/dyshop/goodsApply']" class="filter-item" type="primary"
                icon="el-icon-circle-check" @click="handleApply">批量发送抖音审核绑定</el-button>
            <div style="color:red">注：列表只包含已经申报过抖音的商品</div>
        </div>

        <!-- 查询结果 -->
        <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column align="center" label="商品Id" prop="goodsId">
                <template slot-scope="scope">
                    <el-button type="text" @click="linkGoodsDetail(scope.row.goodsId)">{{ scope.row.goodsId }}</el-button>
                </template>
            </el-table-column>
            <el-table-column align="center" label="商品编号" prop="goodsSn" />
            <el-table-column align="center" label="商品名称" prop="goodsName" />
            <el-table-column align="center" label="抖音编号" prop="dyNo" />
            <el-table-column align="center" label="商品价格" prop="price" />
            <el-table-column align="center" label="上次提报版本" prop="version" />
            <el-table-column align="center" label="上次提报时间" prop="applyTime" />
        </el-table>

    </div>
</template>
  
<script>
import { shopGoods, goodsApply } from '@/api/shop'

export default {
    name: 'dyPoi',
    components: {},
    data() {
        return {
            list: null,
            listLoading: true,
            multipleSelection: []
        }
    },
    created() {
        this.getList()
    },
    methods: {

        getList() {
            this.listLoading = true
            shopGoods().then(response => {
                this.list = response.data.data;
                this.listLoading = false;
            }).catch(() => {
                this.list = []
                this.total = 0
                this.listLoading = false
            })
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handleApply() {
            console.info(this.multipleSelection)
            if (this.multipleSelection.length === 0) {
                this.$notify.error({
                    title: "失败",
                    message: "请选择需要更新的商品",
                });
                return;
            }
            this.$confirm("确定批量更新选中的" + this.multipleSelection.length + "个商品吗?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                let params = [];
                this.multipleSelection.forEach(item => {
                    params.push(item.goodsId);
                })

                goodsApply({ goods: params }).then(response => {
                    this.$notify.success({
                        title: '成功',
                        message: '申请成功，稍后查看申请状态'
                    })
                }).catch(response => {
                    this.$notify.error({
                        title: '失败',
                        message: response.data.errmsg
                    })
                })
            });
        },
        linkGoodsDetail(id) {
            this.$router.push({ path: "/goods/edit", query: { id: id } });
        },
    },
}
</script>
   