<script>
    layui.use(['table', 'form', 'element', 'layer','admin'], function () {
        let table = layui.table;
        let form = layui.form;
        let admin = layui.admin;
        let element = layui.element;
        table.render({
            elem: '#receiptList',
            url: '/api/receipt/getSupplierReceiptList',
            method: 'get',
            size: 'sm',
            cellMinWidth: 80,//全局定义常规单元格的最小宽度
            where: {
                supplier_id: getQueryVariable("supplier_id")
            },
            loading: true,
            first: true,//不显示首页
            last: false,//不显示尾页
            cols: [[
                {field: 'receipt_type', title: '收款账户所在地', align: 'center'},
                {field: 'bank_name', title: '银行名称', align: 'center'},
                {field: 'bank_adderss', title: '开户行', align: 'center'},
                {field: 'account_no', title: '账户号码', align: 'center'},
                {field: 'bank_code', title: '银行编号', align: 'center'},
                {field: 'branch_no', title: '分行编号', align: 'center'},
                {field: 'swift_code', title: '电汇号码', align: 'center'},
                {field: 'account_no', title: '账户号码', align: 'center'},
                {field: 'account_name', title: '账户名称', align: 'center'},
                {field: 'account_adderss', title: '账户地址', align: 'center'},
                {
                    field: 'certificate', title: '供应商银行信息凭证', align: 'center', templet: function (data) {
                        return "<img class='certificate_img' style='width: 70px;height: 60px' src='" + data.certificate + "'>";
                    }
                },
            ]],
            id: 'receiptList',
            page: {},
        });

        table.render({
            elem: '#list'
            , url: '/api/supplier/GetSupplierList'
            , method: 'post'
            , size: 'sm'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度
            , where: {
                source_type: 'all'
            }
            , loading: true
            , first: true //不显示首页
            , last: false //不显示尾页
            , cols: [[
                {type: 'radio'},
                {field: 'supplier_id', title: '供应商ID', align: 'center', width: 80},
                {
                    field: 'supplier_code', title: '供应商编码', align: 'center', width: 90, templet: function (data) {

                        return "<a ew-href='/supplier/SupplierDetail?view=iframe&supplier_id=" + data.supplier_id +
                            "' style='color: dodgerblue' ew-title='供应商详情'>" + data.supplier_code + "</a>"
                    }
                },
                {field: 'supplier_name', title: '供应商名称', align: 'center'},
                {field: 'supplier_group', title: '供应商性质', align: 'center', width: 120},
                {
                    field: 'stockup_type', title: '合作类型', align: 'center', width: 120, templet: function (data) {
                        return "<span title='" + data.stockup_type + "'>" + data.stockup_type + "</span>"
                    }
                },
                {
                    field: 'contact_num', title: '联系人', align: 'center', width: 80, templet: function (data) {
                        return "<a title='点击跳转查看联系人列表'>" + data.contact_num + "</a>"
                    }
                },

                {field: 'has_sku', title: 'SKU上传', align: 'center', width: 80},
                {
                    field: 'status_name', title: '状态', align: 'center', width: 80, templet: function (data) {
                        if (data.status === 3) {
                            return "<span style='color: red' title='" + data.reject_reason + "'>" + data.status_name + "</span>"
                        } else {
                            return data.status_name;
                        }
                    }
                },
                {field: 'channel_username', title: '采购员', align: 'center', width: 150},
                {field: 'purchase_username', title: '渠道开发员', align: 'center', width: 110},
                {field: 'create_name', title: '创建人', align: 'center', width: 80},
                {field: 'update_time', title: '最近修改时间', align: 'center', width: 150},
                {field: 'create_time', title: '创建时间', align: 'center', width: 150},
            ]]
            , id: 'SupplierList'
            , page: {}
        });

        form.on('submit(load)', function (data) {
            form.render();
            //执行重载
            table.reload('SupplierList', {
                page: {
                    curr: 1
                }
                , where: data.field
            });
            return false;
        });

        let supplierId = getQueryVariable('supplier_id')
        // 打开右侧面板
        layer.open({
            type: 2,
            content: '/log/SupplierLog?view=iframe&supplier_id=' + supplierId,
            area: ['400px', '85%'],
            shade: 0,
            offset: 'rb',
            title: '操作日志',
        });

        table.on('tool(list)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;
            let datas = {
                group_id: data.group_id,
                id: data.id
            };
            if (layEvent === 'edit') {
                window.location = '/supplier'
            } else if (layEvent === 'Del') {
                datas.status = 3;
                up_status(datas, '删除');
            }
        });
    });
</script>