<template>
    <div>
        <el-card>
            <el-table v-loading="loading" :data="list" style="width: 100%">
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column label="字典名称" prop="parmName"></el-table-column>
                <el-table-column label="字段" prop="parmKey"></el-table-column>
                <el-table-column label="供应商选入必填" prop="supSelect">

                    <template slot-scope="scope">
                        <el-select v-model="scope.row.supSelect">
                            <el-option label="是" :value=true></el-option>
                            <el-option label="否" :value=false></el-option>
                        </el-select>
                    </template>

                </el-table-column>
                <el-table-column label="供应商新增必填" prop="supAdd">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.supAdd">
                            <el-option label="是" :value=true></el-option>
                            <el-option label="否" :value=false></el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <!--                <el-table-column label="本地新增必填" prop="localAdd">-->
                <!--                    <template slot-scope="scope">-->
                <!--                        <el-select v-model="scope.row.localAdd" >-->
                <!--                            <el-option label="是" :value=true></el-option>-->
                <!--                            <el-option label="否" :value=false></el-option>-->
                <!--                        </el-select>-->
                <!--                    </template>-->
                <!--                </el-table-column>-->
                <el-table-column label="供应商编辑必填" prop="localAdd">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.localEdit">
                            <el-option label="是" :value=true></el-option>
                            <el-option label="否" :value=false></el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column label="说明" prop="remark"></el-table-column>
                <el-table-column label="操作" fixed="right" width="200">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            @click="handleSave(scope.$index, scope.row)"
                        >保存
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <el-pagination
                :page-size="query.limit"
                @current-change="handleCurrentChange"
                layout="prev, pager, next"
                :total="total"
            >
            </el-pagination>
        </el-card>

    </div>
</template>

<script>
import {
    filterList,
    modifySetup
} from "../../../api/param/basicProductConfig";

export default {
    data() {
        return {
            query: {
                page: 1,
                limit: 20
            },
            list: [],
            total: 0,
            loading: true,
            enableMap: {
                true: "是",
                false: "否",
            },
        };
    },
    methods: {
        onReset() {
            this.$router.push({
                path: ""
            });
            this.query = {
                page: 1,
                limit: 20
            };
            this.getList();
        },
        onSubmit() {
            this.getList();
        },
        handleCurrentChange(val) {
            this.query.page = val;
            this.getList();
        },
        getList() {
            this.loading = true;
            filterList(this.query)
                .then(response => {
                    this.loading = false;
                    this.list = response.data.list || [];
                    this.total = response.data.total || 0;
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },
        handleSave(index, row) {
            this.currentCheckIndex = -1;
            modifySetup(row).then((res) => {
                if (res.code == 20000) {
                    this.getList();
                    this.$message.success("保存成功！");
                } else {
                    this.$message.error(res.message);
                }
            })
        },
    },
    filters: {},
    mounted() {
    },
    created() {
        // 加载表格数据
        this.getList();
    }
};
</script>

<style type="text/scss" lang="scss">
</style>
