<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
            <el-form-item label="供应商状态" prop="status"> 
                <el-select v-model="queryParams.status" placeholder="请选择状态" style="width: 240px;">
                    <el-option label="启用" :value="1"></el-option>
                    <el-option label="禁用" :value="2"></el-option> 
                </el-select> 
            </el-form-item>  
            <el-form-item label="供应商名称" prop="supplierName">
                <el-input 
                    v-model="queryParams.supplierName"
                    placeholder="请输入供应商名称"
                    clearable maxlength="30"
                    style="width: 240px" 
                />
            </el-form-item> 
            <!-- <el-form-item label="供应类别" prop="categoryIdList"> 
                <el-cascader
                    v-model="queryParams.categoryIdList"
                    :options="treeTypeOptions"
                    :props="{  
                        multiple:true,
                        emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                        checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                        value:'id',label:'categoryName'
                    }"
                    placeholder="请选择供应类别" collapse-tags
                    clearable style="width: 240px;" 
                />
            </el-form-item>
            <el-form-item label="所属区域" prop="areaId">
                <el-cascader v-model="queryParams.areaId"
                    :options="treeOptions" :filterable="true" style="width: 240px;" :show-all-levels="false"
                    :props="{ 
                    emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                    checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                    value:'id',label:'label'
                    }" clearable>
                </el-cascader>
            </el-form-item> 
            <el-form-item label="主要联系人" prop="linkman">
                <el-input 
                    v-model="queryParams.linkman"
                    placeholder="请输入主要联系人"
                    clearable maxlength="30"
                    style="width: 240px" 
                />
            </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-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            >新增</el-button>
        </el-col>  
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="tableListData" height="800">
        <el-table-column label="序号" align="center" width="80" type="index" fixed="left">
            <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
        </el-table-column>
        <el-table-column label="供应商编号" align="center" prop="supplierNum" :show-overflow-tooltip="true" width="120"/>
        <el-table-column label="供应商名称" align="center" prop="supplierName" :show-overflow-tooltip="true" width="120" />
        <el-table-column label="所属区域" align="center" prop="areaName" :show-overflow-tooltip="true" width="120"/>
        <!-- <el-table-column label="供应商评分" align="center" prop="supplierScore" :show-overflow-tooltip="true" width="120"/> -->
        <el-table-column label="主要联系人" align="center" prop="linkman" :show-overflow-tooltip="true" width="120"/>
        <el-table-column label="用户手机号" align="center" prop="telephone" :show-overflow-tooltip="true"/>
        <el-table-column label="营业执照编号" align="center" prop="" :show-overflow-tooltip="true"/>
        <el-table-column label="食品经营许可证编号" align="center" prop="" :show-overflow-tooltip="true"/>
        <!-- <el-table-column label="供应类别" align="center" prop="" :show-overflow-tooltip="true" width="150"/> -->
        <el-table-column label="地址" align="center" prop="address" :show-overflow-tooltip="true"/>
        <el-table-column label="状态" align="center" prop="" :show-overflow-tooltip="true"/>
        <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
            <template slot-scope="scope"> 
            <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)" 
            >编辑</el-button>
            <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(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"
        />

        <!-- 添加或修改参数配置对话框 -->
        <el-dialog :title="title+'供应商'" :visible.sync="open" width="1000px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="140px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="供应商全称" prop="supplierName">
                            <el-input  v-model="form.supplierName" placeholder="请输入供应商全称" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="供应商简称" prop="supplierSimpleName">
                            <el-input  v-model="form.supplierSimpleName" placeholder="请输入供应商简称" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="供应商电话" prop="telephone">
                            <el-input  v-model="form.telephone" placeholder="请输入供应商电话" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司网站" prop="companyWeb">
                            <el-input  v-model="form.companyWeb" placeholder="请输入公司网站" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="供应商地址" prop="regionProvince">
                            <el-input  v-model="form.regionProvince" placeholder="请输入供应商地址" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="详细地址" prop="address">
                            <el-input  v-model="form.address" placeholder="请输入详细地址" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="开户行" prop="openingBank">
                            <el-input  v-model="form.openingBank" placeholder="请输入开户行" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="银行账号" prop="bankAccount">
                            <el-input  v-model="form.bankAccount" placeholder="请输入银行账号" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="税率" prop="taxRate">
                            <el-select v-model="form.taxRate" placeholder="请选择税率" style="width: 100%;">
                                <el-option label="3%" :value="1"></el-option>
                                <el-option label="6%" :value="2"></el-option> 
                                <el-option label="13%" :value="3"></el-option> 
                            </el-select>  
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="账期" prop="paymentDays">
                             <el-select v-model="form.paymentDays" placeholder="请选择账期" style="width: 100%;">
                                <el-option label="日" :value="1"></el-option>
                                <el-option label="周" :value="2"></el-option> 
                                <el-option label="月" :value="3"></el-option> 
                                <el-option label="两个月" :value="4"></el-option> 
                                <el-option label="季度" :value="5"></el-option> 
                                <el-option label="半年" :value="6"></el-option> 
                                <el-option label="年" :value="7"></el-option> 
                            </el-select>   
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="主要联系人" prop="linkman">
                            <el-input  v-model="form.linkman" placeholder="请输入主要联系人" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="主要联系人手机号" prop="linkmanNumber">
                            <el-input  v-model="form.linkmanNumber" placeholder="请输入主要联系人手机号" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="微信号" prop="wechat">
                            <el-input  v-model="form.wechat" placeholder="请输入微信号" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="邮箱" prop="email">
                            <el-input  v-model="form.email" placeholder="请输入邮箱" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="备用联系人" prop="standbyLinkman">
                            <el-input  v-model="form.standbyLinkman" placeholder="请输入备用联系人" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="备用联系人手机号" prop="standbyPhone">
                            <el-input  v-model="form.standbyPhone" placeholder="请输入备用联系人手机号" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="微信号" prop="standbyWechat">
                            <el-input  v-model="form.standbyWechat" placeholder="请输入微信号" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="邮箱" prop="standbyEmail">
                            <el-input  v-model="form.standbyEmail" placeholder="请输入邮箱" maxlength="30" clearable/>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="所属区域" prop="areaId">
                            <el-cascader v-model="form.areaId"
                                :options="treeOptions" :filterable="true" style="width: 100%;" :show-all-levels="false"
                                :props="{ 
                                emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                                checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                                value:'id',label:'label'
                                }" clearable>
                            </el-cascader>
                        </el-form-item> 
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="主要供应类别" prop="categoryIdList">
                            <el-cascader
                                v-model="form.categoryIdList"
                                :options="treeTypeOptions"
                                :props="{
                                    multiple:true,
                                    emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                                    checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                                    value:'id',label:'categoryName'
                                }"
                                collapse-tags
                                :show-all-levels="false"
                                placeholder="请选择供应类别"
                                clearable style="width: 100%;" 
                            />
                        </el-form-item> 
                    </el-col>



                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { systemAreaTreeApi } from "@/api/base/stall";
import { systemMaterialTreeApi } from "@/api/dish/material";

// import { getPageCanteenApi } from "@/api/base/canteen";

export default {
    name: "",
    dicts: [],
    data() {
        return {
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        //表格数据
        tableListData: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false, 
        // 查询参数
        queryParams: {
            pageNum: 1,
            pageSize: 10,    
            supplierName: undefined,
            areaId: undefined, 
            linkman: undefined, 
            status: undefined, 
            categoryIdList: []
        },
        treeTypeOptions:[],//类别树
        treeOptions:[],//区域树




        // 表单参数
        form: {},
        // 表单校验
        rules: {
          supplierName: [
            { required: true, message: "供应商名称不能为空", trigger: "blur" }
          ], 
          linkman: [
            { required: true, message: "主要联系人不能为空", trigger: "blur" }
          ],  
          linkmanNumber: [
            { required: true, message: "主要联系人手机号不能为空", trigger: "blur" }
          ],  
          categoryIdList: [
            { required: true, message: "主要供应类别不能为空", trigger: "change" }
          ]
        }
        };
    },
    created() { 
          this.getTypeTreeData();
          this.getTreeData();
        //   this.getList();

    },
    methods: {
        //类型树
        getTypeTreeData() {
            let param = {
                // categoryType:1,
            }
            systemMaterialTreeApi(param).then((response) => {
                this.treeTypeOptions = response.data;
            });
        },
        //区域树
        getTreeData() {
            systemAreaTreeApi({}).then((response) => {
                this.treeOptions = response.data;  
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() { 
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 查询列表 */
        getList() {
            this.loading = true;
            let param = {
                "pageNum": this.queryParams.pageNum, 
                "pageSize": this.queryParams.pageSize,
                "supplierName": this.queryParams.supplierName,  
                "categoryIdList": this.queryParams.categoryIdList,  
                "areaId": this.queryParams.areaId,  
                "linkman": this.queryParams.linkman,  
                "status": this.queryParams.status
            }
            // getPageCanteenApi(param).then(response => {
            //     this.tableListData = response.rows;
            //     this.total = Number(response.total);
                this.loading = false;
            // });
        },  
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "新增";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            // const dictId = row.dictId || this.ids
            // getType(dictId).then(response => {
                // this.form = response.data;
                this.open = true;
                this.title = "修改";
            // });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {};
            this.resetForm("form");
        }, 
        /** 提交按钮 */
        submitForm: function() {
            this.$refs["form"].validate(valid => {
            if (valid) {
                if (this.form.dictId != undefined) {
                    // updateType(this.form).then(response => {
                    //     this.$modal.msgSuccess("修改成功");
                    //     this.open = false;
                    //     this.getList();
                    // });
                } else {
                    // addType(this.form).then(response => {
                    //     this.$modal.msgSuccess("新增成功");
                    //     this.open = false;
                    //     this.getList();
                    // });
                }
            }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const dictIds = row.dictId || this.ids;
            this.$modal.confirm('是否确认删除数据项？').then(function() {
                // return delType(dictIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {});
        },
    }
};
</script>
