<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="商品名称" prop="productName">
                <el-input v-model="queryParams.productName" placeholder="请输入商品名称" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

<!--            <el-form-item label="产品条码" prop="barCode">-->
<!--                <el-input v-model="queryParams.barCode" placeholder="请输入产品条码" clearable size="small"-->
<!--                    @keyup.enter.native="handleQuery" />-->
<!--            </el-form-item>-->

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>



        <el-table border v-loading="loading" :data="fsCourseProductList">
            <el-table-column label="商品名称" align="center" prop="productName" />
            <el-table-column label="商品图片" align="center" prop="image" width="120">
                <template slot-scope="scope">
                    <el-popover placement="right" title="" trigger="hover">
                        <img slot="reference" :src="scope.row.image" width="100">
                        <img :src="scope.row.image" style="max-width: 150px;">
                    </el-popover>
                </template>
            </el-table-column>
<!--            <el-table-column label="产品条码" align="center" prop="barCode" />-->
            <el-table-column label="商品价格" align="center" prop="price" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                        @click="chooseCourseProduct(scope.row)">选择此商品</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />


    </div>
</template>

<script>
import { listFsCourseProduct, } from "@/api/course/fsCourseProduct";
import Material from '@/components/Material'
import singleImg from '@/components/Material/single'
import { listStoreProduct } from '@/api/hisStore/storeProduct'
export default {
    name: "CourseProduct",
    components: { Material, singleImg, },
    watch: {
        imageArr: function (val) {
            this.form.imgUrl = val.join(',')
        },
        photoArr: function (val) {
            this.form.images = val.join(',')
        }
    },
    data() {
        return {
            photoArr: [],
            imageArr: [],
            // 遮罩层
            loading: true,
            // 导出遮罩层
            exportLoading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 拍单商品表格数据
            fsCourseProductList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                imgUrl: null,
                images: null,
                isDel: 0,
                isAudit: 1,
                isShow: 1,
                barCode: null,
                sort: null,
                stock: null,
                productContent: null,
                productPrice: null,
                productName: null,
            },
            // 表单参数
            form: {},
            // 表单校验

        };
    },
    created() {
        this.getList();
    },
    methods: {
        chooseCourseProduct(val) {
            this.$emit('courseProductResult', val)
        },
        /** 查询拍单商品列表 */
        getList() {
            this.loading = true;
          listStoreProduct(this.queryParams).then(response => {
                this.fsCourseProductList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                imgUrl: null,
                images: null,
                barCode: null,
                sort: null,
                stock: null,
                productContent: null,
                productPrice: null,
                productName: null,
                createTime: null,
                updateTime: null
            };
            this.resetForm("form");
            this.photoArr = [];
            this.imageArr = [];
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },






    }
};
</script>
